ODEScript Physics
by Gary "ChunkyKs" Briggs · 12/08/2006 (10:29 am) · 106 comments
Download Code File
ODEScript
The Torque C++ modification
This code is an implementation of the ODE API, making it available to torquescript.
As a whole, the API is a "t" [for Torque] prefix on the normal ODE objects, and converted to think in terms of torque and objects rather than functions;
In C:
dBodyID b = dBodyCreate(world);
dBodySetLinearVel(b, x, y, z);
In TorqueScript:
datablock tdBodyData(bodydb) { foo="bar"; }; // foo="bar" is ignored
$b = new tdBody() { worldsim = $odeworld; datablock = bodydb; } ;
$b.SetLinearVel(x,y,z); // C Style
OR
$b.SetLinearVel("x y z"); // TorqueScript Style
Note that both calling styles are supported.
Build Instructions:
1) Edit shapeBase.h, and find this [around like 70 or so]:
friend class ShapeBase;
friend class Vehicle;
and add:
friend class ODEShape;
2) Add all the .cc/.h files in odescript/ to your build, and remember to link with ODE.
3) If you want projectiles to collide with ODEShapes, you'll need to edit game/projectile.cc and add "StaticShapeObjectType |" to your Projectile::csmStaticCollisionMask.
For more detailed instructions for each platform, check buildinstructions.lyx in odescript/.
Thanks to Ray "Noolness" Gebhardt for all his Torque help, including specifically, writing ExampleGameBase and ExampleCollider, from which all my objects derive.
ODERocks
The Torquescript demo of ODEScript
This is a mod for TGE, that should be run with starter.fps or similar, once you have ODEScript [the c++ source modification] built into your Torque install. Run the game with "-mod oderocks" on the command line
Once you're in-game, hold down the C or V button to see a small UI of physics buttons.
This isn't really anything exciting, it just serves to demo some of the objects in ODEScript, and has been used extensively by me during development
Here's a few videos of what it looks like in action:
First Demo [basic chain, single bodies]: youtube.com/watch?v=cA-ncyU51G8
Second Demo ["ragdolls", buoyancy]: youtube.com/watch?v=gjEeN5er6aM
Third Demo [Juggling, Inverse Kinematics]: www.youtube.com/watch?v=PEe55nibKHA
Chunky (-;
icculus.org/~chunky/
ODEScript
The Torque C++ modification
This code is an implementation of the ODE API, making it available to torquescript.
As a whole, the API is a "t" [for Torque] prefix on the normal ODE objects, and converted to think in terms of torque and objects rather than functions;
In C:
dBodyID b = dBodyCreate(world);
dBodySetLinearVel(b, x, y, z);
In TorqueScript:
datablock tdBodyData(bodydb) { foo="bar"; }; // foo="bar" is ignored
$b = new tdBody() { worldsim = $odeworld; datablock = bodydb; } ;
$b.SetLinearVel(x,y,z); // C Style
OR
$b.SetLinearVel("x y z"); // TorqueScript Style
Note that both calling styles are supported.
Build Instructions:
1) Edit shapeBase.h, and find this [around like 70 or so]:
friend class ShapeBase;
friend class Vehicle;
and add:
friend class ODEShape;
2) Add all the .cc/.h files in odescript/ to your build, and remember to link with ODE.
3) If you want projectiles to collide with ODEShapes, you'll need to edit game/projectile.cc and add "StaticShapeObjectType |" to your Projectile::csmStaticCollisionMask.
For more detailed instructions for each platform, check buildinstructions.lyx in odescript/.
Thanks to Ray "Noolness" Gebhardt
ODERocks
The Torquescript demo of ODEScript
This is a mod for TGE, that should be run with starter.fps or similar, once you have ODEScript [the c++ source modification] built into your Torque install. Run the game with "-mod oderocks" on the command line
Once you're in-game, hold down the C or V button to see a small UI of physics buttons.
This isn't really anything exciting, it just serves to demo some of the objects in ODEScript, and has been used extensively by me during development
Here's a few videos of what it looks like in action:
First Demo [basic chain, single bodies]: youtube.com/watch?v=cA-ncyU51G8
Second Demo ["ragdolls", buoyancy]: youtube.com/watch?v=gjEeN5er6aM
Third Demo [Juggling, Inverse Kinematics]: www.youtube.com/watch?v=PEe55nibKHA
Chunky (-;
icculus.org/~chunky/
About the author
#22
I came back to this resource to test thoroughly. Actually, I wanted to simulate golf ball. After playing around with your odeBoulder, I found I need to change some properties of it for my purpose.
Could you let me know how to change its mass, density,drag, friction etc. without harming ode physics. I found odeShapeData is a subclass of shapeBaseData, which has mass,density and drag properties. Is it enough change those properties for my purpose? How about friction?
One more thing, when I applyImpulse to the boulder, it doesn't rotate much enough when moving. It gives me a feeling that it is sliding not rolling. Could you give me an advice about this?
Thank you in advance.
02/19/2007 (7:26 pm)
Hi Gary,I came back to this resource to test thoroughly. Actually, I wanted to simulate golf ball. After playing around with your odeBoulder, I found I need to change some properties of it for my purpose.
Could you let me know how to change its mass, density,drag, friction etc. without harming ode physics. I found odeShapeData is a subclass of shapeBaseData, which has mass,density and drag properties. Is it enough change those properties for my purpose? How about friction?
One more thing, when I applyImpulse to the boulder, it doesn't rotate much enough when moving. It gives me a feeling that it is sliding not rolling. Could you give me an advice about this?
Thank you in advance.
#23
Let's see here;
Mass/density, is an easy one.
If you look at oderock.cs in the server subdir of oderocks, you find the newrock function:
Saliently, after the odemass is created, you set properties on it. I used "%odemass.SetSphereTotal(3, 3);". The mass works just like it does with regular ODE. The ode site documentation is far more descriptive than I could ever be. this page seems like a good first bet.
Next up, drag/friction.
Friction is currently set globally in ODEScript, using global environment variables. Hold down "C" in the demo to see a crowd of sliders for modifying properties like this.
If you look at ODEShape.cc, you'll see where they're pulled in, in ODEShape::processTick around line 215.
There's also some damping factors that you can use. Take a look at tbody.cc, in tdBody::processTick around line 167.
ODEShape was originally only going to be an example implementation of how to use the rest of ODEScript [such as tdBody and tdMass]. Consider it completely open season to manipulate for your own purposes. The other objects should probably be treated a little more gently, as [other than collision], they're the objects actually doing the "phyiscs".
Applying impulses.
If you apply an impulse to a body, it will typically be applied at the center of mass, which doesn't inherently [in fact, explicitly does *not*] start rotation on the body. Try applying impulses to the tdBody in different ways; like these. Also, try increasing friction in general; friction with the ground will probably increase rotation, too.
Overall, if you haven't already done so, I would highly recommend reading through the ODE documentation, since basically ODEScript is a direct mapping of normal ODE into torque.
I would suggest not poking around with shapeBase's variables; ODEScript pretty much ignores them, or only uses them as it sees fit.
Gary (-;
02/20/2007 (4:00 pm)
@HJP:Let's see here;
Mass/density, is an easy one.
If you look at oderock.cs in the server subdir of oderocks, you find the newrock function:
function newrock() {
<snippage>
%odemass = new tdMass() {
datablock = odemassdata;
};
%odemass.SetSphereTotal(3, 3);
<snippage>
%odeobj.SetMass(%odemass);
<snippage>
}Saliently, after the odemass is created, you set properties on it. I used "%odemass.SetSphereTotal(3, 3);". The mass works just like it does with regular ODE. The ode site documentation is far more descriptive than I could ever be. this page seems like a good first bet.
Next up, drag/friction.
Friction is currently set globally in ODEScript, using global environment variables. Hold down "C" in the demo to see a crowd of sliders for modifying properties like this.
If you look at ODEShape.cc, you'll see where they're pulled in, in ODEShape::processTick around line 215.
There's also some damping factors that you can use. Take a look at tbody.cc, in tdBody::processTick around line 167.
ODEShape was originally only going to be an example implementation of how to use the rest of ODEScript [such as tdBody and tdMass]. Consider it completely open season to manipulate for your own purposes. The other objects should probably be treated a little more gently, as [other than collision], they're the objects actually doing the "phyiscs".
Applying impulses.
If you apply an impulse to a body, it will typically be applied at the center of mass, which doesn't inherently [in fact, explicitly does *not*] start rotation on the body. Try applying impulses to the tdBody in different ways; like these. Also, try increasing friction in general; friction with the ground will probably increase rotation, too.
Overall, if you haven't already done so, I would highly recommend reading through the ODE documentation, since basically ODEScript is a direct mapping of normal ODE into torque.
I would suggest not poking around with shapeBase's variables; ODEScript pretty much ignores them, or only uses them as it sees fit.
Gary (-;
#24
Thank you so much for your help. Now I understand why you put so much emphasis on reading ode doc. Even though I read it once, I coudn't get much as I didn't spend enough time. I'm going to read it again paying close attention to.
02/20/2007 (6:13 pm)
@Gary,Thank you so much for your help. Now I understand why you put so much emphasis on reading ode doc. Even though I read it once, I coudn't get much as I didn't spend enough time. I'm going to read it again paying close attention to.
#26
You've been very helpful so far and I hate to bug you again, but I took your advice and build ODE.lib myself. That solved my previous errors but now I'm getting four new linker errors:
1>ode.lib(error.obj) : error LNK2019: unresolved external symbol __imp___snprintf referenced in function _dError
1>ode.lib(convex.obj) : error LNK2019: unresolved external symbol __imp___invalid_parameter_noinfo referenced in function "public: bool __thiscall std::_Tree,struct std::less >,class std::allocator >,0> >::const_iterator::operator==(class std::_Tree,struct std::less >,class std::allocator >,0> >::const_iterator const &)const " (??8const_iterator@?$_Tree@V?$_Tset_traits@U?$pair@II@std@@U?$less@U?$pair@II@std@@@2@V?$allocator@U?$pair@II@std@@@2@$0A@@std@@@std@@QBE_NABV012@@Z)
1>ode.lib(IceRandom.obj) : error LNK2019: unresolved external symbol __imp__srand referenced in function _SRand
1>ode.lib(IceRandom.obj) : error LNK2019: unresolved external symbol __imp__rand referenced in function _Rand
I figured that most of these are pretty benign calls and commented them out of the original ODE code to try and get the stupid thing to build, but that second one has me a bit stumped. Have you ever seen this before? Thanks!
Robert
02/27/2007 (8:47 pm)
Hi Gary,You've been very helpful so far and I hate to bug you again, but I took your advice and build ODE.lib myself. That solved my previous errors but now I'm getting four new linker errors:
1>ode.lib(error.obj) : error LNK2019: unresolved external symbol __imp___snprintf referenced in function _dError
1>ode.lib(convex.obj) : error LNK2019: unresolved external symbol __imp___invalid_parameter_noinfo referenced in function "public: bool __thiscall std::_Tree
1>ode.lib(IceRandom.obj) : error LNK2019: unresolved external symbol __imp__srand referenced in function _SRand
1>ode.lib(IceRandom.obj) : error LNK2019: unresolved external symbol __imp__rand referenced in function _Rand
I figured that most of these are pretty benign calls and commented them out of the original ODE code to try and get the stupid thing to build, but that second one has me a bit stumped. Have you ever seen this before? Thanks!
Robert
#27
Alternatvely, this google cached link implies that there have been changes made to ODE... have you tried a more recent version, or even cvs/svn?
Gary (-;
02/28/2007 (2:24 pm)
@Robert: Hm. Looking about online, it seems you might need to link dynamically with ODE, at least for now. Alternatvely, this google cached link implies that there have been changes made to ODE... have you tried a more recent version, or even cvs/svn?
Gary (-;
#28
I figured out what was causing that long crazy linker error above (the one with "symbol __imp___invalid_parameter_noinfo referenced..."). It was Microsoft's succinct and intuitive way of letting me know that it was having trouble linking a Release library with a Debug application (how embarassing is that for me that I didn't think of that?). So after rectifying that and hammering out a few other unimportant linker errors, I finally have this thing built! Big thanks to Gary for all his help...
03/01/2007 (3:03 pm)
Alright, I figured it's about time I actually CONTRIBUTED something to this forum for a change...I figured out what was causing that long crazy linker error above (the one with "symbol __imp___invalid_parameter_noinfo referenced..."). It was Microsoft's succinct and intuitive way of letting me know that it was having trouble linking a Release library with a Debug application (how embarassing is that for me that I didn't think of that?). So after rectifying that and hammering out a few other unimportant linker errors, I finally have this thing built! Big thanks to Gary for all his help...
#29
now, how can we make it faster? I have a few ideas, but I want to hear yours first.
thanks again,
-jm
PS Mac Pro desktop; how does some kind of threading strike you? useful? ..possible?
03/06/2007 (8:07 pm)
I got this working tonight in a really hacked up tge 1.5; works great, dropped right in. really, thank you.now, how can we make it faster? I have a few ideas, but I want to hear yours first.
thanks again,
-jm
PS Mac Pro desktop; how does some kind of threading strike you? useful? ..possible?
#30
Make it faster? Try just teaking some variables. Specifically worldstep and numworldsteps. Increasing gravity always makes stuff look faster, too :-)
I'm not sure if you mean in terms of "physics is incurring a significant performance penalty according my profiler". In which case, ODE docs have various things about how to improve performance. Check out this. Basically, ODE's solver incurrs less of a penalty the fewer degrees of freedom you remove in each joint, so that might help you out.
Threading's one of those stupid painful topics. Break open a profiler on your code, and find out if ODE is actually a problem; it's probably not. You'd likely do far better threading your AI or something :-)
One of the problems with threading ODE is that it's large and opaque. Your locking primitives would have to lock the entire simulation since ODE doesn't provide more granular access. 101 of threading is that if you're just locking one huge thing with one mutex, then it probably isn't worth it.
Gary (-;
03/16/2007 (12:45 pm)
@JohnM:Make it faster? Try just teaking some variables. Specifically worldstep and numworldsteps. Increasing gravity always makes stuff look faster, too :-)
I'm not sure if you mean in terms of "physics is incurring a significant performance penalty according my profiler". In which case, ODE docs have various things about how to improve performance. Check out this. Basically, ODE's solver incurrs less of a penalty the fewer degrees of freedom you remove in each joint, so that might help you out.
Threading's one of those stupid painful topics. Break open a profiler on your code, and find out if ODE is actually a problem; it's probably not. You'd likely do far better threading your AI or something :-)
One of the problems with threading ODE is that it's large and opaque. Your locking primitives would have to lock the entire simulation since ODE doesn't provide more granular access. 101 of threading is that if you're just locking one huge thing with one mutex, then it probably isn't worth it.
Gary (-;
#31
Agreed; at the time I posted that, I didn't realize I had left another very significant process open in the background that was munching resources of all types (generating world-size landscapes with libnoise).
I did decouple the slew of AI processes from the game engine to realize a significant gain on multiproc machines, though ODE 'performance' was not the motivation; the ODE code is (and was) quite fast. I rescind my previous comment :).
Again, this is a top notch resource. I've been able to add some small touches to my game so far that, to me, increase the immersion factor in a very "real" way. I've a wedding and honeymoon coming up, but after that I'll post some videos; I think the rope bridges are fun if nothing else. The capacity for emergent aspects of gameplay become apparent even just prototyping using this resource.
Cheers,
-jm
03/16/2007 (1:29 pm)
@Gary:Agreed; at the time I posted that, I didn't realize I had left another very significant process open in the background that was munching resources of all types (generating world-size landscapes with libnoise).
I did decouple the slew of AI processes from the game engine to realize a significant gain on multiproc machines, though ODE 'performance' was not the motivation; the ODE code is (and was) quite fast. I rescind my previous comment :).
Again, this is a top notch resource. I've been able to add some small touches to my game so far that, to me, increase the immersion factor in a very "real" way. I've a wedding and honeymoon coming up, but after that I'll post some videos; I think the rope bridges are fun if nothing else. The capacity for emergent aspects of gameplay become apparent even just prototyping using this resource.
Cheers,
-jm
#32
Looking forward to seeing videos,
Gary (-;
03/16/2007 (5:02 pm)
Wow, I'm glad to hear someone's getting such great use out of this!Looking forward to seeing videos,
Gary (-;
#33
.\tmass.cc(6) : fatal error C1083: Cannot open include file: 'ode/ode.h': No such file or directory
tjointconsole.cc
E:\Torque\TGE 1.5\engine\lightingSystem/sgLightManager.h(350) : warning C4311: '' : pointer truncation from 'void *' to 'U32'
E:\Torque\TGE 1.5\engine\lightingSystem/sgLightManager.h(352) : warning C4311: '' : pointer truncation from 'LightInfo *' to 'U32'
E:\Torque\TGE 1.5\engine\platform/platformAL.h(21) : fatal error C1083: Cannot open include file: 'al/altypes.h': No such file or directory
tjoint.cc
can someone help? thanks :)
03/29/2007 (5:16 pm)
I'm getting a lot of errors, mostly just path errors:.\tmass.cc(6) : fatal error C1083: Cannot open include file: 'ode/ode.h': No such file or directory
tjointconsole.cc
E:\Torque\TGE 1.5\engine\lightingSystem/sgLightManager.h(350) : warning C4311: '
E:\Torque\TGE 1.5\engine\lightingSystem/sgLightManager.h(352) : warning C4311: '
E:\Torque\TGE 1.5\engine\platform/platformAL.h(21) : fatal error C1083: Cannot open include file: 'al/altypes.h': No such file or directory
tjoint.cc
can someone help? thanks :)
#34
03/29/2007 (5:21 pm)
btw: I first copied the folder 'odescript' to my 1.5\engine\ directory. Then I added a new project and added the .h to the headers folder & the .cc files to the source folder. In odescript property page I added additional include directories hoping it would help but it didnt. I also added the include/library in tools. Can someone please tell me in detail how to do this step: "and remember to link with ODE." I'm using VS2005 Express, and Im a noob. Thanks again. :)
#35
Additionally for windows users; using the pre-built ODE library for windows that you can download from ode.org appears to incur significant performance problems, if you can get it to link. Rebuild it yourself from ODE source using the ODE .sln file in build/vs2005 [or whichever version is appropriate for you]. Use batch build, and build all of the ReleaseDLLs
Gary (-;
04/02/2007 (10:58 am)
After chatting a lot with MB, it seems that mostly it was related to settings up Visual Studio correctly.Additionally for windows users; using the pre-built ODE library for windows that you can download from ode.org appears to incur significant performance problems, if you can get it to link. Rebuild it yourself from ODE source using the ODE .sln file in build/vs2005 [or whichever version is appropriate for you]. Use batch build, and build all of the ReleaseDLLs
Gary (-;
#36
Thanks for the help Gary! Great resource, you rock!
04/03/2007 (10:05 am)
Yes thats right, setting it up in VS2005 was the problem. I didnt have the odescripts in the correct place in the project. To add the .h & .cc files right click the 'torque demo' project and create a new filter. Then just drag & drop those files into that new filter. After you rebuild the ODE source add the additional include directory and point it to where your library or dll files are for ODE. Also add ode.lib to the linker, and the include & lib directories in options. Any problems adding it email me and I'll step you through it. Thanks for the help Gary! Great resource, you rock!
#38
04/04/2007 (10:15 am)
i tried to install it but when i go into the engine and press C the window shows up, but when i click add rock, or add cube nothing happens. also how do i add these things to starter FPS? i tried to and all it did is cause starter FPS to crash on startup.
#39
What messages do you see in the console? Can you post the last few lines of console.log?
When you say "into the engine", I assume you mean the main menu screen? If you mean starter.fps, how did it show you the menu if it crashed?
What system are you on? Which tools did you build with, and which versions of ODE are you using?
Gary (-;
04/04/2007 (11:33 am)
@Patrick;What messages do you see in the console? Can you post the last few lines of console.log?
When you say "into the engine", I assume you mean the main menu screen? If you mean starter.fps, how did it show you the menu if it crashed?
What system are you on? Which tools did you build with, and which versions of ODE are you using?
Gary (-;
#40
anyway now i can load up starter FPS, and get the menu to open, but the add link/box/rock options still don't appear to do anything. i'm on tiger, and using ODE 0.8
04/04/2007 (2:58 pm)
i messed with it for a while and fixed it, but i'm still not sure how i did, or what was wrong.anyway now i can load up starter FPS, and get the menu to open, but the add link/box/rock options still don't appear to do anything. i'm on tiger, and using ODE 0.8
Torque Owner Gary "ChunkyKs" Briggs
www.mail-archive.com/openssl-users@openssl.org/msg31551.html
__ftol2 errors are caused by differing versions of visual studio. Try downloading a fresh ODE and building the library yourself.
www.differentpla.net/content/2006/09/unresolved-external-symbol-std-string-base-...
Woop! Blablah::_Xran(void) is the same problem. Again, try downloading a fresh ODE source and building it yourself.
This is normally my opportunity to rip on Microsoft, but GNU ['specially the C++ ABI] and Apple [come oooon, breaking everything every GD release] are both guilty of exactly the same stuff. If anyone suffers similar problems on either linux or OSX, there's a healthy chance they're suffering similar problems.
Gary (-;