# Problem with Rotation Interpolator

2 replies [Last post]
alefwmm
Offline
Joined: 2011-09-05

Hey guys, how are you?

I am not that fine. I have a problem with the RotationInterpolator.

Problem: When it starts, it resets the initial configuration of my ColorCube.

What do i do to avoid that? How can I rotate the cube on a random configuration?

## Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mshomam
Offline
Joined: 2011-11-28

The trick is to recognize that applying an additional rotation to a transform is a matrix multiplication. http://methoo.com

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 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 )
{
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;
}
currentRotation.mul( additionalRotation, currentRotation );
postId( MOVE );
}

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