Lesson #2b : Rotations


For this lesson, we will use the source code from the Translation lesson
Well now we know how to place a ColorCube at any location, so now we will
learn how to rotate a ColorCube about its center.

To rotate any object about its center, you should first move the object to the origin.
In the Translations example, the ColorCube is moved to x=0.8,y=1,z=-2 (following is code from prev tutorial)
	BranchGroup objRoot = new BranchGroup(); 

	TransformGroup cctg = new TransformGroup(); 	// a TransformGroup for the ColorCube called cctg

	ColorCube c = new ColorCube(0.5f);	// create a ColorCube object
    	cctg.addChild(c); 			// add ColorCube to cctg

	Transform3D cc3d = new Transform3D(); // a Transform3D allows a TransformGroup to move
	cc3d.setTranslation(new Vector3f (0.8f ,1.0f ,-2.0f )); // set translation to x=0.8, y=1.0, z= -2.0

	cctg.setTransform(cc3d); // set Transform for TransformGroup

	objRoot.addChild(cctg);
So after that code, we should shift the ColorCube back to the origin.
	cc3d.setTranslation(new Vector3f(0,0,0));
	cctg.setTransform(cc3d);
Now if we want to do a Y-Rotation of the ColorCube by 45 degrees:
	Transform3D someRotation = new Transform3D();
	someRotation.rotX(Math.PI);
Then apply the rotation to the current Transform3D, and translate the object back to (0.8,1.0,-2.0)
	cc3d.mul(someRotation);
	cc3d.setTranslation(new Vector3f (0.8f ,1.0f ,-2.0f ));
	cctg.setTransform(cc3d);

OriginalRotated

Source Code for this lesson: lesson02b.java