[ODE] How to use the rotation matrix returned by dGeomGetRotation
Jon Watte
hplus-ode at mindcontrol.org
Sun Oct 10 09:39:00 MST 2004
I think the ODE Wiki FAQ is wrong on matrix conversion.
You do not need to invert or transpose matrices for use
with ODE. If you feed ODE left-handed coordinates and
matrices and forces, it will happily hand you back the
same; the only difference to be aware of is winding order
in trimesh triangle list data.
The rotation matrices returned by ODE consist of three
rows of 4 elements, where the 4th element of each row is
un-used. This is assuming row-major ordering, and putting
vertices as row vectors on the left of the matrix. This
is, in turn, equivalent to putting column vertices on the
right of a column-major matrix, so you can view it that
way too :-)
It's been a while since I did ODE/DirectX integration (I'm
back to good-old OpenGL), but IIRC: To get a matrix ready
for D3D OR OpenGL (same code!), all you have to do is:
float matrix[16];
dReal const * R = dBodyGetRotation( myBody );
memcpy( matrix, R, sizeof(float)*12 );
dReal const * P = dBodyGetPosition( myBody );
memcpy( matrix, P, sizeof(float)*3 );
matrix[15] = 1;
m_p3dd_d3dDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)matrix);
This assumes you're feeding ODE left-handed data just like
you'd feed DirectX.
Cheers,
/ h+
-----Original Message-----
From: ode-bounces at q12.org [mailto:ode-bounces at q12.org]On Behalf Of
Duncan Frostick
Sent: Sunday, October 10, 2004 7:32 AM
To: 'ODE mailing list'
Subject: [ODE] How to use the rotation matrix returned by
dGeomGetRotation
Hi all,
I'm having quite some trouble working with the rotation matrix returned
by dGeomGetRotation. I've got some trimeshes loaded into DX and ODE and
I'm trying to get the position and rotation of the trimeshes from ODE to
render them in the correct locations in DX.
The matrix I'm getting back from ODE on the first (and subsequent)
worldstep is rubbish basically, all 16 elements are 0 except 2 elements
which are 1.875. Even if I combine this with an identity matrix to try
and make it render something visible, there's massive distortion of the
mesh. All I'm doing is getting the rotation matrix from ODE then
converting it using the method outlined on the ODE wiki FAQ area then
using the resultant matrix as the rotation matrix combined with a
translation to the location specified by ODE. That seems to me to be the
most obvious thing to do. The position vector returned by ODE is fine,
just the rotation matrix doesn't seem to make any sense.
What exactly needs to be done to make the rotation matrix returned by
dGeomGetRotation useable? Could I be missing a step in initialising ODE
or my Geom object which is confusing ODE and making it return a garbage
matrix? I've been having trouble with getting trimeshes loaded anyway,
could dodgy trimesh data be causing the rubbish matrix? The test code in
test_moving_triwmesh seems to do this to get the transforms correct:
dGeomID g2 = dGeomTransformGetGeom (g);
const dReal *pos2 = dGeomGetPosition (g2);
const dReal *R2 = dGeomGetRotation (g2);
dVector3 actual_pos;
dMatrix3 actual_R;
dMULTIPLY0_331 (actual_pos,R,pos2); //6
actual_pos[0] += pos[0]; //7
actual_pos[1] += pos[1]; //8
actual_pos[2] += pos[2]; //9
dMULTIPLY0_333 (actual_R,R,R2); //10
drawGeom (g2,actual_pos,actual_R,0);
But I have no idea why and what lines 6, 7, 8, 9 and 10 do (the
functions in 6 and 10 don't seem to be documented) so I can't glean much
information from the test code.
Can anyone help?
Cheers, Duncan
_______________________________________________
ODE mailing list
ODE at q12.org
http://q12.org/mailman/listinfo/ode
More information about the ODE
mailing list