From e427d50d9a3a60c9bdee366c84494424d02a969d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 27 May 2008 17:32:26 +0000 Subject: [PATCH] From Lars Nilson, bug fix to Sector::computeMatrix() --- src/osgSim/Sector.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/osgSim/Sector.cpp b/src/osgSim/Sector.cpp index b46d1ef32..80a2f238a 100644 --- a/src/osgSim/Sector.cpp +++ b/src/osgSim/Sector.cpp @@ -230,20 +230,15 @@ DirectionalSector::DirectionalSector(const osg::Vec3& direction,float horizLobeA void DirectionalSector::computeMatrix() { - float cR = cos(_rollAngle) ; - float sR = sin(_rollAngle) ; - - // Just for clarity - #define D _direction - - _local_to_LP.set( - cR*D[1]+sR*D[0]*D[2], -cR*D[0]+sR*D[1]*D[2], -sR*(D[0]*D[0]+D[1]*D[1]), 0.0, - D[0], D[1], D[2], 0.0, - sR*D[1]-cR*D[0]*D[2], -sR*D[0]-cR*D[1]*D[2], cR*(D[0]*D[0]+D[1]*D[1]), 0.0, - 0.0, 0.0, 0.0, 1.0) ; + double heading = atan2(_direction[0], _direction[1]); + double pitch = atan2(_direction[2], sqrt(_direction[0]*_direction[0] + _direction[1]*_direction[1])); + double roll = _rollAngle; + _local_to_LP = osg::Matrixd::identity(); + _local_to_LP.preMult(osg::Matrix::rotate(heading, 0.0, 0.0, -1.0)); + _local_to_LP.preMult(osg::Matrix::rotate(pitch, 1.0, 0.0, 0.0)); + _local_to_LP.preMult(osg::Matrix::rotate(roll, 0.0, 1.0, 0.0)); } - void DirectionalSector::setDirection(const osg::Vec3& direction) {