We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,047 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Frame Independent Movement and Collision (SDL)

Hello everyone!

I've been having some troubles recently trying to work with frame independent movement (based on 300 pixels per second) and having the object collide with another. I'm still pretty new to this idea, but I don't know how I should go about having the character move back from the object if the object is moving based on time. If you could help me out here I'd really appreciate it! Thanks!

2
Contributors
1
Reply
4 Hours
Discussion Span
9 Months Ago
Last Updated
2
Views
claywin
Newbie Poster
4 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

You would probably be better off using an off-the-shelf library for that, like the Open Dynamics Engine (ODE). It's a simple but pretty solid engine for doing computer game physics realism (not for real simulations, of course). The basic idea with this is that you control your objects (characters, vehicles, projectiles, etc.) by specifying initial velocities and applying force to them (e.g., steering, thrust, etc.). Then, the physics engine takes care of the rest (realizing the motion). ODE has simple collision detection routines too, like primitive to primitive collisions (box-box, box-sphere, etc.). I don't think that it does 2D physics though, if that is what you need.

For doing "frame independent movement", it usually involves at least two threads of execution, one for rendering and one for physics simulations (or motion time-integration). The physics simulation is there to update the position (and orientation) of your models with time. The basis for this is ordinary differential equations (ODE) and numerical integration. First, given a system of rigid bodies (e.g., solid objects), there are laws of classical mechanics that help you to compute the acceleration (and angular acceleration) of a body given its state (position, orientation, velocity and angular velocity) and external forces applied to it (gravity, friction, thrusts, etc.), these are called the governing equations (and in rigid-body dynamics, the easiest form is the Newton-Euler Equations), and they are ordinary differential equations (usually). Collisions come in as a large impact force as two bodies collide (and often, additional techniques are employed to deal with collision responses), and that impact is added to the rest. At every time-step, you take the external forces, current states, and impact forces, and use them to compute the acceleration (and angular accel.) of the bodies, and you use that in a numerical integration scheme to obtain an increment in motion for the next point in time.

By making sure that you can accomplish all your "physics" calculations within the actual time-step used for integration, you can achieve real-time "simulation" of the dynamics of the system. Doing this on a thread separated from the rendering thread ensures that you can do this with much smaller time-steps than the time-step at which the rendering is done. I would say that at the most, your integration time-step should be of about 0.01 second (100 Hz), but the lower the better (1e-4 to 1e-6 are really good). Usually, to achieve real-time performance, you have to give up a significant part of the actual precision of the calculations, this is what the ODE library does.

mike_2000_17
21st Century Viking
Moderator
3,136 posts since Jul 2010
Reputation Points: 2,050
Solved Threads: 625
Skill Endorsements: 41

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0653 seconds using 2.81MB