Skip to main content

question on Transform3D.lookAt(...) / Matrix Algebra

7 replies [Last post]
blueradiobutton
Offline
Joined: 2006-10-18

Hello,

I got managed to modify the view platform transform with lookAt(...) to look at a specific point in space. Now I would like to ensure that after the modification of the transform, one specific side condition is fulfilled: The coordinate system of the scene should still be (displayed) orthogonal to the (swing) frame. This is not always the case when using lookAt(...). Any ideas?

Cheers,
Florian

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pepe
Offline
Joined: 2003-06-10

coordinate system? displayed? Do you mean you have some sort of tri-axis, that indicate the world orientation? Is this related to the compass thread question?
Please, try to add image to posts. It is worth 100 words and questions, and helps answering faster. ( no time needed to wonder if i translated your question correctly... )

blueradiobutton
Offline
Joined: 2006-10-18

Before I used the lookAt() method, my code looked like this:

[code]
// obtain view platform transform and put translational component in vector
TransformGroup viewingPlatformTG = viewingPlatform.getViewPlatformTransform();
Transform3D viewPlatformTGTransform = new Transform3D();
viewingPlatformTG.getTransform(viewPlatformTGTransform);
Vector3d viewPlatformTranslation = new Vector3d();
viewPlatformTGTransform.get(viewPlatformTranslation);

//modify translational vector to move the view platform back
viewPlatformTranslation.z += 12;

//apply new translational vector to transform
viewPlatformTGTransform.setTranslation(viewPlatformTranslation);

viewingPlatformTG.setTransform(viewPlatformTGTransform);
[/code]

This code generated the following output:
http://home.in.tum.de/~schneidf/img/beforeLookAt.png

- (0,0,0) is in the middle of that first shape -

Now when I modify the view platform transforms position to go a bit up and a bit to the right and use lookAt() to make it look at the origin:

[code]
// obtain view platform transform and put translational component in vector
TransformGroup viewingPlatformTG = viewingPlatform.getViewPlatformTransform();
Transform3D viewPlatformTGTransform = new Transform3D();
viewingPlatformTG.getTransform(viewPlatformTGTransform);
Vector3d viewPlatformTranslation = new Vector3d();
viewPlatformTGTransform.get(viewPlatformTranslation);

//modify translational vector
viewPlatformTranslation.x += 4;
viewPlatformTranslation.y += 4;
viewPlatformTranslation.z += 12;

//apply new translational vector to transform
viewPlatformTGTransform.setTranslation(viewPlatformTranslation);

//now make the view platform transform look at the origin and apply it to the view platform
Point3d eyePosition = new Point3d(viewPlatformTranslation);
viewPlatformTGTransform.lookAt(eyePosition, new Point3d(0, 0,0), new Vector3d(0, 1, 0));
viewPlatformTGTransform.invert();
viewingPlatformTG.setTransform(viewPlatformTGTransform);
[/code]

...i get the following picture:
http://home.in.tum.de/~schneidf/img/afterLookAt.png

(the german text displayed on the shape is pure nonsense so don't be bothered by it ;-))

Thanks, pepe, for your support! If there is anything more I can do to clarify my question, let me know it!

pepe
Offline
Joined: 2003-06-10

I tried reading the German, but apart from understanding that was related to a tree, my skills from "gymnasium" are lost. :s
So, well, that German is non-sense to me anyway. :)

If you want your objects to always face the camera, you should use Billboard.
http://download.java.net/media/java3d/javadoc/1.5.0/javax/media/j3d/Bill...

blueradiobutton
Offline
Joined: 2006-10-18

I was so focused on not moving the objects around the virtual universe but only moving the view platform that I didn't think of using billboards.

But maybe you're right in that I should give it a try....

blueradiobutton
Offline
Joined: 2006-10-18

...so I gave it a try and got the following image:

http://home.in.tum.de/~schneidf/img/withBillboard.png

furthermore I adjusted the view platform a little more. And I put some shapes along the z-Axis to see the effect of the Billboard behavior more clearly.

pepe
Offline
Joined: 2003-06-10

As far as i know, you should get the correct result, with polygons approximatively facing the camera.

blueradiobutton
Offline
Joined: 2006-10-18

yeah... thanks for the tip :-)