Added a Matrix::value_type typedef'd trait into osg::Matrix, defaulting its

value to float, and converted the internal code across to use value_type.  This
allows Matrix to be converted to use double's simply by change the definition
of value_type.  Added Matrix::glLoadlMatrix and Matrix::glMultMatrix() to
help encapsulate the changes between float and double matrix usage.

Updated code that uses Matrix so it doesn't assume float or double matrices.
This commit is contained in:
Robert Osfield
2003-09-03 10:47:25 +00:00
parent 9a5ab0ac47
commit bd44cfcfd8
14 changed files with 250 additions and 248 deletions

View File

@@ -370,15 +370,20 @@ osg::Vec4Array* DataInputStream::readVec4Array(){
return a;
}
osg::Matrix DataInputStream::readMatrix(){
osg::Matrix DataInputStream::readMatrix()
{
osg::Matrix mat;
_istream->read((char*)(mat.ptr()), FLOATSIZE*16);
for(int r=0;r<4;r++)
{
for(int c=0;c<4;c++)
{
mat(r,c) = readFloat();
}
}
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readMatrix(): Failed to read Matrix array.");
// float* p = mat.ptr();
// for(int i=0;i<16;i++){
// p[i] = readFloat();
// }
return mat;
}

View File

@@ -260,10 +260,14 @@ void DataOutputStream::writeVec4Array(osg::Vec4Array* a){
}
}
void DataOutputStream::writeMatrix(osg::Matrix mat){
float* p = mat.ptr();
for(int i=0;i<16;i++){
writeFloat(p[i]);
void DataOutputStream::writeMatrix(const osg::Matrix& mat)
{
for(int r=0;r<4;r++)
{
for(int c=0;c<4;c++)
{
writeFloat(mat(r,c));
}
}
}

View File

@@ -52,7 +52,7 @@ public:
void writeVec2Array(osg::Vec2Array* a);
void writeVec3Array(osg::Vec3Array* a);
void writeVec4Array(osg::Vec4Array* a);
void writeMatrix(osg::Matrix mat);
void writeMatrix(const osg::Matrix& mat);
void writeStateSet(osg::StateSet* stateset);
void writeStateAttribute(osg::StateAttribute* sa);

View File

@@ -43,11 +43,13 @@ bool DOFTransform_readLocalData(Object& obj, Input& fr)
{
osg::Matrix matrix;
int k=0;
double v;
for(int i=0;i<4;++i)
{
for(int j=0;j<4;++j)
{
fr[k].getFloat(matrix(i,j));
fr[k].getDouble(v);
matrix(i,j)=v;
k++;
}
}

View File

@@ -13,10 +13,12 @@ bool readMatrix(osg::Matrix& matrix, osgDB::Input& fr)
int row=0;
int col=0;
double v;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
if (fr[0].getFloat(matrix(row,col)))
if (fr[0].getDouble(v))
{
matrix(row,col)=v;
++col;
if (col>=4)
{

View File

@@ -39,11 +39,13 @@ bool TexMat_readLocalData(Object& obj, Input& fr)
Matrix& matrix = texmat.getMatrix();
int k=0;
double v;
for(int i=0;i<4;++i)
{
for(int j=0;j<4;++j)
{
fr[k].getFloat(matrix(i,j));
fr[k].getDouble(v);
matrix(i,j)=v;
k++;
}
}