Currently I'm moving from a low level API (OpenGL via Jogl) to a high level API (Xith3d). :-) Now some maths don't do what I expect them to do...
In Ogl I've first translated a model by its world position and then rotated it by the the three axes (in an order of "importance") to match for example Lightwave's Head (Y), Pitch (X) and Bend (Z) point of view.
Say mPosition is the model's world position and mAngle is its local rotation then I just did:
1 2 3 4
| ogl.glTranslated(mPosition.x, mPosition.y, mPosition.z); ogl.glRotated(mAngle.y, 0.0, 1.0, 0.0); ogl.glRotated(mAngle.x, 1.0, 0.0, 0.0); ogl.glRotated(mAngle.z, 0.0, 0.0, 1.0); |
Worked perfectly. In Xith3d I tried something similar to the Transform3D object of a TransformGroup which contains my Shape3d model as Leaf, however it doesn't rotate as it should. The translation is ok. I combined both transformations: the translation and the rotation, like for example:
1 2 3 4 5 6 7 8
| Transform3D tTrans = new Transform3D(); tTrans.setTranslation(mPosition_point3f);
Transform3D tRotat = new Transform3D(); tRotat.rotXYZ(mAngle_tuple3f);
tTrans.mul(tRotat); mModelsTransformgroup.setTransform(tTrans); |
Where's my mistake please?
The same problem I experience when I want to move/rotate the view (camera) in the above manner, ie without using lookAt(). In OpenGL I simulated the camera by issuing a translation and rotation before any model's been rendered, and in reverse order (ie to move/rotate the universe). Reversed meant rotate first, then translate, and always by the negated values of the camera's position and orientation.
1 2 3 4
| ogl.glRotated(mCameraAngle.z, 0, 0, -1); ogl.glRotated(mCameraAngle.x, -1, 0, 0); ogl.glRotated(mCameraAngle.y, 0, -1, 0); ogl.glTranslated(-mCameraPosition.x, -mCameraPosition.y, -mCameraPosition.z); |
How would I do this in Xith3d/Java3d, when I use the View's Transform3D object?
Thanks.
Btw is such a topic something we could add to the Xith3d Tutorial - or is this too basic?