**Rotating a shape**

i am trying to rotate a shape (which is at the origin) using the arrow keys for direction of rotation. But when it is run, my shape rotates incorrectly (as in it will make some major turns at certain angles) and i cant see how this is happening. Heres the sample code in my own Behaviour Class:

private TransformGroup targetTG; //the target TG that is changed

private Transform3D rotationH = new Transform3D(); //T3D for rotation in X axis

private Transform3D rotationV = new Transform3D(); //t3D for rot in Y

private double angleH = 0.0; //the rotation in X

private double angleV = 0.0; // the rotation in Y

public void processStimulus(Enumeration criteria) {

KeyEvent e = ((KeyEvent)(((WakeupOnAWTEvent)criteria.nextElement()).getAWTEvent() [0])); //gets the keycode of the button thats pressed

if( e.getKeyCode() == KeyEvent.VK_UP ) { //if UP arrow is pressed

angleH = (angleH + 0.1) % (2* Math.PI);

rotationH.rotX(angleH);

rotationH.mul(rotationV);

targetTG.setTransform(rotationH);

}

if( e.getKeyCode() == KeyEvent.VK_DOWN ) { //DOWN arrow

angleH = (angleH - 0.1) % (2* Math.PI);

rotationH.rotX(angleH);

rotationH.mul(rotationV);

targetTG.setTransform(rotationH);

}

if( e.getKeyCode() == KeyEvent.VK_LEFT ) { //LEFT arrow

angleV = (angleV + 0.1) % (2* Math.PI);

rotationV.rotY(angleV);

rotationV.mul(rotationH);

targetTG.setTransform(rotationV);

}

if( e.getKeyCode() == KeyEvent.VK_RIGHT ) { //RIGHT arrow

angleV = (angleV - 0.1) % (2* Math.PI);

rotationV.rotY(angleV);

rotationV.mul(rotationH);

targetTG.setTransform(rotationV);

}

this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));

}

whats going wrong?

[1827 byte] By [jimbob_ex2] at [2007-9-27 21:30:31]
# 1
if you havn't already done so - I suggest posting this is the J3D forum, as it has no direct link to game development.
Abuse at 2007-7-7 3:26:34 > top of Java-index,Other Topics,Java Game Development...
# 2
Err, Abuse, look at the forum thing:Java Game Development Use this forum to discuss Java gaming topics such as game design, algorithms, optimization, 3D workspace, Java 2D[TM], Java 3D[TM], and artificial intelligence.
Woogley at 2007-7-7 3:26:34 > top of Java-index,Other Topics,Java Game Development...
# 3
actually its for my game that i'm making. early stages yet but having this silly problem.I've already posted in the Java 3D forum but its dead over there.anyone know the problem?
jimbob_ex2 at 2007-7-7 3:26:34 > top of Java-index,Other Topics,Java Game Development...
# 4

// hope this helps this uses euler rotations

// its a utility method from from my zbuffer this assumes rotation

// around the point 0,0,0 x,y,z in 3 dimentions

public void RotatePoint(int rdegX,int rdegY,int rdegZ,int x,int y,int z){

if(rdegX > 360 || rdegX < 0){rdegX =0;}if(rdegY > 360 || rdegY < 0){rdegY =0;}if(rdegZ > 360 || rdegZ < 0){rdegZ =0;}

int xb = x;int xc =0;int yb = y;int yc =0;int zb = z;int zc =0;

double radX = (Math.PI * rdegX) / 180;

double radY = (Math.PI * rdegY) / 180;

double radZ = (Math.PI * rdegZ) / 180;

double sinX = Math.sin(radX);double cosX = Math.cos(radX);

double sinY = Math.sin(radY);double cosY = Math.cos(radY);

double sinZ = Math.sin(radZ);double cosZ = Math.cos(radZ);

// y rot

xb = (int)(z * sinY + x * cosY);

zb = (int)(z * cosY - x * sinY);

yb = y;

// x rot

yc = (int)(yb * cosX - zb * sinX);

zc = (int)(yb * sinX + zb * cosX);

xc = xb;

// z rot

xd = (int)(yc * sinZ + xc * cosZ);

yd = (int)(yc * cosZ - xc * sinZ);

zd = zc;

}

public int GetRotatedX(){return xd;}

public int GetRotatedY(){return yd;}

public int GetRotatedZ(){return zd;}

// light

lightxxx at 2007-7-7 3:26:34 > top of Java-index,Other Topics,Java Game Development...