Sign in to follow this  
NickGravelyn

ODE Stepsize

Recommended Posts

I just put a few lines of ODE code into my project to begin using it, but I'm getting a weird error window when I run the project. It says that my stepsize must be greater than 0. I'm using 0.05f as a stepsize like this:
dWorldStep(world, 0.05f);
Any ideas why it's claiming I have a 0 timestep?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Perhaps the second parameter dWorldStep takes an integer type and 0.05f gets rounded to 0?

Share this post


Link to post
Share on other sites
The function declaration is this:
void dWorldStep (dWorldID, dReal stepsize);

The demo apps for ODE use 0.05f as a stepsize, so I'm figuring that it's not getting rounded.

Share this post


Link to post
Share on other sites
Since you arn't controlling how fast your application runs, you need to pass in the difference of time to the step side. This means you're going to have to implement a timer to check how many milliseconds have passed since last update. It will end up being something like this:


static uint deltaTicks = 0;
static uint lastTick = 0;

uint currentTicks = GetTime(); // whatever you use for getting the time
deltaTicks = currentTicks - lastTick;
lastTick = currentTicks; // update the last tick marker

dWorldStep(world, 0.1f * deltaTicks); // 0.1 is speed modifier

Share this post


Link to post
Share on other sites
Quote:
Original post by Jack Sotac
Check out the end of this thread. You may be linking against the wrong version of the ODE library.


That turns out to be right. When I start using the binary version of ODE, it works fine. Now I just have to find a nice way to combine ODE and DirectX meshes...

Share this post


Link to post
Share on other sites
Quote:
Original post by BradDaBug
BTW, it would be well worth your time to implement a fixed timestep system.


How do you suggest I go about this?

Share this post


Link to post
Share on other sites
I think BradDaBug meant you should limit the maximum step size, that way things don't end up in walls (this happens in NFS-MW) or pass through things (this happens in NFSU2). If you've ever used Newton, you might have noticed this happening, since it's built-in, but in ODE, you have to do it yourself. It's not hard to do, all you have to do is get the time as you normally would, check to see if it's greater than the maximum value you've set, and if it is, set it to the maximum value instead, and then pass it off normally. Using Rob Loach's example, you'd do something like this:


...//everything before the step

dReal stepSize = 0.1f * deltaTicks;
#define MAX_STEP_SIZE 0.05f //makes it a little easier to change
if (stepSize > MAX_STEP_SIZE) stepSize = MAX_STEP_SIZE;
#undef MAX_STEP_SIZE

//now we make the step
dWorldStep(world,stepSize);

Share this post


Link to post
Share on other sites
I put that in but now my box just keeps bouncing higher and higher and spinning faster and faster. Is there something else I can do to stop this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Gorax
I think BradDaBug meant you should limit the maximum step size, that way things don't end up in walls (this happens in NFS-MW) or pass through things (this happens in NFSU2).

Although setting a maximum step size is much better than nothing, I meant fixed timesteps. The basic idea is that you set your desired timestep size to something like 0.01 (100 Hz) and then each frame figure out whether you need to take a step or not. Some frames you may not take a step (if you're game is running really fast) and some frames you might take more than one step (if your game is running slower). Whatever happens, each timestep is exactly the same size, completely independent from the frame rate.

Share this post


Link to post
Share on other sites
Sorry about that BradDaBug, I understand what you mean now (oddly enough, I've actually done it before, but a lack of sleep makes it easy to forget things). The only difference between the method I used, and the one you use, is that I assumed everybody's computers were slow, so the maximum time step was required (nothing like not being able to control anything for a few seconds while your computer chokes on something), but in order to keep it stable (so nothing got embedded in the walls, etc.), I had it run through small, fixed time steps (not unlike the ones you mentioned). It's less efficient than your method, but it'd run on (almost) anything without any problems.

NickGravelyn, incase you can't figure out what I'm rambling on about, instead of using some step size up to the maximum step size, run a loop that uses some step size up to some predetermined (smaller) step size that should ensure that nothing stupid happens during the simulation, until the step size acquried in the method I showed you is reached.

Also, your problem is probably the result of you not resetting the 'lastTick' value (I've done it before).

[EDIT]
BradDaBug, feel free to disregard everything I mentioned about my method differing from yours where it doesn't. I really need more sleep...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this