How does the matrix work?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

How does the matrix work?

Postby Skarik » Mon Aug 03, 2009 5:41 pm

Code: Select all
         // -- Set the position --
         float * pfTransformMatrix;
         pfTransformMatrix = new float [16];
         for ( int i = 0; i < 16; i += 1 )
         {
            pfTransformMatrix[i] = 0;
         }
         pfTransformMatrix[0] = x;
         pfTransformMatrix[1] = y;
         pfTransformMatrix[2] = z + 3;

         //pfTransformMatrix[4] = 1;
         //pfTransformMatrix[5] = 0;
         //pfTransformMatrix[6] = 0;

         //pfTransformMatrix[8] = 1;
         //pfTransformMatrix[9] = 1;
         //pfTransformMatrix[10] = 1;

         /*pfTransformMatrix[3] = 1;
         pfTransformMatrix[7] = 1;
         pfTransformMatrix[11] = 1;
         pfTransformMatrix[12] = 1;
         pfTransformMatrix[13] = 1;
         pfTransformMatrix[14] = 1;
         pfTransformMatrix[15] = 1;*/

         // 0  1  2  3
         // 4  5  6  7
         // 8  9  10 11
         // -  -  -  -

         NewtonBodySetMatrix( pMyNewtonBody, pfTransformMatrix );

         delete pfTransformMatrix;


Is it
Code: Select all
 x  y  z  1
 rx ry rz 1
 ?  ?  ?  1
 1  1  1  1


Because right after I do
Code: Select all
   float pfTransformMatrix [16];

   NewtonBodyGetMatrix( pMyNewtonBody, pfTransformMatrix );
   x = pfTransformMatrix[0];
   y = pfTransformMatrix[1];
   z = pfTransformMatrix[2];


And that gives me that
x = .700973
y = .700973
and z is whatever gives me a unit sphere WHICH IS FREAKING MESSED MAN!

I haven't made a matrix class yet, but the engine I'm using does the transformations in the following way:
Code: Select all
x   y   z   1
rx  ry  rz  1
sx  sy  sz  1
1   1   1   1


Anyhow, team's waitin' for this so I'm throwing it to them in case no one here has an answer.
Can't find much documentation on Newton's matrices, anyhow.

Oh, and this is 1.53.

If anybody could help with the matrix format, that would be great. I got the angles converted to the 3d engine's format, just need the position. Then we can have players pushing others off the roof while gunning them down.

Thanks.

Edit: and if it's anything, here's what I've tried as of three hours ago: http://www.box.net/shared/6gupfdrpxl
The current list is twice as long.
Skarik
 
Posts: 11
Joined: Mon Aug 03, 2009 5:31 pm

Re: How does the matrix work?

Postby Marc » Tue Aug 04, 2009 2:12 pm

Hi !

It's like this:

Code: Select all
.  .  .  x
.  .  .  y
.  .  .  z
0  0  0  1


where x, y and z are the position of the body. For the rotation, the upper left area (.) is reqquired to be filled with a rotation matrix => http://en.wikipedia.org/wiki/Rotation_matrix - scroll down for the complete 3d matrix ("Dimension three").

Note that for the layout in memory, newton expects the matrix column by column, not row by row. So for example for a non rotated body, you'ld set the position like this:

Code: Select all
   float t[16];
   t[0]=1;
   t[1]=0;
   t[2]=0;
   t[3]=0;
   t[4]=0;
   t[5]=1;
   t[6]=0;
   t[7]=0;
   t[8]=0;
   t[9]=0;
   t[10]=1;
   t[11]=0;
   t[12]=x;
   t[13]=y;
   t[14]=z;
   t[15]=1;
   NewtonBodySetMatrix(body, t);
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: How does the matrix work?

Postby Skarik » Tue Aug 04, 2009 11:04 pm

May I say that you ABSOLUTELY ROCK ?!?!

Yes, I'll try it in a little bit, but the team will be EXTREMELY happy for this. Finally - after this, we'll be able to finish the model classes, work on some view models, and get some test levels done! EXPLOSIONS AND MAGIC - HERE I COME!!!!

*runs off*
Skarik
 
Posts: 11
Joined: Mon Aug 03, 2009 5:31 pm

Re: How does the matrix work?

Postby JernejL » Wed Aug 05, 2009 3:26 am

What's the matter with this matrix row major, column major stuff? internally in memory both are same, it's just the matter of how you arrange the values when trying to display it's numbers..
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: How does the matrix work?

Postby Marc » Wed Aug 05, 2009 4:57 am

The other way one could arrange the same matrix from above in memory would be:

Code: Select all
   float t[16];
   t[0]=1;
   t[1]=0;
   t[2]=0;
   t[3]=x;
   t[4]=0;
   t[5]=1;
   t[6]=0;
   t[7]=y;
   t[8]=0;
   t[9]=0;
   t[10]=1;
   t[11]=z;
   t[12]=0;
   t[13]=0;
   t[14]=0;
   t[15]=1;
   NOTNewtonBodySetMatrix(body, t);


That's why there is this note about row major and column major in the docs. :)

Just to make clear: Newton does not use this arrangement. Using it for Newton will give crazy results. The correct way is the way from above. :!:
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: How does the matrix work?

Postby Skarik » Wed Aug 05, 2009 3:38 pm

Okay, cool, I've gotten my player to react to gravity using callbacks. Now, my next question is this: does everything have to be done in a callback? I'm trying to move the player in a script that gets the keyboard control, and the force just isn't happening.

Oh, I get it...the force...ohhhhhhh....

Okay, anyways, it also seem that I can't get the gravity right unless I increase the downward force to around 1000. The scale of the game - hell - I can't find the document...I swear I posted that somewhere...Oh, I'm in the wrong scale. I'm supposed to be in 1 unit::1 inch but I'm in 1 unit::1 foot right now. Okay, um, dang.

I still would like to know if I have to do all forces in a callback.

If so, that just *.
Skarik
 
Posts: 11
Joined: Mon Aug 03, 2009 5:31 pm

Re: How does the matrix work?

Postby Skarik » Wed Aug 05, 2009 3:42 pm

MUAHAHAHAHAHAHA

I found a work around. Thanks!
Skarik
 
Posts: 11
Joined: Mon Aug 03, 2009 5:31 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 41 guests