CIS 487/587 Bruce R. Maxim UM-Dearborn

Slides:



Advertisements
Similar presentations
Real-Time Game Physics
Advertisements

Introduction Games have always been a fundamental part of human life. Space storm “ عاصفة الفضاء” is a 3D SCI-FI game that consists of two stages presented.
Rigid Body Dynamics Jim Van Verth
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
Collision Detection and Resolution Zhi Yuan Course: Introduction to Game Development 11/28/
2.1. C OLLISION D ETECTION Overview. Collision detection is used within many types of application, e.g. from robotics, through engineering simulations,
Math / Physics 101 GAM 376 Robin Burke Winter 2008.
Chapter 4.3 Real-time Game Physics. Outline Introduction Motivation for including physics in games Practical development team decisions Particle Physics.
Particle Systems 1 Adapted from: E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
1 7M836 Animation & Rendering Animation Jakob Beetz Joran Jessurun
Game Physics Chris Miles. The Goal To learn how to create game objects with realistic physics models To learn how to simulate aspects of reality in order.
1 Geometry A line in 3D space is represented by  S is a point on the line, and V is the direction along which the line runs  Any point P on the line.
UNC Chapel Hill S. Redon - M. C. Lin Rigid body dynamics II Solving the dynamics problems.
Game Mathematics & Game State The Complexity of Games Expectations of Players Efficiency Game Mathematics o Collision Detection & Response o Object Overlap.
CSCE 590E Spring 2007 Collision Detection By Jijun Tang.
Manipulator Dynamics Amirkabir University of Technology Computer Engineering & Information Technology Department.
CSCE 590E Spring 2007 Basic Physics By Jijun Tang.
Mechanics, Dynamics & Aesthetics The Complexity of Games Expectations of Players Efficiency Game Mathematics o Collision Detection & Response o Object.
Single Point of Contact Manipulation of Unknown Objects Stuart Anderson Advisor: Reid Simmons School of Computer Science Carnegie Mellon University.
Game Physics What is meant by Physics in games (old)? –Collision Detection (testing) But want the physical effect of hitting an immovable object. Also.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Computer graphics & visualization Collision Detection – Narrow Phase.
CS 4730 Collision Detection CS 4730 – Computer Game Design.
3.7. O THER G AME P HYSICS A PPROACHES Overview of other game engine physics approaches.
CS 4730 Physical Simulation CS 4730 – Computer Game Design.
Feature-length films: Games: Desktop Animations: Computer Animation.
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Physically Based Animation.
Spring Topic Outline for Physics 1 Spring 2011.
Lecture VII Rigid Body Dynamics CS274: Computer Animation and Simulation.
Game Physics – Part IV Moving to 3D
CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang.
Spring Rigid Body Simulation. Spring Contents Unconstrained Collision Contact Resting Contact.
3D Graphics for Game Programming Chapter XII Physics-based Simulation.
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Collisions & Contact.
Computer Graphics 2 In the name of God. Outline Introduction Animation The most important senior groups Animation techniques Summary Walking, running,…examples.
Math / Physics 101 GAM 376 Robin Burke Fall 2006.
Concepts for Programming a Rigid Body Physics Engine Part 1 Presented by Scott Hawkins.
Advanced Computer Graphics Rigid Body Simulation Spring 2002 Professor Brogan.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
CSCE 552 Fall 2012 Math, Physics and Collision Detection By Jijun Tang.
Spring Rigid Body Simulation. Spring Contents Unconstrained Collision Contact Resting Contact.
Computer Game Design and Development
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
CS274 Spring 01 Lecture 7 Copyright © Mark Meyer Lecture VII Rigid Body Dynamics CS274: Computer Animation and Simulation.
Advanced Games Development Game Physics CO2301 Games Development 1 Week 19.
Rick Parent - CIS682 Rigid Body Dynamics simulate basic physics of an object subject to forces Keyframing can be tedious - especially to get ‘realism’
Havok Xtra Training
1 Computer Game Physics The very basics. 2 The Basics Force F Mass m Acceleration a: a = F/m Velocity v: v = a*t Position s: s = v*t …if F is constant.
Game Programming 13 Physics in Games (cont.) 2010 년 2 학기 디지털콘텐츠전공.
Introduction to Game Programming & Design III Lecture III.
Animation Animation is about bringing things to life Technically: –Generate a sequence of images that, when played one after the other, make things move.
CSCE 552 Fall 2012 Math, Physics and Collision Detection By Jijun Tang.
Fundamentals of Computer Animation Rigid Body Simulation (1)
Feature-length films: Games: Desktop Animations:.
Advanced Computer Graphics Rigid Body Simulation
Introduction to Game Physics
Done already for your convenience!
Lecture Rigid Body Dynamics.
3.7. Other Game Physics Approaches
2.1. Collision Detection Overview.
Math, Physics and Collision Detection
Chapter 4.2 Collision Detection and Resolution
Mechanics, Dynamics & Aesthetics
Motion in Real and Virtual Worlds
Synthesis of Motion from Simple Animations
Computer Animation Algorithms and Techniques
Advanced Games Development Game Physics
GPAT – Chapter 7 Physics.
Presentation transcript:

CIS 487/587 Bruce R. Maxim UM-Dearborn Computer Game Physics CIS 487/587 Bruce R. Maxim UM-Dearborn

Game Physics Not trying to build a perfect physical model Most things can be approximated assuming Newtonian physics and rigid bodies Use discrete simulation (constant step) techniques Just worry about center of mass for most things

The next 6 slides come from the Rabin text

Why Physics? The Human Experience Emergent Behavior Real-world motions are physically-based Physics can make simulated game worlds appear more natural Makes sense to strive for physically-realistic motion for some types of games Emergent Behavior Physics simulation can enable a richer gaming experience

Why Physics? Developer/Publisher Cost Savings Classic approaches to creating realistic motion: Artist-created keyframe animations Motion capture Both are labor intensive and expensive Physics simulation: Motion generated by algorithm Theoretically requires only minimal artist input Potential to substantially reduce content development cost At the present time, asset creation tools are not mature enough for physics to be as automatic as we would like. It currently requires quite a bit of work to get physics “right.” And so the cost of putting physics into a game may not be significantly cheaper than traditional animation approaches at this time. This should change as the physics tools improve. Artists should not worry that physics simulations will soon take over their jobs. This is particularly true for character and character-like animation. Physics and AI engines aren’t to the level yet where they can properly simulate the personality of characters that shows through in their motions!

High-level Decisions Physics in Digital Content Creation Software: Many DCC modeling tools provide physics Export physics-engine-generated animation as keyframe data Enables incorporation of physics into game engines that do not support real-time physics Straightforward update of existing asset creation pipelines Does not provide player with the same emergent-behavior-rich game experience Does not provide full cost savings to developer/publisher

High-level Decisions 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 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

High-level Decisions License vs. Build Physics Engine: License middleware physics engine Complete solution from day 1 Proven, robust code base (in theory) Most offer some integration with DCC tools Features are always a tradeoff

High-level Decisions License vs. Build Physics Engine: Build physics engine in-house Choose only the features you need Opportunity for more game-specific optimizations Greater opportunity to innovate Cost can be easily be much greater No asset pipeline at start of development

Position and Velocity Where is object at time t (using pixels)? Equations player_x(t) = t * x_velocity + x_initial player_y(t) = t * y_velocity + y_initial Computation player_x = player_x + x_velocity player_y = player_y + y_velocity

Acceleration Computation x_velocity = x_velocity + x_acceleration y_velocity = y_velocity + y_acceleration Use piecewise linear approximation to continuous functions

Gravity Force of attraction between objects F = G * (M1 * M2) / D2 G = gravitational constant D = distance between objects Free falling objects on Earth Equation V(t) = 1/2 * g * t2 g = 9.8 m/sec2 Computation x_velocity = x_velocity + 0 y_velocity = y_velocity + gravity

Projectile Motion X = x + Vx + W Y = y + Vy Vxi = cos(A) * Vi Vyi = sin(A) * Vi Vx = Vx - WR(Vx) Vy - WR(Vy) + G W = wind A = inclination angle Vi = initial velocity WR = wind resistance G = gravity

Friction Conversion of kinetic energy into heat Equation Computation Frictional Force = C * G * M C = force required to maintain constant speed G = gravity M = mass Computation while (velocity > 0) velocity = velocity - friction

The next 21 slides come from the Rabin text

Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring expensive testing 2. Naïve solution is O(n2) time complexity, since every object can potentially collide with every other object

Collision Detection Two basic techniques 1. Overlap testing Detects whether a collision has already occurred 2. Intersection testing Predicts whether a collision will occur in the future

Overlap Testing Facts Concept Most common technique used in games Exhibits more error than intersection testing Concept For every simulation step, test every pair of objects to see if they overlap Easy for simple volumes like spheres, harder for polygonal models

Overlap Testing: Useful Results Useful results of detected collision Time collision took place Collision normal vector

Overlap Testing: Collision Time Collision time calculated by moving object back in time until right before collision Bisection is an effective technique

Overlap Testing: Limitations Fails with objects that move too fast Unlikely to catch time slice during overlap Possible solutions Design constraint on speed of objects Reduce simulation step size

Intersection Testing 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

Intersection Testing: Sphere-Sphere Collision

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

Dealing with Complexity: Simplified Geometry Approximate complex objects with simpler geometry, like this ellipsoid

Dealing with Complexity: 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

Dealing with Complexity: Box Bounding Volumes

Dealing with Complexity: Achieving O(n) Time Complexity One solution is to partition space

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

Collision Resolution: Parts Resolution has three parts 1. Prologue 2. Collision 3. Epilogue

Collision Resolution: Prologue Collision known to have occurred Check if collision should be ignored Other events might be triggered Sound effects Send collision notification messages

Collision Resolution: Collision Place objects at point of impact Assign new velocities Using physics or Using some other decision logic

Collision Resolution: 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

Collision Resolution: Resolving Overlap Testing 1. Extract collision normal 2. Extract penetration depth 3. Move the two objects apart 4. Compute new velocities

Collision Resolution: Extract Collision Normal Find position of objects before impact Use two closest points to construct the collision normal vector

Collision Resolution: Extract Collision Normal Sphere collision normal vector Difference between centers at point of collision

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

Simple Collision Handling Detect that collision has occurred (bounding box) Determine the time of the collision (may need to back up to point of collision) Determine where objects are when they touch Determine the collision normal (angle of incidence = angle of reflection) Determine the velocity vectors after the collision Determine any changes in motion

Simple Kinematics P(x, y) Forward kinematic problem theta2 L2 L1 find position of P from theta1, theta2, L1, L2 use the 2D translation and rotation matrices (TL2*Rtheta2)* (TL1*Rtheta1) generalizes to any number of links theta2 L2 L1 theta1

Particle System Explosions Start with lots of small objects (1 to 4 pixels) Initialize particles with random velocities based on velocity of exploding object Apply gravity Transform color intensity as a function of time Destroy objects when they collide or after a fixed amount of time

The next 7 slides come from the Rabin text

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

Generalized Rigid Bodies – Simulation Angular Kinematics Orientation, 3x3 matrix R or quaternion, q Angular velocity, w As with translational/particle kinematics, all properties are measured in world coordinates Additional Object Properties Inertia tensor, J Center-of-mass Additional State Properties for Simulation Orientation Angular momentum, L=Jw Corresponding state derivatives

Generalized Rigid Bodies - Simulation Torque Analogous to a force Causes rotational acceleration Cause a change in angular momentum Torque is the result of a force (friction, collision response, spring, damper, etc.)

Collision Response Why? Two Basic Approaches 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 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

Collision Response Two Basic Approaches (continued) 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

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

Final Comments Simple Games Generalized Rigid Body Simulation 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

Time-Based Modeling Time t is used in all kinematic equations that move objects (to avoid discontinuities caused by “slower” frame rates) This involves scaling dx and dy based on elapsed time (rather than a virtual clock) This allow constant movement regardless of processor slow downs