Renamed osg::Matric::makeIdent() to osg::Matrix::makeIdentity() to make

it consistent with the rest of the osg::Matrix naming.  Updated OSG
distribution to account for new name.

Added support for the STATIC/DYNAMIC osg::Transform::Type to the .osg
ASCII reader/writer plugin and the flt reader plugin.

Removed the non cost version of osg::Transform::getMatrix() as this could
by pass the dirty mechinism.
This commit is contained in:
Robert Osfield
2001-12-15 16:56:39 +00:00
parent def6234d8c
commit cb8025d913
13 changed files with 85 additions and 60 deletions

View File

@@ -18,10 +18,6 @@ class Quat;
class SG_EXPORT Matrix : public Object
{
private:
float _mat[4][4];
bool fully_realized;
public:
META_Object(Matrix);
@@ -56,18 +52,16 @@ class SG_EXPORT Matrix : public Object
float * ptr() { ensureRealized(); return (float *)_mat; }
const float * ptr() const { ensureRealized(); return (const float *)_mat; }
inline void ensureRealized() const { if (!fully_realized) const_cast<Matrix*>(this)->makeIdent();}
inline void ensureRealized() const { if (!fully_realized) const_cast<Matrix*>(this)->makeIdentity();}
void makeIdent();
void makeIdentity();
void makeScale( const Vec3& );
void makeScale( float, float, float );
void makeTranslate( const Vec3& );
void makeTranslate( float, float, float );
//TODO: original preTrans was optimized (M=Tr*M)
// but also has the assumption that M (this) is an affine transformation Matrix
// can I still do something to optimize the same case now?
void makeRotate( const Vec3& from, const Vec3& to );
void makeRotate( float angle, const Vec3& axis );
void makeRotate( float angle, float x, float y, float z );
@@ -77,7 +71,7 @@ class SG_EXPORT Matrix : public Object
bool invert( const Matrix& );
bool invertAffine( const Matrix& );
//basic utility functions to create new matrices or vectors
//basic utility functions to create new matrices
inline static Matrix identity( void );
inline static Matrix scale( const Vec3& );
inline static Matrix scale( float, float, float );
@@ -110,51 +104,57 @@ class SG_EXPORT Matrix : public Object
void preMult( const Matrix& );
void postMult( const Matrix& );
// Helper class to optimize product expressions somewhat
class MatrixProduct {
public:
const Matrix& A;
const Matrix& B;
MatrixProduct( const Matrix& lhs, const Matrix& rhs ) : A(lhs), B(rhs) {}
};
inline MatrixProduct operator * ( const Matrix& other ) const
{ return MatrixProduct(*this, other); }
inline void operator *= ( const Matrix& other )
{ if( this == &other ) {
Matrix temp(other);
postMult( temp );
}
else postMult( other );
}
inline void operator = ( const MatrixProduct& p )
{
if( this == &(p.A)) postMult(p.B);
else if( this == &(p.B)) preMult(p.A);
else mult( p.A, p.B );
{ if( this == &other ) {
Matrix temp(other);
postMult( temp );
}
else postMult( other );
}
Matrix( const MatrixProduct& p ) //allows implicit evaluation of the product
{ mult( p.A, p.B ); }
Matrix operator *( const Matrix &m )
inline Matrix operator * ( const Matrix &m ) const
{
osg::Matrix r;
r.mult(*this,m);
return r;
}
float * operator [] ( int i ) { return &_mat[i][0]; }
// temporarily commented out while waiting for a more generic implementation
// of MatrixProduct proxy class.
// // Helper class to optimize product expressions somewhat
// class MatrixProduct {
// public:
// const Matrix& A;
// const Matrix& B;
//
// MatrixProduct( const Matrix& lhs, const Matrix& rhs ) : A(lhs), B(rhs) {}
// };
//
// inline MatrixProduct operator * ( const Matrix& other ) const
// { return MatrixProduct(*this, other); }
//
// inline void operator = ( const MatrixProduct& p )
// {
// if( this == &(p.A)) postMult(p.B);
// else if( this == &(p.B)) preMult(p.A);
// else mult( p.A, p.B );
// }
//
// Matrix( const MatrixProduct& p ) //allows implicit evaluation of the product
// { mult( p.A, p.B ); }
private:
float _mat[4][4];
bool fully_realized;
};
//static utility methods
inline Matrix Matrix::identity(void)
{
Matrix m;
m.makeIdent();
m.makeIdentity();
return m;
}

View File

@@ -38,10 +38,10 @@ class SG_EXPORT Transform : public Group
* Matrix explicity set the Matrix to STATIC. The default
* value is DYNAMIC.*/
inline void setType(Type type) { _type = type; }
/** Get the Transform Type.*/
inline const Type getType() const { return _type; }
inline Matrix& getMatrix() { return *_matrix; }
inline const Matrix& getMatrix() const { return *_matrix; }
inline void setMatrix(const Matrix& mat )

View File

@@ -323,7 +323,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
if (_currentReuseMatrixIndex<_reuseMatrixList.size())
{
osg::Matrix* matrix = _reuseMatrixList[_currentReuseMatrixIndex++].get();
matrix->makeIdent();
matrix->makeIdentity();
return matrix;
}

View File

@@ -42,7 +42,7 @@ class CameraPacket {
osg::Vec3 lv = _center-_eye;
osg::Matrix matrix;
matrix.makeIdent();
matrix.makeIdentity();
matrix.makeRotate(angle_offset,_up.x(),_up.y(),_up.z());
lv = lv*matrix;

View File

@@ -11,10 +11,10 @@ using namespace osg;
OrientationConverter::OrientationConverter( void )
{
R.makeIdent();
T.makeIdent();
R.makeIdentity();
T.makeIdentity();
_trans_set = false;
S.makeIdent();
S.makeIdentity();
}
void OrientationConverter::setRotation( const Vec3 &from, const Vec3 &to )

View File

@@ -82,7 +82,7 @@ void Billboard::calcRotation(const Vec3& eye_local, const Vec3& pos_local,Matrix
float ev_length = ev.length();
if (ev_length>0.0f)
{
mat.makeIdent();
mat.makeIdentity();
//float rotation_zrotation_z = atan2f(ev.x(),ev.y());
//mat.makeRotate(inRadians(rotation_z),0.0f,0.0f,1.0f);
float inv = 1.0f/ev_length;
@@ -134,7 +134,7 @@ void Billboard::calcRotation(const Vec3& eye_local, const Vec3& pos_local,Matrix
void Billboard::calcTransform(const Vec3& eye_local, const Vec3& pos_local,Matrix& mat) const
{
// mat.makeTranslate(pos_local[0],pos_local[1],pos_local[2]);
// mat.makeIdent();
// mat.makeIdentity();
calcRotation(eye_local,pos_local,mat);
// mat.postTrans(pos_local[0],pos_local[1],pos_local[2]);

View File

@@ -657,7 +657,7 @@ void Camera::calculateMatricesAndClippingVolume() const
else
{
_modelViewMatrix = new Matrix;
_modelViewMatrix->makeIdent();
_modelViewMatrix->makeIdentity();
}
break;
case(USE_EYE_AND_QUATERNION): // not implemented yet, default to eye,center,up.

View File

@@ -95,7 +95,7 @@ void Matrix::setTrans( const Vec3& v )
_mat[3][2] = v[2];
}
void Matrix::makeIdent()
void Matrix::makeIdentity()
{
SET_ROW(0, 1, 0, 0, 0 )
SET_ROW(1, 0, 1, 0, 0 )

View File

@@ -6,7 +6,7 @@ Transform::Transform()
{
_type = DYNAMIC;
_matrix = new osg::Matrix();
_matrix->makeIdent();
_matrix->makeIdentity();
}

View File

@@ -113,8 +113,8 @@ bool FltFile::readFile(const std::string& fileName)
// havn't found file, look in OSGFILEPATH
char* newFileName = osgDB::findFile(fileName.c_str());
if (!newFileName) return NULL;
if (!fin.open(newFileName)) return NULL;
if (!newFileName) return false;
if (!fin.open(newFileName)) return false;
}
osg::notify(osg::INFO) << "Loading " << fileName << " ... " << std::endl;

View File

@@ -551,6 +551,7 @@ osg::Node* ConvertFromFLT::visitDOF(osg::Group* osgParent, DofRecord* rec)
visitPrimaryNode(transform, (PrimNodeRecord*)rec);
transform->setName(rec->getData()->szIdent);
transform->setType(osg::Transform::DYNAMIC);
// note for Judd (and others) shouldn't there be code in here to set up the transform matrix?
// as a transform with an identity matrix is effectively only a
@@ -1088,8 +1089,8 @@ osg::Node* ConvertFromFLT::visitMatrix(osg::Group* osgParent, MatrixRecord* rec)
{
SMatrix* pSMatrix = (SMatrix*)rec->getData();
osg::Transform* dcs = new osg::Transform;
if (dcs)
osg::Transform* transform = new osg::Transform;
if (transform)
{
osg::Matrix m;
for(int i=0;i<4;++i)
@@ -1107,9 +1108,11 @@ osg::Node* ConvertFromFLT::visitMatrix(osg::Group* osgParent, MatrixRecord* rec)
pos *= (float)_unitScale;
m *= osg::Matrix::translate(pos);
dcs->setMatrix(m);
osgParent->addChild(dcs);
return (osg::Node*)dcs;
transform->setType(osg::Transform::STATIC);
transform->setMatrix(m);
osgParent->addChild(transform);
return (osg::Node*)transform;
}
return NULL;

View File

@@ -39,6 +39,22 @@ bool Transform_readLocalData(Object& obj, Input& fr)
Transform& transform = static_cast<Transform&>(obj);
if (fr[0].matchWord("Type"))
{
if (fr[1].matchWord("DYNAMIC"))
{
transform.setType(osg::Transform::DYNAMIC);
fr +=2 ;
}
else if (fr[1].matchWord("STATIC"))
{
transform.setType(osg::Transform::STATIC);
fr +=2 ;
}
}
static Matrix s_matrix;
if (Matrix* tmpMatrix = static_cast<Matrix*>(fr.readObjectOfType(s_matrix)))
@@ -59,6 +75,12 @@ bool Transform_writeLocalData(const Object& obj, Output& fw)
{
const Transform& transform = static_cast<const Transform&>(obj);
switch(transform.getType())
{
case(osg::Transform::STATIC): fw.indent() << "Type STATIC" << std::endl;
default: fw.indent() << "Type DYNAMIC" << std::endl;
}
fw.writeObject(transform.getMatrix());
return true;

View File

@@ -367,7 +367,7 @@ void Optimizer::FlattenStaticTransformsVisitor::apply(osg::Transform& transform)
_transformList.insert(&transform);
// reset the matrix to identity.
transform.getMatrix().makeIdent();
transform.setMatrix(osg::Matrix::identity());
transform.dirtyBound();