Relative scaling

Started by ErDetEnAnd?, May 11, 2008, 10:22:55 AM

Previous topic - Next topic

ErDetEnAnd?

Hello.

Using Object3D.scale(float) to scale the object causing a tranformation to the object in world space. I though this method was related to object space? Why isn't a matrix needed to scale (transform) the object?

My other approach did have same result:
SimpleVector origin = o3d.getOrigin();
o3d.setScale(0.95f);
o3d.setTranslationMatrix(new Matrix());
o3d.translate(origin);

Truely something I've got wrong here. Please help.

EgonOlsen

#1
I don't really get your problem!? Scaling is being applied to the rotation matrix, not to the translation matrix and it happens (as you've already noticed) in world space. And your problem is now...what?

ErDetEnAnd?

According to your doc, Object3D has two scaling methods, namely: scale and setScale which both takes a float argument. setScale(f) clearly points that its applies it changes in the world, while scale(f) seems only to apply on the object. Is this correct?

QuoteWhy isn't a matrix needed to scale (transform) the object?
- Neither have I a transformation nor a rotation matrix assigned to the object, which scales anyway. Have I got something wrong; dont an object3d need a matrix to make any transformation/rotation calculations?

Absolute scaling with setScale(f) is sufficiently since I just could move the object back to gets original origin (and get the desired relative scaled object):

SimpleVector origin = o3d.getOrigin();
o3d.setScale(0.95f);
o3d.setTranslationMatrix(new Matrix());
o3d.setOrigin(origin);

EgonOlsen

scale and setScale do exactly the same thing in the same space except that setScale resets the scaling to 1 before applying the new scale. You can think of setScale as a combination of scale(1/formerValue); scale(newValue);
You are right that scaling is done by using a transformation matrix, but this matrix is created internally. You can't feed it directly into jPCT, which is why it doesn't support non-uniform scaling (unless you start fiddling around with the rotation matrix yourself...we have some threads about this in the forum).

scale() was first. After i realized that it might have been better to use absolute values for scaling, i've added setScale(). That's why there are two methods for a very similar operation.

ErDetEnAnd?

So you're saying that the API has no relative scale feature, and this must be done by vertex management?

EgonOlsen

scale() is relative, setScale() is absolute. But i'm not sure if we are talking about the same thing here, when we say "relative". With relative, i mean that the values accumulate, so that scale(2); scale(4); results in a scale of 8. With setScale, it would be 4.

ErDetEnAnd?

...which is cumulative. By relative scaling I mean that the new vertices are calculated using the objects vertices only. By absolute scaling you take the objects world vertices into account; scaling the object will move it according to world origin. Down scale an object e.g. 0.9x by absolute means, the object will resize but also move 10% closer to world origin. I want the object to resize while its origin vertex stay unchanged in the world.

EgonOlsen

I see...i guess we were talking of different things then... ;D There is no such kind of scaling, i'm afraid. You'll have to take care of the proper object positioning yourself in this case.

ErDetEnAnd?

If object A and B have the same size but different world origin positions, and should be scaled by factor 0,5, the following would be the case in jPCT (if I got you right):



The gray objects is the scale result. Because the scaling is done on the object's world vertices, A' and B' dont have the same size anymore. Moving B to A, make the scaling and move B' back to it's original position solves the problem, but only while the two objects have the same size.

I find it strange that relative scaling hasn't been requested earlier, but one should not implement something thats not requested. Would you take this feature into considerations, or does it not easily fit into the engine?

EgonOlsen

No, the resulting objects still have the same size after the scaling. The scaling is part of the world transformation, but that doesn't mean that world position affects it. Actually, the result in your example would be this (the red ones):