Author Topic: ClearRotation resets the scale  (Read 3123 times)

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
ClearRotation resets the scale
« on: December 22, 2011, 04:34:05 pm »
Is Object3D.clearRotation() supposed to reset the scaling of the object?

If yes, perhaps we can add a note to the docs mentioning that it will clear the scaling as well.
If not, it may be a bug because scaling gets reset when calling clearRotation() even after I build the object3D before cloning it. I believe the original object3D is also affected so build->clone is irrelevant.

This was driving me nuts for an hour until I traced it to clearRotation()  :P
« Last Edit: December 22, 2011, 04:39:24 pm by K24A3 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ClearRotation resets the scale
« Reply #1 on: December 22, 2011, 04:44:40 pm »
Well...i'm sorry. Yes, it resets the scale because the scale is part of the rotation matrix in jPCT (stupid design decision from ages ago, but not possible to change it now without breaking things, so....). In fact, clearRotation() should also call setScale(1) or otherwise, subsequent calls to setScale() won't work as expected. I'll fix this and enhance the docs. For now, if you use clearRotation() on a scaled object, make sure that you call setScale(1); before doing so.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: ClearRotation resets the scale
« Reply #2 on: December 22, 2011, 04:51:00 pm »
Ok thanks for that. Calling setScale after clearRotation solves the problem

Another issue I ran into is that setScale throws an exception when a negative value or 0 is parsed. Perhaps jPCT could ignore these invalid values and simply set the scale to the lowest possible scale.

The problem being I am scaling objects to zero to 'hide' it and constantly running into exceptions.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ClearRotation resets the scale
« Reply #3 on: December 22, 2011, 05:06:18 pm »
You can't set a scale of 0 as this leads to an invalid rotation matrix. And even if it wouldn't, abusing this to make something invisible isn't a good idea. Use setVisibility(<boolean>) instead.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ClearRotation resets the scale
« Reply #4 on: December 22, 2011, 05:12:32 pm »
Ok thanks for that. Calling setScale after clearRotation solves the problem
Remember to set it to 1 BEFORE calling clearRotation(). Or otherwise, setScale(x) won't scale by x but by former_scale/x.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: ClearRotation resets the scale
« Reply #5 on: December 22, 2011, 05:17:35 pm »
ok I'll make sure I do that. (edit: I thought setScale was absolute? whereas .scale() was incremental?)

In my own functions I prefer to implement internal fixes/workarounds for invalid parameters rather than throw an exception to keep my functions solid/reliable (in this case, default to 0.001f as the scale if invalid) , but I can see how throwing an exception can help with debugging for others in general.
« Last Edit: December 22, 2011, 05:19:16 pm by K24A3 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ClearRotation resets the scale
« Reply #6 on: December 22, 2011, 05:23:26 pm »
Yes, setScale() is absolute...but internally, it relies on scale() and this relies on the rotation matrix. It's a mess, i know that and i'm sorry about it... ;) I was young and needed the...scale...

About the exception: I'm not an exception evangelist, but in this case, i think that scaling to 0 can't be what one wants. If you still want to see the object, it's wrong and if you don't want to see it, it's wrong either, because you'll still process it. If you do this for 1000 objects, they all will be rendered...just scaled to 0. That doesn't make any sense IMHO and that's because i see it as an error.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: ClearRotation resets the scale
« Reply #7 on: December 22, 2011, 05:32:52 pm »
Ok no worries I'll implement the workarounds as suggested.

Usually I don't hide object by setting the scale very low but in my current situation I scale a few objects to zero moments before relocating the object somewhere else out of view. I can understand negative scale values but the 0 scale is where it got me. I now know for future reference :)


Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: ClearRotation resets the scale
« Reply #8 on: December 22, 2011, 05:50:31 pm »
Remember to set it to 1 BEFORE calling clearRotation(). Or otherwise, setScale(x) won't scale by x but by former_scale/x.

..and setting the scale to 1f beforehand fixed the other issue I ran into.
All good now, cheers.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: ClearRotation resets the scale
« Reply #9 on: December 22, 2011, 06:58:44 pm »
I'm confused. Does setScale(1f) change the size of the Object3D or does it just say "consider the scale x to be 1?"

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ClearRotation resets the scale
« Reply #10 on: December 22, 2011, 07:12:34 pm »
It resets the scaling to normal, i.e. no scaling will be applied.

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: ClearRotation resets the scale
« Reply #11 on: December 26, 2011, 06:37:49 am »
I want making a object scaling when it's moving, I use code
like following, but it seems scale not working.
Code: [Select]
Matrix posMatrix1 = ..;                                  // source position
Matrix posMatrix2 = ..;                                  // target position
Object3D dummyParent Object3D.createDummyObj();
Object3D son = ... ;
dummyParent.addChild(son);
posMatrix1 = dummyParent.getRotationMatrix().cloneMatrix();

...  do some move and rotate


dummyParent.setScale(2.0f);                    // ======================  scale
posMatrix2 = dummyParent.getRotationMatrix().cloneMatrix();  // will get scale factor in here ?


Matrix m = new Matrix();
m.interpolate(posMatrix1, posMatrix2, delta);
dummyParent.setRotationMatrix(m.cloneMatrix()); // ==============  will scale factor affect the son Object ?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ClearRotation resets the scale
« Reply #12 on: December 26, 2011, 08:42:07 pm »
Wow...i've never seen such a complicated way to do a linear scaling over time... ;) Why don't you simply increase the value of setScale() over time? Apart from that, your code makes me believe (judging by the names of your variables) that you expect something to move when executing it!? This isn't the case, because you are changing the rotation matrix only but not the translation itself.

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: ClearRotation resets the scale
« Reply #13 on: December 27, 2011, 02:54:37 am »
Actually, I am working on a UI with 3D icon.
said there has three position A,B,C  when the 3D icon move from A to B, it will scale up, and
when it move from B to C , it will scale down, now I am doing moving  by interpolating the matrix between
A,B,C . the moving works fine, and I want scale work this way too.(by interpolate the rotation matrix)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ClearRotation resets the scale
« Reply #14 on: December 27, 2011, 08:09:56 pm »
Are these objects billboards?