Download presentation
Presentation is loading. Please wait.
Published byAgnes Newman Modified over 9 years ago
1
Week 13 - Friday
2
What did we talk about last time? Ray/sphere intersection Ray/box intersection Slabs method Line segment/box overlap test Ray/triangle intersection Ray/polygon intersection
6
Simplest idea: Plug all the vertices of the box into the plane equation n x + d = 0 If you get positive and negative values, then the box is above and below the plane, intersection! There are more efficient ways that can be done by projecting the box onto the plane
7
Seeing if bounding volumes collide is a fundamental part of most collision detection algorithms Does this ship hit that asteroid? Bounding volumes are often arranged in hierarchies of bounding volumes Bounding volumes allow for easy reject cases
8
Sphere/sphere is the easiest Is the distance between their centers bigger than the sum of their radii? If yes, they are disjoint If no, they overlap c1c1 c2c2 r1r1 r2r2
9
Remember that an AABB is defined by two points, a min and a max We go through each axis (x, y, and z) and first check to see if we can reject based on distance on that axis being too large If not, we add the squared axis's distance to the total If you want to do a sphere/OBB intersection, transform the sphere's center into the axes of the OBB and then the OBB will be an AABB
10
intersect( c, r, A ) { d = 0 for i in x,y,z if( (e = c i – a i min ) < 0 ) if( e < -r ) return DISJOINT d = d + e 2 else if ( (e = c i – a i max ) > 0 ) if( e > r ) return DISJOINT d = d + e 2 if ( d > r 2 ) return DISJOINT return OVERLAP } intersect( c, r, A ) { d = 0 for i in x,y,z if( (e = c i – a i min ) < 0 ) if( e < -r ) return DISJOINT d = d + e 2 else if ( (e = c i – a i max ) > 0 ) if( e > r ) return DISJOINT d = d + e 2 if ( d > r 2 ) return DISJOINT return OVERLAP }
11
We test each dimension to see if the min of one box is greater than the max of the other or vice versa If that's ever true, they're disjoint If it's never true, they overlap intersect(A, B ) { for i in x,y,z if(a i min > b i max or b i min > a i max ) return DISJOINT return OVERLAP } intersect(A, B ) { for i in x,y,z if(a i min > b i max or b i min > a i max ) return DISJOINT return OVERLAP }
12
An AABB is a special case of a 6-DOP Use the same test for an AABB, looking at the mins and maxes of each slab Because the axes of a k-DOP are not necessarily orthogonal, this test is inexact (unlike for the AABB) It is conservative: Some disjoint k-DOPs will report that they overlap, but overlapping k-DOPs will never report disjoint intersect(A, B ) { for i in 1 … k/2 if(d i A,min > d i B,max or d i B,min > d i A,max ) return DISJOINT return OVERLAP } intersect(A, B ) { for i in 1 … k/2 if(d i A,min > d i B,max or d i B,min > d i A,max ) return DISJOINT return OVERLAP }
13
Again, an OBB is surprisingly complex The fastest way found involves the separating axis test There are 15 different axes you've got to test for overlap before you can be sure that the boxes overlap When all the math is worked out, the test is quite fast
14
Because anything visible on the screen will be in the view frustum, we can save time by ignoring objects that are not Remember that the frustum is defined by 6 planes: near, far, left, right, top and bottom When test the frustum against bounding volumes, we will want three answers: outside, inside, and intersect
15
To test frustum intersection, it is necessary to know the plane equations for each of the six frustum planes If the view matrix is V and the projection matrix is P, the final transform is M = PV If m i means the i th row of M, the equations for each plane are as follows: -(m 3 + m 0 ) (x, y, z, 1) = 0(left) -(m 3 – m 0 ) (x, y, z, 1) = 0(right) -(m 3 + m 1 ) (x, y, z, 1) = 0(bottom) -(m 3 – m 1 ) (x, y, z, 1) = 0(top) -(m 3 + m 2 ) (x, y, z, 1) = 0(near) -(m 3 – m 2 ) (x, y, z, 1) = 0(far)
16
We take the center of the sphere p and plug it into each of the plane equations, getting signed distance values Note that the normals of the planes point outwards If the distance to any given plane is greater than radius r, the sphere is outside the frustum If the distances to all six planes are less than –r, the sphere is inside Otherwise, the sphere intersects This test is conservative: Reports some outside spheres as intersections
17
We skipped over the section that says how to test a plane for intersection with a box, but it's a simple calculation To do frustum/AABB intersection, we test the AABB against every plane of the frustum If the box is outside any plane, we return outside If the box is not outside any plane but intersects some plane, we return intersects Otherwise, we return inside
18
We will only look at the 2D problem, but the book has discussion of 3D lines as well For a 2D vector (x, y), we define its perp dot product (x, y) = (-y, x) Thus, we can work through the equations of a line (only the path to the value of s is shown) r 1 (s) = r 2 (t) o 1 + sd 1 = o 2 + td 2 sd 1 d 2 = (o 2 – o 1 ) d 2 s = ((o 2 – o 1 ) d 2 ) / (d 1 d 2 )
20
Collision detection
21
Keep working on Project 4 Start Assignment 5 Read Chapter 17
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.