Page 1 of 1

I need access to CMatrix4 M property, but is private.

Posted: Fri Jul 13, 2007 10:02 pm
by sir_gon
I have a code that acceded thus to the members of a matrix:

Code: Select all

matrix4 Matrix;

NewtonBodyGetMatrix(body,(dFloat*)&Matrix.M[0]);
But now M is private. I cant access to this property directly.

I proved with the method to pointer (), but it did not work to me or I applied it bad.

Posted: Fri Jul 13, 2007 10:10 pm
by hybrid
Just replace &Matrix.M[0] by Matrix.pointer(). Will work for sure.

Posted: Fri Jul 13, 2007 10:27 pm
by sir_gon
wow, now i can compile. :D

But, now I do not know like replacing this:

Code: Select all

matrix4 RowMaj2ColumnMaj(matrix4 RowMat)
{
   int Row,Col;
   int i=0;
   matrix4 ColMat=RowMat;

   dFloat Matriz[4][4];

   for(Col=0;Col<4;Col++)
   {
      for (Row=0;Row<4;Row++)
      {
         Matriz[Row][Col]=(dFloat)RowMat.M[i];
         i++;
      }
   }

   i=0;
   for (Row=0;Row<4;Row++)
   {
      for(Col=0;Col<4;Col++)
      {
         ColMat.M[i]=(f32)Matriz[Row][Col];
         i++;
      }
   }

   return ColMat;
}

it's my idea or this code is the same of algoritm of transposed matrix?

if it is thus, he would not be better to replace all that by:

Code: Select all

matrix4 RowMaj2ColumnMaj(matrix4 RowMat)
{
   matrix4 ColMat=RowMat;

   ColMat.getTransposed( RowMat );

   return ColMat;

}
?

Posted: Fri Jul 13, 2007 10:49 pm
by hybrid
Yes, you can use transpose. But you should avoid creating copies fo the matrices as this is expensive. So pass the original matrix as 'const matrix4&' and the target matrix as 'matrix4&'. This avoid two copies.

Posted: Fri Jul 13, 2007 11:00 pm
by sir_gon
Yes, already it had I gave account to me of that, so I am going to try to make it more direct. the important thing is that now it compiles without errors .

thanks. :D