# Quaternion, Smooth cube rotation using "wheel"

I have this piece of code:

private float curDifference = 0;
private float curApplyDifference = 1;
void onMouseRotateDrag (GameObject curPlanche)
{
float posInitX = initMousePosX;//position du curseur au moment du clic
float posInitY = initMousePosY;
float posCurX = Input.mousePosition.x;//position du curseur pendant le drag
float posCurY = Input.mousePosition.y;

if(posInitX-posCurX<0 || posInitY-posCurY<0){//floor() valeur inf et ceil() valeur sup
curDifference = Mathf.Floor((posCurX-posInitX)/100);
if(curDifference <= 0){
curDifference = Mathf.Floor((posCurY-posInitY)/100);
}

if(curTarget.name == "Red"){ // axe X
if(curDifference != curApplyDifference && curDifference>0){
Quaternion curPlanchInitRot = curPlanche.transform.localRotation;//pos d'origine
Quaternion curPlanchTargetRot = curPlanche.transform.localRotation;//pos d'origine puis modifiée
curPlanchTargetRot[0] += (45*curDifference);
curPlanche.transform.localRotation = Quaternion.Lerp(curPlanchInitRot, curPlanchTargetRot, 1.5f);
Debug.Log(curPlanchInitRot+"             "+curPlanchTargetRot);
curApplyDifference = curDifference;
}
}
if(curTarget.name == "Green"){ // axe Y

}
if(curTarget.name == "Blue"){ // axe Z

}
}
}

The function executes when the mouse moves … (after a click on one of the “wheels” of rotation)

I use a set of three rollers to apply the rotations to the cube (on the model of the tool rotation 3DS Max). I made “debug.log” to the right, left, and the results seems correct but the cube does not move. I continued to search …

This is wrong:

curPlanchTargetRot[0] += (45*curDifference);

The quaternion components have nothing to do with the familiar x, y and z degree angles we see in the Inspector - these are the eulerAngles:

curPlanchTargetRot.eulerAngles.x += (45*curDifference);

I have this code wich rotate a cube:

private float curDifference = 0;
private float differenceY = 0;
private float differenceX = 0;
private float curApplyDifference = 1;

void onMouseRotateDrag (GameObject curPlanche)
{
float posInitX = initMousePosX;//position du curseur au moment du clic
float posInitY = initMousePosY;
float posCurX = Input.mousePosition.x;//position du curseur pendant le drag
float posCurY = Input.mousePosition.y;

differenceX = Mathf.Floor((posCurX-posInitX)/150);
differenceY = Mathf.Floor((posCurY-posInitY)/150);
curDifference = differenceX;
if(Mathf.Abs(curDifference)<Mathf.Abs(differenceY)){//floor() valeur inf et ceil() valeur sup
//	curDifference = differenceY;
}

if(curDifference != curApplyDifference){
if(curTarget.name == "RedR"){ // axe X
angles.x = ((-curDifference*90) % 360);
curApplyDifference = curDifference;
}else if(curTarget.name == "GreenR"){ // axe Y
angles.y = ((-curDifference*90) % 360);
curApplyDifference = curDifference;
}else if(curTarget.name == "BlueR"){ // axe Z
angles.z = ((-curDifference*90) % 360);
curApplyDifference = curDifference;
}
posInitX = Input.mousePosition.x;
posInitY = Input.mousePosition.y;
}
}
void Update () {
if(switchControl == true && curTarget != null){
if(curTarget.name == "RedR" || curTarget.name == "GreenR" || curTarget.name == "BlueR"){
Quaternion curPlanchTargetRot = Quaternion.Euler(angles);
curPlanche.transform.rotation = Quaternion.Slerp(curPlanche.transform.rotation, curPlanchTargetRot, 10f*Time.deltaTime);
repereRotation.transform.rotation = Quaternion.Slerp(repereRotation.transform.rotation, curPlanchTargetRot, 10f*Time.deltaTime);
}
}
}

but when I apply a series of rotation, they end up not match with the selected axis.
So I run the code by selecting the cube and rotation values ​​in x, y and z exchange in strange ways.
While I can see visually a rotation only along the X axis, the values ​​X, Y and Z of rotation are changing …
I don’t really understand why … (i also try with localRotation…) or rather how to fix this problem…