Polyart 2D Physics Engine
Section 4: Collision Response
Collision Response
Types of collision prevention fallbacks (Response types)- When one type fails to prevent interpenetration, the next is used
- Impulse - An impulse will be applied to prevent the segments from interpenetrating. Friction is only applied at this step.
- Relative Freeze A - The velocities at the points of collision in the direction of the normal will be set to the average.
- Relative Freeze B - The velocities at the points of collision will be set to the average.
- Movement Fudge - The velocity will be changed JUST for the current frame making the objects move apart. This is useful if the necessary velocity will launch the object unrealisticly fast. Since it modifies a velocity invisible to the other response types and might cause them to malfunction, only a total freeze should be attempted after this.
- Total Freeze - No movement will take place. Since the objects on this frame are not colliding, preventing movement will ensure this on the next frame.
Alternative fallback - Soft/Solid collision structure
- Due to floating point roundoff it may be impossible to prevent collision with tightly wedged objects(such as when they rotate and the new rotation no longer fits the inner object).
- Another collision structure just inside of the current structure could be created.
- Any points inside of this structure will always cause a movement fudge.
- This structure should be considered complely solid and no points will ever be permitted to interpenetrate.
Possible collision scenario
- Force is applied and does not prevent interpenetration
- Movement fudge is applied and also fails
- The object is permitted to penetrate the soft structure and use the solid. Movement fudge is applied again.
- At this last attempt the objects linear velocities are set to be the same and the rotational is set to 0.
Objects already penetrating
- These objects will bypass the normal force application and their fudge velocities will be set to move out of each other
CGeometry2D
- StopPoint(V2 P, V2 N, V2 V)- Sets the velocity of a point P to V in the direction of N.
- Project V onto P. Subtract from the linear velocity
- Subtact the linear contribution from the points velocity to find the rotational
- New rotation speed = cross product velocity and P
Resistance at a point is defined as
F/V = Mass for the linear component + 1 / (1/m + R/I) (for the angular component
Suedocode for proper collision routine
- Create octree sets A + B
- Set collision response to time of collision
- A.CollideWith(B) - response function has two bounding boxes one from A and one from B
- Handle first Collision time
- A.CollideWith(BoxFromB);
- B.CollideWith(BoxFromA);
- Update A and B's position in the octrees
- loop to step 4 if more collisions exist
Temporary Collision response
- Create octree sets A + B
- Set collision response to apply collision impulse
- A.CollideWith(B) - response function has two bounding boxes one from A and one from B
- loop to step 3 if a collision happened
Body Set Detection
- Loop through each body set: CurSet
- Loop through each body on the queue for the current set: CurBody
- Loop though each body set that collides with the current set: CurSet2 Collide CurBody with CurSet2
Pose response
In debug mode after body A collides with body B a collision check is applied again and an error message box popped up on the screen stating the response failed to prevent interpenetration.
Copyright 2004 © Polyart. All rights reserved.
Designed by Kenneth Manta