[ODE] How to "Reset"

Henri Hakl henri at cs.sun.ac.za
Wed Mar 12 06:38:01 2003


This is a multi-part message in MIME format.

------=_NextPart_000_004B_01C2E8AD.E85E5E00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I've found something that works (for me) and I think it is damn quick:

I just store the original position and orientation of the body and just =
set that information again (plus make all velocities zero) works =
perfectly, don't have to worry about joints and stuff (as my joints use =
relative data).

Here's the code I used, very short, very quick - you prolly can't use =
the code as is for your project, but the idea is basic and works :)

procedure MakeBodyBackup;
var
  i : integer;
begin
  i :=3D 0;
  while i < 18 do begin
    BodyBackup[i].pos :=3D =
TVector4(dBodyGetPosition(body[i].physbody)^);
    BodyBackup[i].qat :=3D =
TVector4(dBodyGetQuaternion(body[i].physbody)^);
    inc(i);             =20
  end;
end;

procedure ResetBody;
var
  i : integer;
begin
  i :=3D 0;
  while i < 18 do begin
    dBodySetPosition(body[i].physbody, BodyBackup[i].pos[0], =
BodyBackup[i].pos[1], BodyBackup[i].pos[2]);
    dBodySetQuaternion(body[i].physbody, TdVector4(BodyBackup[i].qat));
    dBodySetLinearVel(body[i].physbody, 0, 0, 0);
    dBodySetAngularVel(body[i].physbody, 0, 0, 0);
    inc(i);
  end;
end;


  ----- Original Message -----=20
  From: Michal Bacik=20
  To: ODE mailing list=20
  Sent: Wednesday, March 12, 2003 3:03 PM
  Subject: RE: [ODE] How to "Reset"


  Surely it is possible. I plan do so myself soon to implement a =
save-game support on physics bodies. But I suppose you'll have to =
read/write directly from dx??? interfaces - internal data structures, =
because not all data are accessible through the ODE interface. You'll =
have to save all data which are changing during the simulation - =
velocities, position, rotation, etc. You may omit saving data which are =
initialized at init time and do not change - e.g. mass, its inertia =
matrix, etc.

  - michal

    Is it possible to "clone" a physics setup? I could initialize a =
system, make a backup and use copies of the backup whenever I wanted to =
reinitialize the system.

      ----- Original Message -----=20
      From: Henri Hakl=20
      To: ode@q12.org=20
      Sent: Tuesday, March 11, 2003 11:20 PM
      Subject: [ODE] How to "Reset"


      Hi ODE pplZ :)

      I'm in the deep programming phase for my current project which =
involves simulating a body in ODE numerous times. During each iteration =
the world (specifically the body) need to be reset to initial =
conditions. What is the best (speak fastest) way of accomplishing this?

      Just reset all segment positions and orientations manually? =
Destroy and recreate? Something else?

      thanks! :)
        Henri

------=_NextPart_000_004B_01C2E8AD.E85E5E00
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>
<DIV><FONT face=3DArial size=3D2>I've found something that works (for =
me) and I=20
think it is damn quick:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I just store the original position and =
orientation=20
of the body and just set that information again (plus make all =
velocities zero)=20
works perfectly, don't have to worry about joints and stuff (as my =
joints use=20
relative data).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here's the code I used, very short, =
very quick -=20
you prolly can't use the code as is for your project, but the idea is =
basic and=20
works :)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>procedure =
MakeBodyBackup;<BR>var<BR>&nbsp;=20
i : integer;<BR>begin<BR>&nbsp; i :=3D 0;<BR>&nbsp; while i &lt; 18 do=20
begin<BR>&nbsp;&nbsp;&nbsp; BodyBackup[i].pos :=3D=20
TVector4(dBodyGetPosition(body[i].physbody)^);<BR>&nbsp;&nbsp;&nbsp;=20
BodyBackup[i].qat :=3D=20
TVector4(dBodyGetQuaternion(body[i].physbody)^);<BR>&nbsp;&nbsp;&nbsp;=20
inc(i);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;=20
<BR>&nbsp; end;<BR>end;</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>procedure =
ResetBody;<BR>var<BR>&nbsp; i :=20
integer;<BR>begin<BR>&nbsp; i :=3D 0;<BR>&nbsp; while i &lt; 18 do=20
begin<BR>&nbsp;&nbsp;&nbsp; dBodySetPosition(body[i].physbody,=20
BodyBackup[i].pos[0], BodyBackup[i].pos[1],=20
BodyBackup[i].pos[2]);<BR>&nbsp;&nbsp;&nbsp;=20
dBodySetQuaternion(body[i].physbody,=20
TdVector4(BodyBackup[i].qat));<BR>&nbsp;&nbsp;&nbsp;=20
dBodySetLinearVel(body[i].physbody, 0, 0, 0);<BR>&nbsp;&nbsp;&nbsp;=20
dBodySetAngularVel(body[i].physbody, 0, 0, 0);<BR>&nbsp;&nbsp;&nbsp;=20
inc(i);<BR>&nbsp; end;<BR>end;<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dmichal@lonelycatgames.com=20
  href=3D"mailto:michal@lonelycatgames.com">Michal Bacik</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dode@q12.org=20
  href=3D"mailto:ode@q12.org">ODE mailing list</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, March 12, 2003 =
3:03=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [ODE] How to =
"Reset"</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
  class=3D164035912-12032003>Surely it is possible. I plan do so myself =
soon to=20
  implement a save-game support on physics bodies. But I suppose you'll =
have to=20
  read/write directly from dx??? interfaces - internal data structures, =
because=20
  not all data are accessible through the ODE interface. You'll have to =
save all=20
  data which are changing during the simulation - velocities, position,=20
  rotation, etc. You may omit saving data which are initialized at init =
time and=20
  do not change - e.g. mass, its inertia matrix, =
etc.</SPAN></FONT></DIV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
  class=3D164035912-12032003></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN =
class=3D164035912-12032003>-=20
  michal</SPAN></FONT></DIV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT>&nbsp;</DIV>
  <BLOCKQUOTE dir=3Dltr=20
  style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px =
solid; MARGIN-RIGHT: 0px">
    <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DArial=20
    size=3D2>Is it possible to "clone" a physics setup? I could =
initialize a=20
    system, make a backup and use copies of the backup whenever I wanted =
to=20
    reinitialize the system.</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <BLOCKQUOTE dir=3Dltr=20
    style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
      <DIV style=3D"FONT: 10pt arial">----- Original Message ----- =
</DIV>
      <DIV=20
      style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
      <A title=3Dhenri@cs.sun.ac.za =
href=3D"mailto:henri@cs.sun.ac.za">Henri=20
      Hakl</A> </DIV>
      <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dode@q12.org=20
      href=3D"mailto:ode@q12.org">ode@q12.org</A> </DIV>
      <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, March 11, =
2003 11:20=20
      PM</DIV>
      <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [ODE] How to =
"Reset"</DIV>
      <DIV><BR></DIV>
      <DIV><FONT face=3DArial size=3D2>Hi ODE pplZ :)</FONT></DIV>
      <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
      <DIV><FONT face=3DArial size=3D2>I'm in the deep programming phase =
for my=20
      current project which involves simulating a body in ODE numerous =
times.=20
      During each iteration the world (specifically the body) need to be =
reset=20
      to initial conditions. What is the best (speak fastest) way of=20
      accomplishing this?</FONT></DIV>
      <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
      <DIV><FONT face=3DArial size=3D2>Just reset all segment positions =
and=20
      orientations manually? Destroy and recreate? Something =
else?</FONT></DIV>
      <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
      <DIV><FONT face=3DArial size=3D2>thanks! :)</FONT></DIV>
      <DIV><FONT face=3DArial size=3D2>&nbsp;=20
  =
Henri</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_004B_01C2E8AD.E85E5E00--