Download presentation
Presentation is loading. Please wait.
1
CSCE 590E Spring 2007 Collision Detection By Jijun Tang
2
Announcements Final game demo will be held at 2:00pm, Tuesday, May 8 th Homework 4 will be given today Second presentation will be held on April 16 th and 18 th April 16 th : Space Banditos, Slackers, Psychosoft April 18 th : Project Gnosis, Cheeze Puffs!, Team Swampus
3
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
4
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
5
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)
6
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
7
Location of Particle in World Space SI Units: meters (m) Changes over time when object moves Particle Position
8
Particle Velocity and Acceleration Velocity (SI units: m/s) First time derivative of position: Acceleration (SI units: m/s 2 ) First time derivative of velocity Second time derivative of position
9
Newton ’ s 2 nd 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)
10
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
11
Concrete Example: Target Practice Target Projectile Launch Position, p init
12
Choose V init to Hit a Stationary Target p target is the stationary target location We would like to choose the initial velocity, V init, required to hit the target at some future time, t hit. Here is our equation of motion at time t hit : Solution in general is a bit tedious to derive … Infinite number of solutions! Hint: Specify the magnitude of V init, solve for its direction Target Practice
13
969.31 Example 1 V init = 25 m/s Value of Radicand of tan equation: Launch angle : 19.4 deg or 70.6 deg
14
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:
15
Finite Difference Methods The Verlet Integrator: Must store state at two prior time steps, S(t) and S(t- t) 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:
16
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
17
Additional forces Linear Spring Viscous Damping Aerodynamic Drag Friction …
18
Linear Springs
19
Viscous Damping
20
Aerodynamic Drag S: projected front area C D : drag coefficient
21
Friction
22
Collision Detection and Resolution
23
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.
24
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
25
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
26
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
27
Bisect Testing: collision detected
28
Bisect Testing: Iteration I
29
Bisect Testing: Iteration II
30
Bisect Testing: Iteration III
31
Bisect Testing: Iteration IV
32
Bisect Testing: Iteration V Time right before the collision
33
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
34
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
35
Intersection Testing (a priori) Predict future collisions When predicted: Move simulation to time of collision Resolve collision Simulate remaining time step
36
Intersection Testing: Swept Geometry Extrude geometry in direction of movement Swept sphere turns into a “ capsule ” shape
37
Intersection Testing: Sphere-Sphere Collision d
38
Special Cases No collision: B2 = 0: both objects are stationary, or they are traveling at parallel When will collision occur?
39
Intersection Testing: Sphere-Sphere Collision Smallest distance ever separating two spheres: If there is a collision
40
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
41
Dealing with Complexity Two issues 1. Complex geometry must be simplified 2. Reduce number of object pair tests
42
Simplified Geometry Approximate complex objects with simpler geometry, like this ellipsoid or bounding boxes
43
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
44
Minkowski Sum
45
Using Minkowski Sum
46
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
47
Box Bounding Volumes
48
More Examples
49
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
50
Reduce Number of Detections O(n) Time Complexity can be achieved. One solution is to partition space
51
Achieving O(n) Time Complexity Another solution is the plane sweep algorithm Requires (re-)sorting in x (y) coordinate
52
Terrain Collision Detection: Height Field Landscape
53
Locate Triangle on Height Field Essentially a 2D problem
54
Locate Point on Triangle Plane equation: A, B, C are the x, y, z components of the triangle plane ’ s normal vector Where with one of the triangles vertices being Giving:
55
Terrain Collision Detection: Locate Point on Triangle The normal can be constructed by taking the cross product of two sides: Solve for y and insert the x and z components of Q, giving the final equation for point within triangle:
56
Treating Nonuniform Polygon Mesh Hard to detect the triangle where the point lies in Using Triangulated Irregular Networks (TINs) Barycentric Coordinates
57
Even with complex data structure, we still have to test each triangle (in a sub region) to see if the point lies in it Using Barycentric Coordinates to do the test
58
Terrain Collision Detection: Locate Point on Triangle Calculate barycentric coordinates for point Q in a triangle ’ s plane If any of the weights (w 0, w 1, w 2 ) are negative, then the point Q does not lie in the triangle
59
Collision Resolution: Examples Two billiard balls strike Calculate ball positions at time of impact Impart new velocities on balls Play “ clinking ” sound effect Rocket slams into wall Rocket disappears Explosion spawned and explosion sound effect Wall charred and area damage inflicted on nearby characters Character walks through wall Magical sound effect triggered No trajectories or velocities affected
60
Collision Resolution: Parts Resolution has three parts 1. Prologue 2. Collision 3. Epilogue
61
Prologue Collision known to have occurred Check if collision should be ignored Other events might be triggered Sound effects Send collision notification messages
62
Collision Place objects at point of impact Assign new velocities Using physics or Using some other decision logic
63
Epilogue Propagate post-collision effects Possible effects Destroy one or both objects Play sound effect Inflict damage Many effects can be done either in the prologue or epilogue
64
Collision Resolution: Resolving Overlap Testing 1. Extract collision normal 2. Extract penetration depth 3. Move the two objects apart 4. Compute new velocities
65
Extract Collision Normal Find position of objects before impact Use two closest points to construct the collision normal vector
66
Extract Collision Normal for Sphere Collision Sphere collision normal vector Difference between centers at point of collision
67
Depth Gilbert-Johnson-keerthi (GJK) bisection to extract the depth of convex objects Minkowski supporting lines
68
Collision Resolution: Resolving Intersection Testing Simpler than resolving overlap testing No need to find penetration depth or move objects apart Simply 1. Extract collision normal 2. Compute new velocities
69
Collision Response Why? Performed to keep objects from interpenetrating To ensure behavior similar to real-world objects Two Basic Approaches Approach 1: Instantaneous change of velocity at time of collision Approach 2: Gradual change of velocity and position over time, following collision
70
Approach 1 Approach 1: Instantaneous change of velocity at time of collision Benefits: Visually the objects never interpenetrate Result is generated via closed-form equations, and is perfectly stable Difficulties: Precise detection of time and location of collision can be prohibitively expensive (frame rate killer) Logic to manage state is complex
71
Approaches 2 Approach 2: Gradual change of velocity and position over time, following collision Benefits Does not require precise detection of time and location of collision State management is easy Potential to be more realistic, if meshes are adjusted to deform according to predicted interpenetration Difficulties Object interpenetration is likely, and parameters must be tweaked to manage this Simulation can be subject to numerical instabilities, often requiring the use of implicit finite difference methods
72
Final Comments Instantaneous Collision Response Classical approach: Impulse-momentum equations See text for full details Gradual Collision Response Classical approach: Penalty force methods Resolve interpenetration over the course of a few integration steps Penalty forces can wreak havoc on numerical integration Instabilities galore Implicit finite difference equations can handle it But more difficult to code Geometric approach: Ignore physical response equations Enforce purely geometric constraints once interpenetration has occurred
73
Final Comments Simple Games Closed-form particle equations may be all you need Numerical particle simulation adds flexibility without much coding effort Collision detection is probably the most difficult part of this Generalized Rigid Body Simulation Includes rotational effects and interesting (non- constant) forces See text for details on how to get started
74
Final Comments Full-Up Simulation The text and this presentation just barely touch the surface Additional considerations Multiple simultaneous collision points Articulating rigid body chains, with joints Friction, rolling friction, friction during collision Mechanically applied forces (motors, etc.) Resting contact/stacking Breakable objects Soft bodies Smoke, clouds, and other gases Water, oil, and other fluids
75
Homework 4 Page 390 problem 1 and 5 Handwriting or printing using Word/Latex Turn in before class No need to upload to dropbox 5 points total (2.5 each) Due on this Wednesday
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.