750 likes | 766 Views
Explore the potential benefits and challenges of real-time physics in game development, including the need for engine upgrades, asset creation updates, and special training. Discover available commercial and free game engine options for implementing physics simulations. Gain an understanding of particle physics, Newton's laws of motion, and finite difference methods for physics simulation. Learn about collision detection techniques and the complexities involved in detecting and resolving collisions in games.
E N D
CSCE 590E Spring 2007 Collision Detection By Jijun Tang
Announcements • Final game demo will be held at 2:00pm, Tuesday, May 8th • Homework 4 will be given today • Second presentation will be held on April 16th and 18th • April 16th: Space Banditos, Slackers, Psychosoft • April 18th: Project Gnosis, Cheeze Puffs!, Team Swampus
Needs to do • Two groups need to send me the first presentation after the class • Some people didn’t send me the members in their small project. • Please send the membership of the small project to stahlj@cse.sc.edu
Real-time Physics in Game at Runtime: • Enables the emergent behavior that provides player a richer game experience • Potential to provide full cost savings to developer/publisher • Difficult • May require significant upgrade of game engine • May require significant update of asset creation pipelines • May require special training for modelers, animators, and level designers • Licensing an existing engine may significantly increase third party middleware costs
Engines • Commercial • Game Dynamics SDK (Havok.com) • Renderware Physics (renderware.com) • NovodeX SDK (novodex.com) • Free • Open Dynamic Engine (ODE) (ode.org) • Tokamak Game Physics SDK (tokamakphysics.com) • Newton Game Dynamics SDK (newtondynamics.com)
Particle Physics • What is a Particle? • A sphere of finite radius with a perfectly smooth, frictionless surface • Experiences no rotational motion (or assume the sphere has no size) • Particle Kinematics • Defines the basic properties of particle motion • Position, Velocity, Acceleration
Particle Position • Location of Particle in World Space • SI Units: meters (m) • Changes over time when object moves
Particle Velocity and Acceleration • Velocity (SI units: m/s) • First time derivative of position: • Acceleration (SI units: m/s2) • First time derivative of velocity • Second time derivative of position
Newton’s 2nd Law of Motion • Paraphrased –“An object’s change in velocity is proportional to an applied force” • The Classic Equation: • m = mass (SI units: kilograms, kg) • F(t) = force (SI units: Newtons)
What is Physics Simulation? • The Cycle of Motion: • Force, F(t), causes acceleration • Acceleration, a(t), causes a change in velocity • Velocity, V(t) causes a change in position • Physics Simulation: • Solving variations of the above equations over time to emulate the cycle of motion
Concrete Example: Target Practice Projectile Launch Position, pinit Target
Target Practice • Choose Vinit to Hit a Stationary Target • ptarget is the stationary target location • We would like to choose the initial velocity, Vinit, required to hit the target at some future time, thit. • Here is our equation of motion at time thit: • Solution in general is a bit tedious to derive… • Infinite number of solutions! • Hint: Specify the magnitude of Vinit, solve for its direction
Example 1 Vinit = 25 m/s Value of Radicand of tanf equation: Launch angle f: 19.4 deg or 70.6 deg 969.31
Finite Difference Methods • The Explicit Euler Integrator: • Properties of object are stored in a state vector, S • Use the above integrator equation to incrementally update S over time as game progresses • Must keep track of prior value of S in order to compute the new • For Explicit Euler, one choice of state and state derivative for particle:
Finite Difference Methods • The Verlet Integrator: • Must store state at two prior time steps, S(t) and S(t-Dt) • Uses second derivative of state instead of the first • Valid for constant time step only (as shown above) • For Verlet, choice of state and state derivative for a particle:
Generalized Rigid Bodies • Key Differences from Particles • Not necessarily spherical in shape • Position, p, represents object’s center-of-mass location • Surface may not be perfectly smooth • Friction forces may be present • Experience rotational motion in addition to translational (position only) motion
Additional forces • Linear Spring • Viscous Damping • Aerodynamic Drag • Friction • …
Aerodynamic Drag S: projected front area CD: drag coefficient
What is Collision Detection • A fundamental problem in computer games, computer animation, physically-based modeling, geometric modeling, and robotics. • Including algorithms: • To check for collision, i.e. intersection, of two given objects • To calculate trajectories, impact times and impact points in a physical simulation.
Collision Detection • Complicated for two reasons • Geometry is typically very complex, potentially requiring expensive testing • Naïve solution is O(n2) time complexity, since every object can potentially collide with every other object • Two basic techniques • Overlap testing: Detects whether a collision has already occurred • Intersection testing: Predicts whether a collision will occur in the future
Overlap Testing (a posteriori) • Overlap testing: Detects whether a collision has already occurred, sometime is referred as a posteriori • Facts • Most common technique used in games • Exhibits more error than intersection testing • Concept • For every (small) simulation step, test every pair of objects to see if they overlap • Easy for simple volumes like spheres, harder for polygonal models
Overlap Testing Results • Useful results of detected collision • Pairs of objects will have collision • Time of collision to take place • Collision normal vector • Collision time calculated by moving object back in time until right before collision • Bisection is an effective technique
Bisect Testing: Iteration V Time right before the collision
Overlap Testing: Limitations • Fails with objects that move too fast (compared to the object) • Thin glass vs. bulltes • Unlikely to catch time slice during overlap
Solution for This Limitation • Speed of the fastest object multiplies the time step should be smaller than the smallest objects in the scene • Possible solutions • Design constraint on speed of objects • Hard to apply without affecting the play • Reduce simulation step size • Too expensive
Intersection Testing (a priori) • Predict future collisions • When predicted: • Move simulation to time of collision • Resolve collision • Simulate remaining time step
Intersection Testing:Swept Geometry • Extrude geometry in direction of movement • Swept sphere turns into a “capsule” shape
Special Cases • No collision: • B2 = 0: both objects are stationary, or they are traveling at parallel • When will collision occur?
Intersection Testing:Sphere-Sphere Collision • Smallest distance ever separating two spheres: • If there is a collision
Intersection Testing:Limitations • Issue with networked games • Future predictions rely on exact state of world at present time • Due to packet latency, current state not always coherent • Assumes constant velocity and zero acceleration over simulation step • Has implications for physics model and choice of integrator
Dealing with Complexity Two issues 1. Complex geometry must be simplified 2. Reduce number of object pair tests
Simplified Geometry • Approximate complex objects with simpler geometry, like this ellipsoid or bounding boxes
Minkowski Sum • By taking the Minkowski Sum of two complex volumes and creating a new volume, overlap can be found by testing if a single point is within the new volume
Bounding Volumes • Bounding volume is a simple geometric shape • Completely encapsulates object • If no collision with bounding volume, no more testing is required • Common bounding volumes • Sphere • Box
Using Bounding Box in Game • Complex objects can have multiple bounding boxes • Human object can have one big bounding box for the whole body • Human object can have one bounding box per limb, head, etc • Bounding box can be hierarchical: • Test the big first • if possible collision, test the smaller ones
Reduce Number of Detections O(n) Time Complexity can be achieved. One solution is to partition space