Jump to content
  • Advertisement
Sign in to follow this  
Considerate

Simulation step using sweep test

This topic is 2839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,
I'm building a simple physics engine with a friend as a school project. We have implemented sweep tests for collision detection and I believe they work fine.
There is a major bug in our implementation though, when two objects are in contact other objects pass right through due to their collision time occurring after the two others'.
I would like to know how you could implement the physics step in a robust way so that it can take all possible collisions into account.
I believe our algorithm for handling the collision detection is flawed.

A pseudo code of our implementation:

Physics step for one frame(time):
for all objects
apply gravity
integrate new acceleration and velocity over time

get first collision:
minCollsionTime = Infinity
for all objects as current
for all objects as other
if current collides with other in time step
if collision time <= minCollisionTime
firstCollision = collision
minCollisionTime = collision time
return firstCollision

if collision occured
handle collision between the two objects
move all objects along their velocities during collision time
calculate new velocities using impulse for collided objects
if (frame time - collision time) > Epsilon and iterations < MAX_ITERATIONS
new step (frame time - collision time)
else
move all objects along their velocities during frame time


My guess is that after all iterations have been processed the objects just continue along their paths and interpenetrate.
I would appreciate all help I can get. Can you please provide an algorithm for the physics step or modifications to ours?

Thank you,
Considerate

Share this post


Link to post
Share on other sites
Advertisement
You need to process all contacts in the world in TOI order... Also - never move objects positions directly, only alter their velocities; moving positions only leads to pain.

There is a solid implementation of this in Box2d for reference purposes :)

Cheers, Paul.

Share this post


Link to post
Share on other sites

You need to process all contacts in the world in TOI order... Also - never move objects positions directly, only alter their velocities; moving positions only leads to pain.

There is a solid implementation of this in Box2d for reference purposes :)

Cheers, Paul.


So the step should go through all collisions that occurred this frame and only affect velocities?
I don't mean to be rude, you clearly seem you know what you're talking about but if one object collides with two other objects
how can we know what position it will collide with the second one on? If we don't move the object the intersection point will be in the wrong location.
Please correct me if I'm wrong.

Thank you for your quick reply,
Considerate

Share this post


Link to post
Share on other sites

[quote name='wildbunny' timestamp='1299705610' post='4783726']
You need to process all contacts in the world in TOI order... Also - never move objects positions directly, only alter their velocities; moving positions only leads to pain.

There is a solid implementation of this in Box2d for reference purposes :)

Cheers, Paul.


So the step should go through all collisions that occurred this frame and only affect velocities?
I don't mean to be rude, you clearly seem you know what you're talking about but if one object collides with two other objects
how can we know what position it will collide with the second one on? If we don't move the object the intersection point will be in the wrong location.
Please correct me if I'm wrong.

Thank you for your quick reply,
Considerate
[/quote]

Sorry, i didn't explain myself at all well there - you are correct, you do need to know where every contact point should be.... if i recall correctly box2d moves a kind of ghost object in the TOI sub-step which lets it understand where to put all the contacts, but doesn't ever actually warp the objects themselves - its all done through velocities in the contact solver.

I recommend have a close look at their implementation for the full story :)

Cheers, Paul.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!