Transformgroup features:
1. place any form, light, or sound in a 3D space to this object.
2. This object is used to define a local coordinate system that can be moved, rotated, or zoomed in and out through settings.
3. This object has two flags, of whichAllow_transform_writeUsed to write the latest data (that is, the data after the coordinate change to the data structure), allowingProgramModify the scenario on the Node during running.Allow_transform_readIt is used to read the data before the location change for judgment and processing. Allows the program to read the scenario on the Node during running.
4. SetAllow_transform_writeTo make the coordinate system motion (this is used when you do not want to read the value at this time, such as reading the moving distance, selecting the rotation angle, and proportional scaling equivalent. To read these values, useAllow_transform_read)
5. To move, rotate, or zoom in the specified local coordinate system through the mouse in the program, you must setAllow_transform_write andAllow_transform_read.
6.JavaThe virtual opportunity creates a separate thread (or process) for the two flags to receive feedback from the scenario. In the control scenario, unnecessary overhead is avoided.
Transform3d features
1. represents the Coordinate Transformation of the specified coordinate, such as rotation, zoom-in, zoom-out, and translation.
2. quat4f (X, Y, Z, W) parameter Introduction
X: X coordinate Y: Y coordinate z: zcoordinate W: angle of rotation of an object, for example:
Quat4f (0.0f, 1.0f, 0.0f, 1.57f) indicates that an object rotates 90 degrees around the Y axis. If the Y axis is only larger, the rotation amplitude is greater.
When the value of X, Y, and Z is not 0, the value size indicates the rotation amplitude. The larger the value, the larger the rotation amplitude in this direction.
3. transform3d has four methods: rotx (), roty (), Rotz (), and settranslation (). When these four methods are used together, only the last one works. To enable rotx, roty, and Rotz to be displayed, you can use setrotation (New quat4 () instead of setrotation () in setrotation (New quat4 ()) both before and after can show the effect.
Example:
ImportJava. Applet. Applet;
ImportJava. AWT. borderlayout;
ImportJavax. Media. j3d.*;
ImportJavax. vecmath.*;
ImportCom. Sun. j3d. utils. Applet. Mainframe;
ImportCom. Sun. j3d. utils. behaviors. Mouse.*;
ImportCom. Sun. j3d. utils. geometry.*;
ImportCom. Sun. j3d. utils. Universe. simpleuniverse;
Public Class Rotate Extends Applet {
Public Branchgroup createscenegraphics ()
{
Branchgroup objroot = New Branchgroup ();
Boundingsphere Bounds = New Boundingsphere ( New Point3d ( 0.0 , 0.0 , 0.0 ), 100 );
Color3f bgcolor = New Color3f ( 1.0f , 1.0f , 1.0f );
Background BG = New Background (bgcolor );
BG. setapplicationbounds (bounds );
Objroot. addchild (BG );
Transform3d t = New Transform3d ();
// T. settranslation (New vector3f (0.8f, 0.6f, 0.0f ));
// T. rotx (0.78 );
// T. roty (0.78 );
// T. Rotz (0.78 );
T. setrotation ( New Quat4f ( 0.0f , 1.0f , 0.0f , 1.57f ));
T. settranslation ( New Vector3f ( 0.0f , 0.0f , 0.0f ));
Transformgroup Trans = New Transformgroup (t );
Trans. setcapability (transformgroup. allow_transform_write );
Trans. addchild ( New Colorcube ( 0.2 ));
Objroot. addchild (trans );
Return Objroot;
}
Public Rotate ()
{
Setlayout ( New Borderlayout ());
Canvas3d C = New Canvas3d ( Null );
Add ( " Center " , C );
Branchgroup scene = Createscenegraphics ();
Simpleuniverse u = New Simpleuniverse (C );
U. getviewingplatform (). setnominalviewingtransform ();
U. addbranchgraph (scene );
}
Public Static VoidMain (string [] ARGs)
{
NewMainframe (NewRotate (),400,300);
}
}
The figure is as follows: