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
#82
Gary (-;
05/13/2007 (8:13 pm)
Check build instructions, section 2 "Changes common to all platforms", step 1 "Necessary Changes"; add that friend declaration to shapeBase.hGary (-;
#83
I did cover it all and the new step in the TGEA (7.2 (f))
But now I got a new issue:
I dont get this error when I compile the normal one (non-modded version.)
Now I googled this and have to throw a BS flag (not you, my frustration....) because I tried 6 different set of instructions and in the last few days I have a brand new install of XP pro along with VS 2005 and the platform SDK and the DirectX SDK and ... Everything followed from the beginning..... I know I'm starting to look a bit spastic but this is a primary goal to get this implemented and would hold the closest title to "coder" atm. Please have just a bit more patients with me in this your really helping me.
05/13/2007 (11:26 pm)
Ok your right I missed that when I remade that whole directory to try it again fresh.I did cover it all and the new step in the TGEA (7.2 (f))
But now I got a new issue:
Quote:This application has failed to start because MSVCR71.dll was not found. Re-installing the application may fix this problem.
I dont get this error when I compile the normal one (non-modded version.)
Now I googled this and have to throw a BS flag (not you, my frustration....) because I tried 6 different set of instructions and in the last few days I have a brand new install of XP pro along with VS 2005 and the platform SDK and the DirectX SDK and ... Everything followed from the beginning..... I know I'm starting to look a bit spastic but this is a primary goal to get this implemented and would hold the closest title to "coder" atm. Please have just a bit more patients with me in this your really helping me.
#84
I don't know a real answer to that, but for an easy one, you'll find that your copy of visual studio comes with "redistributable" versions of MSVCR71.dll [MSVCR is short for Microsoft Visual C Runtime].
On my windows build VM, I have Visual Studio 2005 and the appropriate file is in
C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRT
Yours probably isn't exactly the same [since it's asking for msvcr71.dll, I assume you have visual studio 2003], but you get the idea. Just copy the appropriate .dlls into example/
Alternatively, I *believe* that that file also comes in the .NET framework 1.1. If you plan to do any real future windows development, you should probably have .NET framework pieces installed anyways.
Sorry if this is all a bit vague, I abhor windows and windows development, and am pretty much completely inexperienced with it. The instructions you're using were written by me after successfully building ODEScript+TSE, but I have yet to see it actually execute since I don't have a windows machine that can run it...
Hope there's a glimmer of help in this post someplace.
Gary (-;
05/14/2007 (11:25 am)
Welcome to the world of windows development.I don't know a real answer to that, but for an easy one, you'll find that your copy of visual studio comes with "redistributable" versions of MSVCR71.dll [MSVCR is short for Microsoft Visual C Runtime].
On my windows build VM, I have Visual Studio 2005 and the appropriate file is in
C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRT
Yours probably isn't exactly the same [since it's asking for msvcr71.dll, I assume you have visual studio 2003], but you get the idea. Just copy the appropriate .dlls into example/
Alternatively, I *believe* that that file also comes in the .NET framework 1.1. If you plan to do any real future windows development, you should probably have .NET framework pieces installed anyways.
Sorry if this is all a bit vague, I abhor windows and windows development, and am pretty much completely inexperienced with it. The instructions you're using were written by me after successfully building ODEScript+TSE, but I have yet to see it actually execute since I don't have a windows machine that can run it...
Hope there's a glimmer of help in this post someplace.
Gary (-;
#85
05/23/2007 (10:17 pm)
Any chance you would consider updating the vehicle code with this? Or perhaps making a new type of vehicle? Heck while I am begging, why not throw out if you have looked into making ragdoll players?
#86
05/24/2007 (7:52 am)
speaking of improvements, have you considered implementing breakable joints from the ode-8.0/contrib directory?
#87
@Patrick: It's not difficult at all. Reading it, there's a total of 9 functions, which wouldn't require much witchcraft at all to make them run [other than the callback, which would need to be used to safely delete the relevant object here].
What I want to avoid, though, is demanding modifications of the default library to anyone trying to use ODEScript; I've always had in mind the nebulous goal of build instructions being simple enough that anyone could use them, without requiring modifications to any of the rest of torque, or ODE. I remember having a really hard time making ODEItem run, back in the day, in part because it required ODE modifications.
Gary (-;
05/24/2007 (9:03 pm)
@Ron: I haven't dug into vehicles yet. I'm still not entirely clear on what's broken with them, other than collisions, which this doesn't actually fix.@Patrick: It's not difficult at all. Reading it, there's a total of 9 functions, which wouldn't require much witchcraft at all to make them run [other than the callback, which would need to be used to safely delete the relevant object here].
What I want to avoid, though, is demanding modifications of the default library to anyone trying to use ODEScript; I've always had in mind the nebulous goal of build instructions being simple enough that anyone could use them, without requiring modifications to any of the rest of torque, or ODE. I remember having a really hard time making ODEItem run, back in the day, in part because it required ODE modifications.
Gary (-;
#88
07/20/2007 (7:54 pm)
Resource integrates into TGEA 1.01 without any problems whatsoever.
#89
Gary (-;
07/23/2007 (3:08 pm)
Fantastic! I'm always glad to hear someone else getting good use from it :-)Gary (-;
#90
Try this: Create a cube with size 1,1,1 and density 0.2. It will float. Now create a cube of 10,10,10... it will go down. This is wrong.
Cause:
The ODEScript resource is using the mBuoyancy factor computed by the ShapeBase. This calculation uses the density parameter in the ShapeBaseData datablock (see ShapeBase::updateContainer) not the density assigned in the SetBox method (or related). This may cause a wrong calculation.
Im looking for a solution for this one. If I found something useful Ill send it.
EDIT:
I was considering the default calculations. It works fine provided that you define a datablock for EACH shape and define the density attribute. In my game I must assign a dynamic density for each cube so it may not work. I have found a solution which allows me to set the density for each object. Ill send it in case you find it useful.
07/24/2007 (1:44 pm)
I'm testing this resource and found a problem with buoyancy. It looks like the buoyancy wont accept the object density.Try this: Create a cube with size 1,1,1 and density 0.2. It will float. Now create a cube of 10,10,10... it will go down. This is wrong.
Cause:
The ODEScript resource is using the mBuoyancy factor computed by the ShapeBase. This calculation uses the density parameter in the ShapeBaseData datablock (see ShapeBase::updateContainer) not the density assigned in the SetBox method (or related). This may cause a wrong calculation.
Im looking for a solution for this one. If I found something useful Ill send it.
EDIT:
I was considering the default calculations. It works fine provided that you define a datablock for EACH shape and define the density attribute. In my game I must assign a dynamic density for each cube so it may not work. I have found a solution which allows me to set the density for each object. Ill send it in case you find it useful.
#91
a. Go to ODEShape::processTick and locate this:
And change it with this:
Of course you may optimize it in a single line like:
Now we have the variable, we have to make it accesible for construction.
c. Go to ODEShape::ODEShape() constructor and add this line:
This way we have a default value. so the engine wont crash.
d. Finally, go to void ODEShape::initPersistFields() and add this line on the end of the method:
This will allow for acces to the property. Now compile.
e. in order to make this work, now you have to set the object density in when you create the ODEShape in the script. Like this:
You have to set the object density to the same value used for the ODEMass calls.
Note: once this changes are done, SETTING THE DENSITY IN THE ODEShape IS AN OBLIGATORY REQUIREMENT. Some improvements would be to add another attribute to the class in order to make this variable optional in the calculations.
07/25/2007 (7:49 am)
Ok, I found a quick and dirty solution for my problem. a. Go to ODEShape::processTick and locate this:
if(!InLiquid) {
Con::executef(mDataBlock,4,"onEnterLiquid",scriptThis(), Con::getFloatArg(mWaterCoverage), Con::getIntArg(mLiquidType));
InLiquid=true;
}
// mDrag and mBuoyancy are calculated by ShapeBase, in UpdateContainer.
VectorF floatforce(Con::getFloatVariable("$pref::ODEPhysics::Server::WorldGravityX", 0),
Con::getFloatVariable("$pref::ODEPhysics::Server::WorldGravityY", 0),
Con::getFloatVariable("$pref::ODEPhysics::Server::WorldGravityZ", -5));
floatforce *= -mBuoyancy;
... etc etcAnd change it with this:
if(!InLiquid) {
Con::executef(mDataBlock,4,"onEnterLiquid",scriptThis(), Con::getFloatArg(mWaterCoverage), Con::getIntArg(mLiquidType));
InLiquid=true;
}
// mDrag and mBuoyancy are calculated by ShapeBase, in UpdateContainer.
//Hack... the mBuoyancy is computed with a wrong density, recompute
F32 newBuoyancy = mBuoyancy * mDataBlock->density; //cancel previous buoyancy
newBuoyancy = newBuoyancy / mDensityODE; //new attribute for ODEShape
VectorF floatforce(Con::getFloatVariable("$pref::ODEPhysics::Server::WorldGravityX", 0),
Con::getFloatVariable("$pref::ODEPhysics::Server::WorldGravityY", 0),
Con::getFloatVariable("$pref::ODEPhysics::Server::WorldGravityZ", -5));
floatforce *= -newBuoyancy; //DONT FORGET THIS!!!
... etc etcOf course you may optimize it in a single line like:
floatforce *= - mBuoyancy * mDataBlock->density / mDensityODE; [/code I just wanted to make the idea clear. b. Now we have to add the mDensityODE attribute. Go to the ODEShape.h file and in the ODEShape declaration locate in line 83: [code] bool InLiquid; // This is a state variable for stuff entering/leaving liquidsAnd add:
bool InLiquid; // This is a state variable for stuff entering/leaving liquids F32 mDensityODE; // Set the object density
Now we have the variable, we have to make it accesible for construction.
c. Go to ODEShape::ODEShape() constructor and add this line:
mDensityODE = 1;
This way we have a default value. so the engine wont crash.
d. Finally, go to void ODEShape::initPersistFields() and add this line on the end of the method:
addField("densityODE", TypeF32,
Offset(mDensityODE, ODEShape), "The object density for buoyancy computations");This will allow for acces to the property. Now compile.
e. in order to make this work, now you have to set the object density in when you create the ODEShape in the script. Like this:
%obj = new ODEShape() {
datablock = ODESimpleCube;
contactgroup = $odecollisionjg;
worldsim = $odeworld;
ignorewater = false;
densityODE = %density; //LOOK HERE!!!!
};You have to set the object density to the same value used for the ODEMass calls.
Note: once this changes are done, SETTING THE DENSITY IN THE ODEShape IS AN OBLIGATORY REQUIREMENT. Some improvements would be to add another attribute to the class in order to make this variable optional in the calculations.
#92
Do I have to build the actor up using boxes like you would with Ageia PhysX, or are you just using the blue guy? I was wondering this because I have a player that is composed of one single mesh, and then I'd activate ragdoll on death by applying physics to the verts of each individual node, joined by a joint. Do you understand what I mean?
10/01/2007 (9:09 pm)
QuestionDo I have to build the actor up using boxes like you would with Ageia PhysX, or are you just using the blue guy? I was wondering this because I have a player that is composed of one single mesh, and then I'd activate ragdoll on death by applying physics to the verts of each individual node, joined by a joint. Do you understand what I mean?
#93
Yeah, the one in the videos is made up of boxes instead of one shape with multiple nodes.
If you look in the code, I started working on a way to just animate nodes individually, instead of entire shapes, but two things sprang up:
1) Torque doesn't provide rich enough collision information to figure out which node was hit. It's not really torque's fault, they use bounding boxes, but it's a blocker as-is.
1a) Ben Garney's Polysoup may or may not fix this. I never tried because I wasn't satisfied with the licensing terms, so I didn't download it.
:checks: Huh. Apparently, as of the 17th August, the licensing terms have changed. So maybe it's a lot more feasible now.
2) Somehow my node animations never actually, you know, animated the nodes. I based my stuff off Paul Dana's Turret resource. Just set tdBody.nodename and see what happens.
Look in tbodyconsole.cc, ll 774-843, and tbody.cc, ll 205-221
Gary (-;
10/02/2007 (10:12 am)
@Bryce:Yeah, the one in the videos is made up of boxes instead of one shape with multiple nodes.
If you look in the code, I started working on a way to just animate nodes individually, instead of entire shapes, but two things sprang up:
1) Torque doesn't provide rich enough collision information to figure out which node was hit. It's not really torque's fault, they use bounding boxes, but it's a blocker as-is.
1a) Ben Garney's Polysoup may or may not fix this. I never tried because I wasn't satisfied with the licensing terms, so I didn't download it.
:checks: Huh. Apparently, as of the 17th August, the licensing terms have changed. So maybe it's a lot more feasible now.
2) Somehow my node animations never actually, you know, animated the nodes. I based my stuff off Paul Dana's Turret resource. Just set tdBody.nodename and see what happens.
Look in tbodyconsole.cc, ll 774-843, and tbody.cc, ll 205-221
Gary (-;
#94
10/10/2007 (3:24 am)
Is is possible to implement this to TGEA and is it possible to control ode script object like player?
#95
10/12/2007 (12:48 pm)
Problem with TGEA 1.0.3... Link by water wont swim in water. How i can fix this?
#96
/usr/local/ode/lib/libode.a(libode_a-error.o) reference to undefined _fprintf$LDBLStub
and a bunch of other errors that say that functions in stdio.h aren't defined, any idea what's going wrong?
(i tried it with ODE 8.1 and ODE 9, same error)
10/30/2007 (10:45 am)
i hate to bother you again, but i have to reinstall ode into a separate torque source (i put a big resource in the one that was working, and then found out it was windows only) anyway now i'm getting the error /usr/local/ode/lib/libode.a(libode_a-error.o) reference to undefined _fprintf$LDBLStub
and a bunch of other errors that say that functions in stdio.h aren't defined, any idea what's going wrong?
(i tried it with ODE 8.1 and ODE 9, same error)
#97
Thanks for this!
I was wondering what the next step is?
Am I headed in the right direction:
So we take the box man and slip him inside kork. Then the box upper arm and lower arm become the collision mesh for kork's arm. When you/ode modify the boxy arm I need to make a bone inside the box arm and then it does the animation for kork's mesh vertices.
12/19/2007 (10:40 am)
Gary,Thanks for this!
I was wondering what the next step is?
Am I headed in the right direction:
So we take the box man and slip him inside kork. Then the box upper arm and lower arm become the collision mesh for kork's arm. When you/ode modify the boxy arm I need to make a bone inside the box arm and then it does the animation for kork's mesh vertices.
#98
03/17/2008 (5:27 am)
Does someone have this in a format that's not lyx? I don't have any of the programs needed to use this!
#99
how do i fix this?
05/13/2008 (8:07 am)
i got OS X leopard a while ago and ever since then i haven't been able to use ODE, i get the errors:
"___stderrp"
"___stdoutp"
"___cxa_atexit"
"__ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_"
"__ZSt18_Rb_tree_incrementPKSt18_Rb_tree_node_base"
"__ZSt18_Rb_tree_decrementPSt18_Rb_tree_node_base"
"_fwrite$UNIX2003"
symbol(s) not found
how do i fix this?
#100
It compiles with some minor changes, but after running newbox(); the box just sits where it spawned.
EDIT: Okay, it works (*mostly). The onStaticModified method accepts one more argument now in 1.7.0 than it used to. I added this argument to the ODEscript code and now the engine is calling it properly.
* The simulation is very jerky... and stuff still falls through the floor on occasion :(
05/28/2008 (3:40 pm)
Has anyone got this working with TGEA 1.7.0?It compiles with some minor changes, but after running newbox(); the box just sits where it spawned.
EDIT: Okay, it works (*mostly). The onStaticModified method accepts one more argument now in 1.7.0 than it used to. I added this argument to the ODEscript code and now the engine is calling it properly.
* The simulation is very jerky... and stuff still falls through the floor on occasion :(
Torque Owner G
Now I get this when I try to compile your new set:
I was pretty careful about following the instructions... but I miss things... I don't think I did...
I was wondering... Do I have to implement FPS.Starter? Besides FPS.Starter doesnt have the source changes listed. I noticed that all the demos neglect to include the change logs. I wouldn't mind but Im trying to make a clean set to add all things manually.