Top Banner
CS361 Week 13 - Friday
21

Week 13 - Friday. What did we talk about last time? Ray/sphere intersection Ray/box intersection Slabs method Line segment/box overlap test.

Dec 31, 2015

Download

Documents

Agnes Newman
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

CS361Week 13 - Friday

Page 2: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 3: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

Questions?

Page 4: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

Assignment 5

Page 5: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

Project 4

Page 6: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 7: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 8: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 9: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 10: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

}

Page 11: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

}

Page 12: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

}

Page 13: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 14: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 15: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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)

Page 16: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 17: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

Page 18: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

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

)

Page 19: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

Upcoming

Page 20: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

Next time…

Collision detection

Page 21: Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.

Reminders

Keep working on Project 4 Start Assignment 5 Read Chapter 17