Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (683) Games in Android Showcase (196) games submitted by our members Games in WIP (751) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Jogl/OpenGL to Xith3d Newbie: translate & rota  (Read 4081 times) 0 Members and 1 Guest are viewing this topic.
Preston

Senior Devvie

Medals: 4

 « Posted 2003-11-09 11:36:42 »

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?
shochu

Junior Devvie

Java games rock!

 « Reply #1 - Posted 2003-11-09 12:53:30 »

I think what you want to do is just add the first transform to the branchgroup, then add the next transform to that transform.  Although I don't see why what you're doing wouldn't work.

 1  2  3  4  5  6  7  8  9  10  11  12  13 `            //Translate Transform            avatarTranslateGroup = new TransformGroup();            avatarTranslate = new Transform3D();            avatarTranslate.setTranslation(new Vector3f(0,0,0));            avatarTranslateGroup.setTransform(avatarTranslate);            objRoot.addChild(avatarTranslateGroup);                                    // Rotate a bit around X axis to see the transfrorm effect            Transform3D testRotateX = new Transform3D();            TransformGroup testRotateXGroup = new TransformGroup();            testRotateX.rotX(0.0f);            testRotateXGroup.setTransform(testRotateX);            avatarTranslateGroup.addChild(testRotateXGroup);`
Preston

Senior Devvie

Medals: 4

 « Reply #2 - Posted 2003-11-09 13:58:00 »

Quote
I think what you want to do is just add the first transform to the branchgroup, then add the next transform to that transform.

I see. For each model there's one TransformGroup which does the translation (for the model's world position) and to this group I add another TransformGroup which does the rotation. To this second group I add my Shap3D (leaf node).

Still two questions, please.
a) How I do I put my desired order of rotations (Y-X-Z) into the single transform3d.rotXYZ(..) method call?

b) What's with the VirtualUniverse's View object: it just contains one Transform3D object. Do I have to use the mul() method to combine my two desired transformations?
How the view.lookAt() works internally I'm not sure about.
 Games published by our own members! Check 'em out!
kevglass

« JGO Spiffy Duke »

Medals: 272
Projects: 25
Exp: 18 years

Coder, Trainee Pixel Artist, Game Reviewer

 « Reply #3 - Posted 2003-11-09 14:04:05 »

1)

Don't think you can do it all in one method call I'm afraid.

2)

Yep, you need to build a Transform3D with the appropriate view with mul().

Kev

Preston

Senior Devvie

Medals: 4

 « Reply #4 - Posted 2003-11-09 16:42:37 »

Ok thanks guys, the view now works fine like it should. :-)

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16 `Transform3D tTrans = new Transform3D();tTrans.setTranslation(cameraPosition);Transform3D tRotat = new Transform3D();tRotat.rotY(cameraAngle.y);tTrans.mul(tRotat);tRotat = new Transform3D();tRotat.rotX(cameraAngle.x);tTrans.mul(tRotat);tRotat = new Transform3D();tRotat.rotZ(cameraAngle.z);tTrans.mul(tRotat);universe_view.setTransform(tTrans);`

Similar I could do it for the model's. However with the models I'm unsure if it's faster to tie several Transform3D objects via mul together (like for the view, see above) or to use several TransformGroups for each rotation...

I'm still wondering if there isn't a shorter way to do all this, since now I need more lines of code with a high level API than with a low level one. ;-)
Yuri Vl. Gushchin

Senior Devvie

Speak Java!

 « Reply #5 - Posted 2003-11-09 19:19:46 »

Quote
However with the models I'm unsure if it's faster to tie several Transform3D objects via mul together (like for the view, see above) or to use several TransformGroups for each rotation...

Should be no visible difference

Quote
I'm still wondering if there isn't a shorter way to do all this, since now I need more lines of code with a high level API than with a low level one. ;-)

Hopefully someone will write utility class for that...

Yuri

Yuri Vl. Gushchin
JProof Group
Preston

Senior Devvie

Medals: 4

 « Reply #6 - Posted 2003-11-13 16:13:35 »

The camera moving through the universe and the model's transformation works like a charm.

However I noticed the following. With the View's Transform3D object it's enough to get it and modify it:
 1  2 `Transform3D transform = myView.getTransform();transform.set(viewposition)`

However with a 3d model's transformgroup you've to set the modified Transform3D object in the end.
 1  2  3 `Transform3D transform = myTransformgroup.getTransform();transform.set(modelposition)myTransformgroup.setTransform(transform);`

Well, it looks like the initial line "myTransformgroup.getTransform()" would give me a copy of the Transform3D object, not a reference (like it probably is the case with the view.getTransform above).

Is there any reason for this? Or am I calling the API in a wrong way? Unfortunately the Javadoc of so many (most?) Xith3d methods looks to be empty.
Yuri Vl. Gushchin

Senior Devvie

Speak Java!

 « Reply #7 - Posted 2003-11-13 16:42:33 »

Quote
looks like the initial line "myTransformgroup.getTransform()" would give me a copy of the Transform3D object, not a reference

No, getTransform() gives you a reference.

The difference is that when you set Transform3D to TransformGroup, some other calculations based on new transform also happen - for example, updating Local-To-VWorld transform, updating Group's bounds in World coordinates etc. These calculations needed to cache results of these calculations and avoid re-calculations on every frame rendered.

Every TransformGroup internally holds a copy of direct Local-to-VWorld coordinate transform, which allows to transform points and vectors in one step independently on the number of group nesting levels. This transform Renderer sends directly to OpenGL and hardware. Actual transform associated with the group is not used directly during rendering.

If you modify only content of the transform obtained with getTransform(), you never inform the engine that you changed it and engine has no chance to re-calculate cached direct transform values. That's why you when you change only transform contents it does not work, and when you call setTransform(...) afterwards it works.

In contrast, the view transform is becoming a part of projection transform and combined with View's projection transform at the beginning of the frame rendering process. That's why changes in View transform always have immediate effect.

Yuri

Yuri Vl. Gushchin
JProof Group
Preston

Senior Devvie

Medals: 4

 « Reply #8 - Posted 2003-11-14 05:06:24 »

Thank you for this nice explanation.
Yuri Vl. Gushchin

Senior Devvie

Speak Java!

 « Reply #9 - Posted 2003-11-14 09:30:36 »

Maybe it would be useful to put this topic in FAQ or to-Xith3D migration guide.

Yuri

Yuri Vl. Gushchin
JProof Group
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 orrenravid (227 views) 2016-07-16 03:57:23 theagentd (295 views) 2016-07-11 14:28:54 Hydroque (382 views) 2016-07-06 05:56:57 Hydroque (533 views) 2016-07-03 08:52:54 GrandCastle (403 views) 2016-07-01 09:13:47 GrandCastle (396 views) 2016-07-01 09:09:45 CopyableCougar4 (449 views) 2016-06-25 16:56:52 Hydroque (422 views) 2016-06-22 02:17:53 SwampChicken (387 views) 2016-06-20 13:22:57 SwampChicken (306 views) 2016-06-20 13:22:49
 Archive 30x Slyth2727 24x Brynn 23x EgonOlsen 22x orangepascal 22x TritonDreyja 21x orange451 20x DavidBVal 19x Spasi 18x LiquidNitrogen 11x Phased 11x Opiop 11x princec 11x Longor1996 10x ziozio 10x KaiHH 10x
 Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org