First you have to make the TransformGroup that it is in allow itself to be written to like this...
TransformGroup myTG = new TransformGroup();
myTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
myTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
When ever you want to move the viewpoint around you have to make a new Transform3D object and apply it to the TransformGroup like this...
Transform3D tempT3D = new Transform3D();
myTG.getTransform(tempT3D);
tempT3D.lookAt(new Point3d(x1,y1,z1), new Point3d(x2,y2,z2), new Vector3d(0,1,0));
tempT3D.invert();
myTG.setTransform(tempT3D);
in your main program loop or what ever you are doing, you can change the values of those x y z variables
> the vector is weird, its
> the up direction, from what Ive seen its just set to
> 0,1,0.
not necessarily. What if you WANTED you're camera to see the scene as if it was upside down. Then you would set the vector to (0, -1, 0). And if you were walking on walls, you might set the up vector to (-1, 0, 0).
The main point here is that you are literally defining the position of the camera-man. You define WHERE he is and WHERE he is looking, and Java3D will determine WHAT direction he is looking in, based on those two points. Then you define which direction is up to indicate what the logical direction up is from the perspective of the camera man. That's pretty much all there is to it.
If you want to really know how the guts of the transform work, the project has been open sourced. It's easy to get access to the source code. Otherwise, if you still can't figure out exactly how to use it, don't. Write your own "lookAt" method, and you'll know EXACTLY how it works, because you wrote it, and it will give you more control. And in the attempt to write it, you just might understand exactly how it is that the provided method works.
- Adam