[ODE] 3d world directx -- slipch, please help

Ivan Bolcina ivan.bolcina at volja.net
Fri Oct 18 10:19:02 2002


This is a multi-part message in MIME format.

------=_NextPart_000_0020_01C276DB.162787C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,look at this code:





//get orientation from ode and put it in my d3d Quatrernion

const dReal *qx=3D dBodyGetQuaternion (PhyBody);

D3DXQUATERNION qxx;

qxx.x=3D(float)qx[0];

qxx.y=3D(float)qx[2];

qxx.z=3D(float)qx[1];

qxx.w=3D(float)qx[3];

setOrientation(qxx);                 //to directx



//get positionfrom ode and put it in my D3DXVECTOR3

const dReal * p=3DdBodyGetPosition(PhyBody);

//to directx

m_Position.x=3D(float)p[0];

m_Position.y=3D(float)p[2];

m_Position.z=3D(float)p[1];



//same for velocity

const dReal * p1=3DdBodyGetLinearVel(PhyBody);=20

move.x=3D(float)p1[0];

move.y=3D(float)p1[2];

move.z=3D(float)p1[1];

//end test





//I dont understand ..... :-(((  I wish to get angular rotation around =
x,y,z

//then I wish to find differece between wished angular rotation(from =
joystick) and current angular rotation

//then I wish to apply torque so they eventually mach.

const dReal * rotx=3DdBodyGetAngularVel (PhyBody);

dVector3 result;

dBodyVectorFromWorld(PhyBody, rotx[0],rotx[1],rotx[2],result);

rotate.x=3Dresult[0];

rotate.y=3Dresult[1];

rotate.z=3Dresult[2];


D3DXVECTOR3 =
rotVec=3DMaxRotate*D3DXVECTOR3(controls.axis_lr*1.0f,-controls.axis_ro*1.=
0f,-controls.axis_ud*1.0f);

rotVec-=3Drotate;

if (rotVec.x>0) rotVec.x=3DRotMax;

if (rotVec.x<0) rotVec.x=3D-RotMax;

if (rotVec.y>0) rotVec.y=3DRotMax;

if (rotVec.y<0) rotVec.y=3D-RotMax;

if (rotVec.z>0) rotVec.z=3DRotMax;

if (rotVec.z<0) rotVec.z=3D-RotMax;

dBodyAddRelTorque(PhyBody,70000.0f*rotVec.x,70000.0f*rotVec.y,70000.0f*ro=
tVec.z);





//force which heads me forward, move is current movement, posp is wished =
movement(from joystick)

float facsped=3D1.0f;

if (controls.burner) facsped=3D2.0f;

D3DXVECTOR3 posp;

//m_vz is vector forward

if (controls.burner)

    posp=3Dm_vz*1.0f*SpeedMax*facsped;

else

    posp=3Dm_vz*controls.axis_throttle*SpeedMax*facsped;

//v razliko

posp-=3Dmove;

float len=3DD3DXVec3Length(&posp);

if (len!=3D0.0f)

{

    posp/=3Dlen;

    D3DXVECTOR3 ForceApplied=3Dposp*MaxEngine;=20

    dBodyAddForce(PhyBody,ForceApplied.x,ForceApplied.z,ForceApplied.y); =
       //SEE HERE

}



------=_NextPart_000_0020_01C276DB.162787C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff><FONT size=3D2>
<P><FONT face=3DArial>Hi,look at this code:</FONT></P>
<P><FONT face=3DArial></FONT>&nbsp;</P>
<P><FONT face=3DArial></FONT>&nbsp;</P>
<P><FONT face=3DArial>//get orientation from ode and put it in my d3d=20
Quatrernion</FONT></FONT><FONT color=3D#008000 size=3D2></P></FONT><FONT =
size=3D2>
<P></FONT><FONT color=3D#0000ff size=3D2>const</FONT><FONT size=3D2> =
dReal *qx=3D=20
dBodyGetQuaternion (PhyBody);</P>
<P>D3DXQUATERNION qxx;</P>
<P>qxx.x=3D(</FONT><FONT color=3D#0000ff size=3D2>float</FONT><FONT =
size=3D2>)qx[0];</P>
<P>qxx.y=3D(</FONT><FONT color=3D#0000ff size=3D2>float</FONT><FONT =
size=3D2>)qx[2];</P>
<P>qxx.z=3D(</FONT><FONT color=3D#0000ff size=3D2>float</FONT><FONT =
size=3D2>)qx[1];</P>
<P>qxx.w=3D(</FONT><FONT color=3D#0000ff size=3D2>float</FONT><FONT =
size=3D2>)qx[3];</P>
<P>setOrientation(qxx);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
//to directx</P>
<P><FONT face=3DArial></FONT>&nbsp;</P>
<P><FONT face=3DArial>//get positionfrom ode and put it in my=20
D3DXVECTOR3</FONT></P>
<P></FONT><FONT color=3D#0000ff size=3D2>const</FONT><FONT size=3D2> =
dReal *=20
p=3DdBodyGetPosition(PhyBody);</FONT></P>
<P><FONT size=3D2>//to directx</P>
<P>m_Position.x=3D(</FONT><FONT color=3D#0000ff =
size=3D2>float</FONT><FONT=20
size=3D2>)p[0];</P>
<P>m_Position.y=3D(</FONT><FONT color=3D#0000ff =
size=3D2>float</FONT><FONT=20
size=3D2>)p[2];</P>
<P>m_Position.z=3D(</FONT><FONT color=3D#0000ff =
size=3D2>float</FONT><FONT=20
size=3D2>)p[1];</FONT></P>
<P><FONT size=3D2></FONT>&nbsp;</P>
<P><FONT size=3D2><FONT face=3DArial>//same for velocity</FONT></P>
<P></FONT><FONT color=3D#0000ff size=3D2>const</FONT><FONT size=3D2> =
dReal *=20
p1=3DdBodyGetLinearVel(PhyBody); </P>
<P>move.x=3D(</FONT><FONT color=3D#0000ff size=3D2>float</FONT><FONT=20
size=3D2>)p1[0];</P>
<P>move.y=3D(</FONT><FONT color=3D#0000ff size=3D2>float</FONT><FONT=20
size=3D2>)p1[2];</P>
<P>move.z=3D(</FONT><FONT color=3D#0000ff size=3D2>float</FONT><FONT=20
size=3D2>)p1[1];</P>
<P></FONT><FONT color=3D#008000 size=3D2>//end test</P>
<P><FONT face=3DArial color=3D#000000></FONT>&nbsp;</P>
<P><FONT face=3DArial color=3D#000000></FONT>&nbsp;</P>
<P><FONT face=3DArial color=3D#000000>//I dont understand ..... =
:-(((&nbsp; I wish=20
to get angular rotation around x,y,z</FONT></P>
<P><FONT face=3DArial color=3D#000000>//then I wish to find differece =
between wished=20
angular rotation(from joystick) and current angular rotation</FONT></P>
<P><FONT face=3DArial color=3D#000000>//then I wish to apply torque so =
they=20
eventually mach.</FONT></P></FONT><FONT size=3D2>
<P></FONT><FONT color=3D#0000ff size=3D2>const</FONT><FONT size=3D2> =
dReal *=20
rotx=3DdBodyGetAngularVel (PhyBody);</P>
<P>dVector3 result;</P>
<P>dBodyVectorFromWorld(PhyBody, rotx[0],rotx[1],rotx[2],result);</P>
<P>rotate.x=3Dresult[0];</P>
<P>rotate.y=3Dresult[1];</P>
<P>rotate.z=3Dresult[2];</P>
<P></P></FONT><FONT size=3D2>
<P>D3DXVECTOR3=20
rotVec=3DMaxRotate*D3DXVECTOR3(controls.axis_lr*1.0f,-controls.axis_ro*1.=
0f,-controls.axis_ud*1.0f);</P>
<P>rotVec-=3Drotate;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2> =
(rotVec.x&gt;0)=20
rotVec.x=3DRotMax;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2> =
(rotVec.x&lt;0)=20
rotVec.x=3D-RotMax;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2> =
(rotVec.y&gt;0)=20
rotVec.y=3DRotMax;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2> =
(rotVec.y&lt;0)=20
rotVec.y=3D-RotMax;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2> =
(rotVec.z&gt;0)=20
rotVec.z=3DRotMax;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2> =
(rotVec.z&lt;0)=20
rotVec.z=3D-RotMax;</P></FONT><FONT size=3D2>
<P>dBodyAddRelTorque(PhyBody,70000.0f*rotVec.x,70000.0f*rotVec.y,70000.0f=
*rotVec.z);</P></FONT><FONT=20
size=3D2>
<P><FONT color=3D#0000ff></FONT><FONT =
color=3D#0000ff></FONT></FONT><FONT=20
color=3D#0000ff size=3D2></FONT>&nbsp;</P>
<P><FONT color=3D#0000ff size=3D2></FONT>&nbsp;</P>
<P><FONT color=3D#0000ff size=3D2>//force which heads me forward, move =
is current=20
movement, posp is wished movement(from joystick)</FONT></P>
<P><FONT color=3D#0000ff size=3D2>float</FONT><FONT size=3D2> =
facsped=3D1.0f;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2> =
(controls.burner)=20
facsped=3D2.0f;</P>
<P>D3DXVECTOR3 posp;</P>
<P>//m_vz is vector forward</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2>=20
(controls.burner)</P>
<P>&nbsp;&nbsp;&nbsp; posp=3Dm_vz*1.0f*SpeedMax*facsped;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>else</P></FONT><FONT size=3D2>
<P>&nbsp;&nbsp;&nbsp; =
posp=3Dm_vz*controls.axis_throttle*SpeedMax*facsped;</P>
<P></FONT><FONT color=3D#008000 size=3D2>//v razliko</P></FONT><FONT =
size=3D2>
<P>posp-=3Dmove;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>float</FONT><FONT size=3D2>=20
len=3DD3DXVec3Length(&amp;posp);</P>
<P></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT size=3D2> =
(len!=3D0.0f)</P>
<P>{</P>
<P>&nbsp;&nbsp;&nbsp; posp/=3Dlen;</P>
<P>&nbsp;&nbsp;&nbsp; D3DXVECTOR3 ForceApplied=3Dposp*MaxEngine; </P>
<P>&nbsp;&nbsp;&nbsp;=20
dBodyAddForce(PhyBody,ForceApplied.x,ForceApplied.z,ForceApplied.y);&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
//SEE HERE</P>
<P>}</P></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0020_01C276DB.162787C0--