local rotation

Hi,

Here’s the link: http://www.kingsware.de/j3d/gamerot.zip

I have a new problem. I update only the x- and y-rotation of my ship every Frame. It sets the rotation by looking at the Mouse position. But my ship rotates over all axis x,y AND z, but not at the same time!!! It looks like Java3D decides, which are the x and y axis from the viewplatforms point of view!! Is that right?

How can I set a “local”-Rotation, which rotates the local axis not the “viewed” one???

I had the same problem, only the other way around, with Translation. The ship moved on the global axis instead of flying, depending on the ships current rotation.

I fixed this problem like this(not exactly):


  //Position
  Vector3f position = new Vector3f(x,y,z);
  Transform3D posTrans = new Transform3D();
 
  //Rotation
  Transform3D rotX3d = new Transform3D();
  Transform3D rotY3d = new Transform3D();
  Transform3D rotXY3d = new Transform3D();

  //change the XY-Rotation (with MouseAngle)
  rotX3d.rotX(xAngle);
  rotY3d.rotY(yAngle);
  
  rotXY3d.mul(rotX3d, rotY3d);

  //The solution! now the positiontranslation is local!
  rotXY3d.transform(position);

  posTrans.set(position);

is there any possibility to do this with rotation. There must be the possibility to rotate over the local axis!

Greets and thanks,
Juan

Uuh I’ve read something about the following function:

view.getLocalToVWorld(Transform3D trans)

is this a possibility? Anyone fixed this problem, yet

Hi
Create a transform3D that contains the transform you wish to perform, then multiply your ships current transform3d by the new one, that will perform the transform around the ships current position, rather than around the world axes.

Thank you endolf! This is the first time I got the problem solved, before you answered.

My only problem is, that the View doesn’t follow properly! The view should be behind the Ship even when it is rotating, and look at it. I tried like in the following code:


  vpNewPosition.x = shipPosition.x + vpSTARTX; //vpSTARTX = 0.0f
  vpNewPosition.y = shipPosition.y + vpSTARTY; //vpSTARTY = 50.0f
  vpNewPosition.z = shipPosition.z + vpSTARTZ; //vpSTARTZ = 130.0f  
  
  shipRotXY3d.transform(vpNewPosition); 
    
  vpTrans3d.lookAt(vpNewPosition, shipPosition, vUp);
  
  vpTrans3d.invert();

  vpTrans.setTransform(vpTrans3d);

Greets,
Juan

Your best bet would be to copy the ship transform 3d, translate it by how ever much behind/above you want the view to be and use that as the view position.

That’s what I do! But you forget, that behind is not the same like behind, when the ship rotates ;)!

Because there is a rotational component, too!

Greets,
Juan

Hi
multiply the copy by a transform with the local translation (130 and 50 if I read another post right), the multiplication will mean it’s relative to the local axis specified in the copy.

To endolf:

multiplying the Transforms has the ugly sideeffect, that when multyplying translation with rotation the ship rotation flickers, the other way around the translation flickers. I don’t know why, but using two transformgroups with seperated Transforms solves this problem. So I have a translation TG with a rotation TG as child and the Ship BG as a child of rotation TG!

This works!

Hi
I have no idea why you get teh flicker. My post was in relation to gettign the transform for the view rather than the ship, but as you have two transforms it’s harder. You could of course copy the ship transforms into two new transform groups, then place the view translation in another transform group under that. If I recal to then set that in the virtual universe you need to add them to a multitransformgroup or something like that.

HTH

Endolf

[quote]Hi
Create a transform3D that contains the transform you wish to perform, then multiply your ships current transform3d by the new one, that will perform the transform around the ships current position, rather than around the world axes.
[/quote]
The translational component is local then, but the rotational component not!


   //Change the position
  positionChange.x = //Change of x position (local)
  positionChange.y = //Change of y position (local)
  positionChange.z = //Change of z position (local)

  //Change the x and y rotation by mouse position
  rotX3d.setRotation(matrixForXrot);
  rotY3d.setRotation(matrixForYrot);
  rotZ3d.setRotation(matrixForZrot); //0
  rotXY3d.mul(rotX3d, rotY3d);
  rotXYZ3d.mul(rotXY3d, rotZ3d);

  rotXYZ3d.mul(oldRotXYZ3d);
  oldRotXYZ3d = new Transform3D(rotXYZ3d);

  rotXYZ3d.transform(positionChange);

  newPosition.x = oldPosition.x + positionChange.x;
  newPosition.y = oldPosition.y + positionChange.y;
  newPosition.z = oldPosition.z + positionChange.z;

  rotXYZ3d.setTranslation(newPosition);

  return rotXYZ3d;

this looks like this:

http://www.kingsware.de/j3d/shiprot.zip

When the ship is oriented to the front(like in the beginning), the ship rotates up and down, when you move your mouse up and down.
BUT when the ship is oriented to the left (or right), the ship rolls around the z-axis!

The ship alway rotates around the global axis!!!

How can I get this problem fixed?

Thank you very much!
Juan

using:


   rotX3d.rotX(xAngle);
  rotY3d.rotY(yAngle);
  rotZ3d.rotZ(zAngle);

  rotXYZ3d.mul(rotX3d);
  rotXYZ3d.mul(rotY3d);
  rotXYZ3d.mul(rotZ3d);

instead of:


   rotX3d.rotX(xAngle);
  rotY3d.rotY(yAngle);
  rotZ3d.rotZ(zAngle);

  rotXY3d.mul(rotX3d, rotY3d);
  rotXYZ3d.mul(rotXY3d, rotZ3d);

seems to solve the problem, but when the view follows the ship you’ll remark, that the z-axis isn’t static, too! Even though now the local axis is used!

How can I make the z-axis static!

Greets Juan