Public Group

# Quaternions rotation code

This topic is 1745 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 9
• ### Forum Statistics

• Total Topics
634085
• Total Posts
3015407
×