Skip to main content

Problem with rotations

1 reply [Last post]
alefwmm
Offline
Joined: 2011-09-05
Points: 0

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??

PLease I nees help.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mikelizzi2
Offline
Joined: 2011-10-13
Points: 0

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 TransformGroup navigationTransformGroup;
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
*/
public BehaviorNavigation( TransformGroup tg )
{
BehaviorNavigation.navigationTransformGroup = tg;
navigationTransformGroup.getTransform( navigationTransform );
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();
navigationTransform.setIdentity();
navigationTransformGroup.setTransform( navigationTransform );
postId( MOVE );
}

/**
* additionalRotation
* = 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':
additionalRotation.rotX( Math.toRadians( angleChange ) );
break;
case 'y':
additionalRotation.rotY( Math.toRadians( angleChange ) );
break;
case 'z':
additionalRotation.rotZ( Math.toRadians( angleChange ) );
break;
}
currentRotation.mul( additionalRotation, currentRotation );
navigationTransform.setRotation( currentRotation );
navigationTransformGroup.setTransform( navigationTransform );
postId( MOVE );
}

/**
* @param xTranslation
* @param yTranslation
* @param zTranslation
*/
public void executeBehavior( double xTranslation, double yTranslation, double zTranslation )
{
translationVector.set( xTranslation, yTranslation, zTranslation );
navigationTransformGroup.getTransform( navigationTransform );
navigationTransform.setTranslation( translationVector );
navigationTransformGroup.setTransform( navigationTransform );
postId( MOVE );
}
}