1 / 22

CS361

Week 13 - Wednesday. CS361. Last time. What did we talk about last time? Intersection testing Bounding volumes Sphere AABB OBB k-DOP XNA tools. Questions?. Project 4. XNA Picker. Getting Bounding Spheres from XNA Models. Intersection Methods. Ray/sphere intersection.

gotzon
Download Presentation

CS361

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 13 - Wednesday CS361

  2. Last time • What did we talk about last time? • Intersection testing • Bounding volumes • Sphere • AABB • OBB • k-DOP • XNA tools

  3. Questions?

  4. Project 4

  5. XNA Picker

  6. Getting Bounding Spheres from XNA Models

  7. Intersection Methods

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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,zthen 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. Quiz

  20. Upcoming

  21. Next time… • Finish intersection test methods

  22. Reminders • Keep working on Project 4 • Keep reading Chapter 16

More Related