< Zurück | Inhalt | Weiter >

From MixedTest.java


//Create a TransformGroup and attach a RotationInterpolator to spin

//the ColorCube about its vertical axis TransformGroup objTrans = new TransformGroup();

objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);


BoundingSphere bounds =

new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);


Transform3D yAxis = new Transform3D();

Alpha rotationAlpha = new Alpha(−1, Alpha.INCREASING_ENABLE,

0, 0,

4000, 0, 0,

0, 0, 0);


RotationInterpolator rotator = new RotationInterpolator( rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI*2.0f);

rotator.setSchedulingBounds(bounds);


//add the RotationInterpolator to its parent TransformGroup objTrans.addChild(rotator);


//create the ColorCube and add to its parent TransformGroup objTrans.addChild( new ColorCube() );>


image


Comparing figures 4.18 and 4.19, one might wonder why the grid of points (rendered in immediate mode) has become smaller. The answer is that the MixedTest example introduces a TransformGroup on the view side of the scenegraph. This TransformGroup shifts the position of the viewer backward relative to the scene so that the ColorCube is visible. The ImmediateTest example also sets a similar backward translation in the preRender method, before setting the Model matrix within the renderField method. The net effect

is that the immediate mode PointArray has been translated backward twice relative to the viewer—once by the transformation on the View (retained) side of the scenegraph, and once explicitly in the immediate mode code. To render the immediate mode points irrespective of any transformation already applied by virtue of the view side of the scenegraph, one would have to calculate the view transformation, invert it, and multiply it by the desired Model transformation, all before applying it to the GraphicsContext3D. By inverting the view transformation, the effect of the transformation will be canceled.