Using Java 3D's View Model as a Camera Model

So far, we have avoided trying to think of the view model as a camera. However, the camera model is a stalwart approach to thinking about 3D and is the basis of most other packages and language. To use the view model as a camera model, you must set the compatibility mode to true using the View object's setCompatibilityModeEnable() method.

SetCompatibilityModeEnable(true)

Once the application is in compatibility mode, it becomes possible to use the tried and true camera model. The reason to incorporate compatibility mode is to provide a link to applications that incorporate the camera model. Remember, these applications do considerable work to control the view transformation. Developers who had gone to such trouble might want to import their custom view computations directly into Java 3D without worrying about making the application take advantage of the Java 3D view system. A new application would not choose to go this route.

Several functions are useful in compatibility mode. Transform3D's lookAt() function creates the viewing matrix. The constructor is as follows:

lookAt(Point3d eye, Point3d center, Vector3d up)

After invoking this method on the Transform3D, remember to invert the Transform3D and then set the view platform's TransformGroup to the inverted Transform3D.

The following code snippet demonstrates this use:

. . .
Transform 3D tview = new Transform3D();
tview.lookAt(new Point3d(0., 0., Math.cos(angle),
             new Point3d(0., 0., 0.).
             new Vector3d(0., 1.0, 0.));
tview.invert();
vpTrans.setTransform(tview);

Alternatively, you can set the View's setVpcToEc() method directly with the result of lookAt(). That would work best if the view platform TransformGroup is identity.

Two other methods available in compatibility mode (not covered in this text) are frustum() and perspective(), which work just like the OpenGL equivalents and can be passed to View through the setLeftProjection() and setRightProjection() methods. Additionally compatibility methods allow the developer to set clipping planes and the field of view.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset