2003-01-10 17:25:42 +08:00
|
|
|
#include "Matrix.h"
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2003-01-10 17:25:42 +08:00
|
|
|
bool readMatrix(osg::Matrix& matrix, osgDB::Input& fr)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
|
|
|
bool iteratorAdvanced = false;
|
2003-01-10 17:25:42 +08:00
|
|
|
|
|
|
|
if (fr.matchSequence("Matrix {"))
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2003-01-10 17:25:42 +08:00
|
|
|
int entry = fr[0].getNoNestedBrackets();
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2003-01-10 17:25:42 +08:00
|
|
|
fr += 2;
|
|
|
|
|
|
|
|
int row=0;
|
|
|
|
int col=0;
|
2003-09-03 18:47:25 +08:00
|
|
|
double v;
|
2003-01-10 17:25:42 +08:00
|
|
|
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
if (fr[0].getFloat(v))
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2003-09-03 18:47:25 +08:00
|
|
|
matrix(row,col)=v;
|
2003-01-10 17:25:42 +08:00
|
|
|
++col;
|
|
|
|
if (col>=4)
|
|
|
|
{
|
|
|
|
col = 0;
|
|
|
|
++row;
|
|
|
|
}
|
|
|
|
++fr;
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2003-01-10 17:25:42 +08:00
|
|
|
else fr.advanceOverCurrentFieldOrBlock();
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
iteratorAdvanced = true;
|
2003-01-10 17:25:42 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
return iteratorAdvanced;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-10 17:25:42 +08:00
|
|
|
bool writeMatrix(const osg::Matrix& matrix, osgDB::Output& fw)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2003-01-24 17:35:05 +08:00
|
|
|
fw.indent() << "Matrix {" << std::endl;
|
2003-01-10 17:25:42 +08:00
|
|
|
fw.moveIn();
|
2001-12-15 18:00:43 +08:00
|
|
|
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;
|
2003-01-10 17:25:42 +08:00
|
|
|
fw.moveOut();
|
2003-01-24 17:35:05 +08:00
|
|
|
fw.indent() << "}"<< std::endl;
|
2001-09-20 05:08:56 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|