Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SER431 Lecture 05

SER431 Lecture 05

Advanced Graphics
Bounding Volumes
(201808)

Javier Gonzalez-Sanchez

August 30, 2018
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs SER 431 Advanced Graphics Lecture 05: Bounding Volumes (Boxes)

    Javier Gonzalez-Sanchez [email protected] PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 3 jgs

    Think about this § A class Mesh All data is here § A class Renderer Render a mesh object with and without textures, normals, etc. Render a mesh object and visualize its AABB or its normal lines. § What about textures? § Where do we do collision detection?
  3. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 5 jgs

    Primitives as Bounding Volumes § Simple primitives are used as bounding volumes for more complex objects § Bounding volumes can be used for approximate intersection tests: § If the bounding volumes of two objects do not intersect à the objects themselves do not intersect. § If the bounding volumes of two objects overlap then maybe there is an intersection maybe not
  4. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 6 jgs

    Bounding Volumes § Axis-aligned Bounding Box (AABB) The planes of the box are aligned with the world coordinates § Object-oriented Bounding Box (OBB) The planes are aligned to enclose the object as close as possible Minimum Volume bounding boxes
  5. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 7 jgs

    Bounding Volumes § Spheres Enclosing sphere § Convex Hull Closest (convex) fit Smallest ratio
  6. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 8 jgs

    §Axis-aligned Bounding Box (AABB) § An AABB is defined by its minimal and maximal positions in space Pmin=(xmin, ymin, zmin), Pmax = (xmax, ymax, zmax) § Calculate Initialize pmin to +infinite or the first vertex Initialize pmax to –infinite or the first vertex foreach vertex p do { if (p.x < pmin.x) then pmin.x = p.x if (p.y < pmin.y) then pmin.y = p.y if (p.z > pmax.z) then pmax.z = p.z }
  7. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 9 jgs

    Snippet #define MIN2(a,b) (((a) < (b))?(a):(b)) #define MAX2(a,b) (((a) > (b))?(a):(b)) // calculate bounding box (AABB) void calculateAABB() { vector<Vec3f>& v = m->dot_vertex; if (v.empty()) return; boundingMaxPoint = boundingMinPoint = v[0]; for (unsigned int i = 1; i < v.size(); i++) { boundingMinPoint.x = MIN2(boundingMinPoint.x, v[i].x); boundingMinPoint.y = MIN2(boundingMinPoint.y, v[i].y); boundingMinPoint.z = MIN2(boundingMinPoint.z, v[i].z); boundingMaxPoint.x = MAX2(boundingMaxPoint.x, v[i].x); boundingMaxPoint.y = MAX2(boundingMaxPoint.y, v[i].y); boundingMaxPoint.z = MAX2(boundingMaxPoint.z, v[i].z); } }
  8. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 10 jgs

    Intersection Computations (AABB) § Compare min and max in X, Y and Z directions § If all of them intersect, then the object intersects
  9. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 11 jgs

    Snippet // use AABB bounding box to detect intersection bool intersect(Mesh* A Mesh* B) { Vec3f a1 = A->worldBoundingMinPoint; Vec3f b1 = A->worldBoundingMaxPoint; Vec3f a2 = B->worldBoundingMinPoint; Vec3f b2 = B->worldBoundingMaxPoint; int x = 0, y = 0, z = 0; if ((a1.x >= a2.x && a1.x <= b2.x) || (b1.x >= a2.x && a1.x <= b2.x) || (a2.x >= a1.x && a2.x <= b1.x) || (b2.x >= a1.x && b2.x <= b1.x)) x = 1; if ((a1.y >= a2.y && a1.y <= b2.y) || (b1.y >= a2.y && a1.y <= b2.y) || (a2.y >= a1.y && a2.y <= b1.y) || (b2.y >= a1.y && b2.y <= b1.y)) y = 1; if ((a1.z >= a2.z && a1.z <= b2.z) || (b1.z >= a2.z && a1.z <= b2.z) || (a2.z >= a1.z && a2.z <= b1.z) || (b2.z >= a1.z && b2.z <= b1.z)) z = 1; if (x == 1 && y == 1 && z == 1) { return true; } else return false; }
  10. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 12 jgs

    Updating AABB § Translation invariant ✘ Any other kind of movements, box no longer remains axis-aligned ✘ Needs to be recomputed frame by frame § Very simple computation
  11. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 13 jgs

    Hierarchical Bounding Volumes § At the bottom of such a hierarchy a primitive of one type bounds another § For instance, using axis aligned bounding boxes (AABB), to bound triangles. The overlap test between two AABBs less expensive than the triangle- triangle intersection test.
  12. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 14 jgs

    Hierarchical Bounding Volumes § Similar to spatial subdivision § But for each object Slightly different § Union of children may not encompass the parent § If does not intersect, do not explore the children § If intersects, do bounding volume intersection on children § Continue till you get to the triangle-triangle intersection (Very few of them needs to be computed)
  13. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 15 jgs

    Homework Add Objects to your world Calculate AABB Draw AABB with lines What about drawing the Normal lines?
  14. jgs SER431 Advanced Graphics Javier Gonzalez-Sanchez [email protected] Fall 2018 Disclaimer.

    These slides can only be used as study material for the class SER431 at ASU. They cannot be distributed or used for another purpose.