Made the more of the OSG's referenced object desctructors protected to ensure

that they arn't created on the stack inappropriately.

Split the implemention of Matrix up so that it is a simple no referenced counted
class and can be safefly created on the stack.  To support referenced counting a
seperate subclass now exists, this is RefMatrix which inherits from both Matrix and
Object.
This commit is contained in:
Robert Osfield
2003-01-10 09:25:42 +00:00
parent f948a3de7c
commit f36bc69c58
53 changed files with 446 additions and 441 deletions

View File

@@ -48,7 +48,7 @@ Node *makeTank( void )
getDatabaseCenterRadius( dbcenter, &dbradius );
ref_ptr<Matrix> mat = new Matrix(
Matrix mat(
0.05, 0, 0, 0,
0, 0.05, 0, 0,
0, 0, 0.05, 0,
@@ -142,7 +142,7 @@ Node *makeTank( void )
}
for( i = 0; i < c; i++ )
conv( vc[i], *mat, vc[i] );
conv( vc[i], mat, vc[i] );
gset->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,prev_c,c-prev_c));

View File

@@ -123,12 +123,12 @@ void MyCullCallback::doPreRender(osg::Node&, osgUtil::CullVisitor& cv)
zfar *= 1.1f;
// set up projection.
osg::Matrix* projection = new osg::Matrix;
osg::RefMatrix* projection = new osg::RefMatrix;
projection->makeFrustum(-right,right,-top,top,znear,zfar);
cv.pushProjectionMatrix(projection);
osg::Matrix* matrix = new osg::Matrix;
osg::RefMatrix* matrix = new osg::RefMatrix;
matrix->makeLookAt(bs.center()+osg::Vec3(0.0f,2.0f,0.0f)*bs.radius(),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));
cv.pushModelViewMatrix(matrix);

View File

@@ -128,12 +128,12 @@ void MyCullCallback::doPreRender(osg::Node&, osgUtil::CullVisitor& cv)
zfar *= 1.1f;
// set up projection.
osg::Matrix* projection = new osg::Matrix;
osg::RefMatrix* projection = new osg::RefMatrix;
projection->makeFrustum(-right,right,-top,top,znear,zfar);
cv.pushProjectionMatrix(projection);
osg::Matrix* matrix = new osg::Matrix;
osg::RefMatrix* matrix = new osg::RefMatrix;
matrix->makeLookAt(bs.center()+osg::Vec3(0.0f,2.0f,0.0f)*bs.radius(),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));
cv.pushModelViewMatrix(matrix);

View File

@@ -125,12 +125,12 @@ void CreateShadowTextureCullCallback::doPreRender(osg::Node& node, osgUtil::Cull
float right = top;
// set up projection.
osg::Matrix* projection = new osg::Matrix;
osg::RefMatrix* projection = new osg::RefMatrix;
projection->makeFrustum(-right,right,-top,top,znear,zfar);
cv.pushProjectionMatrix(projection);
osg::Matrix* matrix = new osg::Matrix;
osg::RefMatrix* matrix = new osg::RefMatrix;
matrix->makeLookAt(_position,bs.center(),osg::Vec3(0.0f,1.0f,0.0f));

View File

@@ -359,7 +359,7 @@ Vec3 Camera::getSideVector() const
}
void Camera::attachTransform(TransformMode mode, Matrix* matrix)
void Camera::attachTransform(TransformMode mode, RefMatrix* matrix)
{
switch(mode)
{
@@ -369,7 +369,7 @@ void Camera::attachTransform(TransformMode mode, Matrix* matrix)
if (_eyeToModelTransform.valid())
{
_attachedTransformMode = mode;
if (!_modelToEyeTransform.valid()) _modelToEyeTransform = new Matrix;
if (!_modelToEyeTransform.valid()) _modelToEyeTransform = new RefMatrix;
if (!_modelToEyeTransform->invert(*_eyeToModelTransform))
{
notify(WARN)<<"Warning: Camera::attachTransform() failed to invert _modelToEyeTransform"<<std::endl;
@@ -388,7 +388,7 @@ void Camera::attachTransform(TransformMode mode, Matrix* matrix)
if (_modelToEyeTransform.valid())
{
_attachedTransformMode = mode;
if (!_eyeToModelTransform.valid()) _eyeToModelTransform = new Matrix;
if (!_eyeToModelTransform.valid()) _eyeToModelTransform = new RefMatrix;
if (!_eyeToModelTransform->invert(*_modelToEyeTransform))
{
notify(WARN)<<"Warning: Camera::attachTransform() failed to invert _modelToEyeTransform"<<std::endl;

View File

@@ -67,7 +67,7 @@ void CollectOccludersVisitor::apply(osg::Transform& node)
// push the culling mode.
pushCurrentMask();
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(getModelViewMatrix());
ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix());
node.getLocalToWorldMatrix(*matrix,this);
pushModelViewMatrix(matrix.get());
@@ -86,7 +86,7 @@ void CollectOccludersVisitor::apply(osg::Projection& node)
// push the culling mode.
pushCurrentMask();
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(node.getMatrix());
ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(node.getMatrix());
pushProjectionMatrix(matrix.get());
handle_cull_callbacks_and_traverse(node);

View File

@@ -10,7 +10,8 @@ CullStack::CullStack()
_frustumVolume=-1.0f;
_bbCornerNear = 0;
_bbCornerFar = 7;
_currentReuseMatrixIndex=0;
_currentReuseMatrixIndex=0;
_identity = new RefMatrix();
}
@@ -126,7 +127,7 @@ void CullStack::popViewport()
_MVPW_Stack.pop_back();
}
void CullStack::pushProjectionMatrix(Matrix* matrix)
void CullStack::pushProjectionMatrix(RefMatrix* matrix)
{
_projectionStack.push_back(matrix);
@@ -181,7 +182,7 @@ void CullStack::popProjectionMatrix()
popCullingSet();
}
void CullStack::pushModelViewMatrix(Matrix* matrix)
void CullStack::pushModelViewMatrix(RefMatrix* matrix)
{
_modelviewStack.push_back(matrix);

View File

@@ -1,30 +1,17 @@
#include <osg/DisplaySettings>
#include <osg/ref_ptr>
#include <algorithm>
using namespace osg;
using namespace std;
class DisplaySettingsPtr
{
public:
DisplaySettingsPtr() : _ptr(0L) {}
DisplaySettingsPtr(DisplaySettings* t): _ptr(t) {}
DisplaySettingsPtr(const DisplaySettingsPtr& rp):_ptr(rp._ptr) { }
~DisplaySettingsPtr() { if (_ptr) delete _ptr; _ptr=0L; }
inline DisplaySettings* get() { return _ptr; }
DisplaySettings* _ptr;
};
DisplaySettings* DisplaySettings::instance()
{
static DisplaySettingsPtr s_displaySettings = new DisplaySettings;
static ref_ptr<DisplaySettings> s_displaySettings = new DisplaySettings;
return s_displaySettings.get();
}
DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced()
{
copy(vs);

View File

@@ -24,12 +24,12 @@ using namespace osg;
Matrix::Matrix() : Object()
Matrix::Matrix()
{
makeIdentity();
}
Matrix::Matrix( const Matrix& other) : Object()
Matrix::Matrix( const Matrix& other)
{
set( (const float *) other._mat );
}

View File

@@ -5,14 +5,12 @@ using namespace osg;
MatrixTransform::MatrixTransform():
_inverseDirty(false)
{
_matrix = new Matrix;
_inverse = new Matrix;
}
MatrixTransform::MatrixTransform(const MatrixTransform& transform,const CopyOp& copyop):
Transform(transform,copyop),
_matrix(new Matrix(*transform._matrix)),
_inverse(new Matrix(*transform._inverse)),
_matrix(transform._matrix),
_inverse(transform._inverse),
_inverseDirty(transform._inverseDirty)
{
}
@@ -21,8 +19,7 @@ MatrixTransform::MatrixTransform(const Matrix& mat )
{
_referenceFrame = RELATIVE_TO_PARENTS;
_matrix = new Matrix(mat);
_inverse = new Matrix();
_matrix = mat;
_inverseDirty = false;
}
@@ -35,11 +32,11 @@ bool MatrixTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) con
{
if (_referenceFrame==RELATIVE_TO_PARENTS)
{
matrix.preMult(*_matrix);
matrix.preMult(_matrix);
}
else // absolute
{
matrix = *_matrix;
matrix = _matrix;
}
return true;
}

View File

@@ -4,18 +4,17 @@ using namespace osg;
Projection::Projection()
{
_matrix = new Matrix;
}
Projection::Projection(const Projection& projection,const CopyOp& copyop):
Group(projection,copyop),
_matrix(new Matrix(*projection._matrix))
_matrix(projection._matrix)
{
}
Projection::Projection(const Matrix& mat )
{
_matrix = new Matrix(mat);
_matrix = mat;
}

View File

@@ -170,8 +170,8 @@ bool ShadowVolumeOccluder::computeOccluder(const NodePath& nodePath,const Convex
CullingSet& cullingset = cullStack.getCurrentCullingSet();
const Matrix& MV = cullStack.getModelViewMatrix();
const Matrix& P = cullStack.getProjectionMatrix();
const RefMatrix& MV = cullStack.getModelViewMatrix();
const RefMatrix& P = cullStack.getProjectionMatrix();
// take a reference to the NodePath to this occluder.
_nodePath = nodePath;

View File

@@ -10,7 +10,7 @@ using namespace osg;
State::State()
{
_contextID = 0;
_identity = new osg::Matrix(); // default Matrix constructs to identity.
_identity = new osg::RefMatrix(); // default RefMatrix constructs to identity.
_projection = _identity;
_modelView = _identity;

View File

@@ -91,7 +91,7 @@ void VertexProgram::apply(State& state) const
++itr)
{
::glMatrixMode((*itr).first);
::glLoadMatrixf((*itr).second->ptr());
::glLoadMatrixf((*itr).second.ptr());
}
::glMatrixMode(GL_MODELVIEW); // restore matrix mode
}

View File

@@ -28,22 +28,9 @@ void PrintFilePathList(std::ostream& stream,const FilePathList& filepath)
}
}
class RegistryPtr
{
public:
RegistryPtr() : _ptr(0L) {}
RegistryPtr(Registry* t): _ptr(t) {}
RegistryPtr(const RegistryPtr& rp):_ptr(rp._ptr) { }
~RegistryPtr() { if (_ptr) delete _ptr; _ptr=0L; }
inline Registry* get() { return _ptr; }
Registry* _ptr;
};
Registry* Registry::instance()
{
static RegistryPtr s_nodeFactory = new Registry;
static ref_ptr<Registry> s_nodeFactory = new Registry;
return s_nodeFactory.get();
}

View File

@@ -611,14 +611,14 @@ void Viewer::showStats(const unsigned int /*viewport*/)
* RO, July 2001.
*/
Statistics *primStats=new Statistics[maxbins]; // array of bin stats
std::vector<Statistics> primStats(maxbins); // array of bin stats
ViewportList::iterator itr;
for(itr=_viewportList.begin();
itr!=_viewportList.end();
++itr)
{
osgUtil::RenderStage *stage = itr->sceneView->getRenderStage();
stage->getPrims(primStats, maxbins);
stage->getPrims(&primStats.front(), maxbins);
}
int nbinsUsed=(primStats[0].getBins()<maxbins)?primStats[0].getBins():maxbins;
int ntop=0; // offset
@@ -628,7 +628,6 @@ void Viewer::showStats(const unsigned int /*viewport*/)
//osg::notify(osg::INFO) << "ntop "<< ntop<< std::endl;
}
maxbins=(primStats[0].getBins()>maxbins)?primStats[0].getBins():maxbins;
delete [] primStats; // free up
}
if (_printStats==Statistics::STAT_DC) { // yet more stats - read the depth complexity
int wid=_ww, ht=_wh; // temporary local screen size - must change during this section
@@ -1207,12 +1206,12 @@ void Viewer::keyboard(unsigned char key, int x, int y)
cov.pushViewport(sceneView->getViewport());
if (sceneView->getProjectionMatrix()) cov.pushProjectionMatrix(sceneView->getProjectionMatrix());
else if (sceneView->getCamera()) cov.pushProjectionMatrix(new Matrix(sceneView->getCamera()->getProjectionMatrix()));
else cov.pushProjectionMatrix(new Matrix());
else if (sceneView->getCamera()) cov.pushProjectionMatrix(new RefMatrix(sceneView->getCamera()->getProjectionMatrix()));
else cov.pushProjectionMatrix(new RefMatrix());
if (sceneView->getModelViewMatrix()) cov.pushModelViewMatrix(sceneView->getModelViewMatrix());
else if (sceneView->getCamera()) cov.pushModelViewMatrix(new Matrix(sceneView->getCamera()->getModelViewMatrix()));
else cov.pushModelViewMatrix(new Matrix());
else if (sceneView->getCamera()) cov.pushModelViewMatrix(new RefMatrix(sceneView->getCamera()->getModelViewMatrix()));
else cov.pushModelViewMatrix(new RefMatrix());
sceneView->getSceneData()->accept(cov);

View File

@@ -55,7 +55,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
if (!Primitive_readLocalData(fr,geom)) ++fr;
if (!Primitive_readLocalData(fr,geom)) fr.advanceOverCurrentFieldOrBlock();
}
++fr;

View File

@@ -1,64 +1,49 @@
#include "osg/Matrix"
#include "Matrix.h"
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool Matrix_readLocalData(Object& obj, Input& fr);
bool Matrix_writeLocalData(const Object& obj, Output& fw);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_MatrixFuncProxy
(
new osg::Matrix,
"Matrix",
"Object Matrix",
&Matrix_readLocalData,
&Matrix_writeLocalData
);
bool Matrix_readLocalData(Object& obj, Input& fr)
bool readMatrix(osg::Matrix& matrix, osgDB::Input& fr)
{
bool iteratorAdvanced = false;
Matrix& matrix = static_cast<Matrix&>(obj);
bool matched = true;
for(int k=0;k<16 && matched;++k)
if (fr.matchSequence("Matrix {"))
{
matched = fr[k].isFloat();
}
if (matched)
{
int k=0;
for(int i=0;i<4;++i)
int entry = fr[0].getNoNestedBrackets();
fr += 2;
int row=0;
int col=0;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
for(int j=0;j<4;++j)
if (fr[0].getFloat(matrix(row,col)))
{
fr[k].getFloat(matrix(i,j));
k++;
++col;
if (col>=4)
{
col = 0;
++row;
}
++fr;
}
else fr.advanceOverCurrentFieldOrBlock();
}
fr += 16;
iteratorAdvanced = true;
}
}
return iteratorAdvanced;
}
bool Matrix_writeLocalData(const Object& obj, Output& fw)
bool writeMatrix(const osg::Matrix& matrix, osgDB::Output& fw)
{
const Matrix& matrix = static_cast<const Matrix&>(obj);
fw.indent() << "Matrix {";
fw.moveIn();
fw.indent() << matrix(0,0) << " " << matrix(0,1) << " " << matrix(0,2) << " " << matrix(0,3) << std::endl;
fw.indent() << matrix(1,0) << " " << matrix(1,1) << " " << matrix(1,2) << " " << matrix(1,3) << std::endl;
fw.indent() << matrix(2,0) << " " << matrix(2,1) << " " << matrix(2,2) << " " << matrix(2,3) << std::endl;
fw.indent() << matrix(3,0) << " " << matrix(3,1) << " " << matrix(3,2) << " " << matrix(3,3) << std::endl;
fw.moveOut();
fw.indent() << "}";
return true;
}

View File

@@ -4,6 +4,8 @@
#include <osgDB/Input>
#include <osgDB/Output>
#include "Matrix.h"
using namespace osg;
using namespace osgDB;
@@ -54,17 +56,12 @@ bool MatrixTransform_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true;
}
}
static Matrix s_matrix;
}
if (Matrix* tmpMatrix = static_cast<Matrix*>(fr.readObjectOfType(s_matrix)))
Matrix matrix;
if (readMatrix(matrix,fr))
{
transform.setMatrix(*tmpMatrix);
delete tmpMatrix;
transform.setMatrix(matrix);
iteratorAdvanced = true;
}
@@ -76,7 +73,7 @@ bool MatrixTransform_writeLocalData(const Object& obj, Output& fw)
{
const MatrixTransform& transform = static_cast<const MatrixTransform&>(obj);
fw.writeObject(transform.getMatrix());
writeMatrix(transform.getMatrix(),fw);
return true;
}

View File

@@ -5,6 +5,8 @@
#include "osgDB/Input"
#include "osgDB/Output"
#include "Matrix.h"
using namespace osg;
using namespace osgDB;
@@ -27,11 +29,10 @@ bool Projection_readLocalData(Object& obj, Input& fr)
Projection &myobj = static_cast<Projection &>(obj);
bool iteratorAdvanced = false;
static Matrix s_matrix;
if (Matrix* tmpMatrix = static_cast<Matrix*>(fr.readObjectOfType(s_matrix)))
Matrix matrix;
if (readMatrix(matrix,fr))
{
myobj.setMatrix(*tmpMatrix);
myobj.setMatrix(matrix);
iteratorAdvanced = true;
}
@@ -43,7 +44,7 @@ bool Projection_writeLocalData(const Object& obj, Output& fw)
{
const Projection& myobj = static_cast<const Projection&>(obj);
fw.writeObject(myobj.getMatrix());
writeMatrix(myobj.getMatrix(),fw);
return true;
}

View File

@@ -297,106 +297,6 @@ bool Cylinder_writeLocalData(const Object& obj, Output& fw)
}
//////////////////////////////////////////////////////////////////////////////
// forward declare functions to use later.
bool InfinitePlane_readLocalData(Object& obj, Input& fr);
bool InfinitePlane_writeLocalData(const Object& obj, Output& fw);
//register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_InfinitePlaneFuncProxy
(
new osg::InfinitePlane,
"InfinitePlane",
"Object InfinitePlane",
&InfinitePlane_readLocalData,
&InfinitePlane_writeLocalData,
DotOsgWrapper::READ_AND_WRITE
);
bool InfinitePlane_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
//InfinitePlane& infplane = static_cast<InfinitePlane&>(obj);
return iteratorAdvanced;
}
bool InfinitePlane_writeLocalData(const Object& obj, Output& fw)
{
//const InfinitePlane& infplane = static_cast<const InfinitePlane&>(obj);
return true;
}
//////////////////////////////////////////////////////////////////////////////
// forward declare functions to use later.
bool TriangleMesh_readLocalData(Object& obj, Input& fr);
bool TriangleMesh_writeLocalData(const Object& obj, Output& fw);
//register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_TriangleMeshFuncProxy
(
new osg::TriangleMesh,
"TriangleMesh",
"Object ",
&TriangleMesh_readLocalData,
&TriangleMesh_writeLocalData,
DotOsgWrapper::READ_AND_WRITE
);
bool TriangleMesh_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
// TriangleMesh& mesh = static_cast<TriangleMesh&>(obj);
return iteratorAdvanced;
}
bool TriangleMesh_writeLocalData(const Object& obj, Output& fw)
{
// const TriangleMesh& mesh = static_cast<const TriangleMesh&>(obj);
return true;
}
//////////////////////////////////////////////////////////////////////////////
// forward declare functions to use later.
bool ConvexHull_readLocalData(Object& obj, Input& fr);
bool ConvexHull_writeLocalData(const Object& obj, Output& fw);
//register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_ConvexHullFuncProxy
(
new osg::ConvexHull,
"ConvexHull",
"Object ",
&ConvexHull_readLocalData,
&ConvexHull_writeLocalData,
DotOsgWrapper::READ_AND_WRITE
);
bool ConvexHull_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
// ConvexHull& geom = static_cast<ConvexHull&>(obj);
return iteratorAdvanced;
}
bool ConvexHull_writeLocalData(const Object& obj, Output& fw)
{
// const ConvexHull& geom = static_cast<const ConvexHull&>(obj);
return true;
}
//////////////////////////////////////////////////////////////////////////////
// forward declare functions to use later.
bool HeightField_readLocalData(Object& obj, Input& fr);
@@ -632,3 +532,106 @@ bool CompositeShape_writeLocalData(const Object& obj, Output& fw)
}
//
//
// //////////////////////////////////////////////////////////////////////////////
// // forward declare functions to use later.
// bool InfinitePlane_readLocalData(Object& obj, Input& fr);
// bool InfinitePlane_writeLocalData(const Object& obj, Output& fw);
//
// //register the read and write functions with the osgDB::Registry.
// RegisterDotOsgWrapperProxy g_InfinitePlaneFuncProxy
// (
// new osg::InfinitePlane,
// "InfinitePlane",
// "Object InfinitePlane",
// &InfinitePlane_readLocalData,
// &InfinitePlane_writeLocalData,
// DotOsgWrapper::READ_AND_WRITE
// );
//
// bool InfinitePlane_readLocalData(Object& obj, Input& fr)
// {
// bool iteratorAdvanced = false;
//
// //InfinitePlane& infplane = static_cast<InfinitePlane&>(obj);
//
// return iteratorAdvanced;
// }
//
// bool InfinitePlane_writeLocalData(const Object& obj, Output& fw)
// {
// //const InfinitePlane& infplane = static_cast<const InfinitePlane&>(obj);
//
// return true;
// }
//
//
// //////////////////////////////////////////////////////////////////////////////
//
// // forward declare functions to use later.
// bool TriangleMesh_readLocalData(Object& obj, Input& fr);
// bool TriangleMesh_writeLocalData(const Object& obj, Output& fw);
//
// //register the read and write functions with the osgDB::Registry.
// RegisterDotOsgWrapperProxy g_TriangleMeshFuncProxy
// (
// new osg::TriangleMesh,
// "TriangleMesh",
// "Object ",
// &TriangleMesh_readLocalData,
// &TriangleMesh_writeLocalData,
// DotOsgWrapper::READ_AND_WRITE
// );
//
// bool TriangleMesh_readLocalData(Object& obj, Input& fr)
// {
// bool iteratorAdvanced = false;
//
// // TriangleMesh& mesh = static_cast<TriangleMesh&>(obj);
//
// return iteratorAdvanced;
// }
//
// bool TriangleMesh_writeLocalData(const Object& obj, Output& fw)
// {
// // const TriangleMesh& mesh = static_cast<const TriangleMesh&>(obj);
//
// return true;
// }
//
//
// //////////////////////////////////////////////////////////////////////////////
// // forward declare functions to use later.
// bool ConvexHull_readLocalData(Object& obj, Input& fr);
// bool ConvexHull_writeLocalData(const Object& obj, Output& fw);
//
// //register the read and write functions with the osgDB::Registry.
// RegisterDotOsgWrapperProxy g_ConvexHullFuncProxy
// (
// new osg::ConvexHull,
// "ConvexHull",
// "Object ",
// &ConvexHull_readLocalData,
// &ConvexHull_writeLocalData,
// DotOsgWrapper::READ_AND_WRITE
// );
//
// bool ConvexHull_readLocalData(Object& obj, Input& fr)
// {
// bool iteratorAdvanced = false;
//
// // ConvexHull& geom = static_cast<ConvexHull&>(obj);
//
// return iteratorAdvanced;
// }
//
// bool ConvexHull_writeLocalData(const Object& obj, Output& fw)
// {
// // const ConvexHull& geom = static_cast<const ConvexHull&>(obj);
//
// return true;
// }
//
//

View File

@@ -113,7 +113,7 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
{
osg::Matrix matrix = cv->getModelViewMatrix();
osg::Matrix& projection = cv->getProjectionMatrix();
osg::RefMatrix& projection = cv->getProjectionMatrix();
osgUtil::RenderGraph* rg = cv->getCurrentRenderGraph();
if (rg->leaves_empty())

View File

@@ -259,7 +259,7 @@ void CullVisitor::apply(Geode& node)
StateSet* node_state = node.getStateSet();
if (node_state) pushStateSet(node_state);
Matrix& matrix = getModelViewMatrix();
RefMatrix& matrix = getModelViewMatrix();
for(unsigned int i=0;i<node.getNumDrawables();++i)
{
Drawable* drawable = node.getDrawable(i);
@@ -304,7 +304,7 @@ void CullVisitor::apply(Billboard& node)
if (node_state) pushStateSet(node_state);
const Vec3& eye_local = getEyeLocal();
const Matrix& modelview = getModelViewMatrix();
const RefMatrix& modelview = getModelViewMatrix();
for(unsigned int i=0;i<node.getNumDrawables();++i)
{
@@ -314,7 +314,7 @@ void CullVisitor::apply(Billboard& node)
// need to modify isCulled to handle the billboard offset.
// if (isCulled(drawable->getBound())) continue;
Matrix* billboard_matrix = createOrReuseMatrix(modelview);
RefMatrix* billboard_matrix = createOrReuseMatrix(modelview);
node.getMatrix(*billboard_matrix,eye_local,pos);
@@ -347,7 +347,7 @@ void CullVisitor::apply(LightSource& node)
StateSet* node_state = node.getStateSet();
if (node_state) pushStateSet(node_state);
Matrix& matrix = getModelViewMatrix();
RefMatrix& matrix = getModelViewMatrix();
StateAttribute* light = node.getLight();
if (light)
{
@@ -366,7 +366,7 @@ void CullVisitor::apply(ClipNode& node)
StateSet* node_state = node.getStateSet();
if (node_state) pushStateSet(node_state);
Matrix& matrix = getModelViewMatrix();
RefMatrix& matrix = getModelViewMatrix();
const ClipNode::ClipPlaneList& planes = node.getClipPlaneList();
for(ClipNode::ClipPlaneList::const_iterator itr=planes.begin();
@@ -413,7 +413,7 @@ void CullVisitor::apply(Transform& node)
StateSet* node_state = node.getStateSet();
if (node_state) pushStateSet(node_state);
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(getModelViewMatrix());
ref_ptr<RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix());
node.getLocalToWorldMatrix(*matrix,this);
pushModelViewMatrix(matrix.get());
@@ -447,7 +447,7 @@ void CullVisitor::apply(Projection& node)
_computed_znear = FLT_MAX;
_computed_zfar = -FLT_MAX;
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(node.getMatrix());
ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(node.getMatrix());
pushProjectionMatrix(matrix.get());
handle_cull_callbacks_and_traverse(node);
@@ -580,7 +580,7 @@ void CullVisitor::apply(Impostor& node)
// within the impostor distance threshold therefore attempt
// to use impostor instead.
Matrix& matrix = getModelViewMatrix();
RefMatrix& matrix = getModelViewMatrix();
// search for the best fit ImpostorSprite;
ImpostorSprite* impostorSprite = node.findBestImpostorSprite(eyeLocal);
@@ -748,7 +748,7 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
zfar *= 1.1f;
// set up projection.
osg::Matrix* projection = new osg::Matrix;
osg::RefMatrix* projection = new osg::RefMatrix;
if (isPerspectiveProjection)
{
// deal with projection issue move the top and right points
@@ -768,7 +768,7 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
Vec3 rotate_from = bs.center()-eye_local;
Vec3 rotate_to = getLookVectorLocal();
osg::Matrix* rotate_matrix = new osg::Matrix(
osg::RefMatrix* rotate_matrix = new osg::RefMatrix(
osg::Matrix::translate(-eye_local)*
osg::Matrix::rotate(rotate_from,rotate_to)*
osg::Matrix::translate(eye_local)*

View File

@@ -215,15 +215,15 @@ void IntersectVisitor::pushMatrix(const Matrix& matrix)
if (cis->_matrix.valid())
{
nis->_matrix = new Matrix;
nis->_matrix = new RefMatrix;
nis->_matrix->mult(matrix,*(cis->_matrix));
}
else
{
nis->_matrix = new Matrix(matrix);
nis->_matrix = new RefMatrix(matrix);
}
Matrix* inverse_world = new Matrix;
RefMatrix* inverse_world = new RefMatrix;
inverse_world->invert(*(nis->_matrix));
nis->_inverse = inverse_world;
@@ -527,7 +527,7 @@ void IntersectVisitor::apply(Transform& node)
{
if (!enterNode(node)) return;
osg::ref_ptr<Matrix> matrix = new Matrix;
osg::ref_ptr<RefMatrix> matrix = new RefMatrix;
node.getLocalToWorldMatrix(*matrix,this);
pushMatrix(*matrix);

View File

@@ -206,8 +206,8 @@ void SceneView::cull()
_state->setDisplaySettings(_displaySettings.get());
osg::ref_ptr<osg::Matrix> projection = _projectionMatrix.get();
osg::ref_ptr<osg::Matrix> modelview = _modelviewMatrix.get();
osg::ref_ptr<osg::RefMatrix> projection = _projectionMatrix.get();
osg::ref_ptr<osg::RefMatrix> modelview = _modelviewMatrix.get();
if (_camera.valid())
{
@@ -235,15 +235,15 @@ void SceneView::cull()
if (_displaySettings.valid())
_camera->setScreenDistance(_displaySettings->getScreenDistance());
if (!projection) projection = new osg::Matrix(_camera->getProjectionMatrix());
if (!modelview) modelview = new osg::Matrix(_camera->getModelViewMatrix());
if (!projection) projection = new osg::RefMatrix(_camera->getProjectionMatrix());
if (!modelview) modelview = new osg::RefMatrix(_camera->getModelViewMatrix());
//cout <<"fovx="<<_camera->calc_fovx()<<endl;
}
if (!projection) projection = new osg::Matrix();
if (!modelview) modelview = new osg::Matrix();
if (!projection) projection = new osg::RefMatrix();
if (!modelview) modelview = new osg::RefMatrix();
if (!_cullVisitor)
{
@@ -288,18 +288,18 @@ void SceneView::cull()
if (_displaySettings->getStereoMode()==osg::DisplaySettings::LEFT_EYE)
{
// set up the left eye.
osg::ref_ptr<osg::Matrix> projectionLeft = new osg::Matrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
(*projection));
osg::ref_ptr<osg::RefMatrix> projectionLeft = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
(*projection));
osg::ref_ptr<osg::Matrix> modelviewLeft = new osg::Matrix( (*modelview) *
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
es,0.0f,0.0f,1.0f));
osg::ref_ptr<osg::RefMatrix> modelviewLeft = new osg::RefMatrix( (*modelview) *
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
es,0.0f,0.0f,1.0f));
_cullVisitor->setTraversalMask(_cullMaskLeft);
cullStage(projectionLeft.get(),modelviewLeft.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get());
@@ -313,17 +313,17 @@ void SceneView::cull()
else if (_displaySettings->getStereoMode()==osg::DisplaySettings::RIGHT_EYE)
{
// set up the right eye.
osg::ref_ptr<osg::Matrix> projectionRight = new osg::Matrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
(*projection));
osg::ref_ptr<osg::RefMatrix> projectionRight = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
(*projection));
osg::ref_ptr<osg::Matrix> modelviewRight = new osg::Matrix( (*modelview) *
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
-es,0.0f,0.0f,1.0f));
osg::ref_ptr<osg::RefMatrix> modelviewRight = new osg::RefMatrix( (*modelview) *
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
-es,0.0f,0.0f,1.0f));
_cullVisitor->setTraversalMask(_cullMaskRight);
cullStage(projectionRight.get(),modelviewRight.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get());
@@ -348,14 +348,14 @@ void SceneView::cull()
// set up the left eye.
osg::ref_ptr<osg::Matrix> projectionLeft = new osg::Matrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
(*projection));
osg::ref_ptr<osg::RefMatrix> projectionLeft = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
(*projection));
osg::ref_ptr<osg::Matrix> modelviewLeft = new osg::Matrix( (*modelview) *
osg::ref_ptr<osg::RefMatrix> modelviewLeft = new osg::RefMatrix( (*modelview) *
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
@@ -366,17 +366,17 @@ void SceneView::cull()
// set up the right eye.
osg::ref_ptr<osg::Matrix> projectionRight = new osg::Matrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
(*projection));
osg::ref_ptr<osg::RefMatrix> projectionRight = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
(*projection));
osg::ref_ptr<osg::Matrix> modelviewRight = new osg::Matrix( (*modelview) *
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
-es,0.0f,0.0f,1.0f));
osg::ref_ptr<osg::RefMatrix> modelviewRight = new osg::RefMatrix( (*modelview) *
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
-es,0.0f,0.0f,1.0f));
_cullVisitorRight->setTraversalMask(_cullMaskRight);
cullStage(projectionRight.get(),modelviewRight.get(),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get());
@@ -407,7 +407,7 @@ void SceneView::cull()
}
void SceneView::cullStage(osg::Matrix* projection,osg::Matrix* modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage)
void SceneView::cullStage(osg::RefMatrix* projection,osg::RefMatrix* modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage)
{
if (!_sceneData || !_viewport->valid()) return;