Rotation with/without shifting axes

I’m just learing Java3D and for the first project I want to make the BlockOut game. The problem I have is about rotation.

Rotating the visual representation of active block is done by six keys, two per axis, one adds, one subtracts 90 degrees. If I do rotation with three Transform3Ds(each for one axis) multiplied together, the effect is not ok.
I understand the reason: this way of rotation shifts axes. For example, rotating something round x axis for 90 degree, shifts y axis to the position of z axis. The y rotation is then done around the original z axis, not original y axis as wanted. And so on for z rotation. But I want the pressing of certain axis keyboars keys to rotate the visual block in that axis exactly.

Now, I also know how to solve this problem mathematicaly for each point, I’ve done it for the data representation which is 3-dimensional array. Simplified version:
(x,y,z) - 3Dpoint
//x rotation for 90deg
(y,z) = rotate point (y,z) round x axis(2d rotation) for 90deg
and repeat this for other two axis.
Notice that the result of x rotation is used in y rot and this one in z rotation.

Now the real question is: how do I do this last type of rotation with Transform3D(thati need to set it to TransformGroup)?

I don’t know if I understand your problem correctly as I don’t know the Blockout game, and I’m a newbie too, but it should help you if you use one single Transform3D centrally and six in the Behaviors (for every direction). Your processStimulus should then get the central t3d, multiply it with the local and store it back into the TransformGroup.

I modified Sun’s HelloUniverse so that it should be the way you want. I can’t paste everything because this MessageBox has a max amount of chars:

// the lines in createSceneGraph
Transform3D before = new Transform3D(); // <----------------- THE ROTATION BEFORE
before.rotX(0.5);
TransformGroup objTrans = new TransformGroup(before);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
RotBehavior behave = new RotBehavior(objTrans);
behave.setSchedulingBounds(bounds);
objRoot.addChild(behave);
objRoot.addChild(objTrans);

// to be continued …

// 2nd part: the Behavior class

private class RotBehavior extends Behavior{
TransformGroup tg = null;
Transform3D t3d = null;
Transform3D rot = null;

        RotBehavior(TransformGroup tg){
              this.tg = tg;
              
              t3d = new Transform3D();
              rot = new Transform3D();
              rot.rotY(0.05);
        }
        
        public void initialize(){
              this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
        }
        
        public void processStimulus(Enumeration criteria){
              System.out.println("Accessing processStimulus...");
              this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
              
              tg.getTransform(t3d);
              t3d.mul(rot);
              tg.setTransform(t3d);                  
        }
        
        
  }

Obviously I didn’t explain the question good enough.

Everything that was said about game and keys was just hepling me explaining things.

One thing I should tell is that rotation about each of the axis is always 90deg, and instant, there is no animation.

I get my game mechanics, I just dont get java3D or mathematics.

What I was asking is this how to create a Transform3D instance that would do the rotation about x axis for (xChange * Math.PI/2), about y axis for (yChange * Math.PI/2) and about z axis for (zChange * Math.PI/2), where xChange, yChange, zChange is one of {0, 1, 2, 3}.
But WITHOUT THE EFFECT OF ROTATION OF COORDINANTE SYSTEM!!!
So creating three thransforms and multiplying them does not go, because first transform, lets say arround x for alpha degrees rotates coordinate system arround x (for alpha degrees). So if I first apply rotation about x for 90 degrees, coordinate system is rotated for 90 degrees. This means, that y axis was rotated to original z axis. When I apply rotation about y axis, the rotaion really occurs round original z axis. And that is what I don’t want, I want the y rotaion to happend round original(not x-rotated) y axis. Same for z transformation. So when the user presses x+90deg key and then y+ 90deg key, the y rotation happens round y axis, not z.

As I see it this should really be the common problem for any angles rotaion(not just k*90deg).

i think what you’re trying doesn’t work as you would like simply because you don’t apply the transform at the right place! :stuck_out_tongue:
what you want is always to rotate things compared to the root axis, and not to the relative axis, so change them at the root! :wink:

Use only one TG (with read/write capability bits) for all the rotations, then:
myTG.getTransform(transform);
rot.rotX(…); // or rotY, or rotZ
transform.mul(rot, transform); //or the opposite, i never remember!
myTG.setTransform(transform);

Finally got time for this…

I solved my problem. :smiley:

Thank you misterX!

… and thank all others for replies, too!

Time is precious nowadays, I know!