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

@@ -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;
}