Jump to content
  • Advertisement
BlackJoker

Rotation tool user experience like in unity/maya

This topic is 382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I am trying to implement rotation tool in my own engine, which will have same user experience as rotation tool in unity or maya.

When user rotate object by tool, it also rotates, but its axis visually does not rotate on the back side of the tool - they are always near camera view +/-90 on the X/Y/Z axes.

I used this code to achieve rotation to face for each of the axes:

// objectPosition is your object's position
// objectToFacePosition is the position of the object to face
// upVector is the nominal "up" vector (typically Vector3.Y)
// Note: this does not work when objectPosition is straight below or straight above objectToFacePosition
QuaternionF RotateToFace(Vector3F objectPosition, Vector3F objectToFacePosition, Vector3F upVector)
{
  Vector3F D = (objectPosition - objectToFacePosition);
  Vector3F right = Vector3F.Normalize(Vector3F.Cross(upVector, D));
  Vector3F backward = Vector3F.Normalize(Vector3F.Cross(right, upVector));
  Vector3F up = Vector3F.Cross(backward, right);
  Matrix4x4F rotationMatrix = new Matrix4x4F(right.X, right.Y, right.Z, 0, up.X, up.Y, up.Z, 0, backward.X, backward.Y, backward.Z, 0, 0, 0, 0, 1);
  QuaternionF orientation;
  QuaternionF.RotationMatrix(ref rotationMatrix, out orientation);
  return orientation;
}

And then I just apply resulting rotateToFaceQuaternion for each axis.

If I apply rotateToFaceQuaternion, axis always move towards to the camera (which is correct), but when I try to rotate the whole tool by some quaternion, it will not rotate correctly: current_rotation * rotateToFaceQuaternion = incorrect result, because after applying this rotation to the axis of the tool, they will rotate to the other side of the tool (which is not correct).

 

My question is: how to rotate axis of the tool in such way, that they always rotates towards to the camera, but also could be rotated +/- 90 degrees and if current axis reaches edge of the tool from one side, it will appear on the other side immediately (like in unity or maya) i. e. not to allow axis to appear on the other side of the tool.

 

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!