PSE Game Physics - TUM · S. Rettenberger, R. WittmannjPSE Game PhysicsjSession (6)j20.05.2016 10...
Transcript of PSE Game Physics - TUM · S. Rettenberger, R. WittmannjPSE Game PhysicsjSession (6)j20.05.2016 10...
PSE Game Physics
Session (6)Angular momentum, microcollisions, damping
Sebastian Rettenberger, Roland WittmannTechnische Universitat Munchen
20.05.2016
Outline
Angular momentumAngular velocity - starting pointTorqueAngular momentum
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 2
Angular velocity - starting point
• With our quaternions, we are able to setup the rotation of an object.• Question: How to express the angular velocity in 3D?• Describe the angular velocity ~vr by a simple vector:
~vr = s ·~r
that is a product of the norm of the angular speed s and the normalizedaxis of rotation ~r .
s
r
vr
• Remark: s corresponds to the time derivative θ of the rotation angle θ andhas the unit angle per second.
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 3
Angular velocity - multiple velocities
• Translational velocities are additive under composition:
~v = ~v1 + ~v2
• Angular velocities are additive under composition, too (although theexplanation is not trivial):
~vr = ~vr1 + ~vr2
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 4
Angular velocity - from acceleration to velocity
• For the translational acceleration, we used the explicit Euler toapproximate the updated velocity:
~v(t + ∆t) = ~v(t) + ∆t · ~a
and an implicit Euler to update the position of the object (using thetranslate() method in the engine):
~x(t + ∆t) = ~x(t) + ∆t · ~v(t + ∆t)
• For a given angular acceleration ~α, we can update the angular velocitywith a similar method:
~vr (t + ∆t) = ~vr (t) + ∆t · ~α
What about updating the rotation?
q(t + ∆t) =???
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 5
From angular velocity to quaternions
• Remember Session (3):• Given rotation axis (x , y , z) and angle θ = |~vr |∆t
→ qr :=
wijk
=
cos θ
2x sin θ
2y sin θ
2z sin θ
2
∈ R× R3
• Computing a single timestep given an angular velocity vector ~vr , aquaternion can be set up representing the rotation for a single timestep.
• Thus, you are able to compute the new quaternion of the next timestep:
q(t + ∆t) = q(t) · qr (∆t)
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 6
Moving on...
• So far we (should) know:• What an angular velocity vector is.• How to rotate an object during each timestep.
• Update angular velocity of objects using angular acceleration.• Update the orientation by converting the angular rotation to a quaternion and
applying the rotational quaternion to the one describing the orientation of theobject.
• Next: How to modify the angular velocity of an object OR how to obtain~α?
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 7
Torque(Drehmoment)
Figure : Force acting on object
• Let’s assume to have a directed force ~F (e. g. created by a spring)exceeded on the point ~x ′ relative to the center of mass of an object.
• Then the torque is computed by
~τ = ~x ′ × ~F
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 8
Multiple Torques
Figure : Multiple forces acting on an object
• We are not only interested in a single torque acting on an object• When multiple forces are exceeded on an object, they have to be
combined somehow• Similar to forces, torques can be added up:
~τ =∑
i
~x ′i × ~Fi
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 9
Inertia(Massentragheit)
• Change of angular velocity due to torque clearly depends on the shapeof the object!
• This information can be expressed in form of the inertia tensor.• For spheres and boxes, these tensors are
ISphere =
23 mr2 . .
. 23 mr2
. . 23 mr2
IBox =
1
12 m(w2 + d2) . .
. 112 m(h2 + d2)
. . 112 m(h2 + w2)
See http://en.wikipedia.org/wiki/List_of_moments_of_inertia for more inertia tensors
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 10
Inertia (1/2)
• Similar to the translational force ~F = m ·~a, we get a formula for the torquedepending on the angular acceleration α and the inertia tensor:
~τ = I~α
• Since we are interested in computing the change in the angularacceleration, we are allowed to rewrite the equation:
~α = I−1~τ
• Warning: This formula is valid only in object space!!!However, the forces exerted on the object might only be given in worldspace.
⇒ convert to world space
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 11
Inertia (2/2)
• The torque τ is given as a vector• Object→World space: inverse transposed matrix (see session (2))• World→ Object space: transposed matrix• Putting everything together, the angular acceleration vector is computed
by~α = M−T I−1MT~τ
with model matrix M
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 12
Angular momentum
• We start by looking at our “simple“ translational case. There wecomputed the momentum by
~pl = m · ~v
• For angular rotations, we express the angular momentum in a similarway:
~pr = I · ~vr
• The angular momentum change created by a translational momentumchange at point ~x ′ on the object is given by
∆~pr = ~x ′ ×∆~pl
• Finally we can express the change of angular velocity due to momentumby
∆~vr = I−1∆~pr = I−1(~x ′ ×∆~pl )
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 13
Angular collision impulse
• From the translational case, we know that due to the collision, the“velocity has to change“ to match vs = −Cr · vc and other physicalproperties.
• In particular, the velocity of both collision points has to match thisformula.
• Our goal is to compute the impulse which has to be applied to thecollision points to match vs.
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 14
Step 1) Compute the closing velocity
• The velocity of a point on the surface of the object is given by
~v = ~vr × ~x ′ + ~vl
with angular velocity ~vr , ~x ′ as the vector from the center of mass to thecollision point and ~vl the (linear) translational velocity.
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 15
Step 1) Compute the closing velocity (con’d)
• Since only the velocity towards the collision normal may be modified(without friction!), this fraction is computed by using the dot product:
vc = ~n · ~vA − ~n · ~vB
• Now we are able to compute the separating velocity with the sameformulas as for the purely translational case.
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 16
Step 2) Compute the change in velocity for unitimpulse
• It’s problematic to rearrange the formulas to directly compute the amountof impulse which has to be applied to gain a specific separating velocity.
• Therefore we utilize an important property of the impulse (similar toNewtons 3rd law):When an impulse is exceeded to an object during a collision, an impulseof same magnitude but opposite direction is exceeded to the other object.
• Important: The direction of the unit impulse of one object aims to theopposite direction of the unit impulse applied to the other object.
• The change in velocity is computed based on applying a unit impulse toboth objects which is explained sucessively in the next slides.
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 17
Step 2) Compute the change in velocity for unitimpulse (con’d)
• The unit impulse is parallel to the collision normal.• Computing the change in translational velocity for the unit impulse
is(/should be) known from previous sessions:
∆~vl = ~n ·m−1
• The change in angular velocity is computed using
∆~vr = M−T I−1MT︸ ︷︷ ︸Inertia to world space
( ~x ′︸︷︷︸lever arm
× ~n︸︷︷︸unit impulse
)
• Finally, we compute the change of velocity in the specific point on theobject:
∆~v = ∆~vl + ∆~vr × ~x ′
• This has to be computed for both objects!
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 18
Step 3) Computing the impulse to apply (1/3)
• From step 1), we know the closing velocity:
vc = ~n · ~vA − ~n · ~vB
• With the coefficient of restitution, we can compute the separatingvelocity using the formula:
Cr = −vs
vc
• From step 2), we can also compute the change of velocity in thedirection of the normal for the unit impulse:
∆s = ∆~v · ~n
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 19
Step 3) Computing the impulse to apply (2/3)
• The difference of the separating and closing velocities from step 1) isobviously not equal to the change of velocities was computed with theunit impulse.
• However, it is equal to a fraction f of the unit impulse and since alloperations are linear:
vs − vc = f · (∆sA + ∆sB)
(Depending on your implementation, maybe you have to change the signof one component!)
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 20
Step 3) Computing the impulse to apply (3/3)
• Current state: We know the fraction of the unit impulse which has to beapplied to both objects to gain the separating velocity!
• There are 2 ways how to apply this impulse:• Either we apply the impulse which is now well known by multiplying
the fraction f with the unit impulse which has to be applied to gainthe separating velocity or
• we use directly the fraction f to compute the change of translationaland angular velocity for each object by using our previouslycomputed variables ∆~vl and ∆~vr .
~vl = ~vl + f ·∆~vl
~vr = ~vr + f ·∆~vr
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 21
Summary (1/2)
Steps to resolve a collision:• Choose as (initially wrong) impulse the unit vector ~n (which is the collision
normal).• For each object, compute the change of linear and rotation velocity (∆~vl
and ∆~vr ) in the collision point, that would occur if we applied the unitimpulse ~n (slide 18).
• For each object, compute the total velocity change ∆~v at the collisionpoint by adding up linear velocity and cross product of rotation velocityand lever arm:
∆~v = ∆~vl + ∆~vr × ~x ′
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 22
Summary (2/2)Compute a reasonable fraction f of the unit impulse:
• Applying the unit impulse to two colliding objects, we would get theseparating velocity:
vs = vc + (∆~vA −∆~vB) · ~n
However, vs does not fulfill the condition (slide 19):
vs = −Cr · vc
• So in order to fulfill the condition, we have to multiply the unit impulse witha fraction f . Since all performed operations are linear, we get:
−Cr · vc = vs = vc + f · (∆~vA −∆~vB) · ~n
• Solve the formula by f and set:
~vl = ~vl + f ·∆~vl
~vr = ~vr + f ·∆~vr
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 23
Some more hints & comments:
• Always consider the different spaces (model or world space) in whichyou’re doing the computations. Sometimes you’ll have to do sometransformations.
• To gain better results, also the interpenetration has to account for therotations of objects.
S. Rettenberger, R. Wittmann | PSE Game Physics | Session (6) | 20.05.2016 24