computer game design and development mathematics, collision, and physics havok destruction

21
Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Upload: alexandra-patterson

Post on 17-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Computer Game Design and Development

Mathematics, Collision, and Physics

Havok Destruction

Page 2: 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)

Page 3: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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)

Page 4: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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…

Page 5: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Overlap Bisection

Page 6: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Limitations of Overlap Testing

Design constraint? Speed of objects * time step < size of all objects?Reduce time step?

Page 7: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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

Page 8: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Collision ApproximationsMinkowski Sum – sweep origin of X across Y

Intersection technique.These are the same!

Page 9: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Bounding Volumes and Boxes

AABB OBB

Page 10: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

About Bounding Volumes

• Simplest is sphere• Next is capsule (2 spheres and a cylinder), • Next are AABBs• What can we do about character collisions?

Page 11: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Performance(avoiding O(n2))

Possible collisionbetween R and Bsince 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?

Page 12: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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

Page 13: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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

Page 14: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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

Page 15: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Center of Mass

Page 16: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Collision Response (frictionless)

Page 17: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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…

Page 18: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Rigid Body CollisionCenter of Mass Consideration

Page 19: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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

Page 20: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

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

Page 21: Computer Game Design and Development Mathematics, Collision, and Physics Havok Destruction

Demos

http://www.havok.com/content/view/584/96/

http://www.tokamakphysics.com/index.htm