From e17261c45fbbb9a9d82622287e6cda5b6c06aaca Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 17 Apr 2002 09:48:19 +0000 Subject: [PATCH] Changed the osg::Billboard comution so that it get passed in the current modelview matrix rathan than an identity matrix, this matrix is then modified locally. Changed the osg::Matrix set methods so they are inline. Added a few useful comments to MemoryManager.cpp to help people understand the assert's better. --- include/osg/Billboard | 10 +++++----- include/osg/Matrix | 21 +++++++++++++++++++-- include/osgUtil/CullVisitor | 6 +++--- src/osg/Billboard.cpp | 7 ++++++- src/osg/Matrix.cpp | 13 ------------- src/osg/MemoryManager.cpp | 14 +++++++++----- src/osgUtil/CullVisitor.cpp | 27 +++++++-------------------- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/include/osg/Billboard b/include/osg/Billboard index 13afb5daf..fb57066a0 100644 --- a/include/osg/Billboard +++ b/include/osg/Billboard @@ -83,7 +83,7 @@ class SG_EXPORT Billboard : public Geode struct ComputeBillboardCallback : public osg::Referenced { /** Get the transformation matrix which moves from local coords to world coords.*/ - virtual const bool computeMatrix(const Matrix& matrix, const Billboard* billboard, const Vec3& eye_local, const Vec3& up_local, const Vec3& pos_local) const; + virtual const bool computeMatrix(const Matrix& modelview, const Billboard* billboard, const Vec3& eye_local, const Vec3& pos_local) const; }; friend struct osg::Billboard::ComputeBillboardCallback; @@ -99,12 +99,12 @@ class SG_EXPORT Billboard : public Geode const ComputeBillboardCallback* getComputeBillboardCallback() const { return _computeBillboardCallback.get(); } - inline const bool getMatrix(Matrix& matrix, const Vec3& eye_local, const Vec3& up_local, const Vec3& pos_local) const + inline const bool getMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const { if (_computeBillboardCallback.valid()) - return _computeBillboardCallback->computeMatrix(matrix,this,eye_local,up_local,pos_local); + return _computeBillboardCallback->computeMatrix(modelview,this,eye_local,pos_local); else - return computeMatrix(matrix,eye_local,up_local,pos_local); + return computeMatrix(modelview,eye_local,pos_local); } protected: @@ -113,7 +113,7 @@ class SG_EXPORT Billboard : public Geode virtual const bool computeBound() const; - virtual const bool computeMatrix(Matrix& matrix, const Vec3& eye_local, const Vec3& up_local, const Vec3& pos_local) const; + virtual const bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const; enum AxisAligned { diff --git a/include/osg/Matrix b/include/osg/Matrix index ec9c98d77..0908bd151 100644 --- a/include/osg/Matrix +++ b/include/osg/Matrix @@ -12,6 +12,7 @@ #include #include +#include namespace osg { @@ -37,7 +38,7 @@ class SG_EXPORT Matrix : public Object virtual ~Matrix() {} - Matrix& operator = (const Matrix& ); + int compare(const Matrix& m) const { return memcmp(_mat,m._mat,sizeof(_mat)); } @@ -56,7 +57,23 @@ class SG_EXPORT Matrix : public Object - void set( float const * const ); + inline Matrix& operator = (const Matrix& other) + { + if( &other == this ) return *this; + set((float const * const)(other._mat)); + return *this; + } + + inline void set(const Matrix& other) + { + set((float const * const)(other._mat)); + } + + inline void set(float const * const ptr) + { + std::copy(ptr,ptr+16,(float*)(_mat)); + } + void set( float a00, float a01, float a02, float a03, float a10, float a11, float a12, float a13, float a20, float a21, float a22, float a23, diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index 2b4ec9e43..0d889df15 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -408,7 +408,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor MatrixList _reuseMatrixList; unsigned int _currentReuseMatrixIndex; - inline osg::Matrix* createOrReuseMatrix() + inline osg::Matrix* createOrReuseMatrix(const osg::Matrix value) { // skip of any already reused matrix. while (_currentReuseMatrixIndex<_reuseMatrixList.size() && @@ -423,12 +423,12 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor if (_currentReuseMatrixIndex<_reuseMatrixList.size()) { osg::Matrix* matrix = _reuseMatrixList[_currentReuseMatrixIndex++].get(); - matrix->makeIdentity(); + matrix->set(value); return matrix; } // otherwise need to create new matrix. - osg::Matrix* matrix = new osg::Matrix(); + osg::Matrix* matrix = new osg::Matrix(value); _reuseMatrixList.push_back(matrix); ++_currentReuseMatrixIndex; return matrix; diff --git a/src/osg/Billboard.cpp b/src/osg/Billboard.cpp index ca13b12c3..9d7a8514a 100644 --- a/src/osg/Billboard.cpp +++ b/src/osg/Billboard.cpp @@ -98,8 +98,11 @@ const bool Billboard::removeDrawable( Drawable *gset ) return false; } -const bool Billboard::computeMatrix(Matrix& matrix, const Vec3& eye_local, const Vec3& /*up_local*/, const Vec3& pos_local) const +const bool Billboard::computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const { + //Vec3 up_local(matrix(0,1),matrix(1,1),matrix(2,1)); + + Matrix matrix; Vec3 ev(pos_local-eye_local); switch(_cachedMode) @@ -161,6 +164,8 @@ const bool Billboard::computeMatrix(Matrix& matrix, const Vec3& eye_local, const matrix.setTrans(pos_local); + modelview.preMult(matrix); + return true; } diff --git a/src/osg/Matrix.cpp b/src/osg/Matrix.cpp index 9037da1d2..81a443319 100644 --- a/src/osg/Matrix.cpp +++ b/src/osg/Matrix.cpp @@ -50,19 +50,6 @@ Matrix::Matrix( float a00, float a01, float a02, float a03, SET_ROW(3, a30, a31, a32, a33 ) } -Matrix& Matrix::operator = (const Matrix& other ) -{ - if( &other == this ) return *this; - set((const float*)other._mat); - return *this; -} - -void Matrix::set( float const * const def ) -{ - memcpy( _mat, def, sizeof(_mat) ); -} - - void Matrix::set( float a00, float a01, float a02, float a03, float a10, float a11, float a12, float a13, float a20, float a21, float a22, float a23, diff --git a/src/osg/MemoryManager.cpp b/src/osg/MemoryManager.cpp index 2b6767f62..d418b4316 100644 --- a/src/osg/MemoryManager.cpp +++ b/src/osg/MemoryManager.cpp @@ -1342,12 +1342,16 @@ void m_deallocator(const char *sourceFile, const unsigned int sourceLine, con // If you hit this assert, you were trying to deallocate RAM that was not allocated in a way that is compatible with // the deallocation method requested. In other words, you have a allocation/deallocation mismatch. + // Types of errors in your code look for are AllocationType DeallocationType but should Dealloc with + // new delete [] or free delete + // new [] delete, or free delete [] + // malloc delete, delete [] free m_assert((deallocationType == m_alloc_delete && au->allocationType == m_alloc_new ) || - (deallocationType == m_alloc_delete_array && au->allocationType == m_alloc_new_array) || - (deallocationType == m_alloc_free && au->allocationType == m_alloc_malloc ) || - (deallocationType == m_alloc_free && au->allocationType == m_alloc_calloc ) || - (deallocationType == m_alloc_free && au->allocationType == m_alloc_realloc ) || - (deallocationType == m_alloc_unknown ) ); + (deallocationType == m_alloc_delete_array && au->allocationType == m_alloc_new_array) || + (deallocationType == m_alloc_free && au->allocationType == m_alloc_malloc ) || + (deallocationType == m_alloc_free && au->allocationType == m_alloc_calloc ) || + (deallocationType == m_alloc_free && au->allocationType == m_alloc_realloc ) || + (deallocationType == m_alloc_unknown ) ); // If you hit this assert, then the "break on dealloc" flag for this allocation unit is set. Interrogate the 'au' // variable to determine information about this allocation unit. diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 017fa3384..33ecf38de 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -452,8 +452,7 @@ void CullVisitor::apply(Billboard& node) if (node_state) pushStateSet(node_state); const Vec3& eye_local = getEyeLocal(); - const Vec3& up_local = getUpLocal(); - Matrix* matrix = getCurrentMatrix(); + const Matrix& modelview = getModelViewMatrix(); for(int i=0;ipostMult(*matrix); - } StateSet* stateset = drawable->getStateSet(); @@ -480,14 +476,7 @@ void CullVisitor::apply(Billboard& node) { Vec3 center; - if (matrix) - { - center = pos*(*matrix); - } - else - { - center = pos; - } + center = pos*modelview; float depth; switch(_tsm) @@ -576,8 +565,7 @@ void CullVisitor::apply(Transform& node) StateSet* node_state = node.getStateSet(); if (node_state) pushStateSet(node_state); - ref_ptr matrix = createOrReuseMatrix(); - *matrix = *getCurrentMatrix(); + ref_ptr matrix = createOrReuseMatrix(getModelViewMatrix()); node.getLocalToWorldMatrix(*matrix,this); pushModelViewMatrix(matrix.get()); @@ -608,8 +596,7 @@ void CullVisitor::apply(Projection& node) StateSet* node_state = node.getStateSet(); if (node_state) pushStateSet(node_state); - ref_ptr matrix = createOrReuseMatrix(); - *matrix = node.getMatrix(); + ref_ptr matrix = createOrReuseMatrix(node.getMatrix()); pushProjectionMatrix(matrix.get()); handle_cull_callbacks_and_traverse(node);