380 likes | 550 Views
Havok Xtra Training. http://www.havok.com/xtra xtra@havok.com. Introduction. Physics Simulation? Havok Xtra Workflow Tutorials Gotchas. Physics Simulation. Initialize Step Advance simulation by h seconds 10 Apply Forces 20 Do Collision Detection 30 Do Collision Resolution
E N D
Havok Xtra Training http://www.havok.com/xtra xtra@havok.com
Introduction • Physics Simulation? • Havok Xtra Workflow • Tutorials • Gotchas
Physics Simulation • Initialize • Step • Advance simulation by h seconds • 10 Apply Forces • 20 Do Collision Detection • 30 Do Collision Resolution • 40 Go to 10 • Shutdown
r(t0+ h) estimated new position h v(t0) real new position r(t0) Step ?
Step Simulated position • Improve by: • decreasing step size • introducing sub steps Actual position
Step • Sub steps
Step • Stepping strategy • Fixed • havok.step( 1.0 / the tempo ) • + system can be optimized for the time step • - less control over simulation level of detail • Variable • havok.step( newTime - oldTime ) • + real-time if linked to system clock • - can introduce escalating, large time steps • Hybrid
W3D Files HKE Files Havok Xtra Workflow • Content Creation • Setup • Control
Content Creation • Shockwave 3D members • Rigid bodies must link to a visual equivalent • Geometry • Lingo • Exported from a modeling package • W3D • HKE
Geometry • Implicit • Plane • Sphere • Convex • Compound • Concave • Proxies
Geometry • Representations
Proxies • Representations • Physics • Display
max Havok Guidelines • Supported • Rigid Bodies • Springs • Dashpots • Unsupported • Deformable Bodies • Constraints • Display Information
max Havok Guidelines • Compound Rigid Bodies • Groups should be open • Rigid Body Collections • Check the integrator • Disable unnecessary collisions • Proxy Geometry • Transforms must be aligned
max Havok Guidelines • Integrator CPU Accuracy • Havok Xtra members use Euler • Max Havok defaults to Runga Kutta
Setup • Initialize • Blank HKE • Scale • Tolerance • Imported HKE
Setup • Initialize • How is the simulation displayed? • Physics objects must link to a visual equivalent • What is the mapping between the physics simulation and its display?
Scale • Size matters • Physics units are meters, seconds and kilograms • Display unit may be different • havok.initialize(member, tolerance, worldScale) • Examples: • havok.initialize(1, 0.1, 1.0) -- meters • havok.initialize(1, 4, 0.0254) -- inches • havok.initialize(1, 10, 1000) -- kilometers
5 20 7.5 Scale • Box falls in: • ~1 second if units are meters • ~40 seconds if units are in kilometers
Setup • Initialize property hk, s on beginSprite me hk = member("HKE") s = member("W3D") hk.initialize( s ) end on exitFrame me hk.step() end on endSprite me hk.shutdown() s.resetWorld() end
Setup • Rigid Body s = member(“W3D") hk = member(“HKE") mr = s.newModelResource(“MDLRes", #box) m = s.newModel(“MDL") m.addModifier(#meshdeform) if bWantFixed then rb = hk.makeMovableRigidBody(m.name, 10.0) else rb = hk.makeFixedRigidBody(m.name) end if
Control • Input • Properties • Functions • Behaviors • Step call backs • Output • Properties • Collision Details • Collision call backs
Control Setup Initial Conditions: Define Geometry Initial position and velocity, gravity, wind, air resistance, Time step = h = 1/60 seconds Display: Draw object at specified new location. Update System: Update State: Calculate forces, velocity, acceleration... Call LINGO: LINGO specific updates applied. Advance time to t = t + h: Integrate Calculate new position & orientation Collision Callback: Called when a certain pair of objects collide. Information about the collision is returned to the user here so that they may take appropriate action. Detect Collision: Determine all colliding objects. Use physics parameters to Determine appropriate response
Control • Global Control • Time Step • Gravity • Deactivation Parameters • Drag Parameters • Local Control • Rigid Bodies
Use right hand rule for angular quantities: +ve CCW rotation -ve CW rotation Rigid Bodies • Vectors: • position (m) • velocity (m/s) • angular velocity (rad/s) • momentum (kg m/s) • angular momentum (kg rad/s) • force (kg m/s2 = N) • torque (kg m2/s2 = Nm ) • acceleration (m/s2) • angular acceleration (rad/m2) • Scalars: • mass (kg) • friction • restitution
Rigid Bodies applyForce No immediate change in velocity applyImpulse Immediate change in velocity
Rigid Bodies • Alter position: • rb.position = vector(2.0, 3.0, 4.0) • Alter velocity: • rb.linearVelocity = vector(1.0, 0.0, 0.0) • rb.applyImpulse(vector(1.0, 0.0, 0.0)) • rb.applyImpulseAtPoint(impulse, point) • Alter acceleration: • rb.applyForce(vector(1.0, 0.0, 0.0)) • rb.applyForceAtPoint(force, point) ! DANGER ! force applied at center of mass induces spin
Rigid Bodies • Alter orientation: • body.rotation = [vector(0.0, 1.0, 0.0), 90] • Alter angular velocity: • body.angularVelocity = vector(1.0, 0.0, 0.0) • body.applyAngularImpulse(vector(2.0, 0.0, 0.0)) • Alter angular acceleration: • body.applyTorque(vector(2.0, 0.0, 0.0)) ! DANGER ! Axis = (1.0, 0.0, 0.0) Magnitude = 2.0
Rigid Bodies • Problem with direct manipulation set position ! DANGER ! Interpenetrations = not good set orientation
Rigid Bodies desired new position • attemptMoveTo(pos, axis, angle) • moves object to position & orientation and checks for interpenetration • returns true if successful • returns false if move illegal and put back • interpolatingMoveTo(pos, axis, angle) • positions object as close to desired location as possible • returns parametric distance • 1.0 if moved completely • 0.5 if moved halfway • 0.0 if not moved at all interpolatingMoveTo gets 70% there
Behaviors • Apply Constant Acceleration on enterFrame me rb = hk.rigidBody( pModel ) if not voidP( rb ) then rb.applyForce( acc * rb.mass ) end if end enterFrame • Anti-gravity behavior if force is negation of havok.gravity? rb.applyForce( acc * rb.mass * pHavok.substeps )
Behaviors • Step callbacks • Anti-gravity on beginSprite me hk.registerStepCallback(#antigrav,me) end beginSprite on antiGrav me, newTime acc = -hk.gravity rb = hk.rigidBody( pModel ) if not voidP( rb ) then rb.applyForce( acc * rb.mass ) end if end antiGrav
Time t Time t+h Region of interpenetration Collision Detection • Back-stepping
tolerance Collision Detection • Tolerance • Physical simulations have a limited resolution • Tolerance accounts for numerical inaccuracies • LOW numerically instable • HIGH noticeable gaps between objects: • Rule of thumb: tolerance = world scale / 10.0
Collision Detection • Call me after a collision hk.registerInterest( rb1, #all, f, t, #handler, me ) • Callback passed collision details on handler( me, details ) put details end • Lost Interest hk.removeInterest( rb.name)
B A Collision Detection • Details • Name of Rigid Body A • Name of Rigid Body B • Contact Point • Contact Normal • Normal Relative Velocity
Collision Detection • Not all collisions are needed hk.disableCollision( rb1, rb2 ) • Might not need any hk.disableAllCollision( rb1 ) • Or maybe some hk.enableCollision( rb.name, “Ground”)
Gotchas • Initialize:only ever one simulation activate • Initialize:what the scaling