collision detection and response. motivation opengl is a rendering system opengl is a rendering...

20
Collision Detection Collision Detection and Response and Response

Upload: alvin-mccoy

Post on 13-Dec-2015

237 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Collision Detection and Collision Detection and ResponseResponse

Page 2: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

MotivationMotivation

OpenGL is a rendering systemOpenGL is a rendering system OpenGL has no underlying knowledge of OpenGL has no underlying knowledge of

the objects it drawsthe objects it draws Collision Detection == Intersection Collision Detection == Intersection

DetectionDetection

Page 3: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

MotivationMotivation

Collision DetectionCollision Detection Identifying the intersection of 3D modelsIdentifying the intersection of 3D models

Collision ResponseCollision Response Calculating the appropriate post collision Calculating the appropriate post collision

response of the 3D modelsresponse of the 3D models AssumptionsAssumptions

Closed 3D polygonal objectsClosed 3D polygonal objects

Page 4: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Overall ApproachOverall Approach

Where is collision detection and Where is collision detection and response in code?response in code?

In animation functionIn animation functionUsually in Idle or DisplayUsually in Idle or DisplayUpdate object positionsUpdate object positionsIf (CollisionDetection())If (CollisionDetection())

Collision Response()Collision Response()Draw ObjectsDraw Objects

Page 5: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Collision DetectionCollision Detection

Basic Collision Detection functionBasic Collision Detection function for (i=0;i<num_of_objects-1;i++)for (i=0;i<num_of_objects-1;i++)

for (j=i+1;j<num_of_objects;j++)for (j=i+1;j<num_of_objects;j++)X=TestIntersection(Object I, Object j)X=TestIntersection(Object I, Object j)If (x==1) return 1;If (x==1) return 1;

Page 6: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Collision Detection PackagesCollision Detection Packages

SWIFT++SWIFT++http://www.cs.unc.edu/~geom/SWIFT++http://www.cs.unc.edu/~geom/SWIFT++

//Works on ‘polygon soup’Works on ‘polygon soup’

Page 7: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Why is collision detection Why is collision detection difficult?difficult?

Too many calculationsToo many calculationsReduce # of calculationsReduce # of calculations

AccuracyAccuracyAccept approximationsAccept approximations

Lots of poor casesLots of poor casesGuarantee detection?Guarantee detection?Accuracy requirements?Accuracy requirements?

http://www.cs.unc.edu/~geom/http://www.cs.unc.edu/~geom/collide/index.shtmlcollide/index.shtml

Page 8: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Reduce CalculationsReduce Calculations

Reduce object Reduce object complexitycomplexity

Test with only Test with only other objects other objects that might be that might be within collision within collision spacesspacesSpatial divisionsSpatial divisions

Pre-process vs. Pre-process vs. runtimeruntime

Page 9: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Approximate Object ShapeApproximate Object Shape

For many For many applications, it is not applications, it is not necessary to get necessary to get absolute collision absolute collision detection accuracydetection accuracy

How can we How can we approximate the approximate the shape?shape?

Page 10: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Bounding BoxesBounding Boxes

Calculate a 3D box that Calculate a 3D box that bounds the objectbounds the object

In the collision detection In the collision detection test, use the 3D box to test, use the 3D box to test for collision in place test for collision in place of the full modelof the full model

Two typesTwo types Axis AlignedAxis Aligned

Bounding boxes are aligned Bounding boxes are aligned w/ the world coordinate w/ the world coordinate axesaxes

Object AlignedObject Aligned Bounding boxes are aligned Bounding boxes are aligned

w/ the object coordinate w/ the object coordinate axesaxes

Page 11: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Axis Aligned Bounding BoxesAxis Aligned Bounding Boxes

How do we calculate a How do we calculate a AABB?AABB? Take max and min for each Take max and min for each

dimensiondimension ProsPros

Very fastVery fast Works for many situationsWorks for many situations

ConsCons Collision detection accuracy Collision detection accuracy

reduced for many casesreduced for many cases

Page 12: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Axis Aligned Bounding BoxesAxis Aligned Bounding Boxes

How do we calculate How do we calculate intersections?intersections? Calculate overlap for the min-Calculate overlap for the min-

max range for each dimensionmax range for each dimension ProsPros

Very fastVery fast Works for many situationsWorks for many situations

ConsCons Collision detection accuracy Collision detection accuracy

reduced for many casesreduced for many cases

Page 13: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Object-Aligned Bounding Object-Aligned Bounding BoxesBoxes

Calculate BB based on object’s primary dimensionsCalculate BB based on object’s primary dimensions Object’s dimensions could be encoded in model or Object’s dimensions could be encoded in model or

calculated real-timecalculated real-time Apply M matrix to bounding box coordinatesApply M matrix to bounding box coordinates

Page 14: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Other bounding shapesOther bounding shapes

BoxesBoxesCubesCubesCylindersCylindersPolygonsPolygonsUser-defined User-defined

shapesshapesShould be easy to Should be easy to

calculate and testcalculate and test

Page 15: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Bounding Box ApproachBounding Box Approach

Test collisions Test collisions with BBwith BB

Can either report Can either report collisioncollision

Or then calculate Or then calculate more accurate more accurate collisioncollision Benefits of this Benefits of this

include more include more accurate responseaccurate response

Page 16: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Poor casesPoor cases

Thin objectsThin objects

Page 17: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Poor casesPoor cases

Numerical PrecisionNumerical Precision

Page 18: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Collision ResponseCollision Response

Assuming rigid bodiesAssuming rigid bodies Idea is to “rewind time” and to point Idea is to “rewind time” and to point

of collision and calculate resulting of collision and calculate resulting locationlocation

Page 19: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Why is collision response Why is collision response difficult?difficult?

Resolving interpenetration is difficultResolving interpenetration is difficultMultiple objectsMultiple objects

http://www.peroxide.dk/download/tutorials/tut10/pics/pic04.jpg

Page 20: Collision Detection and Response. Motivation OpenGL is a rendering system OpenGL is a rendering system OpenGL has no underlying knowledge of the objects

Numerical ImprecisionNumerical Imprecision

VibrationsVibrationsSolutions? Minimum deltaSolutions? Minimum delta