210 likes | 234 Views
Computer Game Design and Development. Mathematics, Collision, and Physics. Havok Destruction. Basic Problem. Without physics: There’s no gravity There’s no friction There are no collisions Objects pass through one another We must determine: If objects collide (collision detection)
E N D
Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction
Basic Problem • Without physics: • There’s no gravity • There’s no friction • There are no collisions • Objects pass through one another • We must determine: • If objects collide (collision detection) • Where/when they collided (collision resolution)
Collision Detection • Bullets (very fast) • Characters (very complex) • Naïve algorithms run in O(n2) • Two primary methods: • Overlap testing (most common) • Intersection testing (sweeping)
Overlap Testing • Determines if two objects overlap (duh!) • Check each vertex of an object inside another? • Exhibits the most error • Is discrete (i.e. checks an exact point in time) • Results: • Give a time of collision • Give a normal of collision • Uses bisection…
Limitations of Overlap Testing Design constraint? Speed of objects * time step < size of all objects? Reduce time step?
Intersection Testing • “Sweep” an object from one pointto another (i.e. “extrude” – sphere • becomes capsule). • Can calculate t with an equation-> • See book for equation • Doesn’t work well for network games
Collision ApproximationsMinkowski Sum – sweep origin of X across Y Intersection technique. These are the same!
Bounding Volumes and Boxes AABB OBB
About Bounding Volumes • Simplest is sphere • Next is capsule (2 spheres and a cylinder), • Next are AABBs • What can we do about character collisions?
Performance(avoiding O(n2)) Possible collisionbetween R and B since overlap in all axis (2 in this case) • Subdivide such that on averageone object in each cell. • Test against neighboring cells • What if all are in one cell? • Variable-sized objects? “Plane sweep” needs to be sorted! Which algorithm? Quicksort?Bubblesort?
Terrain Collision • Determine which quad is easy • Heightmap (x and z are fixed, y is variable) • Which triangle in the quad? • Compare x with z http://creators.xna.com/en-US/sample/collision3dheightmap
Resolving Collision • Gross collision & subdivide if needed • Three phases • Prologue – ignore or trigger other events • Collision – objects moved to point of impact, new velocities, calculate normal and penetration • Epilogue – destroy object, effects, damage, etc
Particle Physics Basics • Use consistent units (SI) – or bad stuff happens • Particle kinematics • Position (p) in 3-space, vector3 (x,y,z) = p(t) • Velocity (v) = change in position over time, V(t) • Acceleration (a) = change in velocity over time, a(t) • Force (f) = results in change in acceleration over time, F(t) = ma(t) • Calculus • Derivatives and integrals go from one to another
Other Definitions • Kinematic objects: those that move • Static objects: those that don’t, but affect those that do (terrain) • Rigid bodies: objects that do not deform • Soft bodies: • those that do • Center of gravity changes • Cloth, deflated ball…
More Definitions • Constraints: • Limitations on what objects can do • Joint types: ball joint, hinge joint, sliding joint • Ragdoll physics: • Animated bones replaced by rigid bodies • Good for violent death animations • http://www.youtube.com/watch?v=4gR_dP4HaF8
Physics Engines • Commercial • Game Dynamics SDK (Havok) • Renderware Physics • PhysX (NVIDIA) • NovodeX SDK • Free/Shareware • Open Dynamics Engine (ODE) • Tokamak Game Physics SDK • Newton Game Dynamics SDK • Bullet SDK
Demos http://www.havok.com/content/view/584/96/ http://www.tokamakphysics.com/index.htm