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:
parent
b76888ffb9
commit
e17261c45f
@ -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
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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;i<node.getNumDrawables();++i)
|
||||
{
|
||||
@ -465,13 +464,10 @@ void CullVisitor::apply(Billboard& node)
|
||||
|
||||
updateCalculatedNearFar(pos);
|
||||
|
||||
Matrix* billboard_matrix = createOrReuseMatrix();
|
||||
node.getMatrix(*billboard_matrix,eye_local,up_local,pos);
|
||||
Matrix* billboard_matrix = createOrReuseMatrix(modelview);
|
||||
|
||||
node.getMatrix(*billboard_matrix,eye_local,pos);
|
||||
|
||||
if (matrix)
|
||||
{
|
||||
billboard_matrix->postMult(*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<osg::Matrix> matrix = createOrReuseMatrix();
|
||||
*matrix = *getCurrentMatrix();
|
||||
ref_ptr<osg::Matrix> 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<osg::Matrix> matrix = createOrReuseMatrix();
|
||||
*matrix = node.getMatrix();
|
||||
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(node.getMatrix());
|
||||
pushProjectionMatrix(matrix.get());
|
||||
|
||||
handle_cull_callbacks_and_traverse(node);
|
||||
|
Loading…
Reference in New Issue
Block a user