Geometry Primer Lines and rays Planes Spheres Frustums Triangles Polygon Polyhedron Lines and Rays Given 2 points, we can parametrically define a line which passes through these two points as P(t) = (1-t)P1 + tP2 The line segment between these two points corresponds to all values of t between zero and one A ray is defined parametrically as P(t) = Po + tV Where t is greater than or equal to zero Allowing negative values of t will give a valid equation for a line Planes Plane equation Ax + By + Cz + D = 0 A, B, and C are the respective x, y, and z coordinates of a vector normal to the plane D = -N.Po If N is a unit vector, the equation N is the plane normal vector Po is an arbitrary point on the plane d = N.Q + D Gives the distance from the plane to an arbitrary point Q If d > 0, Q lies on the positive side of the plane. Otherwise Q lies on the negative side of the plane. Use this to test for path-plane collision A Different Plane Equation Point – normal form N.(P – Po) = 0 P and Po are arbitrary points on the plane Stored as a point and a normal in many applications, or calculated on the fly from three points. Given by equation Line N.Q + D = 0 – Plane intersection Example Spheres Sphere equation - x0)2 + (y - y0)2 + (z - z0)2 = r2 r is the radius, and is centered at (x0,y0,z0) (x In an application, store the center point and the radius. Frustums A frustum as a volume of space containing everything visible in a scene. A frustum can be defined by a: Near plane (or near plane distance) Far plane (or far plane distance) Field of view FOVx or FOVy? Aspect ratio Alternatively, it can be described by the six planes which bound it. Frustum Illus. Triangle Polygon Polyhedron Convex polyhedrons are also known as polytopes, and are often used to approximate non-convex meshes where speed is an issue. Also known as brushes. Applied Geometry Collision models for games can be approximated using fundamental shapes E.g. Use boxes for limbs of characters, 3 spheres for an ant… Visibility Determination *Bounding box test Bounding sphere test Bounding Box Axis aligned, or AABB Find minimum and maximum points and use these to construct box Oriented, or OBB Find natural axes for points Compute dot product of each vertex position with unit vectors R, S, T of the natural axis and take the minimum and maximum values Planes are given by: <R, -min{Pi.R}> <-R, max{Pi.R}> Collision Detection Sphere – Sphere Sphere - Plane *AABB – AABB *OBB – OBB *Box – Plane Ray – Plane Ray – Triangle Ray – Triangle Intersection Example Investigate other methods Badoul’s algorithm Moller-Haines’ algorithm www.realtimerendering.com D3DX algorithm D3DX common source Usage / Examples Detecting when a user has clicked an object Determining if, when, and where objects have collided Decide how to respond to collision Reading Chapters 4, 5, 7, 8 in Mathematics for 3D Game Programming and Computer Graphics cover the material presented here