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.
This commit is contained in:
Robert Osfield 2002-04-17 09:48:19 +00:00
parent b76888ffb9
commit e17261c45f
7 changed files with 49 additions and 49 deletions

View File

@ -83,7 +83,7 @@ class SG_EXPORT Billboard : public Geode
struct ComputeBillboardCallback : public osg::Referenced struct ComputeBillboardCallback : public osg::Referenced
{ {
/** Get the transformation matrix which moves from local coords to world coords.*/ /** 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; friend struct osg::Billboard::ComputeBillboardCallback;
@ -99,12 +99,12 @@ class SG_EXPORT Billboard : public Geode
const ComputeBillboardCallback* getComputeBillboardCallback() const { return _computeBillboardCallback.get(); } 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()) if (_computeBillboardCallback.valid())
return _computeBillboardCallback->computeMatrix(matrix,this,eye_local,up_local,pos_local); return _computeBillboardCallback->computeMatrix(modelview,this,eye_local,pos_local);
else else
return computeMatrix(matrix,eye_local,up_local,pos_local); return computeMatrix(modelview,eye_local,pos_local);
} }
protected: protected:
@ -113,7 +113,7 @@ class SG_EXPORT Billboard : public Geode
virtual const bool computeBound() const; 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 enum AxisAligned
{ {

View File

@ -12,6 +12,7 @@
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>
#include <algorithm>
namespace osg { namespace osg {
@ -37,7 +38,7 @@ class SG_EXPORT Matrix : public Object
virtual ~Matrix() {} virtual ~Matrix() {}
Matrix& operator = (const Matrix& );
int compare(const Matrix& m) const { return memcmp(_mat,m._mat,sizeof(_mat)); } 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, void set( float a00, float a01, float a02, float a03,
float a10, float a11, float a12, float a13, float a10, float a11, float a12, float a13,
float a20, float a21, float a22, float a23, float a20, float a21, float a22, float a23,

View File

@ -408,7 +408,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
MatrixList _reuseMatrixList; MatrixList _reuseMatrixList;
unsigned int _currentReuseMatrixIndex; unsigned int _currentReuseMatrixIndex;
inline osg::Matrix* createOrReuseMatrix() inline osg::Matrix* createOrReuseMatrix(const osg::Matrix value)
{ {
// skip of any already reused matrix. // skip of any already reused matrix.
while (_currentReuseMatrixIndex<_reuseMatrixList.size() && while (_currentReuseMatrixIndex<_reuseMatrixList.size() &&
@ -423,12 +423,12 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
if (_currentReuseMatrixIndex<_reuseMatrixList.size()) if (_currentReuseMatrixIndex<_reuseMatrixList.size())
{ {
osg::Matrix* matrix = _reuseMatrixList[_currentReuseMatrixIndex++].get(); osg::Matrix* matrix = _reuseMatrixList[_currentReuseMatrixIndex++].get();
matrix->makeIdentity(); matrix->set(value);
return matrix; return matrix;
} }
// otherwise need to create new matrix. // otherwise need to create new matrix.
osg::Matrix* matrix = new osg::Matrix(); osg::Matrix* matrix = new osg::Matrix(value);
_reuseMatrixList.push_back(matrix); _reuseMatrixList.push_back(matrix);
++_currentReuseMatrixIndex; ++_currentReuseMatrixIndex;
return matrix; return matrix;

View File

@ -98,8 +98,11 @@ const bool Billboard::removeDrawable( Drawable *gset )
return false; 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); Vec3 ev(pos_local-eye_local);
switch(_cachedMode) switch(_cachedMode)
@ -161,6 +164,8 @@ const bool Billboard::computeMatrix(Matrix& matrix, const Vec3& eye_local, const
matrix.setTrans(pos_local); matrix.setTrans(pos_local);
modelview.preMult(matrix);
return true; return true;
} }

View File

@ -50,19 +50,6 @@ Matrix::Matrix( float a00, float a01, float a02, float a03,
SET_ROW(3, a30, a31, a32, a33 ) 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, void Matrix::set( float a00, float a01, float a02, float a03,
float a10, float a11, float a12, float a13, float a10, float a11, float a12, float a13,
float a20, float a21, float a22, float a23, float a20, float a21, float a22, float a23,

View File

@ -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 // 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. // 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 ) || 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_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_malloc ) ||
(deallocationType == m_alloc_free && au->allocationType == m_alloc_calloc ) || (deallocationType == m_alloc_free && au->allocationType == m_alloc_calloc ) ||
(deallocationType == m_alloc_free && au->allocationType == m_alloc_realloc ) || (deallocationType == m_alloc_free && au->allocationType == m_alloc_realloc ) ||
(deallocationType == m_alloc_unknown ) ); (deallocationType == m_alloc_unknown ) );
// If you hit this assert, then the "break on dealloc" flag for this allocation unit is set. Interrogate the 'au' // 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. // variable to determine information about this allocation unit.

View File

@ -452,8 +452,7 @@ void CullVisitor::apply(Billboard& node)
if (node_state) pushStateSet(node_state); if (node_state) pushStateSet(node_state);
const Vec3& eye_local = getEyeLocal(); const Vec3& eye_local = getEyeLocal();
const Vec3& up_local = getUpLocal(); const Matrix& modelview = getModelViewMatrix();
Matrix* matrix = getCurrentMatrix();
for(int i=0;i<node.getNumDrawables();++i) for(int i=0;i<node.getNumDrawables();++i)
{ {
@ -465,13 +464,10 @@ void CullVisitor::apply(Billboard& node)
updateCalculatedNearFar(pos); updateCalculatedNearFar(pos);
Matrix* billboard_matrix = createOrReuseMatrix(); Matrix* billboard_matrix = createOrReuseMatrix(modelview);
node.getMatrix(*billboard_matrix,eye_local,up_local,pos);
node.getMatrix(*billboard_matrix,eye_local,pos);
if (matrix)
{
billboard_matrix->postMult(*matrix);
}
StateSet* stateset = drawable->getStateSet(); StateSet* stateset = drawable->getStateSet();
@ -480,14 +476,7 @@ void CullVisitor::apply(Billboard& node)
{ {
Vec3 center; Vec3 center;
if (matrix) center = pos*modelview;
{
center = pos*(*matrix);
}
else
{
center = pos;
}
float depth; float depth;
switch(_tsm) switch(_tsm)
@ -576,8 +565,7 @@ void CullVisitor::apply(Transform& node)
StateSet* node_state = node.getStateSet(); StateSet* node_state = node.getStateSet();
if (node_state) pushStateSet(node_state); if (node_state) pushStateSet(node_state);
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(); ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(getModelViewMatrix());
*matrix = *getCurrentMatrix();
node.getLocalToWorldMatrix(*matrix,this); node.getLocalToWorldMatrix(*matrix,this);
pushModelViewMatrix(matrix.get()); pushModelViewMatrix(matrix.get());
@ -608,8 +596,7 @@ void CullVisitor::apply(Projection& node)
StateSet* node_state = node.getStateSet(); StateSet* node_state = node.getStateSet();
if (node_state) pushStateSet(node_state); if (node_state) pushStateSet(node_state);
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(); ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(node.getMatrix());
*matrix = node.getMatrix();
pushProjectionMatrix(matrix.get()); pushProjectionMatrix(matrix.get());
handle_cull_callbacks_and_traverse(node); handle_cull_callbacks_and_traverse(node);