PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6)...

21
Technische Universit¨ at M ¨ unchen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012 M. Schreiber, K. Unterweger: PSE Game Physics Session (6)Angular momentum, microcollisions, damping, 21.05.2012 1

Transcript of PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6)...

Page 1: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

PSE Game Physics

Session (6)Angular momentum, microcollisions, damping

Martin Schreiber, Kristof Unterweger

21.05.2012

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 1

Page 2: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Outline

Angular momentumAngular velocity - starting pointTorqueAngular momentum

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 2

Page 3: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Angular velocity - starting point

• With our quaternions, we are able to setup the rotation of anobject.

• Question: How to express the angular velocity?• Describe the angular velocity with a simple vector:

~vr = s ·~r

with ~vr being the angular velocity, s the angular speed and ~r thenormalized axis of rotation.

• Remark: s corresponds to the angle of rotation α per second.

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 3

Page 4: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Angular velocity - multiple velocities

• Looking at the translational velocity, we are allowed to simplysum different velocity vectors:

~v = ~v1 + ~v2

• Using angular velocity vectors, we are also allowed to simply addboth vectors:

~vr = ~vr1 + ~vr2

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 4

Page 5: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Angular velocity - from acceleration to velocity

• For the translational acceleration, we used the explicit Euler tocompute the updated velocity:

~v(t + ∆t) = ~v(t) + ∆t · ~a

and to update the position of the object (using the translate()method in the engine):

~x(t + ∆t) = ~x(t) + ∆t · ~v(t + ∆t)

• For a given angular acceleration ~α, we can update the angularvelocity with a similar method:

~vr (t + ∆t) = ~vr (t) + ∆t · ~α

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 5

Page 6: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

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 ,a quaternion can be set up representing the rotation for a singletimestep.

• Thus, you are able to compute the new quaternion of the nexttimestep:

q(t + ∆t) = q(t) · qr (t)

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 6

Page 7: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

How to move 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 onedescribing the orientation of the object.

• Next: How to modify the angular velocity of an object OR how toobtain ~α?

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 7

Page 8: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Torque (Drehmoment)

Abbildung: Force acting on object

• Let’s assume to have a directed force ~F (e. g. created by aspring) exceeded on the point ~x ′ relative to the center of mass ofan object.

• Then the torque is computed by

~τ = ~x ′ × ~F

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 8

Page 9: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Multiple Torques

Abbildung: 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• According to the summation of angular velocities, we can just

add them up:~τ =

∑i

~x ′i × ~Fi

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 9

Page 10: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Inertia (Massentraegheit)

• Change of angular velocity due to torque clearly depends on theshape of 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

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 10

Page 11: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Inertia (1/2)

• Similar to the translational force ~F = m · ~a, we get a formula forthe torque depending on the angular acceleration α and theinertia tensor:

~τ = I~α

• Since we are interested in computing the change in theangular acceleration, 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 inworld space.

⇒ convert to world space

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 11

Page 12: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

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

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 12

Page 13: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

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 asimilar way:

~pr = I · ~vr

• The angular momentum created by a translational momentumacting at point ~x ′ on the object is given by

~pr = ~x ′ × ~pl

• Finally we can express the change of angular velocity due tomomentum by

~vr = I−1~pr = I−1(~x ′ × ~pl )

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 13

Page 14: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

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 otherphysical properties.

• In particular, the velocity of both collision points has to matchthis formula.

• Our goal is to compute the impulse which has to be appliedto the collision points to match vs.

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 14

Page 15: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

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 massto the collision point and ~vl the (linear) translational velocity.

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 15

Page 16: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Step 1) Compute the closing velocity (con’d)

• Since only the velocity towards the collision normal may bemodified (without friction!), this fraction is computed by using thedot product:

vc = ~n · ~vA − ~n · ~vB

• Now we are able to compute the separating velocity with thesame formulas as for the purely translational case.

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 16

Page 17: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Step 2) Compute the change in velocity for unitimpulse

• It’s problematic to rearrange the formulas to directly compute theamount of impulse which has to be applied to gain a specificseparating velocity.

• Therefore we utilize an important property of the impulse (similarto Newtons 3rd law):When an impulse is exceeded to an object during a collision, animpulse of same magnitude but opposite direction is exceeded tothe other object.

• Important: The direction of the unit impulse of one object aims tothe opposite direction of the unit impulse applied to the otherobject.

• The change in velocity is computed based on applying a unitimpulse to both objects which is explained sucessively in thenext slides.

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 17

Page 18: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

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 onthe object:

∆~v = ∆~vl + ∆~vr × ~x ′

• This has to be computed for both objects!

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 18

Page 19: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Step 3) Computing the impulse to apply (1/2)• So far we know the change of velocity for both collision points.• Since the separating velocity only accounts towards the normal,

we may consider only the speed in direction of the normal:

∆s = ∆~v · ~n• The change in separating velocity of both objects when

exceeding a unit impulse to both objects is given by simplyadding ∆s of both objects (Depending on your implementation,maybe you have to change the sign of one component!)

• Knowing the closing velocity and the coefficient of restitution,we can compute the separating velocity using the formula

Cr =vs

vc

• By knowing the separating velocity, we can now compute thefraction f of the unit impulse (i.e. the fraction of the separatingvelocity) to apply.

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 19

Page 20: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Step 3) Computing the impulse to apply (2/2)

• Current state: We know the fraction of the unit impulse which hasto be applied 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 knowned by

multiplying the fraction f with the unit impulse which has tobe applied to gain the separating velocity or

• we use directly the fraction f to compute the change oftranslational and angular velocity for each object by usingour previously computed variables ∆~vl and ∆~vr .

~vl = ~vl + f ·∆~vl

~vr = ~vr + f ·∆~vr

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 20

Page 21: PSE Game Physics - in.tum.de fileTechnische Universit¨at Munc¨ hen PSE Game Physics Session (6) Angular momentum, microcollisions, damping Martin Schreiber, Kristof Unterweger 21.05.2012

Technische Universitat Munchen

Some more hints & comments:

• Always consider the different spaces (model or world space) inwhich you’re doing the computations. Sometimes you’ll have todo some transformations.

• To gain better results, also the interpenetration has to accountfor the rotations of objects.

M. Schreiber, K. Unterweger: PSE Game Physics

Session (6)Angular momentum, microcollisions, damping, 21.05.2012 21