Havok Xtra Workflow

Download Report

Transcript Havok Xtra Workflow

Havok Xtra Training
http://www.havok.com/xtra
[email protected]
Introduction
•
Physics Simulation?
•
Havok Xtra Workflow
– Tutorials
– Gotchas
Physics Simulation
•
•
Initialize
Step
– Advance simulation by h seconds
• 10
• 20
• 30
• 40
•
Apply Forces
Do Collision Detection
Do Collision Resolution
Go to 10
Shutdown
Step
r(t0 + h)
h v(t0)
r(t0)
estimated new
position
real new position
Step
Simulated position
Actual position
•
Improve by:
– decreasing step size
– introducing sub steps
Step
•
Sub steps
Step
•
Stepping strategy
– Fixed
•
havok.step( 1.0 / the tempo )
•
havok.step( newTime - oldTime )
– + system can be optimized for the time step
– - less control over simulation level of detail
– Variable
–+
–– Hybrid
real-time if linked to system clock
can introduce escalating, large time steps
Havok Xtra Workflow
•
Content Creation
W3D Files
•
Setup
•
Control
HKE Files
Content Creation
•
Shockwave 3D members
•
•
Lingo
Exported from a modeling package
– Rigid bodies must link to a visual equivalent
– Geometry
– W3D
– HKE
Geometry
•
Implicit
•
Convex
•
•
Concave
Proxies
– Plane
– Sphere
– Compound
Geometry
•
Representations
Proxies
•
Representations
– Physics
– Display
max Havok Guidelines
•
Supported
•
Unsupported
– Rigid Bodies
– Springs
– Dashpots
– Deformable Bodies
– Constraints
– Display Information
max Havok Guidelines
•
Compound Rigid Bodies
•
Rigid Body Collections
•
Proxy Geometry
– Groups should be open
– Check the integrator
– Disable unnecessary collisions
– Transforms must be aligned
max Havok Guidelines
•
•
•
Integrator
CPU
Accuracy
Euler
Low
Low
Back-Euler
Medium
Medium
Runga Kutta (RK45)
High
High
Midpoint
Medium
Medium-High
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
Scale
20
5
7.5
•
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
Update System:
Display:
Draw object at specified new location.
Update State:
Calculate forces, velocity, acceleration...
Call LINGO:
LINGO specific updates applied.
Advance time to t = t + h: Integrate
Calculate new position & orientation
Detect Collision:
Determine all colliding objects.
Use physics parameters to
Determine appropriate response
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.
Control
• Global Control
– Time Step
– Gravity
– Deactivation Parameters
– Drag Parameters
• Local Control
– Rigid Bodies
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
Use right hand rule for angular quantities:
+ve  CCW rotation
-ve  CW rotation
Rigid Bodies
applyForce
No immediate change
in velocity
applyImpulse
Immediate change in
velocity
Rigid Bodies
•
•
•
Alter position:
–
! DANGER !
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)
force applied at
center of mass
induces spin
Rigid Bodies
•
•
•
Alter orientation:
–
! DANGER !
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))
Axis = (1.0, 0.0, 0.0)
Magnitude = 2.0
Rigid Bodies
•
Problem with direct manipulation
set position
! DANGER !
set orientation
Interpenetrations
= not good
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
Collision Detection
Time t
Time t+h
Region of interpenetration
•
Back-stepping
Collision Detection
•
Tolerance
– Physical simulations have a limited resolution
– Tolerance accounts for numerical inaccuracies
•
•
LOW  numerically instable
HIGH  noticeable gaps between objects:
tolerance
– 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 )
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