Added Matrix*::getRotate()/setRotate(Quat), deprecating Matrix*::get(Quat&), Matrix*::set(Quat&)

This commit is contained in:
Robert Osfield 2006-07-31 17:31:21 +00:00
parent 28cf404a25
commit 564ee34f76
20 changed files with 99 additions and 80 deletions

View File

@ -184,7 +184,7 @@ void GliderManipulator::addMouseEvent(const GUIEventAdapter& ea)
void GliderManipulator::setByMatrix(const osg::Matrixd& matrix) void GliderManipulator::setByMatrix(const osg::Matrixd& matrix)
{ {
_eye = matrix.getTrans(); _eye = matrix.getTrans();
matrix.get(_rotation); _rotation = matrix.getRotate();
_distance = 1.0f; _distance = 1.0f;
} }
@ -214,8 +214,7 @@ void GliderManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv
_eye = eye; _eye = eye;
_distance = lv.length(); _distance = lv.length();
rotation_matrix.get(_rotation); _rotation = rotation_matrix.getRotate().inverse();
_rotation = _rotation.inverse();
} }

View File

@ -182,7 +182,7 @@ void TestManipulator::addMouseEvent(const GUIEventAdapter& ea)
void TestManipulator::setByMatrix(const osg::Matrixd& matrix) void TestManipulator::setByMatrix(const osg::Matrixd& matrix)
{ {
_center = matrix.getTrans(); _center = matrix.getTrans();
matrix.get(_rotation); _rotation = matrix.getRotate();
_distance = 1.0f; _distance = 1.0f;
} }
@ -212,8 +212,7 @@ void TestManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,c
_center = eye+lv; _center = eye+lv;
_distance = lv.length(); _distance = lv.length();
rotation_matrix.get(_rotation); _rotation = rotation_matrix.getRotate().inverse();
_rotation = _rotation.inverse();
} }

View File

@ -180,8 +180,7 @@ class TexMatCullCallback : public osg::NodeCallback
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv); osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if (cv) if (cv)
{ {
osg::Quat quat; osg::Quat quat = cv->getModelViewMatrix().getRotate();
cv->getModelViewMatrix().get(quat);
_texmat->setMatrix(osg::Matrix::rotate(quat.inverse())); _texmat->setMatrix(osg::Matrix::rotate(quat.inverse()));
} }
} }

View File

@ -222,14 +222,14 @@ void testGetQuatFromMatrix() {
// create two matrices based on the input quats // create two matrices based on the input quats
osg::Matrixd mat1,mat2; osg::Matrixd mat1,mat2;
mat1.set(rot_quat1); mat1.makeRotate(rot_quat1);
mat2.set(rot_quat2); mat2.makeRotate(rot_quat2);
// create an output quat by matrix multiplication and get // create an output quat by matrix multiplication and get
osg::Matrixd out_mat; osg::Matrixd out_mat;
out_mat = mat2 * mat1; out_mat = mat2 * mat1;
osg::Quat out_quat2; osg::Quat out_quat2;
out_mat.get(out_quat2); out_quat2 = out_mat.getRotate();
// if the output quat length is not one // if the output quat length is not one
// or if the component magnitudes do not match, // or if the component magnitudes do not match,

View File

@ -183,8 +183,7 @@ public:
const osg::Matrix R = osg::Matrix::rotate( osg::DegreesToRadians(112.0f), 0.0f,0.0f,1.0f)* const osg::Matrix R = osg::Matrix::rotate( osg::DegreesToRadians(112.0f), 0.0f,0.0f,1.0f)*
osg::Matrix::rotate( osg::DegreesToRadians(90.0f), 1.0f,0.0f,0.0f); osg::Matrix::rotate( osg::DegreesToRadians(90.0f), 1.0f,0.0f,0.0f);
osg::Quat q; osg::Quat q = MV.getRotate();
MV.get(q);
const osg::Matrix C = osg::Matrix::rotate( q.inverse() ); const osg::Matrix C = osg::Matrix::rotate( q.inverse() );
_texMat.setMatrix( C*R ); _texMat.setMatrix( C*R );

View File

@ -17,7 +17,7 @@
// define USE_DEPRECATED_API is used to include in API which is being fazed out // define USE_DEPRECATED_API is used to include in API which is being fazed out
// if you can compile your apps with this turned off you are // if you can compile your apps with this turned off you are
// well placed for compatablity with future versions. // well placed for compatablity with future versions.
//#define USE_DEPRECATED_API #define USE_DEPRECATED_API
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning( disable : 4244 ) #pragma warning( disable : 4244 )

View File

@ -34,7 +34,7 @@ class OSG_EXPORT Matrixd
Matrixd( const Matrixf& mat ); Matrixd( const Matrixf& mat );
inline explicit Matrixd( float const * const ptr ) { set(ptr); } inline explicit Matrixd( float const * const ptr ) { set(ptr); }
inline explicit Matrixd( double const * const ptr ) { set(ptr); } inline explicit Matrixd( double const * const ptr ) { set(ptr); }
inline explicit Matrixd( const Quat& quat ) { set(quat); } inline explicit Matrixd( const Quat& quat ) { makeRotate(quat); }
Matrixd(value_type a00, value_type a01, value_type a02, value_type a03, Matrixd(value_type a00, value_type a01, value_type a02, value_type a03,
value_type a10, value_type a11, value_type a12, value_type a13, value_type a10, value_type a11, value_type a12, value_type a13,
@ -88,10 +88,6 @@ class OSG_EXPORT Matrixd
value_type a20, value_type a21, value_type a22,value_type a23, value_type a20, value_type a21, value_type a22,value_type a23,
value_type a30, value_type a31, value_type a32,value_type a33); value_type a30, value_type a31, value_type a32,value_type a33);
void set(const Quat& q);
void get(Quat& q) const;
value_type * ptr() { return (value_type*)_mat; } value_type * ptr() { return (value_type*)_mat; }
const value_type * ptr() const { return (const value_type *)_mat; } const value_type * ptr() const { return (const value_type *)_mat; }
@ -289,6 +285,14 @@ class OSG_EXPORT Matrixd
inline Vec4f operator* ( const Vec4f& v ) const; inline Vec4f operator* ( const Vec4f& v ) const;
inline Vec4d operator* ( const Vec4d& v ) const; inline Vec4d operator* ( const Vec4d& v ) const;
#ifdef USE_DEPRECATED_API
inline void set(const Quat& q) { makeRotate(q); }
inline void get(Quat& q) const { q = getRotate(); }
#endif
void setRotate(const Quat& q);
Quat getRotate() const;
void setTrans( value_type tx, value_type ty, value_type tz ); void setTrans( value_type tx, value_type ty, value_type tz );
void setTrans( const Vec3f& v ); void setTrans( const Vec3f& v );
void setTrans( const Vec3d& v ); void setTrans( const Vec3d& v );

View File

@ -34,7 +34,7 @@ class OSG_EXPORT Matrixf
Matrixf( const Matrixd& mat ); Matrixf( const Matrixd& mat );
inline explicit Matrixf( float const * const ptr ) { set(ptr); } inline explicit Matrixf( float const * const ptr ) { set(ptr); }
inline explicit Matrixf( double const * const ptr ) { set(ptr); } inline explicit Matrixf( double const * const ptr ) { set(ptr); }
inline explicit Matrixf( const Quat& quat ) { set(quat); } inline explicit Matrixf( const Quat& quat ) { makeRotate(quat); }
Matrixf( value_type a00, value_type a01, value_type a02, value_type a03, Matrixf( value_type a00, value_type a01, value_type a02, value_type a03,
value_type a10, value_type a11, value_type a12, value_type a13, value_type a10, value_type a11, value_type a12, value_type a13,
@ -88,10 +88,6 @@ class OSG_EXPORT Matrixf
value_type a20, value_type a21, value_type a22,value_type a23, value_type a20, value_type a21, value_type a22,value_type a23,
value_type a30, value_type a31, value_type a32,value_type a33); value_type a30, value_type a31, value_type a32,value_type a33);
void set(const Quat& q);
void get(Quat& q) const;
value_type * ptr() { return (value_type*)_mat; } value_type * ptr() { return (value_type*)_mat; }
const value_type * ptr() const { return (const value_type *)_mat; } const value_type * ptr() const { return (const value_type *)_mat; }
@ -290,6 +286,15 @@ class OSG_EXPORT Matrixf
inline Vec4f operator* ( const Vec4f& v ) const; inline Vec4f operator* ( const Vec4f& v ) const;
inline Vec4d operator* ( const Vec4d& v ) const; inline Vec4d operator* ( const Vec4d& v ) const;
#ifdef USE_DEPRECATED_API
inline void set(const Quat& q) { makeRotate(q); }
inline void get(Quat& q) const { q = getRotate(); }
#endif
void setRotate(const Quat& q);
Quat getRotate() const;
void setTrans( value_type tx, value_type ty, value_type tz ); void setTrans( value_type tx, value_type ty, value_type tz );
void setTrans( const Vec3f& v ); void setTrans( const Vec3f& v );
void setTrans( const Vec3d& v ); void setTrans( const Vec3d& v );

View File

@ -159,8 +159,7 @@ void AutoTransform::accept(NodeVisitor& nv)
if (_autoRotateMode==ROTATE_TO_SCREEN) if (_autoRotateMode==ROTATE_TO_SCREEN)
{ {
osg::Quat rotation; osg::Quat rotation = cs->getModelViewMatrix().getRotate();
cs->getModelViewMatrix().get(rotation);
setRotation(rotation.inverse()); setRotation(rotation.inverse());
} }
else if (_autoRotateMode==ROTATE_TO_CAMERA) else if (_autoRotateMode==ROTATE_TO_CAMERA)

View File

@ -62,7 +62,7 @@ void Matrix_implementation::set( value_type a00, value_type a01, value_type a02,
#define QZ q._v[2] #define QZ q._v[2]
#define QW q._v[3] #define QW q._v[3]
void Matrix_implementation::set(const Quat& q_in) void Matrix_implementation::setRotate(const Quat& q_in)
{ {
Quat q(q_in); Quat q(q_in);
double length2 = q.length2(); double length2 = q.length2();
@ -103,29 +103,35 @@ void Matrix_implementation::set(const Quat& q_in)
_mat[0][0] = 1.0 - (yy + zz); _mat[0][0] = 1.0 - (yy + zz);
_mat[1][0] = xy - wz; _mat[1][0] = xy - wz;
_mat[2][0] = xz + wy; _mat[2][0] = xz + wy;
_mat[3][0] = 0.0;
_mat[0][1] = xy + wz; _mat[0][1] = xy + wz;
_mat[1][1] = 1.0 - (xx + zz); _mat[1][1] = 1.0 - (xx + zz);
_mat[2][1] = yz - wx; _mat[2][1] = yz - wx;
_mat[3][1] = 0.0;
_mat[0][2] = xz - wy; _mat[0][2] = xz - wy;
_mat[1][2] = yz + wx; _mat[1][2] = yz + wx;
_mat[2][2] = 1.0 - (xx + yy); _mat[2][2] = 1.0 - (xx + yy);
_mat[3][2] = 0.0;
#if 0
_mat[0][3] = 0.0; _mat[0][3] = 0.0;
_mat[1][3] = 0.0; _mat[1][3] = 0.0;
_mat[2][3] = 0.0; _mat[2][3] = 0.0;
_mat[3][0] = 0.0;
_mat[3][1] = 0.0;
_mat[3][2] = 0.0;
_mat[3][3] = 1.0; _mat[3][3] = 1.0;
#endif
} }
#if 1 #if 1
// David Spillings implementation Mk 2 // David Spillings implementation Mk 2
void Matrix_implementation::get( Quat& q ) const Quat Matrix_implementation::getRotate() const
{ {
Quat q;
// From http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm // From http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
QW = 0.5 * sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] + _mat[1][1] + _mat[2][2] ) ); QW = 0.5 * sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] + _mat[1][1] + _mat[2][2] ) );
QX = 0.5 * sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] - _mat[1][1] - _mat[2][2] ) ); QX = 0.5 * sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] - _mat[1][1] - _mat[2][2] ) );
@ -135,6 +141,8 @@ void Matrix_implementation::get( Quat& q ) const
QX = QX * osg::sign( _mat[1][2] - _mat[2][1]) ; QX = QX * osg::sign( _mat[1][2] - _mat[2][1]) ;
QY = QY * osg::sign( _mat[2][0] - _mat[0][2]) ; QY = QY * osg::sign( _mat[2][0] - _mat[0][2]) ;
QZ = QZ * osg::sign( _mat[0][1] - _mat[1][0]) ; QZ = QZ * osg::sign( _mat[0][1] - _mat[1][0]) ;
return q;
} }
#else #else
@ -332,62 +340,78 @@ void Matrix_implementation::makeTranslate( value_type x, value_type y, value_typ
void Matrix_implementation::makeRotate( const Vec3f& from, const Vec3f& to ) void Matrix_implementation::makeRotate( const Vec3f& from, const Vec3f& to )
{ {
makeIdentity();
Quat quat; Quat quat;
quat.makeRotate(from,to); quat.makeRotate(from,to);
set(quat); setRotate(quat);
} }
void Matrix_implementation::makeRotate( const Vec3d& from, const Vec3d& to ) void Matrix_implementation::makeRotate( const Vec3d& from, const Vec3d& to )
{ {
makeIdentity();
Quat quat; Quat quat;
quat.makeRotate(from,to); quat.makeRotate(from,to);
set(quat); setRotate(quat);
} }
void Matrix_implementation::makeRotate( value_type angle, const Vec3f& axis ) void Matrix_implementation::makeRotate( value_type angle, const Vec3f& axis )
{ {
makeIdentity();
Quat quat; Quat quat;
quat.makeRotate( angle, axis); quat.makeRotate( angle, axis);
set(quat); setRotate(quat);
} }
void Matrix_implementation::makeRotate( value_type angle, const Vec3d& axis ) void Matrix_implementation::makeRotate( value_type angle, const Vec3d& axis )
{ {
makeIdentity();
Quat quat; Quat quat;
quat.makeRotate( angle, axis); quat.makeRotate( angle, axis);
set(quat); setRotate(quat);
} }
void Matrix_implementation::makeRotate( value_type angle, value_type x, value_type y, value_type z ) void Matrix_implementation::makeRotate( value_type angle, value_type x, value_type y, value_type z )
{ {
makeIdentity();
Quat quat; Quat quat;
quat.makeRotate( angle, x, y, z); quat.makeRotate( angle, x, y, z);
set(quat); setRotate(quat);
} }
void Matrix_implementation::makeRotate( const Quat& quat ) void Matrix_implementation::makeRotate( const Quat& quat )
{ {
set(quat); makeIdentity();
setRotate(quat);
} }
void Matrix_implementation::makeRotate( value_type angle1, const Vec3f& axis1, void Matrix_implementation::makeRotate( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2, value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3) value_type angle3, const Vec3f& axis3)
{ {
makeIdentity();
Quat quat; Quat quat;
quat.makeRotate(angle1, axis1, quat.makeRotate(angle1, axis1,
angle2, axis2, angle2, axis2,
angle3, axis3); angle3, axis3);
set(quat); setRotate(quat);
} }
void Matrix_implementation::makeRotate( value_type angle1, const Vec3d& axis1, void Matrix_implementation::makeRotate( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2, value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3) value_type angle3, const Vec3d& axis3)
{ {
makeIdentity();
Quat quat; Quat quat;
quat.makeRotate(angle1, axis1, quat.makeRotate(angle1, axis1,
angle2, axis2, angle2, axis2,
angle3, axis3); angle3, axis3);
set(quat); setRotate(quat);
} }
void Matrix_implementation::mult( const Matrix_implementation& lhs, const Matrix_implementation& rhs ) void Matrix_implementation::mult( const Matrix_implementation& lhs, const Matrix_implementation& rhs )

View File

@ -35,11 +35,8 @@ class ApplyMatrixVisitor : public NodeVisitor
virtual void apply(CameraView& cv) virtual void apply(CameraView& cv)
{ {
Quat rotation;
_matrix.get(rotation);
cv.setPosition(_matrix.getTrans()); cv.setPosition(_matrix.getTrans());
cv.setAttitude(rotation); cv.setAttitude(_matrix.getRotate());
} }
virtual void apply(MatrixTransform& mt) virtual void apply(MatrixTransform& mt)
@ -49,11 +46,8 @@ class ApplyMatrixVisitor : public NodeVisitor
virtual void apply(PositionAttitudeTransform& pat) virtual void apply(PositionAttitudeTransform& pat)
{ {
Quat rotation;
_matrix.get(rotation);
pat.setPosition(_matrix.getTrans()); pat.setPosition(_matrix.getTrans());
pat.setAttitude(rotation); pat.setAttitude(_matrix.getRotate());
} }
osg::Matrix _matrix; osg::Matrix _matrix;

View File

@ -27,22 +27,22 @@ using namespace osg;
void Quat::set(const Matrixf& matrix) void Quat::set(const Matrixf& matrix)
{ {
matrix.get(*this); *this = matrix.getRotate();
} }
void Quat::set(const Matrixd& matrix) void Quat::set(const Matrixd& matrix)
{ {
matrix.get(*this); *this = matrix.getRotate();
} }
void Quat::get(Matrixf& matrix) const void Quat::get(Matrixf& matrix) const
{ {
matrix.set(*this); matrix.makeRotate(*this);
} }
void Quat::get(Matrixd& matrix) const void Quat::get(Matrixd& matrix) const
{ {
matrix.set(*this); matrix.makeRotate(*this);
} }

View File

@ -217,7 +217,7 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
osg::CoordinateFrame cf=getCoordinateFrame(ep); osg::CoordinateFrame cf=getCoordinateFrame(ep);
Matrixd rotation_matrix; Matrixd rotation_matrix;
rotation_matrix.set(_rotation); rotation_matrix.makeRotate(_rotation);
osg::Vec3d sv = osg::Vec3d(1.0,0.0,0.0) * rotation_matrix; osg::Vec3d sv = osg::Vec3d(1.0,0.0,0.0) * rotation_matrix;
osg::Vec3d bp = ep; osg::Vec3d bp = ep;
bp -= getUpVector(cf)*_modelScale; bp -= getUpVector(cf)*_modelScale;
@ -446,7 +446,7 @@ void DriveManipulator::addMouseEvent(const GUIEventAdapter& ea)
void DriveManipulator::setByMatrix(const osg::Matrixd& matrix) void DriveManipulator::setByMatrix(const osg::Matrixd& matrix)
{ {
_eye = matrix.getTrans(); _eye = matrix.getTrans();
matrix.get(_rotation); _rotation = matrix.getRotate();
} }
osg::Matrixd DriveManipulator::getMatrix() const osg::Matrixd DriveManipulator::getMatrix() const
@ -476,8 +476,7 @@ void DriveManipulator::computePosition(const osg::Vec3d& eye,const osg::Vec3d& c
0.0, 0.0, 0.0, 1.0); 0.0, 0.0, 0.0, 1.0);
_eye = eye; _eye = eye;
rotation_matrix.get(_rotation); _rotation = rotation_matrix.getRotate().inverse();
_rotation = _rotation.inverse();
} }

View File

@ -191,7 +191,7 @@ void FlightManipulator::addMouseEvent(const GUIEventAdapter& ea)
void FlightManipulator::setByMatrix(const osg::Matrixd& matrix) void FlightManipulator::setByMatrix(const osg::Matrixd& matrix)
{ {
_eye = matrix.getTrans(); _eye = matrix.getTrans();
matrix.get(_rotation); _rotation = matrix.getRotate();
_distance = 1.0f; _distance = 1.0f;
} }
@ -223,8 +223,7 @@ void FlightManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& ce
_eye = eye; _eye = eye;
_distance = lv.length(); _distance = lv.length();
rotation_matrix.get(_rotation); _rotation = rotation_matrix.getRotate().inverse();
_rotation = _rotation.inverse();
} }

View File

@ -353,7 +353,7 @@ void NodeTrackerManipulator::computeNodeCenterAndRotation(osg::Vec3d& nodeCenter
double azim = atan2(-localToFrame(0,1),localToFrame(0,0)); double azim = atan2(-localToFrame(0,1),localToFrame(0,0));
osg::Quat nodeRotationRelToFrame, rotationOfFrame; osg::Quat nodeRotationRelToFrame, rotationOfFrame;
nodeRotationRelToFrame.makeRotate(-azim,0.0,0.0,1.0); nodeRotationRelToFrame.makeRotate(-azim,0.0,0.0,1.0);
coordinateFrame.get(rotationOfFrame); rotationOfFrame = coordinateFrame.getRotate();
nodeRotation = nodeRotationRelToFrame*rotationOfFrame; nodeRotation = nodeRotationRelToFrame*rotationOfFrame;
break; break;
} }
@ -365,14 +365,14 @@ void NodeTrackerManipulator::computeNodeCenterAndRotation(osg::Vec3d& nodeCenter
double sz = 1.0/sqrt(localToWorld(0,2)*localToWorld(0,2) + localToWorld(1,2)*localToWorld(1,2) + localToWorld(2,2)*localToWorld(2,2)); double sz = 1.0/sqrt(localToWorld(0,2)*localToWorld(0,2) + localToWorld(1,2)*localToWorld(1,2) + localToWorld(2,2)*localToWorld(2,2));
localToWorld = localToWorld*osg::Matrixd::scale(sx,sy,sz); localToWorld = localToWorld*osg::Matrixd::scale(sx,sy,sz);
localToWorld.get(nodeRotation); nodeRotation = localToWorld.getRotate();
break; break;
} }
case(NODE_CENTER): case(NODE_CENTER):
default: default:
{ {
CoordinateFrame coordinateFrame = getCoordinateFrame(nodeCenter); CoordinateFrame coordinateFrame = getCoordinateFrame(nodeCenter);
coordinateFrame.get(nodeRotation); nodeRotation = coordinateFrame.getRotate();
break; break;
} }
} }
@ -406,9 +406,8 @@ void NodeTrackerManipulator::computePosition(const osg::Vec3d& eye,const osg::Ve
osg::Matrixd lookat; osg::Matrixd lookat;
lookat.makeLookAt(eye,center,up); lookat.makeLookAt(eye,center,up);
lookat.get(_rotation);
_rotation = _rotation.inverse(); _rotation = lookat.getRotate().inverse();
} }
bool NodeTrackerManipulator::calcMovement() bool NodeTrackerManipulator::calcMovement()
@ -457,7 +456,7 @@ bool NodeTrackerManipulator::calcMovement()
else else
{ {
osg::Matrix rotation_matrix; osg::Matrix rotation_matrix;
rotation_matrix.set(_rotation); rotation_matrix.makeRotate(_rotation);
osg::Vec3d lookVector = -getUpVector(rotation_matrix); osg::Vec3d lookVector = -getUpVector(rotation_matrix);
osg::Vec3d sideVector = getSideVector(rotation_matrix); osg::Vec3d sideVector = getSideVector(rotation_matrix);

View File

@ -221,7 +221,7 @@ void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix)
{ {
_center = eye+ lookVector; _center = eye+ lookVector;
_distance = lookVector.length(); _distance = lookVector.length();
matrix.get(_rotation); _rotation = matrix.getRotate();
return; return;
} }
@ -261,7 +261,7 @@ void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix)
matrix* matrix*
osg::Matrixd::translate(-_center); osg::Matrixd::translate(-_center);
rotation_matrix.get(_rotation); _rotation = rotation_matrix.getRotate();
hitFound = true; hitFound = true;
} }
@ -372,8 +372,7 @@ void TerrainManipulator::computePosition(const osg::Vec3d& eye,const osg::Vec3d&
osg::Matrixd rotation_matrix = osg::Matrixd::lookAt(eye,center,up); osg::Matrixd rotation_matrix = osg::Matrixd::lookAt(eye,center,up);
rotation_matrix.get(_rotation); _rotation = rotation_matrix.getRotate().inverse();
_rotation = _rotation.inverse();
CoordinateFrame coordinateFrame = getCoordinateFrame(_center); CoordinateFrame coordinateFrame = getCoordinateFrame(_center);
_previousUp = getUpVector(coordinateFrame); _previousUp = getUpVector(coordinateFrame);
@ -421,7 +420,7 @@ bool TerrainManipulator::calcMovement()
else else
{ {
osg::Matrix rotation_matrix; osg::Matrix rotation_matrix;
rotation_matrix.set(_rotation); rotation_matrix.makeRotate(_rotation);
osg::Vec3d lookVector = -getUpVector(rotation_matrix); osg::Vec3d lookVector = -getUpVector(rotation_matrix);
osg::Vec3d sideVector = getSideVector(rotation_matrix); osg::Vec3d sideVector = getSideVector(rotation_matrix);
@ -459,7 +458,7 @@ bool TerrainManipulator::calcMovement()
double scale = -0.3f*_distance; double scale = -0.3f*_distance;
osg::Matrix rotation_matrix; osg::Matrix rotation_matrix;
rotation_matrix.set(_rotation); rotation_matrix.makeRotate(_rotation);
// compute look vector. // compute look vector.
@ -577,7 +576,7 @@ void TerrainManipulator::clampOrientation()
if (_rotationMode==ELEVATION_AZIM) if (_rotationMode==ELEVATION_AZIM)
{ {
osg::Matrix rotation_matrix; osg::Matrix rotation_matrix;
rotation_matrix.set(_rotation); rotation_matrix.makeRotate(_rotation);
osg::Vec3d lookVector = -getUpVector(rotation_matrix); osg::Vec3d lookVector = -getUpVector(rotation_matrix);
osg::Vec3d upVector = getFrontVector(rotation_matrix); osg::Vec3d upVector = getFrontVector(rotation_matrix);

View File

@ -189,7 +189,7 @@ void TrackballManipulator::addMouseEvent(const GUIEventAdapter& ea)
void TrackballManipulator::setByMatrix(const osg::Matrixd& matrix) void TrackballManipulator::setByMatrix(const osg::Matrixd& matrix)
{ {
_center = osg::Vec3(0.0f,0.0f,-_distance)*matrix; _center = osg::Vec3(0.0f,0.0f,-_distance)*matrix;
matrix.get(_rotation); _rotation = matrix.getRotate();
} }
osg::Matrixd TrackballManipulator::getMatrix() const osg::Matrixd TrackballManipulator::getMatrix() const
@ -221,8 +221,7 @@ void TrackballManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3&
_center = center; _center = center;
_distance = lv.length(); _distance = lv.length();
rotation_matrix.get(_rotation); _rotation = rotation_matrix.getRotate().inverse();
_rotation = _rotation.inverse();
} }
@ -276,7 +275,7 @@ bool TrackballManipulator::calcMovement()
float scale = -0.3f*_distance; float scale = -0.3f*_distance;
osg::Matrix rotation_matrix; osg::Matrix rotation_matrix;
rotation_matrix.set(_rotation); rotation_matrix.makeRotate(_rotation);
osg::Vec3 dv(dx*scale,dy*scale,0.0f); osg::Vec3 dv(dx*scale,dy*scale,0.0f);

View File

@ -666,7 +666,7 @@ void Viewer::frame()
// record the position of the view point. // record the position of the view point.
osg::Matrixd matrix; osg::Matrixd matrix;
matrix.invert(getViewMatrix()); matrix.invert(getViewMatrix());
matrix.get(_orientation); _orientation = matrix.getRotate();
double newPosition[3]; double newPosition[3];
newPosition[0] = matrix(3,0); newPosition[0] = matrix(3,0);

View File

@ -45,8 +45,6 @@ BEGIN_VALUE_REFLECTOR(osg::Matrixd)
I_Method1(void, set, IN, float const *const, ptr); I_Method1(void, set, IN, float const *const, ptr);
I_Method1(void, set, IN, double const *const, ptr); I_Method1(void, set, IN, double const *const, ptr);
I_Method16(void, set, IN, osg::Matrixd::value_type, a00, IN, osg::Matrixd::value_type, a01, IN, osg::Matrixd::value_type, a02, IN, osg::Matrixd::value_type, a03, IN, osg::Matrixd::value_type, a10, IN, osg::Matrixd::value_type, a11, IN, osg::Matrixd::value_type, a12, IN, osg::Matrixd::value_type, a13, IN, osg::Matrixd::value_type, a20, IN, osg::Matrixd::value_type, a21, IN, osg::Matrixd::value_type, a22, IN, osg::Matrixd::value_type, a23, IN, osg::Matrixd::value_type, a30, IN, osg::Matrixd::value_type, a31, IN, osg::Matrixd::value_type, a32, IN, osg::Matrixd::value_type, a33); I_Method16(void, set, IN, osg::Matrixd::value_type, a00, IN, osg::Matrixd::value_type, a01, IN, osg::Matrixd::value_type, a02, IN, osg::Matrixd::value_type, a03, IN, osg::Matrixd::value_type, a10, IN, osg::Matrixd::value_type, a11, IN, osg::Matrixd::value_type, a12, IN, osg::Matrixd::value_type, a13, IN, osg::Matrixd::value_type, a20, IN, osg::Matrixd::value_type, a21, IN, osg::Matrixd::value_type, a22, IN, osg::Matrixd::value_type, a23, IN, osg::Matrixd::value_type, a30, IN, osg::Matrixd::value_type, a31, IN, osg::Matrixd::value_type, a32, IN, osg::Matrixd::value_type, a33);
I_Method1(void, set, IN, const osg::Quat &, q);
I_Method1(void, get, IN, osg::Quat &, q);
I_Method0(osg::Matrixd::value_type *, ptr); I_Method0(osg::Matrixd::value_type *, ptr);
I_Method0(const osg::Matrixd::value_type *, ptr); I_Method0(const osg::Matrixd::value_type *, ptr);
I_Method0(void, makeIdentity); I_Method0(void, makeIdentity);
@ -86,6 +84,8 @@ BEGIN_VALUE_REFLECTOR(osg::Matrixd)
I_Method1(osg::Vec4d, preMult, IN, const osg::Vec4d &, v); I_Method1(osg::Vec4d, preMult, IN, const osg::Vec4d &, v);
I_Method1(osg::Vec4f, postMult, IN, const osg::Vec4f &, v); I_Method1(osg::Vec4f, postMult, IN, const osg::Vec4f &, v);
I_Method1(osg::Vec4d, postMult, IN, const osg::Vec4d &, v); I_Method1(osg::Vec4d, postMult, IN, const osg::Vec4d &, v);
I_Method1(void, setRotate, IN, const osg::Quat &, q);
I_Method0(osg::Quat, getRotate);
I_Method3(void, setTrans, IN, osg::Matrixd::value_type, tx, IN, osg::Matrixd::value_type, ty, IN, osg::Matrixd::value_type, tz); I_Method3(void, setTrans, IN, osg::Matrixd::value_type, tx, IN, osg::Matrixd::value_type, ty, IN, osg::Matrixd::value_type, tz);
I_Method1(void, setTrans, IN, const osg::Vec3f &, v); I_Method1(void, setTrans, IN, const osg::Vec3f &, v);
I_Method1(void, setTrans, IN, const osg::Vec3d &, v); I_Method1(void, setTrans, IN, const osg::Vec3d &, v);
@ -95,6 +95,7 @@ BEGIN_VALUE_REFLECTOR(osg::Matrixd)
I_Method1(void, preMult, IN, const osg::Matrixd &, x); I_Method1(void, preMult, IN, const osg::Matrixd &, x);
I_Method1(void, postMult, IN, const osg::Matrixd &, x); I_Method1(void, postMult, IN, const osg::Matrixd &, x);
I_WriteOnlyProperty(float const *const, ); I_WriteOnlyProperty(float const *const, );
I_ReadOnlyProperty(osg::Quat, Rotate);
I_ReadOnlyProperty(osg::Vec3d, Scale); I_ReadOnlyProperty(osg::Vec3d, Scale);
I_ReadOnlyProperty(osg::Vec3d, Trans); I_ReadOnlyProperty(osg::Vec3d, Trans);
END_REFLECTOR END_REFLECTOR

View File

@ -45,8 +45,6 @@ BEGIN_VALUE_REFLECTOR(osg::Matrixf)
I_Method1(void, set, IN, float const *const, ptr); I_Method1(void, set, IN, float const *const, ptr);
I_Method1(void, set, IN, double const *const, ptr); I_Method1(void, set, IN, double const *const, ptr);
I_Method16(void, set, IN, osg::Matrixf::value_type, a00, IN, osg::Matrixf::value_type, a01, IN, osg::Matrixf::value_type, a02, IN, osg::Matrixf::value_type, a03, IN, osg::Matrixf::value_type, a10, IN, osg::Matrixf::value_type, a11, IN, osg::Matrixf::value_type, a12, IN, osg::Matrixf::value_type, a13, IN, osg::Matrixf::value_type, a20, IN, osg::Matrixf::value_type, a21, IN, osg::Matrixf::value_type, a22, IN, osg::Matrixf::value_type, a23, IN, osg::Matrixf::value_type, a30, IN, osg::Matrixf::value_type, a31, IN, osg::Matrixf::value_type, a32, IN, osg::Matrixf::value_type, a33); I_Method16(void, set, IN, osg::Matrixf::value_type, a00, IN, osg::Matrixf::value_type, a01, IN, osg::Matrixf::value_type, a02, IN, osg::Matrixf::value_type, a03, IN, osg::Matrixf::value_type, a10, IN, osg::Matrixf::value_type, a11, IN, osg::Matrixf::value_type, a12, IN, osg::Matrixf::value_type, a13, IN, osg::Matrixf::value_type, a20, IN, osg::Matrixf::value_type, a21, IN, osg::Matrixf::value_type, a22, IN, osg::Matrixf::value_type, a23, IN, osg::Matrixf::value_type, a30, IN, osg::Matrixf::value_type, a31, IN, osg::Matrixf::value_type, a32, IN, osg::Matrixf::value_type, a33);
I_Method1(void, set, IN, const osg::Quat &, q);
I_Method1(void, get, IN, osg::Quat &, q);
I_Method0(osg::Matrixf::value_type *, ptr); I_Method0(osg::Matrixf::value_type *, ptr);
I_Method0(const osg::Matrixf::value_type *, ptr); I_Method0(const osg::Matrixf::value_type *, ptr);
I_Method0(void, makeIdentity); I_Method0(void, makeIdentity);
@ -86,6 +84,8 @@ BEGIN_VALUE_REFLECTOR(osg::Matrixf)
I_Method1(osg::Vec4d, preMult, IN, const osg::Vec4d &, v); I_Method1(osg::Vec4d, preMult, IN, const osg::Vec4d &, v);
I_Method1(osg::Vec4f, postMult, IN, const osg::Vec4f &, v); I_Method1(osg::Vec4f, postMult, IN, const osg::Vec4f &, v);
I_Method1(osg::Vec4d, postMult, IN, const osg::Vec4d &, v); I_Method1(osg::Vec4d, postMult, IN, const osg::Vec4d &, v);
I_Method1(void, setRotate, IN, const osg::Quat &, q);
I_Method0(osg::Quat, getRotate);
I_Method3(void, setTrans, IN, osg::Matrixf::value_type, tx, IN, osg::Matrixf::value_type, ty, IN, osg::Matrixf::value_type, tz); I_Method3(void, setTrans, IN, osg::Matrixf::value_type, tx, IN, osg::Matrixf::value_type, ty, IN, osg::Matrixf::value_type, tz);
I_Method1(void, setTrans, IN, const osg::Vec3f &, v); I_Method1(void, setTrans, IN, const osg::Vec3f &, v);
I_Method1(void, setTrans, IN, const osg::Vec3d &, v); I_Method1(void, setTrans, IN, const osg::Vec3d &, v);
@ -95,6 +95,7 @@ BEGIN_VALUE_REFLECTOR(osg::Matrixf)
I_Method1(void, preMult, IN, const osg::Matrixf &, x); I_Method1(void, preMult, IN, const osg::Matrixf &, x);
I_Method1(void, postMult, IN, const osg::Matrixf &, x); I_Method1(void, postMult, IN, const osg::Matrixf &, x);
I_WriteOnlyProperty(float const *const, ); I_WriteOnlyProperty(float const *const, );
I_ReadOnlyProperty(osg::Quat, Rotate);
I_ReadOnlyProperty(osg::Vec3d, Scale); I_ReadOnlyProperty(osg::Vec3d, Scale);
I_ReadOnlyProperty(osg::Vec3d, Trans); I_ReadOnlyProperty(osg::Vec3d, Trans);
END_REFLECTOR END_REFLECTOR