Changed the implementation of osg::Quat::makeRotate(heading,pitch,roll) so that
it conforms to the OpenFlight convention of euler angles. Added documentation into Matrix and Quat to reflect this. Added so test code to osgcube for stress testing memory allocation and deallocation. Commented out the registering of app and cull callbacks in osghud.
This commit is contained in:
parent
1131be56dc
commit
e3958790a2
@ -94,7 +94,14 @@ class SG_EXPORT Matrix : public Object
|
||||
void makeRotate( float angle, const Vec3& axis );
|
||||
void makeRotate( float angle, float x, float y, float z );
|
||||
void makeRotate( const Quat& );
|
||||
void makeRotate( float, float, float ); //Euler angles
|
||||
|
||||
/** make a rotation Matrix from euler angles.
|
||||
* assume Z up, Y north, X east and euler convention
|
||||
* as per Open Flight & Performer.
|
||||
* Applies a positive rotation about Y axis for roll,
|
||||
* then applies a positive roation about X for pitch,
|
||||
* and finally a negative rotation about the Z axis.*/
|
||||
void makeRotate( float heading, float pitch, float roll); //Euler angles
|
||||
|
||||
|
||||
/** Set to a orthographic projection. See glOrtho for further details.*/
|
||||
@ -127,15 +134,17 @@ class SG_EXPORT Matrix : public Object
|
||||
|
||||
//basic utility functions to create new matrices
|
||||
inline static Matrix identity( void );
|
||||
inline static Matrix scale( const Vec3& );
|
||||
inline static Matrix scale( float, float, float );
|
||||
inline static Matrix translate( const Vec3& );
|
||||
inline static Matrix translate( float, float, float );
|
||||
inline static Matrix rotate( const Vec3&, const Vec3& );
|
||||
inline static Matrix rotate( float, float, float, float );
|
||||
inline static Matrix scale( const Vec3& sv);
|
||||
inline static Matrix scale( float sx, float sy, float sz);
|
||||
inline static Matrix translate( const Vec3& dv);
|
||||
inline static Matrix translate( float x, float y, float z);
|
||||
inline static Matrix rotate( const Vec3& from, const Vec3& to);
|
||||
inline static Matrix rotate( float angle, float x, float y, float z);
|
||||
inline static Matrix rotate( float angle, const Vec3& axis);
|
||||
inline static Matrix rotate( const Quat&);
|
||||
inline static Matrix inverse( const Matrix&);
|
||||
/** construct rotation matrix from euler angles, for conventions see makeRotate().*/
|
||||
inline static Matrix rotate( float heading, float pitch, float roll);
|
||||
inline static Matrix rotate( const Quat& quat);
|
||||
inline static Matrix inverse( const Matrix& matrix);
|
||||
|
||||
/** Create a orthographic projection. See glOrtho for further details.*/
|
||||
inline static Matrix ortho(const double left, const double right,
|
||||
@ -277,6 +286,12 @@ inline Matrix Matrix::rotate(float angle, const Vec3& axis )
|
||||
m.makeRotate(angle,axis);
|
||||
return m;
|
||||
}
|
||||
inline Matrix Matrix::rotate(float heading, float pitch, float roll)
|
||||
{
|
||||
Matrix m;
|
||||
m.makeRotate(heading,pitch,roll);
|
||||
return m;
|
||||
}
|
||||
inline Matrix Matrix::rotate(const Vec3& from, const Vec3& to )
|
||||
{
|
||||
Matrix m;
|
||||
|
@ -70,13 +70,13 @@ class SG_EXPORT Quat
|
||||
Also define methods for conjugate and the multiplicative inverse.
|
||||
------------------------------------------------------------- */
|
||||
/// Multiply by scalar
|
||||
inline const Quat operator * (const float& rhs) const
|
||||
inline const Quat operator * (const float rhs) const
|
||||
{
|
||||
return Quat(_fv*rhs);
|
||||
}
|
||||
|
||||
/// Unary multiply by scalar
|
||||
inline Quat& operator *= (const float& rhs)
|
||||
inline Quat& operator *= (const float rhs)
|
||||
{
|
||||
_fv*=rhs;
|
||||
return *this; // enable nesting
|
||||
@ -200,7 +200,7 @@ class SG_EXPORT Quat
|
||||
Not inlined - see the Quat.cpp file for implementation
|
||||
-------------------------------------------------------- */
|
||||
void makeRotate ( const float angle,
|
||||
const float x, const float y, const float z );
|
||||
const float x, const float y, const float z );
|
||||
void makeRotate ( const float angle, const Vec3& vec );
|
||||
|
||||
/** Make a rotation Quat which will rotate vec1 to vec2.
|
||||
@ -210,7 +210,12 @@ class SG_EXPORT Quat
|
||||
are co-incident or opposite in direction.*/
|
||||
void makeRotate( const Vec3& vec1, const Vec3& vec2 );
|
||||
|
||||
/** make a rotation Quat from euler angles.*/
|
||||
/** make a rotation Quat from euler angles.
|
||||
* assume Z up, Y north, X east and euler convention
|
||||
* as per Open Flight & Performer.
|
||||
* Applies a positive rotation about Y axis for roll,
|
||||
* then applies a positive roation about X for pitch,
|
||||
* and finally a negative rotation about the Z axis.*/
|
||||
void makeRotate( float heading, float pitch, float roll);
|
||||
|
||||
|
||||
|
@ -18,6 +18,13 @@
|
||||
// Global variables - this is basically the stuff which will be animated
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
|
||||
osg::Geode* createCube(); //Forward Declaration added by SMW
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MyTransformCallback : public osg::NodeCallback{
|
||||
|
||||
public:
|
||||
@ -52,6 +59,23 @@ class MyTransformCallback : public osg::NodeCallback{
|
||||
_nodeToOperateOn->setMatrix(matrix);
|
||||
|
||||
_previousTraversalNumber = nv->getTraversalNumber();
|
||||
|
||||
// Some memory stress testing added by Steve to reveal crashes under Windows.
|
||||
// // Start Added by SMW
|
||||
// osg::Transform* Tnode = (osg::Transform *)node;
|
||||
// int i;
|
||||
// osg::Node *n;
|
||||
// while (Tnode->getNumChildren() > 0)
|
||||
// {
|
||||
// n = Tnode->getChild(0);
|
||||
// Tnode->removeChild(n);
|
||||
// }
|
||||
// for (i = 0;i < 500;i++)
|
||||
// {
|
||||
// Tnode->addChild( createCube() );
|
||||
// }
|
||||
// // End Added by SMW
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -340,8 +340,8 @@ int main( int argc, char **argv )
|
||||
set2dScene(modelview_abs);
|
||||
|
||||
projection->addChild(modelview_abs);
|
||||
projection->setAppCallback(osgNew MyCallback("App callback"));
|
||||
projection->setCullCallback(osgNew MyCallback("Cull callback"));
|
||||
// projection->setAppCallback(osgNew MyCallback("App callback"));
|
||||
// projection->setCullCallback(osgNew MyCallback("Cull callback"));
|
||||
|
||||
group->addChild(projection);
|
||||
|
||||
|
@ -36,23 +36,24 @@ void Quat::makeRotate( const float angle, const Vec3& vec )
|
||||
makeRotate( angle, vec[0], vec[1], vec[2] );
|
||||
}
|
||||
|
||||
|
||||
// assume Z up, Y north, X east and euler convention
|
||||
// as per Open Flight & Performer.
|
||||
// applies a positive rotation about Y axis for roll,
|
||||
// then applies a positive roation about X for pitch,
|
||||
// and finally a negative rotation about the Z axis.
|
||||
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);
|
||||
|
||||
Quat q_roll; q_roll.makeRotate(roll,0.0,1.0,0.0);
|
||||
Quat q_pitch; q_pitch.makeRotate(pitch,1.0,0.0,0.0);
|
||||
Quat q_heading; q_heading.makeRotate(-heading,0.0,0.0,1.0);
|
||||
|
||||
// note reverse order than would be done using matrices
|
||||
// which raises the interesting question whether the definition
|
||||
// of Quat*Quat should be changed to fit with the v' = v x M
|
||||
// convention of Matrix. Will investigate further later on.
|
||||
// Robert Osfield. April 2002.
|
||||
*this = q_heading*q_pitch*q_roll;
|
||||
}
|
||||
|
||||
// Make a rotation Quat which will rotate vec1 to vec2
|
||||
@ -288,3 +289,47 @@ void Quat::get( Matrix& m ) const
|
||||
m(2,3) = 0;
|
||||
m(3,3) = 1;
|
||||
}
|
||||
|
||||
#ifdef OSG_USE_UNIT_TESTS
|
||||
void test_Quat_Eueler(float heading,float pitch,float roll)
|
||||
{
|
||||
osg::Quat q;
|
||||
q.makeRotate(heading,pitch,roll);
|
||||
|
||||
osg::Matrix q_m;
|
||||
q.get(q_m);
|
||||
|
||||
osg::Vec3 xAxis(1,0,0);
|
||||
osg::Vec3 yAxis(0,1,0);
|
||||
osg::Vec3 zAxis(0,0,1);
|
||||
|
||||
cout << "heading = "<<heading<<" pitch = "<<pitch<<" roll = "<<roll<<endl;
|
||||
|
||||
cout <<"q_m = "<<q_m;
|
||||
cout <<"xAxis*q_m = "<<xAxis*q_m << endl;
|
||||
cout <<"yAxis*q_m = "<<yAxis*q_m << endl;
|
||||
cout <<"zAxis*q_m = "<<zAxis*q_m << endl;
|
||||
|
||||
osg::Matrix r_m = osg::Matrix::rotate(roll,0.0,1.0,0.0)*
|
||||
osg::Matrix::rotate(pitch,1.0,0.0,0.0)*
|
||||
osg::Matrix::rotate(-heading,0.0,0.0,1.0);
|
||||
|
||||
cout << "r_m = "<<r_m;
|
||||
cout <<"xAxis*r_m = "<<xAxis*r_m << endl;
|
||||
cout <<"yAxis*r_m = "<<yAxis*r_m << endl;
|
||||
cout <<"zAxis*r_m = "<<zAxis*r_m << endl;
|
||||
|
||||
cout << endl<<"*****************************************" << endl<< endl;
|
||||
|
||||
}
|
||||
|
||||
void test_Quat()
|
||||
{
|
||||
|
||||
test_Quat_Eueler(osg::DegreesToRadians(20),0,0);
|
||||
test_Quat_Eueler(0,osg::DegreesToRadians(20),0);
|
||||
test_Quat_Eueler(0,0,osg::DegreesToRadians(20));
|
||||
test_Quat_Eueler(osg::DegreesToRadians(20),osg::DegreesToRadians(20),osg::DegreesToRadians(20));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user