Jump to content
  • Advertisement
Sign in to follow this  
AhmedCoeia

Quaternions rotation code

This topic is 2023 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

I have seen that piece of code, but I don't get it what's really doing, in mathematical way. Source is a 3D Model of a bike. The normal comes from a ray casting to the ground, and mFrontWheelNormal, is coming from another ray casting.

I'm using Unity3D.

Quaternion rotFront =
        Quaternion.AngleAxis(Source.rotation.eulerAngles.y, normal) *
                Quaternion.FromToRotation(new Vector3(0, 1, 0),
                                          mFrontWheelNormal.GetVector3());
Edited by AhmedCoeia

Share this post


Link to post
Share on other sites
Advertisement

When you multiply two quaternions you are composing the two transformations together. The resulting rotation is the rotation obtained by first rotating according to right-most quaternion and then according to the left-most one. In your case, your first rotation maps (0, 1, 0) to mFrontWheelNormal and you then rotate around the normal vector by the angle Source.rotation.eulerAngles.y.

Share this post


Link to post
Share on other sites

I do not know the Unity API, but I think it is the rotation around the axis cross((0, 1, 0), mFrontWheelNormal) with angle equal to the angle between the two vectors. The effect of the rotation should be to move something aligned with (0,1,0) to something aligned with mFrontWheelNormal.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!