Problems with Rotations

Problems with Rotations

Post by Michael St » Sat, 25 Dec 2004 07:25:08


am trying to convert Sun's SphereMotion into a program that works for me. I'm trying to build these ellipsoids that rotate when the user uses the arrow keys on the keyboard, however, I am having no luck.

My entire source can be found at www.astroh.org/SphereMotion.java but here are the relevant parts.


All my System.out commands are just for debugging purposes.


public void keyPressed( KeyEvent evt ){


switch(evt.getKeyCode())
{

case KeyEvent.VK_UP : System.out.println("Up");
xRot+=0.1;
xRott3d.rotX(xRot);
userRot.setTransform(xRott3d);
System.out.println(xRot);
System.out.println(xRott3d);
//System.out.println(userRot);
break;
case KeyEvent.VK_DOWN : System.out.println("Down");
xRot-=0.1;
xRott3d.rotX(xRot);
userRot.setTransform(xRott3d);
System.out.println(xRot);
break;
case KeyEvent.VK_LEFT : System.out.println("Left");
yRot+=0.1;
yRott3d.rotY(yRot);
userRot.setTransform(yRott3d);
System.out.println(yRot);
break;
case KeyEvent.VK_RIGHT: System.out.println("Right");
yRot-=0.1;
yRott3d.rotY(yRot);
userRot.setTransform(yRott3d);
System.out.println(yRot);
break;
case KeyEvent.VK_G : System.out.println("Clockwise");
zRot+=0.1;
zRott3d.rotZ(zRot);
userRot.setTransform(zRott3d);
System.out.println(zRot);
break;
case KeyEvent.VK_B : System.out.println("Counter-clockwise");
zRot-=0.1;
zRott3d.rotZ(zRot);
userRot.setTransform(zRott3d);
System.out.println(zRot);
break;
}

}
...
Canvas3D c = new Canvas3D(null);
c.addKeyListener( this );
...
BranchGroup sceneTot = new BranchGroup();
sceneTot.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
sceneTot.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
BranchGroup sceneRot = new BranchGroup();
sceneRot.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
sceneRot.setCapability(BranchGroup.ALLOW_CHILDREN_READ);

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