Main Menu

Group Scale

Started by AGP, September 24, 2014, 05:41:20 PM

Previous topic - Next topic

AGP

Do you know what would most definitely be useful? Group stuff. For instance, a World.groupAll() method followed by a World.getGroup(...).scale(10f). Up until this latest build of jpct there was no real way of knowing the scale of your scene. I'm finding too many scenes are either too small or too large for their own good (shadows, for instance, get hurt from this). Anyway, it's just a suggestion.

EgonOlsen

I'm not sure what this is supposed to do...you can easily apply a scale on all objects of a world in maybe three lines of code. It this supposed to do anything different?

AGP

Yes, it scales them in place. As it is, if I were to increase both a set and a character, one would go right through the other. But not just scale, either, the title of the thread should have been "Group Stuff." Scaling, rotating, translating.

EgonOlsen

I don't see the point. You can already build group by assigning objects to a common parent. Adding something similar to World is just replicating the same thing with different means.

AGP

Children don't get scaled along with their parents, and these groups would hold cameras, lights, and such. But alright.

EgonOlsen

That's would somehow make jPCT a scene graph engine through the back door. jPCT isn't meant to be a scene graph engine on purpose. If you want a container for cameras, lights and objects that belong to a virtual group, just use a World. Nothing prevents you from rendering multiple worlds into a scene. If you want to group objects in any other way, use parent/child relations. The only thing that remains is the scale. But if you really want this, just do something like


import java.util.Enumeration;

import com.threed.jpct.Object3D;
import com.threed.jpct.World;

public class ScalableWorld extends World {
public void scale(float value) {
for (@SuppressWarnings("unchecked")
Enumeration<Object3D> enny=this.getObjects(); enny.hasMoreElements();) {
enny.nextElement().setScale(value);
}
}
}


AGP

But again, won't that make things go through each other when scaling up and grow apart from each other when scaling down?

EgonOlsen

I think that i finally get what you actually meant... ;) Well, in that case, this should do it, at least for Object3Ds:


import java.util.Enumeration;

import com.threed.jpct.Object3D;
import com.threed.jpct.World;

public class ScalableWorld extends World {
public void scale(float value) {
for (@SuppressWarnings("unchecked")
Enumeration<Object3D> enny=this.getObjects(); enny.hasMoreElements();) {
                        Object3D obj=enny.nextElement();
obj.setScale(value);
                        SimpleVector t=obj.getTranslation();
                        obj.clearTranslation();
                        t.scalarMul(value);
                        obj.translate(t);
}
}
}

AGP

That makes sense, thank you.