Upload
agnes-newman
View
217
Download
1
Embed Size (px)
Citation preview
Last time
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
Plane/box intersection
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
BV/BV intersection
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
Sphere/sphere intersection
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
c1
c2r1
r2
Sphere/box intersection
Remember that an AABB is defined by two points, amin and amax
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
Sphere/box pseudocode
intersect( c, r, A ){d = 0for i in x,y,z
if( (e = ci – aimin) < 0 )
if( e < -r ) return DISJOINTd = d + e2
else if ( (e = ci – aimax) > 0 )
if( e > r ) return DISJOINTd = d + e2
if ( d > r2 ) return DISJOINTreturn OVERLAP
}
AABB/AABB intersection
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,zif(ai
min > bimax or bi
min > aimax )
return DISJOINTreturn OVERLAP
}
k-DOP/k-DOP intersection 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/2if(di
A,min > diB,max or di
B,min > diA,max )
return DISJOINTreturn OVERLAP
}
OBB/OBB intersection
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
View frustum intersection 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
Frustum planes
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 mi means the ith row of M, the equations for each plane are as follows: -(m3 + m0) • (x, y, z, 1) = 0 (left)
-(m3 – m0) • (x, y, z, 1) = 0 (right)
-(m3 + m1) • (x, y, z, 1) = 0 (bottom)
-(m3 – m1) • (x, y, z, 1) = 0 (top)
-(m3 + m2) • (x, y, z, 1) = 0 (near)
-(m3 – m2) • (x, y, z, 1) = 0 (far)
Frustum/sphere intersection 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
Frustum/box intersection
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
Line/line intersection
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) r1(s) = r2(t)
o1 + sd1 = o2 + td2
sd1 • d2 = (o2 – o1) • d2
s = ((o2 – o1) • d2) / (d1 • d2
)