[ODE] How to use the rotation matrix returned by dGeomGetRotation

Ander ander_taylor at hotmail.com
Mon Oct 11 09:15:01 MST 2004


Hi Duncan,

This works for me.

    Private Function MatrixConvertToDX(ByVal Matrix As ManagedODE.Matrix3)
As DxVBLibA.D3DMATRIX

        Dim mat As DxVBLibA.D3DMATRIX

        mat.m11 = CSng(Matrix.m11)
        mat.m12 = CSng(Matrix.m12)
        mat.m13 = CSng(Matrix.m13)
        mat.m21 = CSng(Matrix.m21)
        mat.m22 = CSng(Matrix.m22)
        mat.m23 = CSng(Matrix.m23)
        mat.m31 = CSng(Matrix.m31)
        mat.m32 = CSng(Matrix.m32)
        mat.m33 = CSng(Matrix.m33)
        mat.m14 = 0
        mat.m24 = 0
        mat.m34 = 0
        mat.m44 = 1
        MatrixConvertToDX = mat

    End Function

Cheers,

Ander



-----Original Message-----
From: ode-bounces at q12.org [mailto:ode-bounces at q12.org] On Behalf Of Duncan
Frostick
Sent: Monday, 11 October 2004 3:51 AM
To: Jon Watte; 'ODE mailing list'
Subject: Re: [ODE] How to use the rotation matrix returned by
dGeomGetRotation

Cheers for the reply Jon,

I gave that a go but the problem with it is that it leaves the end of 
the matrix untouched. I'd rather not type it all out to illustrate so 
here's a debugger screenie of what the matrix looks like after that code 
has executed (the position of the geom was 0,0,0 anyway, the code 
inserted 0,0,0 into indices 0, 1 and 2 which deleted a 1.875 in index 
1): http://www.duncanf.co.uk/~dunc/project/matrix.png

As a bit of a stab in the dark I tried constructing a matrix like this. 
Here's a link the the definition of the D3DXMATRIX struct so you don't 
have to search for it: 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/
directx/graphics/reference/d3dx/structures/d3dxmatrix.asp

D3DXMATRIX compositeTransform;

dReal const * rot = dGeomGetRotation( meshGeomID );
dReal const * pos = dGeomGetPosition( meshGeomID );

compositeTransform._11 = rot[0];
compositeTransform._12 = rot[1];
compositeTransform._13 = rot[2];
compositeTransform._14 = pos[0];
compositeTransform._21 = rot[4];
compositeTransform._22 = rot[5];
compositeTransform._23 = rot[6];
compositeTransform._24 = pos[1];
compositeTransform._31 = rot[7];
compositeTransform._32 = rot[8];
compositeTransform._33 = rot[9];
compositeTransform._34 = pos[2];
compositeTransform._41 = 0;
compositeTransform._42 = 0;
compositeTransform._43 = 0;
compositeTransform._44 = 1;

But that fails miserably too, any chance you could describe the steps 
needed to construct the correct matrix in a bit more detail? Also, does 
it have anything to do with me using dGeomGetRotation as opposed to 
dBodyGetRotation? I can't give the geom a body with mass because I don't 
understand how to setup a dMass object properly yet (though that's 
another thing so don't worry about that!).

Cheers, Duncan


Jon Watte wrote:
> 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.
_______________________________________________
ODE mailing list
ODE at q12.org
http://q12.org/mailman/listinfo/ode


More information about the ODE mailing list