and Response
How to do this?
Here is where I
want my object to
be
Here is where my
object is
Here is where my
object is going to be
A box that is
Airplane Orientation 2
AABB
Do a bunch of ifs
if(
px<= maxx &&
py<= maxy &&
pz<= maxz &&
px>= minx &&
py>= miny &&
pz>= minz )
minx
maxy
maxx
miny
Comparing AABBs
if mins/maxes overlap
then collide = true
else collide = false; Bmax
Bminx
Bmaxx
Amaxx
Aminx
Bminy
AABB Approach
Initialization: Iterate through
vertices and find mins and maxes
AABB Approach
Initialization
iterate through all vertices of your model to find the mins
and maxes for x, y, and z
During runtime
Test if any of the AABB mins/maxes of one object overlap
with another objects AABB mins/maxes
MAKE SURE THAT THE AABB VALUES ARE IN THE SAME
COORDINATE FRAME (e.g., world coordinates)!
If they arent, then manually transform them so they are.
This is equivalent to multiplying the 8 points by a matrix for
each object
Then make sure to recalculate your mins/maxes from the 8
transformed points!
Note: it is possible to do this with only 2 points from the box:
(minx,miny,minz), (maxx,maxy,maxz), but not required
Shoot a projectile
Equation: Ax+By+Cz+D = 0
[A,B,C] is the normal of the plane
D is how far from the origin it is
p = (xp,yp,zp)
What is the shortest distance from p to the
plane?
[A,B,C]
P
gluLookat()
glPushMatrix()
glTranslatefv(p);
Draw sphere projectile
glPopMatrix()
glPushMatrix();
glRotate(a,x,y,z)
glTranslate(tx,ty,tz)
Draw a BB
glPopMatrix()
RT matrix
direction
Current Position
Rayorigin
io
Ray direct
n
Next
Position
Ray-Plane Intersections
Rayorigin+Raydirection*hypotenuse = i
Refdirection
N
io
Ray direct
Rayorigin
ad
ja c
en
Calculate a Refection
io
Ray direct
Rayorigin
ad
ja c
en
A box that
Stays oriented to the model
regardless of transformations
These are often defined by artists in
the 3D modeling program
There are algorithms to compute the
minimum OBB, but this is out of
scope for this class
How to create the initial box?
1) Either:
Iterate through vertices (same as AABB
Make a nice box with a modeling program
Airplane Orientation 1
Airplane Orientation 2
v2
v3
v1
Equation: Ax+By+Cz+D = 0
[A,B,C] is the normal of the plane
D is how far from the origin it is
p = (xp,yp,zp)
What is the shortest distance from p to the
plane?
[A,B,C]
Separating Axes