Download presentation
Presentation is loading. Please wait.
Published bySilvester Mason Modified over 8 years ago
1
Fundamentals of Computer Animation Collision Detection and Response
2
So far, no interaction between rigid bodies Bodies in Collision Collisions and Contact Collision detection – determining if, when and where a collision occurs Collision response – calculating the state (velocity, …) after the collision
3
What should we do when there is a collision? Collisions and Contact
4
Restart the simulation at the time of the collision Rolling Back the Simulation Collision time can be found by bisection, etc.
5
Ray-Scene Intersection
6
Types of Geometry Points Lines, Rays and Line Segments Spheres, Cylinders and Cones Cubes, rectilinear boxes - Axis aligned or arbitrarily aligned –AABB: Axis aligned bounding box –OBB: Oriented bounding box k-dops – shapes bounded by planes at fixed orientations Convex, manifold meshes – any mesh can be triangulated –Concave meshes can be broken into convex chunks, by hand Triangle soup More general curved surfaces, but not used (often) in games 8-dop AABB OBB
7
Ray-Sphere Intersection
8
Ray-Sphere Intersection I
9
Ray-Sphere Intersection II
10
Ray-Sphere Intersection
11
Ray-Triangle Intersection
12
Ray-Plane Intersection
13
Ray-Triangle I Intersection
14
Ray-Triangle II Intersection
15
Other Ray-Primitive Intersections
16
Intersection Tests: How About Object-Object ? We’ll cover: –Spheres –Oriented Boxes –Capsules –Lozenges –Cylinders –Ellipsoids –Triangles But first let’s check some basic issues on collision/response…
17
Exploit coherency through witnessing Collision Detection Speed up with bounding boxes, grids, hierarchies, etc. separating plane Two convex objects are non-penetrating iff there exists a separating plane between them First find a separating plane and see if it is still valid after the next simulation step
18
Collision Detection
19
Conditions for collision Collision Detection separatingcontactcolliding
20
Collision Detection and Response Collision Detection –Moving Sphere - Plane –Moving Sphere - Moving Sphere Physically Based Modeling –Collision Response –Moving Under Gravity Using Euler Equations
21
Ray-Plane Intersection
22
Sphere-Sphere Collision A sphere is represented using its center and its radius d Intersection if d is less than the sum of their two radius
23
How About 2 MOVING spheres? Their paths cross in-between but this is not enough to prove that an intersection occurred (they could pass at a different time) nor can the collision point be determined. 2 spheres move during a time step from one point to another
24
How About 2 MOVING spheres? Sliced time step up into smaller pieces. Move the spheres according to that sliced time step using its velocity, and check for collisions. If at any point collision is found (which means the spheres have already penetrated each other) then –Take the previous position as the intersection point –(we could start interpolating between these points to find the exact intersection position, but that is mostly not required). The smaller the time steps, the more slices we use the more accurate the method is. As an example lets say the time step is 1 and our slices are 3. We would check the two balls for collision at time 0, 0.33, 0.66, 1.
25
Sphere-Plane Collision Determine the exact collision point between a particle and a plane. The start position of the ray is the position of the particle and the direction of the ray is its velocity (speed and direction).
26
Sphere-Plane Collision Each sphere has a radius, take the center of the sphere as the particle and offset the surface along the normal of each plane of interest. Our actual primitives of interest are the ones represented by continuous lines, but the collision testing is done with the offset primitives (represented with dotted lines). In essence we perform the intersection test with a little offset plane.
27
Sphere-Plane Collision Using this little trick the ball does not penetrate the surface if an intersection is determined with its center. Otherwise we get the situation where the sphere penetrates the surface. This happens because we determine the intersection between its center and the primitives.
28
Exact Collision Time We move the sphere (according to its velocity), calculate its new position and find the distance between the start and end point. To calculate the exact time we solve the following simple equation: Tc= Dsc*T / Dst –Dst distance between start - end point –Dsc the distance between start - collision point –T the time step as T
29
The Collision Point The returned time Tc is a fraction of the whole time step, so if the time step was 1 sec, and we found an intersection exactly in the middle of the distance, the calculated collision time would be 0.5 sec. this is interpreted as "0.5 sec after the start there is an intersection". Now the intersection point can be calculated by just multiplying Tc with the current velocity and adding it to the start point. Collision point = Start + Velocity*Tc This is the collision point on the offset primitive, to find the collision point on the real primitive we add to that point the reverse of the normal at that point (which is also returned by the intersection routines) by the radius of the sphere.
30
Collision Response
31
Collision Response Sphere approaching a Plane What kind of response? Totally elastic! No kinetic energy is lost response is “perfectly bouncy”
32
“Perfectly Bouncy” Response
33
Soft Body Collision Collision Force is applied to prevent interpenetration
34
Soft Body Collision Collision Apply forces and change the velocity
35
Harder Collision Collision Higher force over a shorter time
36
Rigid Body Collision Collision Impulsive force produces a discontinuous velocity
37
How to “Suggest” Sphere “Deformation”? k, in [0,1] coefficient of restitution
38
Using Coefficient of Restitution: As k gets smaller more and more energy is lost less and less bouncy
39
Using Coefficient of Restitution: As k gets smaller more and more energy is lost less and less bouncy
40
U1 and U2 velocity vectors of the two spheres at the time of impact X_Axis vector which joins the 2 centers of the spheres U1x, U2x projected vectors of the velocity vectors U1,U2 onto the axis (X_Axis) vector U1y and U2y are the projected vectors of the velocity vectors U1,U2 onto the axis which is perpendicular to the X_Axis Collisions Between Spheres (1)
41
a) Find X_Axis X_Axis = (center2 - center1); Unify X_Axis, X_Axis.unit(); b) Find Projections U1x= X_Axis * (X_Axis dot U1) U1y= U1 - U1x U2x =-X_Axis * (-X_Axis dot U2) U2y =U2 - U2x c) Find New Velocities (U1x * M1)+(U2x*M2)-(U1x-U2x)*M2 V1x= ---------------------------------------------------- M1+M2 (U1x * M1)+(U2x*M2)-(U2x-U1x)*M1 V2x= ------------------------------------------------------ M1+M2 d) Find The Final Velocities V1y=U1y V2y=U2y V1=V1x+V1y V2=V2x+V2y M1, M2 is the mass of the two spheres V1,V2 are the new velocities after the impact, V1x, V1y, V2x, V2y are the projections of the velocity vectors onto the X_Axis.
42
Moving Under Gravity All the computations are going to be performed using time steps. This means that the whole simulation is advanced in certain time steps during which all the movement, collision and response tests are performed. As an example we can advanced a simulation 2 sec. on each frame. Based on Euler equations, the velocity and position at each new time step is computed as follows: Velocity_New = Velovity_Old + Acceleration*TimeStep Position_New = Position_Old + Velocity_New*TimeStep
43
Moving Under Gravity Velocity_New = Velovity_Old + Acceleration*TimeStep Position_New = Position_Old + Velocity_New*TimeStep Now the objects are moved and tested against collision using this new velocity. The Acceleration for each object is determined by accumulating the forces which are acted upon it and divide by its mass according to this equation: Force = mass * acceleration But in our case the only force the objects get is the gravity, which can be represented right away as a vector indicating acceleration. In our case something negative in the Y direction like (0,-0.5,0).
44
At the beginning of each time step Calculate the new velocity of each sphere Move them testing for collisions. If a collision occurs during a time step (say after 0.5 sec with a time step equal to 1 sec.): Advance the object to this position Compute the reflection (new velocity vector) Move the object for the remaining time (which is 0.5 in our example) testing again for collisions during this time. This procedure gets repeated until the time step is completed.
45
Collisions Between Spheres (2) Spheres of equal size and weight. For now let’s ignore the rotation and do not consider friction The sphere collision will behave exactly like a particle at the sphere's center of mass.
46
Setup + Terminology Ball A is moving at a speed of 20 feet per second and collides with ball B at a 40 degree angle. Impact a collision between two rigid bodies, which occurs in a very short time and during which the two bodies exert relatively large forces on each other Impulsive force the force between these two bodies during the collision (symbolized by j) Line of collision The common normal to the surfaces of the bodies in contact
47
New velocity along the line of collision: Impulsive force between the bodies? The impulse acts on both bodies at the same time The forces exerted by two particles on each other are equal in magnitude and opposite in direction. Since the impulse forces are equal and opposite, momentum is therefore conserved before and after the collision. –Momentum of a rigid body is mass times velocity (mv).
48
We need to derive the impulse force directly. The impulse force creates a change in momentum of the two bodies with the following relationship:
49
We need to derive the impulse force directly. The impulse force creates a change in momentum of the two bodies with the following relationship: The impulse equation for a general body that does not rotate. Chris Hecker "Physics, Part 3: Collision Response,"Physics, Part 3: Collision Response Behind the Screen, Game Developer, February/March 1997
50
k, in [0,1] coefficient of restitution
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.