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

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
sir_gon
Posts: 13
Joined: Mon Oct 23, 2006 12:38 am
Contact:

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

Post 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.
Mi blog y Portafolio: http://devgon.wordpress.com
Image
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Just replace &Matrix.M[0] by Matrix.pointer(). Will work for sure.
sir_gon
Posts: 13
Joined: Mon Oct 23, 2006 12:38 am
Contact:

Post 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;

}
?
Mi blog y Portafolio: http://devgon.wordpress.com
Image
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
sir_gon
Posts: 13
Joined: Mon Oct 23, 2006 12:38 am
Contact:

Post 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
Mi blog y Portafolio: http://devgon.wordpress.com
Image
Image
Post Reply