Physics: The complete ODE-implementing guide (for beginners)

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.

Which dynamics engine do you use?

ODE
24
80%
OgreTok
4
13%
other
2
7%
 
Total votes: 30

User avatar
Filip
Gnoblar
Posts: 2
Joined: Sun Feb 29, 2004 1:09 pm
Location: Czech Republic

Physics: The complete ODE-implementing guide (for beginners)

Post by Filip »

Okay,
since I feel owing you guys a lot (about five answers on five critical questions), I decided to pay off a little.

This is a complete ODE-implementing guide. It's meant for beginners as well as for troubled advanced users and is mostly compilation of posts from Antiarc and people from the ODE mailing list. I only fixed some incongruities and things that didn't work on my system.

It's intended for MSVC 6.0, Service Pack 5, but it should work for any later version with only minor changes.

ODE stands for Open Dynamics Engine. It gives you the ability to introduce high quality and stable physics into your engine. For many games (like racing) this means a radical difference between playable and unplayable. For most others it can be at least a major feature.
ODE shares it's position with OgreTok here on Ogre3D Forums. OgreTok is an implementation of Tokamak dynamics engine. It's said to be easier to use, but less powerful and less stable. I can't really tell if that's truth, I never played with this engine. Anyway, if you'd first like to try OgreTok, just download that from Ogre3D.org's download page and good luck. (It's part of Ogre Add-Ons CVS Snapshot archive under Source Releases / Unstable CVS Snapshots category. Here.)


Now, here start's the guide:

1) Get the ODE source from http://q12.org/ode/. Get the GNU make.exe from here and copy it to the ODE directory.

2) In a console (DOS-prompt), run your vcvars32.bat file to set your path variables for making source under Windows. If this doesn't work (the windows don't have enough spare variables memory), add vcvars32.bat to your autoexec.bat and restart.
Let the prompt running.

3) Edit the ode/config/user-settings file. Change PLATFORM to msvc, so you have this:

Code: Select all

PLATFORM=msvc
And if you're planning to use mesh collision, uncomment OPCODE_DIRECTORY:

Code: Select all

OPCODE_DIRECTORY=OPCODE
4) If you're planning to use mesh collision, you'll first have to compile OPCODE (OPtimized COllision DEtection), which is included in the ODE source install. Just run your MSVC, open (ode_directory)/OPCODE/Opcode.dsp and build opcode.lib. Find your opcode.lib and place it in a suitable place (maybe msvc lib dir? it is included in the vcvars32.bat). You may have to add your stlport_vc6_static.lib there too.

5) Return to command prompt, go to the ODE directory and run make.exe. Hold your breath and ignore any non-critical errors. Try the ODE tests in (ode_directory)/ode/test. If everything works just fine, then congratulations -- you lucky bastard! :lol:
Anyway, you may notice that the mesh collision doesn't work (run test_moving_trimesh.exe and see if the balls and boxes do actually rebound from the two rabbits). This was my case, so here's the solution:

You may skip this, if everything worked fine for you.
What you have to do now is to build ODE with MSVC. Go to this page (ODE Wiki Area) to get full description of how to do that.
There is a major change thought, since you need a LIB, not an EXE. I recommend first following the instructions on the page and seeing if you can get the test_moving_trimesh.exe working. You'll have to additionally include OPCODE directory and opcode.lib. And you'll have to add dTRIMESH_ENABLED preprocessor definition in the Project Settings C/C++ Tab.
After that you see it works, make a new project - not a console application, but a static library. There's no option for including LIBs when making other LIB, but don't worry. MSVC will do that for you, just don't forget to include to OPCODE directory and define dTRIMESH_ENABLED again (I'm not sure if this is really necessary, but who knows...).
Ignore any warnings in the process of compiling - there will be many of them.
Hmpf, I hope this worked, 'cause I really wouldn't know what to advice you then.

6) Copy ode/ode.lib to ogremain/lib/debug and the ode/include/ode directory to ogremain/include.

7) Add ode.lib to your additional libraries under the Linker portion of your project properties. Add opcode.lib too, in case you want to use the mesh collision.

8) Include ODE libraries in your program like this:

Code: Select all

#include "Ogre.h"

#include "OgreNoMemoryMacros.h" 
#include "ode/ode.h" 
#include "OgreMemoryMacros.h"
9) Installed!
Antiarc wrote:ODE is now installed! To use it, you'll simply create Body objects and logically tie those to SceneNodes by mirroring a Body object's position with the SceneNode's position. You will apply forces to a Body, then get the body's position and change your "sibling" SceneNode's position to match. Hope you enjoy!
10) Get your API reference and read through the very useful ODE FAQ. There you'll also find answer for the question How can I implement my collision callback as a C++ member function?. Important!
Another very useful source of information is Antiarc's Using ODE in your projects! topic here on Ogre Forums including geekd's codes to translate between ODE Bodies and Ogre SceneNodes.


I hope you got the thing running. You're gonna love it!
Bye
- Filip
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

You didn't mention changing the makefile to include the /MD[d] option, as mentioned in this thread, which I found was required to stop ODE crashing on the first collision when linked with other multithreaded dll libs like OGRE. Is it because this the default now (I haven't used ODE in some months), or does it need to be added?
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Nice :)

Maybe you could link some of the topics with ODE questions/answers in your post too, for example the recent one about stacking ( http://www.ogre3d.org/phpBB2/viewtopic.php?t=3941 ) People are bound to have problems like this when starting with Ode :)

BTW the other dynamics engine is called 'Tokamak' not 'OgreTok', Ogretok is the name of the binding to Ogre.
User avatar
Filip
Gnoblar
Posts: 2
Joined: Sun Feb 29, 2004 1:09 pm
Location: Czech Republic

okay

Post by Filip »

Okay, guys, thanks for the additions.

sinbad: I don't have any problems with the sharing (yet?), so I didn't know about this one.
No, it's not default. So people, please, if you encounter this problem, be good boys and go to the above listed sinbad's thread.

wumpus: Stacking is not as much connected with actual 'getting it to work', but still it's very important, so thanks.
:wumpus: wrote:BTW the other dynamics engine is called 'Tokamak' not 'OgreTok', Ogretok is the name of the binding to Ogre.
Okay, I know that, but in Ogre - as far as I know - people are mostly using the OgreTok binding instead of coding their own.

Thanks again :wink:
- Filip