Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,

Similar presentations


Presentation on theme: "Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,"— Presentation transcript:

1 Week 13 - Monday

2  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips, fans, and meshes  Simplification ▪ Static ▪ Dynamic ▪ View-dependent

3

4

5

6  We need to test for various intersections for lots of reasons  What object is the mouse hovering over (or your gun pointing at)? (Called picking)  Do these two objects collide?  Does a ray hit a bounding box?  As with everything in real time graphics, it needs to be efficient

7

8  It's a challenging (and computationally expensive) task to see if a ray intersects with, say, a demon model  Instead, models are often surrounded by bounding volumes that are easy to test intersection against  If a ray or another model (or another model's bounding volume) intersects with a bounding volume, we can compute a more exact intersection  If not, it doesn't matter

9 Bounding Sphere  Easy to do intersection tests with  Poor fit for many rectangular objects  More costly intersection tests  Better fit for rectangular objects  No computational savings at all  Perfect fit for cow Bounding BoxBounding Cow

10  A ray r(t) is defined by an origin point o and a direction vector d  d is usually normalized  Negative t values are behind the starting point of the ray and usually don't count  If d is normalized, positive t values give the distance of the point from o  It is also common to store l, the maximum distance along the ray we want to look

11  An implicit surface is one described by a vector equation where any point on the surface has a value of 0  f(p) = f(p x, p y, p z ) = 0  Implicit sphere: f(p) = p x 2 + p y 2 + p z 2 - r 2 = 0  An explicit surface is one parameterized by two parameters   Explicit sphere:

12  An axis-aligned bounding box (AABB) (also known as a rectangular box) is a box whose faces have normals pointing the same way as the x, y, and z axes  It's a non-rotated box in 3 space  It can be defined with two points (lower corner and upper corner)

13  An oriented bounding box (OBB) is an AABB that has been arbitrarily rotated  It can be described by  A center point b c  Three normalized vectors b u, b v, and b w giving the side directions of the box  And half-lengths (from center to wall) h u B, h v B, and h w B

14  A k discrete oriented polytope (k-DOP) has k/2 normalized normals n i  For each n i, there are two values d i min and d i max which defines a slab S i that is the volume between the two planes  The k-DOP is the intersections of all the slabs

15  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 or 2. A face of B or 3. An edge from each polyhedron (take the cross product)  This definition of polyhedra is general enough to include triangles and line segments

16

17  An AABB is the easiest  Take the minimum and maximum points in each axis and, BOOM, you've got an AABB  A k-DOP is not much harder  Take the minimum and maximum values in each of the k/2 axes and use those to define the slabs  You have to have axes in mind ahead of time

18  Not as simple as you might think  One approach:  Make an AABB and use the center and diagonal of the corners to make your sphere  Or:  Make the AABB and do another pass through the vertices, taking the one furthest from the center as the radius  There are other more complicated ideas

19  The relative probability that a random point is inside an object is proportional to the object's volume  However, the relative probability that a random ray intersects an object is proportional to its surface area

20  Messiest yet!  Find the convex hull of the object  Find the centroid of the entire convex hull  Compute a matrix using math from the book  The eigenvectors of the matrix are the direction vectors of the box  Use them to find the extreme points for each axis  There are other approaches

21  Perform computations early that could easily get a reject or accept  If possible, reuse results from previous tests  If you are using multiple tests, experiment with the order in which you apply them  Postpone expensive calculations (trig, square roots, and divisions) until you absolutely need them  Reduce the problem to a lower dimension whenever possible  If one ray or object is being tested against many others, try to compute whatever you can for that one item a single time  Expensive intersection tests should always come after some simpler BV test  Use empirical timing data to see what really works best  Write robust code, particularly with respect to floating point issues

22

23  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 t 2 + 2tb + c = 0, where b = d (o – c) and c = (o – c) (o – c) – r 2  If the discriminant is negative, the ray does not hit the sphere, otherwise, we can compute the location(s) where it does

24  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 l 2 = l l  If l 2 < r 2, 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: m 2 = l 2 – s 2  If m 2 > r 2, the ray will miss, otherwise it hits

25

26  There are a few basic primitives that SharpDX uses for intersection testing  Plane  Defined by a normal and a distance from the origin along that normal  Or you can make one with three points  Ray  Defined by a starting point and a direction vector  Vector3  Used (unsurprisingly) for points

27  BoundingBox  Axis aligned bounding box  Defined by two points  BoundingSphere  Defined by a center point and a radius  BoundingFrustum  Defined by a matrix (view x projection)

28

29  More intersection test methods  Ray/box intersection  Line segment/box overlap  Ray/triangle intersection  Plane/box intersection

30  Keep working on Project 4  Keep reading Chapter 16


Download ppt "Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,"

Similar presentations


Ads by Google