Convert dMatrix to D3DXMATRIX

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Convert dMatrix to D3DXMATRIX

Postby KingSnail » Sat Jan 02, 2010 10:01 pm

Hello,

I am a semi noobie game developer trying to integrate the newton engine into my engine for the first time,
so far I got some crazy flying boxes and broken collision,
But I believe I will get there. I want to know how to convert the dMatrix found in the dMaths library of newton to D3DXMATRIX.
I am following the tutorial and on the transform callback and I just need to make the final matrix that is sent to the shader to transform geometry.
Anyone can help?
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Convert dMatrix to D3DXMATRIX

Postby Julio Jerez » Sat Jan 02, 2010 10:15 pm

teh dMatrix hav eteh same layout as a d3dMatrix. you can just copy the element member by member and it should be fine, i think
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convert dMatrix to D3DXMATRIX

Postby KingSnail » Sun Jan 03, 2010 12:32 am

I tried both these methods, both give wrong results (crazy flying polygons)
Am I at least doing this step right? (The dMatrix is m_matrix)

ty->world_matrix._11 = ty->m_matrix[1][1];
ty->world_matrix._12 = ty->m_matrix[1][2];
ty->world_matrix._13 = ty->m_matrix[1][3];
ty->world_matrix._14 = ty->m_matrix[1][4];

ty->world_matrix._21 = ty->m_matrix[2][1];
ty->world_matrix._22 = ty->m_matrix[2][2];
ty->world_matrix._23 = ty->m_matrix[2][3];
ty->world_matrix._24 = ty->m_matrix[2][4];

ty->world_matrix._31 = ty->m_matrix[3][1];
ty->world_matrix._32 = ty->m_matrix[3][2];
ty->world_matrix._33 = ty->m_matrix[3][3];
ty->world_matrix._34 = ty->m_matrix[3][4];

ty->world_matrix._41 = ty->m_matrix[4][1];
ty->world_matrix._42 = ty->m_matrix[4][2];
ty->world_matrix._43 = ty->m_matrix[4][3];
ty->world_matrix._44 = ty->m_matrix[4][4];

////////////////////////////////////////////////////////
//Tried this too

ty->world_matrix._11 = ty->m_matrix[0][0];
ty->world_matrix._12 = ty->m_matrix[0][1];
ty->world_matrix._13 = ty->m_matrix[0][3];
ty->world_matrix._14 = ty->m_matrix[0][2];

ty->world_matrix._21 = ty->m_matrix[1][0];
ty->world_matrix._22 = ty->m_matrix[1][1];
ty->world_matrix._23 = ty->m_matrix[1][2];
ty->world_matrix._24 = ty->m_matrix[1][3];

ty->world_matrix._31 = ty->m_matrix[2][0];
ty->world_matrix._32 = ty->m_matrix[2][1];
ty->world_matrix._33 = ty->m_matrix[2][2];
ty->world_matrix._34 = ty->m_matrix[2][3];

ty->world_matrix._41 = ty->m_matrix[3][0];
ty->world_matrix._42 = ty->m_matrix[3][1];
ty->world_matrix._43 = ty->m_matrix[3][2];
ty->world_matrix._44 = ty->m_matrix[3][3];
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Convert dMatrix to D3DXMATRIX

Postby Julio Jerez » Sun Jan 03, 2010 8:39 am

what are you displaying a mesh tree.

I suggess to make a simpel mesh and render at the origin with an didentiry matrix, that will rule out the posibility that teh matriux is wrong.
My guess isthat the construction of the mesh itself is wrong
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convert dMatrix to D3DXMATRIX

Postby KingSnail » Mon Jan 04, 2010 6:43 pm

Hi, thanks for replies, It turns out I didnt have the currect matrix set on the body.

I now have another small question, how to convert from rotation quaternion to rotation vector.
I tried using the convert to euler angles method of the quaternion and it seems to work, but the cubes only rotate one way so I am not sure.
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Convert dMatrix to D3DXMATRIX

Postby Julio Jerez » Mon Jan 04, 2010 7:19 pm

KingSnail wrote:I now have another small question, how to convert from rotation quaternion to rotation vector.

what is a rotation vector?
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convert dMatrix to D3DXMATRIX

Postby KingSnail » Mon Jan 04, 2010 7:40 pm

Code: Select all
void Transform(const NewtonBody * body, const dFloat * matrix, int thread)
{
    BaseEntity * ent2 = (BaseEntity*)NewtonBodyGetUserData(body);
     Statue * ent = (Statue*)ent2;

   // get the position from the matrix
   dVector posit (matrix[12], matrix[13], matrix[14], 1.0f);
   dQuaternion rotation;
 
   // we will ignore the Rotation part of matrix and use the quaternion rotation stored in the body
   NewtonBodyGetRotation(body, &rotation.m_q0);

   dVector euler = rotation.GetXYZ_EulerAngles(); //I am not using quaternion and vector like in tutorial because I really dont understand quaternions, I am just using 2 vectors which later make a world matrix

   ent->mrot = D3DXVECTOR3(euler.m_x, euler.m_y, euler.m_z);
   ent->mpos = D3DXVECTOR3(posit.m_x, posit.m_y, posit.m_z);
}
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Convert dMatrix to D3DXMATRIX

Postby Julio Jerez » Mon Jan 04, 2010 7:41 pm

if you use direct x why do you need euler angles? you can just copy the matrix into the d3d objects
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convert dMatrix to D3DXMATRIX

Postby KingSnail » Mon Jan 04, 2010 8:27 pm

I tried just copying it but it gives all sorts of artifacts,
But I mean the way I did it, is it correct?
Because if its correct I could leave it like this for a while and work on other collision things
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Convert dMatrix to D3DXMATRIX

Postby Julio Jerez » Mon Jan 04, 2010 8:38 pm

to my knowledge the d3d matrix and the dMatrix have an one to one mapping, you should be able to just do
memcpy (d3dMatrx, newtonMatrix)
and it should work just fine.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convert dMatrix to D3DXMATRIX

Postby KingSnail » Tue Jan 05, 2010 4:45 am

Ok I did that and it works! thanks so much Julio
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 631 guests

cron