From b9f1b7aa6fe959e2c7f381f3a9150a862422205c Mon Sep 17 00:00:00 2001 From: Don BURNS Date: Tue, 11 Dec 2001 17:00:29 +0000 Subject: [PATCH] Fixed Matrix::rotate( Vec3 from, Vec3 to); was using to X from to derive axis, which causes a left-handed rotation. Fixed to from X to. --- src/osg/Matrix.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/osg/Matrix.cpp b/src/osg/Matrix.cpp index 37e19e00a..8c501c63d 100644 --- a/src/osg/Matrix.cpp +++ b/src/osg/Matrix.cpp @@ -162,7 +162,10 @@ void Matrix::makeRot( const Vec3& from, const Vec3& to ) double d = from * to; // dot product == cos( angle between from & to ) if( d < 0.9999 ) { double angle = acos(d); - Vec3 axis = to ^ from; //we know ((to) x (from)) is perpendicular to both + // For right-handed rotations, cross product must be from x to, not + // to x from + //Vec3 axis = to ^ from; //we know ((to) x (from)) is perpendicular to both + Vec3 axis = from ^ to; //we know ((from) x (to)) is perpendicular to both makeRot( inRadians(angle) , axis ); } else @@ -174,7 +177,8 @@ void Matrix::makeRot( float angle, const Vec3& axis ) makeRot( angle, axis.x(), axis.y(), axis.z() ); } -void Matrix::makeRot( float angle, float x, float y, float z ) { +void Matrix::makeRot( float angle, float x, float y, float z ) +{ float d = sqrt( x*x + y*y + z*z ); if( d == 0 ) return;