Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------------------
- quaternion &quaternion::fromAngleAxis(const float angle, const vec3 &axis)
- {
- float halfAngle = angle * 0.5f;
- float scale = sin(halfAngle) / axis.magnitude();
- x = axis.x * scale;
- y = axis.y * scale;
- z = axis.z * scale;
- w = cos(halfAngle);
- return *this;
- }
- //-----------------------------------------------------------------------
- void quaternion::toAngleAxis(float &angle, vec3 &axis) const
- {
- float halfAngle = acos(w);
- float scale = 1.0f / sin(halfAngle);
- angle = halfAngle * 2.0f;
- axis.x = x * scale;
- axis.y = y * scale;
- axis.z = z * scale;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement