Rotating with Quaternions

I'm trying to rotate an object in 3 ways:



One rotate the object backwards (in the direction contrary to the velocity of ) on the XoY plane

other half pi right and another left. The code i made really doesn't work correctly even if it interpolates the rotation correctly

I think i'm using the Quarternions wrong. If you can help me i'd aprecciate it.



I'm leaving the code here. This class method rotate is called on update of the ship subclass, if it is not rotatating already. If it is it continues the rotation.


package interfaces;


import org.lwjgl.util.vector.Matrix;

import sun.security.action.GetLongAction;

import com.jme.math.FastMath;
import com.jme.math.Matrix3f;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;

public abstract class Ship implements Moving {

   public abstract boolean isAlive();
   public abstract void setAlive(boolean a);
   public abstract int getDamage();
   public abstract void damage(int damage);
   

   /*The inverting indicator*/
   private boolean isInverting;
   public static final int INVERT_RIGHT = 1;
   public static final int INVERT_LEFT = 2;
   public static final int INVERT_BACK = 3;
   private int CURRENT_INVERT_TYPE = -1;
   private float INVERT_TIME;
   
   
   
   private Quaternion desiredRotation;
   private Quaternion originalRotation;
   private float interpolation = 0.0f;
   private int c1 = 1, c2 = 1, c3 = 1;
   
   public void invert(Node model, int invertType, float timeDelta){
      
      CURRENT_INVERT_TYPE = invertType;
      setInverting(true);
      
      if( desiredRotation == null) {
         originalRotation = new Quaternion(model.getLocalRotation());
         /**
          * Rotate over the planes
          */
         if(invertType == INVERT_RIGHT){
            desiredRotation = new Quaternion(model.getLocalRotation()).fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y);
         }else if (invertType == INVERT_LEFT){
            desiredRotation = new Quaternion(model.getLocalRotation()).fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y);   
            
         }else if (invertType == INVERT_BACK){
            desiredRotation = new Quaternion(model.getLocalRotation()).fromAngleAxis(FastMath.PI, Vector3f.UNIT_X);
         }
      }
      
      interpolation = Math.min(1.0f, interpolation + timeDelta/getInvertTime());
      model.getLocalRotation().slerp(originalRotation, desiredRotation, interpolation);
      
      
      if(interpolation == 1.0f){
         setInverting(false);
         desiredRotation = null;
         if (CURRENT_INVERT_TYPE == INVERT_BACK){
            getVelocity().y = - getVelocity().y; //After inverting completly invert the velocity (only then)
         }
         CURRENT_INVERT_TYPE = -1;
         interpolation = 0.0f;
      }
      
   }
   
   protected void setInvertTime(float invertTime) {
      INVERT_TIME = invertTime;
   }
   protected float getInvertTime() {
      return INVERT_TIME;
   }
   public int getCurrentInvertType(){
      return CURRENT_INVERT_TYPE;
   }
   protected void setInverting(boolean isInverting) {
      this.isInverting = isInverting;
   }
   public boolean isInverting() {
      return isInverting;
   }
   
   
   
   
   
}



Really apreciate it.