I've a scene with a cube that I can rotate around yaw, pitch and roll. I do this by click the circles and drag the mouse on x/y-axis. I want similar functionality as the Unity rotation tool in editor mode.
My problem is that I can't figure out how to transform the mouse movement so the rotation doesn't become reversed if the cube is rotated 180 degrees in some axis. And how to use correct mouse direction depending on how the cube is rotated.
An image of the cube:
Here I get the mouse input
var direction = InputHandler.GetMouseDirection();
Vector3 diff = new Vector3(direction.X, direction.Y, 0);
if (selectedIntersect == Intersect.Yaw) //green
block.Rotate2(diff.X, 0, 0);
else if (selectedIntersect == Intersect.Pitch) //blue
block.Rotate2(0, 0, diff.Y);
else if (selectedIntersect == Intersect.Roll) //red
block.Rotate2(0, diff.Y, 0);
Here I rotate the cube:
public void Rotate2(float yaw, float pitch, float roll)
{
Quaternion yawrotation = Quaternion.CreateFromAxisAngle(
Vector3.Normalize(this.WorldRotation.Up), MathHelper.ToRadians(yaw));
Quaternion pitchrotation = Quaternion.CreateFromAxisAngle(
Vector3.Normalize(this.WorldRotation.Right), MathHelper.ToRadians(pitch));
Quaternion rollrotation = Quaternion.CreateFromAxisAngle(
Vector3.Normalize(this.WorldRotation.Forward), MathHelper.ToRadians(roll));
Quaternion.Concatenate(ref orientation, ref yawrotation, out orientation);
Quaternion.Concatenate(ref orientation, ref pitchrotation, out orientation);
Quaternion.Concatenate(ref orientation, ref rollrotation, out orientation);
}


