Week 13 - Wednesday. What did we talk about last time? Intersection testing Bounding volumes ...

22
CS361 Week 13 - Wednesday

Transcript of Week 13 - Wednesday. What did we talk about last time? Intersection testing Bounding volumes ...

Page 1: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

CS361Week 13 - Wednesday

Page 2: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Last time

What did we talk about last time? Intersection testing Bounding volumes

Sphere AABB OBB k-DOP

SharpDX tools

Page 3: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Questions?

Page 4: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Project 4

Page 5: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Getting Bounding Spheres from SharpDX Models

Page 6: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

SharpDX Picker

Page 7: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Intersection Methods

Page 8: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Ray/sphere intersection

We can write the implicit sphere equation as f(p) = ||p – c|| – r = 0 p is any point on the surface c is the center r is the radius

By substituting in r(t) for p, we can eventually get the equation t2 + 2tb + c = 0, where b = d • (o – c) and c = (o – c) •(o – c) – r2

If the discriminant is negative, the ray does not hit the sphere, otherwise, we can compute the location(s) where it does

Page 9: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Optimized ray/sphere

Looking at it geometrically, we can optimize the test Find the vector from the ray origin to the center of the

sphere l = c – 0 Find the squared length l2 = l • l If l2 < r2, then o is in the sphere, intersect! If not, project l onto d: s = l • d If s < 0, then the ray points away from the sphere, reject Otherwise, use the Pythagorean theorem to find the

squared distance from the sphere center to the projection: m2 = l2 – s2

If m2 > r2, the ray will miss, otherwise it hits

Page 10: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Ray/box intersection

Ray box intersection is a key element to have in your arsenal

Bounding boxes are a very common form of bounding volume

A ray/box intersection is often the first test you will use before going down deeper

There are a couple of methods Slabs method Line segment/box overlap test

Page 11: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Slabs method

First find the t value where the ray intersects each plane The box is made up of 3 slabs

Find the min t and max t for each slab The final tmin is the max of all the tmin values The final tmax is the min of all the tmax values If tmin ≤ tmax, the ray intersects the box, otherwise it does not

The idea can be extended to frustums and k-DOPs

Page 12: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Separating axis test

For two arbitary, convex, disjoint polyhedra A and B, there exists a separating axis where the projections of the polyhedra are also disjoint

Furthermore, there is an axis that is orthogonal to (making the separating plane parallel to)1. A face of A or2. A face of B or3. An edge from each polyhedron (take the cross product)

This definition of polyhedra is general enough to include triangles and line segments

Page 13: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Line segment/box overlap test This method uses the separating axis test and only works

for AABBs and line segments The AABB has its center at (0,0,0) and size half vector h The line segment is defined by center c and half vector w

If |ci| > wi + hi for any i x,y,z then disjoint There is another test for each axis that is the cross

product of the x, y, and z axis and w If any test passes, then disjoint Only if all tests fail, then overlap

Page 14: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Triangle representation

One way to represent a triangle is with barycentric coordinates

For triangles, barycentric coordinates are weights that describe where in the triangle you are, relative to the three vertices

These weights are commonly labeled u, v, and w and have the following properties u ≥ 0, v ≥ 0, w ≥ 0 and u + v + w ≤ 1

Page 15: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Ray triangle intersection

We represent a point f(u,v) on a triangle with the following explicit formula f(u,v) = (1 – u – v)p0 + up1 + vp2

Then, setting the ray equal to this equation gives o + td = (1 – u – v)p0 + up1 + vp2

This is simply a vector representation of three equations with three unknowns

If the solution has a positive t, and u and v between 0 and 1, it's an intersection

Page 16: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Ray/polygon intersection

First we compute the intersection of the ray and the plane of the polygon

Then we determine if that point is inside the polygon (in 2D)

The plane of the polygon is np • x + dp = 0 np is the plane normal

dp is the distance along the normal from the origin to the plane Intersection is found by:

np • (o + td) + dp = 0 Then project onto xy, xz, or yz plane (whichever maximizes

polygon area) and see if the point is in the polygon

Page 17: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Crossings test

If you want to see if a point is inside a polygon, you shoot a ray from that point along the positive x axis

If it intersects edges of the p0lygon an even number of times, it is outside, otherwise it is inside

Problems can happen if a ray intersects a vertex, so we treat all vertices with y ≥ 0 as being strictly above the x axis

Page 18: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

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 19: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Quiz

Page 20: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Upcoming

Page 21: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Next time…

Finish intersection test methods

Page 22: Week 13 - Wednesday.  What did we talk about last time?  Intersection testing  Bounding volumes  Sphere  AABB  OBB  k-DOP  SharpDX tools.

Reminders

Keep working on Project 4 Keep reading Chapter 16