Download presentation
Presentation is loading. Please wait.
1
Week 13 - Wednesday CS361
2
Last time What did we talk about last time? Before that… Exam 2!
Polygonal techniques Tessellation and triangulation Triangle strips, fans, and meshes Simplification Static Dynamic View-dependent
3
Questions?
4
Project 4
5
Student Lecture: Intersection Tests and Bounding Volumes
6
Intersection Test Methods
7
Intersection testing 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
8
Definitions
9
Bounding volumes 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
10
Bounding volume examples
Bounding Sphere Bounding Box Bounding Cow 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
11
Ray 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
12
Surface An implicit surface is one described by a vector equation where any point on the surface has a value of 0 f(p) = f(px, py, pz) = 0 Implicit sphere: f(p) = px2 + py2 + pz2 - r2 = 0 An explicit surface is one parameterized by two parameters Explicit sphere:
13
Axis-aligned bounding box
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)
14
Oriented bounding box An oriented bounding box (OBB) is an AABB that has been arbitrarily rotated It can be described by A center point bc Three normalized vectors bu, bv, and bw giving the side directions of the box And half-lengths (from center to wall) huB, hvB, and hwB
15
k-DOP A k discrete oriented polytope (k-DOP) has k/2 normalized normals ni For each ni, there are two values dimin and dimax which defines a slab Si that is the volume between the two planes The k-DOP is the intersections of all the slabs
16
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) A face of A or A face of B or An edge from each polyhedron (take the cross product) This definition of polyhedra is general enough to include triangles and line segments
17
Creating Bounding Volumes
18
AABB and k-DOPs An AABB is the easiest A k-DOP is not much harder
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
19
Bounding spheres Not as simple as you might think One approach: Or:
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
20
Geometric probability
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
21
OBB 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
22
Rules of thumb 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
23
Intersection Methods
24
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
25
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
26
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
27
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
28
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) A face of A or A face of B or An edge from each polyhedron (take the cross product) This definition of polyhedra is general enough to include triangles and line segments
29
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
30
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
31
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
32
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
33
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
34
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
35
MonoGame Intersection Tools
36
MonoGame primitives There are a few basic primitives that MonoGame 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
37
MonoGame bounding volumes
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)
38
Upcoming
39
Next time… Finish intersection test methods
Bounding volume intersections
40
Reminders Keep working on Project 4 Keep reading Chapter 16
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.