Presentation is loading. Please wait.

Presentation is loading. Please wait.

What you will learn today

Similar presentations


Presentation on theme: "What you will learn today"— Presentation transcript:

1 What you will learn today
How to implement simple collision detection

2 Sphere Collisions How do we know if these have collided?

3 Sphere Collisions Distance!

4 Sphere Collisions More precisely :
if( length(sphereApos - sphereBPos) < radiusA+ radiusB){ What is a potential problem with this approach? What if the spheres are moving really fast?

5 Activity: Are these spheres going to collide?
5 min, discuss with neighbors Are these spheres going to collide? How can you tell if they collided between frames? sphereAPos = (.4,.1, 0) sphereARadius = .5 sphereAMovementDir = (0,2,0) sphereAPos += sphereAMovementDir; sphereBPos = (.1, .6, .1) sphereBRadius= .3 sphereBMovementDir =(0,-2,0) sphereBPos += sphereBMovementDir;

6 ‘Swept’ Sphere-Sphere Collisions
for_games.php?page=2

7 Axis Aligned Bounding Boxes(AABB)
A box that is Defined by the min and max coordinates of an object Always aligned with the coordinate axes How can we tell if a point p is inside the box? Initial Airplane Orientation Airplane Orientation 2

8 Detecting Collisions with AABB
Do a bunch of ifs if( px<= maxx && py<= maxy && pz<= maxz && px>= minx && py>= miny && pz>= minz ) then collide = true; else collide = false minx maxx maxy P miny

9 Detecting Collisions with AABB
if mins/maxes overlap then collide = true else collide = false; Bminx Bmaxx Bmaxy Aminx Amaxx Bminy

10 AABB Approach Initialization: Iterate through the model’s vertices and find mins and maxes Apply Transformations and Iterate through AABB vertices to find mins and maxes

11 AABB Approach Initialization During runtime
iterate through all vertices of your model to find the mins and maxes for x, y, and z During runtime Test if any of the AABB mins/maxes of one object overlap with another object’s AABB mins/maxes MAKE SURE THAT THE AABB VALUES ARE IN THE SAME FRAME (e.g., world coordinates)! This is equivalent to multiplying the 8 points by a matrix for each object Then make sure to recalculate your mins/maxes from the 8 transformed points! Note: it is possible to do this with only 2 points from the box: (minx,miny,minz), (maxx,maxy,maxz), but not required

12 Manually Transforming Objects for Collisions
Manually transform all things collideable into world coordinates: mat4 trans = // object->world transformation glm::rotate(a,x,y,z)*glm::translate(p); mymesh.draw(trans); for(int i = 0; i< 8; i++) // transform BB to world worldBB[i] = trans*mymesh.BB[i]; Now recalculate mins/maxes from worldBB and use for collision detection calculations! tests_for_games.php?page=3

13 Review: What you learned today
How to implement simple collision detection Sphere collisions Axis Aligned Bounding Boxes (AABB) REMEMBER TO TRANSFORM EVERYTHING INTO WORLD SPACE BEFORE COLLISION DETECTION


Download ppt "What you will learn today"

Similar presentations


Ads by Google