If an object is rotated 90 degrees around it's X axis (so the object's Y axis is now aligned with the world's Z axis ), when it's translated along the Z axis it actually moves along the world's Y axis ..... is this correct?
For the behavior you are looking for here, you need to convert your translation from world-space into object-space. This is done by taking the rotations of the rotated Object3D and applying them to the translation Vector3D:
// Grab a handle to the Object3D's rotation matrix:
Matrix m = new Matrix( myObject3D.getRotationMatrix() );
// Apply this rotation matrix to the translation vector:
myVector3D.matMul( mI );
Important note: If your rotated Object3D is the child of another Object3D, you will most likely want to take ALL of the inherited rotations into account. This takes a few more lines of code, but it's not too difficult:
// Grab a handle to the Object3D's world transformation matrix:
Matrix m = new Matrix( myObject3D.getWorldTransformation() );
// Turn that into a rotation matrix:
float[] dm = m.getDump();
for( int i = 12; i < 15; i++ )
{
dm[i] = 0;
}
dm[15] = 1;
m.setDump( dm );
// Apply this rotation matrix to the translation vector:
myVector3D.matMul( mI );
And as a follow on, after rotating an object how can it be re-aligned with the world's axis so that the rotation is not undone?
This can be done by rotating the mesh of the Object3D and then replacing its rotation matrix with a new one:
myObject3D.rotateY( (float)Math.PI / 2.0f ); // do some rotations
myObject3D.rotateMesh();
myObject3D.setRotationMatrix( new Matrix() );
Note: I pulled these off the top of my head, so you may need to check for typos