Added makeRotate(heading,pitch,roll) to Quat in prep for new classes for

animation paths.
This commit is contained in:
Robert Osfield 2002-02-26 20:01:04 +00:00
parent 260fd17573
commit 7c0eb0f380
3 changed files with 27 additions and 18 deletions

View File

@ -210,6 +210,10 @@ class SG_EXPORT Quat
are co-incident or opposite in direction.*/ are co-incident or opposite in direction.*/
void makeRotate( const Vec3& vec1, const Vec3& vec2 ); void makeRotate( const Vec3& vec1, const Vec3& vec2 );
/** 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.*/ /** Return the angle and vector components represented by the quaternion.*/
void getRotate ( float& angle, float& x, float& y, float& z ) const; void getRotate ( float& angle, float& x, float& y, float& z ) const;
/** Return the angle and vector represented by the quaternion.*/ /** Return the angle and vector represented by the quaternion.*/

View File

@ -149,24 +149,11 @@ void Matrix::makeRotate( const Quat& q )
q.get(*this); q.get(*this);
} }
void Matrix::makeRotate( float yaw, float pitch, float roll) void Matrix::makeRotate( float heading, float pitch, float roll)
{ {
Quat quat;
// lifted straight from SOLID library v1.01 Quaternion.h quat.makeRotate(heading,pitch,roll);
// available from http://www.win.tue.nl/~gino/solid/ quat.get(*this);
// 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);
} }
void Matrix::mult( const Matrix& lhs, const Matrix& rhs ) void Matrix::mult( const Matrix& lhs, const Matrix& rhs )

View File

@ -36,6 +36,24 @@ void Quat::makeRotate( const float angle, const Vec3& vec )
makeRotate( angle, vec[0], vec[1], vec[2] ); 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 // Make a rotation Quat which will rotate vec1 to vec2
// Generally take adot product to get the angle between these // Generally take adot product to get the angle between these