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

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

Embed Size (px)

Citation preview

  • Collision Detection And Response Jae ChunKyungSoo Im Chau Vo Hoang Vu

  • Collision DetectionDefinitionTechnique of deciding if an object has collided with another object or some aspect of the environment.ApplicationVirtual environments / simulationComputer animation (physically based)Game development

  • Collision Detection MethodsCollision detection can be done in many ways. There isnt a generic algorithm that works for all collisions.

  • 1. BIOTBinary Image Overlap TestingUses 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.

  • 1. BIOTProsMost precise method of collision detection between bitmapped images.Works for all shapes.ConsToo much computation -> slow

  • 2. Bounding BoxSuppose 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.

  • 2. Bounding BoxPseudo CodeIf (bottom1 < top2) && (right1 > left2) => collidedIf (top1 > bottom2) && (left1 < right2) => collided

  • 3. Sphere - Sphere Collision DetectionA. 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.

  • 3. Sphere - Sphere Collision DetectionB. 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.

  • 3. Sphere - Sphere Collision DetectionFor 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.

  • 4. Sphere - Sphere Collision Detection - A Better Approach

    First cast a ray from the center of the sphere with respect to the balls direction.Find the point of intersection between the two rays.

  • 4. Sphere - Sphere Collision Detection - A Better ApproachWith 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.

  • Collision ResponseNow 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.

  • A. Sphere - Plane Collision ResponseV is the new direction vector V is the old direction vector before the collision N is the Normal at the collision point

  • A. Sphere - Plane Collision ResponseThen 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.

  • B. Sphere - Sphere Collision ResponseU1, 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.

  • B. Sphere - Sphere Collision ResponseObjective 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

  • B. Sphere - Sphere Collision ResponseSteps:1) Find X_AxisX_Axis = (center2 - center1);make X_Axis into unit vector

    2) Find U1x, U1y, U2x, U2yU1x = X_Axis * (X_Axis dot U1) U1y = U1 - U1xU2x = -X_Axis * (-X_Axis dot U2) U2y = U2 - U2x

  • B. Sphere - Sphere Collision Response3) Plug the values into the Elastic Collision Formula to find final velocities of V1x, V2xNote: 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 ballV1f = V1x+V1yV2f = V2x+V2y

  • Sources / Credits / ReferencesBlack Art of 3D Game Programming by Andre LaMothe (1995) (Text + Image on slide 5)http://www.cs.jhu.edu/~cohen/VW2000/Lectures/Collision_Detection.bw.pdf (Text)http://www.cc.gatech.edu/classes/AY2001/cs4455_spring/Lectures/18MoSim+CollDet+Wrap.ppt (Text)http://nehe.gamedev.net/tutorials/lesson31.asp (Text + Images on slide 16, 18)

    Original example/help code written by Jaeil Choi ([email protected])

    *