Slide 1

Slide 1 text

jgs SER 431 Advanced Graphics Lecture 05: Bounding Volumes (Boxes) Javier Gonzalez-Sanchez [email protected] PERALTA 230U Office Hours: By appointment

Slide 2

Slide 2 text

jgs It could be time to do Software Engineering

Slide 3

Slide 3 text

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?

Slide 4

Slide 4 text

jgs Bounding Volumes (Boxes)

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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 }

Slide 9

Slide 9 text

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& 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); } }

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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; }

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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.

Slide 14

Slide 14 text

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)

Slide 15

Slide 15 text

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?

Slide 16

Slide 16 text

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.