Jan262010

Jan262010 - UC Santa Cruz Computer Science Game Design...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science – Game Design UC Santa Cruz 11/10/10 Common Bounding Volumes Most introductory game programming texts call AABBs simply “bounding Circle/Spher e Axis-Aligned Bounding Box (AABB) Oriented Bounding Box (OBB) Convex Hull Better bounds, better culling Faster test, less memory
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Computer Science – Game Design UC Santa Cruz 11/10/10 Circle Bounding Box Simple storage, easy intersection test Rotationally invariant struct Point { int x; int y; } struct circle { Point c; // center int r; // radius } r c bool circle_intersect(circle a, circle b) { Point d; // d = b.c – a.c d.x = a.c.x – b.c.x; d.y = a.c.y – b.c.y; int dist2 = d.x*d.x + d.y*d.y; // d dot d int radiusSum = a.r + b.r; if (dist2 < = radiusSum * radiusSum) { return true; } else { return false; } } Compare Euclidean distance between circle centers against sum of circle radii.
Background image of page 2
Computer Science – Game Design UC Santa Cruz 11/10/10 Axis-Aligned Bounding Three common representations Min-max Min-widths // min.x < =x < =max.x // min.y < =y < =max.y struct AABB { Point min; Point max; } // min.x < =x < =min.x+dx // min.y < =y < =min.y+dy struct AABB { Point min; int dx; // x width int dy; // y width } // | c.x-x | < = rx | c.y-y | < = ry struct AABB { Point c; int rx; // x radius int ry; // y radius } min max min c dx dy ry rx Can easily be extended to 3D
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Computer Science – Game Design UC Santa Cruz Axis Aligned Bounding Box Intersection (min- max) Two AABBs intersect only if they overlap on both axes a.max.x<b.min.x a.min.x>b.max.x a.min.x=b.min.x a.max.y<b.min.y a.min.y>b.max.y a.min.y=b.min.y bool IntersectAABB(AABB a, AABB b) { { if (a.max.x < b.min.x || a.min.x < b.max.x) return false; if (a.max.y < b.min.y || a.min.y < b.max.y) return false; return true; }
Background image of page 4
Computer Science – Game Design UC Santa Cruz Axis Aligned Bounding Box Intersection (min- width) Two AABBs intersect only if they overlap on both axes -(a.min.x- b.min.x)>a.dx (a.min.x- b.min.x)>b.dx a.min.x=b.min.x -(a.min.y- b.min.y)>a.dy (a.min.y- b.min.y)>b.dy a.min.y=b.min.y bool IntersectAABB(AABB a, AABB b) { { int t; t=a.min.x-b.min.x; if (t > b.dx || -t > a.dx) return false; t=a.min.y-b.min.y; if (t > b.dy || -t > a.dy) return false; return true; } // Note: requires more operations than // min-max case (2 more subtractions, 2 more negations)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Computer Science – Game Design UC Santa Cruz AABB Intersection (center- Two AABBs intersect only if they overlap on both axes b.c.x-a.c.x > a.rx+b.ry a.c.x-b.c.x > a.rx+b.rx a.c.x=b.c.x b.c.y-a.c.y > a.ry+b.ry a.c.y-b.c.y > a.ry+b.ry a.c.y=b.c.y bool IntersectAABB(AABB
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 25

Jan262010 - UC Santa Cruz Computer Science Game Design...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online