Public Group

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.

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 on other sites

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 on other sites

I got the 2nd rotation, but what is meant by mapping (0,1,0) to mFrontWheelNormal ?

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.

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11