From 64c5fb644a76351cfbad46ad120df08b3caf5b91 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 10 Dec 2002 19:58:03 +0000 Subject: [PATCH] From Micheal Gronager, fix to osg::Quat::getRotate(..) to handle zero rotations. Port of Sequence to subclass directly from osg::Group. --- src/osg/Quat.cpp | 35 +++++++++++++++++------------------ src/osg/Sequence.cpp | 5 +++++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/osg/Quat.cpp b/src/osg/Quat.cpp index 10733a4ee..2972f69a7 100644 --- a/src/osg/Quat.cpp +++ b/src/osg/Quat.cpp @@ -103,34 +103,33 @@ void Quat::makeRotate( const Vec3& from, const Vec3& to ) } -// Get the angle of rotation and axis of this Quat object. -// Won't give very meaningful results if the Quat is not associated -// with a rotation! void Quat::getRotate( float& angle, Vec3& vec ) const { - float sinhalfangle = sqrt( _fv[0]*_fv[0] + _fv[1]*_fv[1] + _fv[2]*_fv[2] ); - /// float coshalfangle = _fv[3]; - - /// These are not checked for performance reasons ? (cop out!) - /// Point for discussion - how do one handle errors in the osg? - /// if ( abs(sinhalfangle) > 1.0 ) { error }; - /// if ( abs(coshalfangle) > 1.0 ) { error }; - - // *angle = atan2( sinhalfangle, coshalfangle ); // see man atan2 - // -pi < angle < pi - angle = 2 * atan2( sinhalfangle, _fv[3] ); - vec = Vec3(_fv[0], _fv[1], _fv[2]) / sinhalfangle; + getRotate(angle,vec[0],vec[1],vec[2]); } +// Get the angle of rotation and axis of this Quat object. +// Won't give very meaningful results if the Quat is not associated +// with a rotation! void Quat::getRotate( float& angle, float& x, float& y, float& z ) const { float sinhalfangle = sqrt( _fv[0]*_fv[0] + _fv[1]*_fv[1] + _fv[2]*_fv[2] ); angle = 2 * atan2( sinhalfangle, _fv[3] ); - x = _fv[0] / sinhalfangle; - y = _fv[1] / sinhalfangle; - z = _fv[2] / sinhalfangle; + if(sinhalfangle) + { + x = _fv[0] / sinhalfangle; + y = _fv[1] / sinhalfangle; + z = _fv[2] / sinhalfangle; + } + else + { + x = 0.0f; + y = 0.0f; + z = 1.0f; + } + } diff --git a/src/osg/Sequence.cpp b/src/osg/Sequence.cpp index 48a219491..91177c83c 100644 --- a/src/osg/Sequence.cpp +++ b/src/osg/Sequence.cpp @@ -1,4 +1,5 @@ #include +#include using namespace osg; @@ -177,6 +178,10 @@ void Sequence::traverse(NodeVisitor& nv) } setValue(sw); } + else + { + osg::notify(osg::WARN) << "osg::Sequence::traverse(NodeVisitor&) requires a valid FrameStamp to function, sequence not updated.\n"; + } } // now do the traversal