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
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.
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.
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.
Quote from: K24A3 on December 22, 2011, 04:51:00 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.
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.
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.
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 :)
Quote from: EgonOlsen on December 22, 2011, 05:12:32 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.
I'm confused. Does setScale(1f) change the size of the Object3D or does it just say "consider the scale x to be 1?"
It resets the scaling to normal, i.e. no scaling will be applied.
I want making a object scaling when it's moving, I use code
like following, but it seems scale not working.
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 ?
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.
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)
Are these objects billboards?
no. but for now, they face to the screen on the same side.
Well, interpolate(...) calls othonormalize() to ensure that it's a orthonormal matrix. And in this process, the matrix gets normalized...and so your scaling is gone. But as said: This is a overcomplicated way to change a scaling over time. Just interpolate the scaling value itself instead of the matrix and all is fine.
I've lost a lot of time because of this scale problem this week... Maybe you could make this post sticky or write the issue on the setScale()'s javadoc... I'm sure this would help a lot :)
I agree...i'll add it.