From c69a8a5b803114561c0c1ef165ab44535c11ce96 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 4 Jun 2004 10:05:18 +0000 Subject: [PATCH] Added check to Quat::makeRotate(,,,) to catch zero lengh axis. --- src/osg/Quat.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/osg/Quat.cpp b/src/osg/Quat.cpp index 9649b00c3..49bc6bd34 100644 --- a/src/osg/Quat.cpp +++ b/src/osg/Quat.cpp @@ -50,7 +50,17 @@ void Quat::get(Matrixd& matrix) const /// (radians) around the axis (x,y,z) void Quat::makeRotate( value_type angle, value_type x, value_type y, value_type z ) { - value_type inversenorm = 1.0/sqrt( x*x + y*y + z*z ); + const value_type epsilon = 0.0000001; + + value_type length = sqrt( x*x + y*y + z*z ); + if (length < epsilon) + { + // ~zero length axis, so reset rotation to zero. + *this = Quat(); + return; + } + + value_type inversenorm = 1.0/length; value_type coshalfangle = cos( 0.5*angle ); value_type sinhalfangle = sin( 0.5*angle );