diff --git a/include/osg/Quat b/include/osg/Quat index 615e47613..8ccf88681 100644 --- a/include/osg/Quat +++ b/include/osg/Quat @@ -210,7 +210,11 @@ class SG_EXPORT Quat are co-incident or opposite in direction.*/ void makeRotate( const Vec3& vec1, const Vec3& vec2 ); - /** Return the angle and vector components represented by the quaternion.*/ + /** make a rotation Quat from euler angles.*/ + void makeRotate( float heading, float pitch, float roll); + + + /** Return the angle and vector components represented by the quaternion.*/ void getRotate ( float& angle, float& x, float& y, float& z ) const; /** Return the angle and vector represented by the quaternion.*/ void getRotate ( float& angle, Vec3& vec ) const; diff --git a/src/osg/Matrix.cpp b/src/osg/Matrix.cpp index 386d1528f..6bb9f7951 100644 --- a/src/osg/Matrix.cpp +++ b/src/osg/Matrix.cpp @@ -149,24 +149,11 @@ void Matrix::makeRotate( const Quat& q ) q.get(*this); } -void Matrix::makeRotate( float yaw, float pitch, float roll) +void Matrix::makeRotate( float heading, float pitch, float roll) { - - // lifted straight from SOLID library v1.01 Quaternion.h - // available from http://www.win.tue.nl/~gino/solid/ - // and also distributed under the LGPL - float cosYaw = cos(yaw / 2); - float sinYaw = sin(yaw / 2); - float cosPitch = cos(pitch / 2); - float sinPitch = sin(pitch / 2); - float cosRoll = cos(roll / 2); - float sinRoll = sin(roll / 2); - Quat q(sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw, - cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw, - cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw, - cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw); - - q.get(*this); + Quat quat; + quat.makeRotate(heading,pitch,roll); + quat.get(*this); } void Matrix::mult( const Matrix& lhs, const Matrix& rhs ) diff --git a/src/osg/Quat.cpp b/src/osg/Quat.cpp index c58c69764..daf7300b5 100644 --- a/src/osg/Quat.cpp +++ b/src/osg/Quat.cpp @@ -36,6 +36,24 @@ void Quat::makeRotate( const float angle, const Vec3& vec ) makeRotate( angle, vec[0], vec[1], vec[2] ); } +void Quat::makeRotate( float heading, float pitch, float roll) +{ + + // lifted straight from SOLID library v1.01 Quaternion.h + // available from http://www.win.tue.nl/~gino/solid/ + // and also distributed under the LGPL + float cosHeading = cos(heading / 2); + float sinHeading = sin(heading / 2); + float cosPitch = cos(pitch / 2); + float sinPitch = sin(pitch / 2); + float cosRoll = cos(roll / 2); + float sinRoll = sin(roll / 2); + set(sinRoll * cosPitch * cosHeading - cosRoll * sinPitch * sinHeading, + cosRoll * sinPitch * cosHeading + sinRoll * cosPitch * sinHeading, + cosRoll * cosPitch * sinHeading - sinRoll * sinPitch * cosHeading, + cosRoll * cosPitch * cosHeading + sinRoll * sinPitch * sinHeading); + +} // Make a rotation Quat which will rotate vec1 to vec2 // Generally take adot product to get the angle between these