Author Topic: Relative scaling  (Read 3598 times)

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Relative scaling
« on: May 11, 2008, 10:22:55 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Relative scaling
« Reply #1 on: May 11, 2008, 10:55:01 am »
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?
« Last Edit: May 11, 2008, 11:29:19 am by EgonOlsen »

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Relative scaling
« Reply #2 on: May 11, 2008, 11:25:48 am »
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?

Quote
Why 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);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Relative scaling
« Reply #3 on: May 11, 2008, 11:34:33 am »
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.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Relative scaling
« Reply #4 on: May 11, 2008, 11:57:42 am »
So you're saying that the API has no relative scale feature, and this must be done by vertex management?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Relative scaling
« Reply #5 on: May 11, 2008, 02:42:46 pm »
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.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Relative scaling
« Reply #6 on: May 11, 2008, 03:46:46 pm »
...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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Relative scaling
« Reply #7 on: May 11, 2008, 06:49:47 pm »
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.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Relative scaling
« Reply #8 on: May 12, 2008, 10:27:01 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Relative scaling
« Reply #9 on: May 12, 2008, 10:59:57 am »
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):