Quaternions rotation code

Started by
2 comments, last by apatriarca 10 years ago

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());
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.

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

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.

This topic is closed to new replies.

Advertisement