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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
// }
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
Reference in New Issue
Block a user