# Problem with rotations

alefwmm
Offline
Joined: 2011-09-05

I am having problems while rotating a ColorCube.

I have 3 TranformGroups connect with 3 RotationInterpolators.(One interpolator for each dimension)

Image:

When i use the y-axisRotationInterpolator, it changes the axes of x-axisRotationInterpolator. The same when i use the z-axesRotationInterpolator, it changes both x an y orientation.

How can I avoid this when rotating??

mikelizzi2
Offline
Joined: 2011-10-13

I had been living with the same problem until your post got me thinking.
I believe I have the answer now. See example code below.
The trick is to recognize that applying an additional rotation to a transform is a matrix multiplication.
But (Matrix1 times Matrix2) is not the same as (Matrix2 times Matrix1).
For my purposes (and yours too) the methods in the vechmath library do it backwards!

public final class BehaviorNavigation extends Behavior
{
private static WakeupCriterion criterion;
private static Transform3D navigationTransform = new Transform3D();
private static Vector3d translationVector = new Vector3d();
private static Matrix3d additionalRotation = new Matrix3d();
private static Matrix3d currentRotation = new Matrix3d();
private static final int MOVE = 1;

/**
* @param TransformGroup
*/
{
currentRotation.setIdentity();
}

/**
* This is a required method for a brhavior class.
* It defines a triggering criteria called MOVE
* and tells the behavior to "wakeup" when that
* criteria is posted.
*/
public void initialize()
{
criterion = new WakeupOnBehaviorPost( this, MOVE );
this.wakeupOn( criterion );
}

/**
* This is a required method for a brhavior class.
* It doesn't need to do much because any changes
* to the scene graph transforms automatically trigger
* a redraw. So it just resets the triggering criteria.
*
* @param Enumeration
*/
public void processStimulus( Enumeration criteria )
{
wakeupOn( criterion );
}

public void executeResetBehavior()
{
currentRotation.setIdentity();
postId( MOVE );
}

/**
* = a Matrix3d object to hold the additional rotation in matrix form
* currentRotation
* = a Matrix3d object to hold the current rotation in matrix form
* must be initialized to Identity.
*
* @param axis
* @param angleChange - in degrees
*/
public void executeBehavior( char axis, int angleChange )
{
switch ( axis )
{
case 'x':
break;
case 'y':
break;
case 'z':
break;
}
postId( MOVE );
}

/**
* @param xTranslation
* @param yTranslation
* @param zTranslation
*/
public void executeBehavior( double xTranslation, double yTranslation, double zTranslation )
{
translationVector.set( xTranslation, yTranslation, zTranslation );