Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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 2996 times)
0 Members and 1 Guest are viewing this topic.
Offline 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?
Offline 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);
Offline 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!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
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

Offline 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. ;-)
Offline 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
Offline 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.
Offline 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
Offline Preston

Senior Devvie


Medals: 4



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

Thank you for this nice explanation.
Offline 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (60 views)
2014-12-09 22:41:13

BurntPizza (95 views)
2014-12-08 04:46:31

JscottyBieshaar (55 views)
2014-12-05 12:39:02

SHC (71 views)
2014-12-03 16:27:13

CopyableCougar4 (73 views)
2014-11-29 21:32:03

toopeicgaming1999 (133 views)
2014-11-26 15:22:04

toopeicgaming1999 (124 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!