Presentation is loading. Please wait.

Presentation is loading. Please wait.

Collision Detection And Response Jae Chun KyungSoo Im Chau Vo Hoang Vu.

Similar presentations


Presentation on theme: "Collision Detection And Response Jae Chun KyungSoo Im Chau Vo Hoang Vu."— Presentation transcript:

1 Collision Detection And Response Jae Chun KyungSoo Im Chau Vo Hoang Vu

2 Collision Detection Definition –Technique of deciding if an object has collided with another object or some aspect of the environment. Application –Virtual environments / simulation –Computer animation (physically based) –Game development

3 Collision Detection Methods Collision detection can be done in many ways. There isn’t a generic algorithm that works for all collisions.

4 1. BIOT Binary Image Overlap Testing –Uses the logical AND. –Logically AND two bitmaps for every pixel in each image. –If there is a region that both objects are occupying at the same time, the result of the AND operation will be an area of pixels. –If such area exists, the two objects have collided.

5 1. BIOT Pros –Most precise method of collision detection between bitmapped images. –Works for all shapes. Cons –Too much computation -> slow

6 2. Bounding Box –Suppose you have 2 objects of irregular shapes. –Represent each object with a bounding box (or a sphere). –Test if the bounding boxes overlap. Pros : Faster than BIOT. Cons : Can detect a collision when graphically, a collision has not occurred. –Solution1: Shrink size of the bounding box. –Solution2: Have multiple bounding boxes.

7 2. Bounding Box Pseudo Code –If (bottom1 left2) => collided –If (top1 > bottom2) && (left1 collided

8 3. Sphere - Sphere Collision Detection A. To determine if two static spheres collide: –Find distance between the 2 centers. –They collide if this distance is less than the sum of their two radii.

9 3. Sphere - Sphere Collision Detection B. To determine if two moving spheres collide: –First, decide the time intervals at which you want perform collision tests. –Then move the spheres according to that time interval using its velocity. (d = d0 + vt) –After that, check for collisions using the same method as checking for static spheres.

10 3. Sphere - Sphere Collision Detection –For example, suppose that your time interval is 1 milisecond. –Then every time 1 ms has passed, call the function that checks to see if the two spheres collide. Note: This method becomes more accurate if we use smaller time intervals. –But hardware might not be able to support it.

11 4. Sphere - Sphere Collision Detection - A Better Approach –First cast a ray from the center of the sphere with respect to the ball’s direction. –Find the point of intersection between the two rays.

12 4. Sphere - Sphere Collision Detection - A Better Approach –With this information there are may ways to detect collisions. One approach is to check for collision only when the balls are near the intersection point. –Another approach is to use laws of physics and calculate the time it takes for each ball to arrive to the intersection point. If the travel time for each ball are same, the two balls collide.

13 Collision Response –Now that we can detect collisions, the next step is to respond to these collisions. –Often times laws of physics are applied to determine how to respond to a collision.

14 A. Sphere - Plane Collision Response –V’ is the new direction vector V is the old direction vector before the collision N is the Normal at the collision point

15 A. Sphere - Plane Collision Response –Then the new vector V’ is calculated as follows: V’= 2 * ( -V dot N ) * N + V (where V and N are unit vectors) This works for all surfaces if a collision point and normal can be found.

16 B. Sphere - Sphere Collision Response –U1, U2 : velocity vectors of the two spheres at the time of impact. –X_Axis : a vector that 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 : the projected vectors of the velocity vectors U1,U2 onto the axis which is perpendicular to the X_Axis. –M1, M2 : masses of the two spheres.

17 B. Sphere - Sphere Collision Response –Objective is to find vectors V1,V2 which are the new velocities after the impact. –Use Elastic Collision Formula : V1x = [(m1-m2)/(m1+m2)] U1x + [(2m2)/(m1+m2)] U2x V2x = [(2m1)/(m1+m2)] U1x + [(m2-m1)/(m1+m2)] U2x

18 B. Sphere - Sphere Collision Response Steps: –1) Find X_Axis X_Axis = (center2 - center1); make X_Axis into unit vector –2) Find U1x, U1y, U2x, U2y U1x = X_Axis * (X_Axis dot U1) U1y = U1 - U1x U2x = -X_Axis * (-X_Axis dot U2) U2y = U2 - U2x

19 B. Sphere - Sphere Collision Response –3) Plug the values into the Elastic Collision Formula to find final velocities of V1x, V2x Note: Since the vectors U1y and U2y do not touch with each other, we know that the final velocity vector for these will be the same. (V1y = U1y and V2y = U2y) –4) Find the final velocity vector for each ball V1f = V1x+V1y V2f = V2x+V2y

20 Sources / Credits / References Black Art of 3D Game Programming by Andre LaMothe (1995) (Text + Image on slide 5) http://www.cs.jhu.edu/~cohen/VW2000/Lectures/Colli sion_Detection.bw.pdf (Text) http://www.cs.jhu.edu/~cohen/VW2000/Lectures/Colli sion_Detection.bw.pdf http://www.cc.gatech.edu/classes/AY2001/cs4455_sp ring/Lectures/18MoSim+CollDet+Wrap.ppt (Text) http://www.cc.gatech.edu/classes/AY2001/cs4455_sp ring/Lectures/18MoSim+CollDet+Wrap.ppt http://nehe.gamedev.net/tutorials/lesson31.asp (Text + Images on slide 16, 18) http://nehe.gamedev.net/tutorials/lesson31.asp Original example/help code written by Jaeil Choi (jerry@cc.gatech.edu)


Download ppt "Collision Detection And Response Jae Chun KyungSoo Im Chau Vo Hoang Vu."

Similar presentations


Ads by Google