Lecture 010

Basics of Physics

Static Actor: fixed in coordinate Dynamic Actor: movable objects according to physics law Trigger: non blocking collision commonly used for logic control Kinematic Actor: object that move but not according to physics law (break feedback)

Actor Shapes

Actor Shapes

Spheres: commonly used for small objects Capsules: commonly used for characters Boxes: commonly used for anything Convex Mesh: stones, particles Triangle Meshes: static mesh Height Fields: terrain

Wrapping Geometry

Wrapping Geometry

Shape Properties

Properties:

Physics Material: Different Friction and Restitution

Physics Material: Different Friction and Restitution

We need to assume constant density. The behavior of physics will change when there is any error in calculation. For example, Gomboc shape is the only known shape that has exactly one balance point with uniform density.

Gömböc.gif

Gömböc.gif

Physics material is the idea of having a material not just for rendering, but for physical calculation such as friction and restitution. Physics material can also be associated with sound. We pack rendering, physics, and interaction all within the material.

Force

Example Force:

Explicit Euler's Method

\begin{align*} \vec{v}(t_1) &= \vec{v}(t_0) + M^{-1} \vec{F}(t_0) \delta t\\ \vec{x}(t_1) &= \vec{x}(t_0) + \vec{v}(t_0) \delta t\\ \end{align*}

Problem with Explicit Euler's Method

Problem with Explicit Euler's Method

In above formula, we use last frame's state to predict the future state. However, due to discrete steps, energy is not conservative. Reducing step size \delta t can be closer to ground truth, but it will not converge.

Implicit Euler's Method

We use the unknown force in the future to calculate current state.

Problem with Implicit Euler's Method

Problem with Implicit Euler's Method

We prefer implicit method over explicit method because we don't like to generate energy from the void, but we can lose energy to the void.

Semi-implicit Euler's Method

Semi-Implicit Euler's Method

Semi-Implicit Euler's Method

In Semi-Implicit Euler's Method, we modify implicit euler's method:

The result will converge to the circle. But it is conditionally stable. When it is used to calculate periodic springs, the period is longer than ground truth.

Rigid Body

Position: \vec{x}

Linear Velocity: \vec{v} = \frac{d\vec{x}}{dt}

Acceleration: \vec{a} = \frac{d^2 \vec{x}}{dt^2}

Mass: M

Momentum: \vec{p} = M\vec{v}

Force: \vec{F} = \frac{d\vec{p}}{dt} = M \vec{a}

Orientation: R

Angular Velocity \vec{w}

Angular Acceleration \vec{\alpha}

Rotational Inertia Tensor

Rotational Inertia Tensor

Inertia Tensor: I

Conservation of Angular Momentum

Conservation of Angular Momentum

Angular Momentum: \vec{L}

Conservation of Momentum: proved with assumption that physics law is the same in every position in the Universe. Conservation of Angular Momentum: proved with assumption that physics law is the same in every facing direction in the Universe.

Note that energy is not conserved. (Only conserve after you consider mass as energy)

Torque: \vec{\tau}

Angular vs. Linear

Angular vs. Linear

Simple Rigid Dynamics

Simple Rigid Dynamics

Collision Detection

Broad Phase

BVH for Collision

BVH for Collision

While BVH is fast, axis-aligned bounding box (AABB) provides faster query.

Swap-and-sweep: AABB Collision

Swap-and-sweep: AABB Collision

We sort every AABB to two arrays: the object is coliding when both x-axis and y-axis bounding box overlap

When we update dynamic object, Swap-and-sweep only adjust a few moving elements in the array.

Narrow Phase

Simple Geometry

Sphere Intersection

Sphere Intersection

Sphere Intersection

Sphere-Capsule Test

Sphere-Capsule Test

Capsule-Capsule Test

Capsule-Capsule Test

For convax geometry, we use Minkowski Sum

Convex Geometry

Minkowski Sum

Minkowski Sum

Minkowski Sum is sum of two (infinite) sets. Let set A be all points in the first geometry and let B be all points in the second geometry. The Minkowski Sum of A, B is a set containing every point from A summed with every point from B.

Convex Minkowski Sum

Convex Minkowski Sum

For convex geometry, we can simplify the sum with infinite series to just a few points. This guarantees the resulting geometry is also convex.

Convex Minkowski Subtraction

Convex Minkowski Subtraction

We can then use Minkowski Subtraction to tell us whether geometry A, B collide. If the point 0 is in the set of Minkowski Subtraction, then two geometry collide. We can tell whether the origin is in the set by doing a segment orientation detection. (like rasterizing triangles) However, there exists a better method:

GJK Algorithm

  1. Find a highest point in A and a lowest point in B (with respect to any direction)
  2. Do Minkowski Subtraction, and you will guaranteed to get a boundary vertex C in the resulting Minkowski set (simplex contains only one point).
  3. Calculate the nearest direction to the origin, if the nearest distance is reduced, then continue
  4. Do it again, use the direction, find a high and low points in A, B, and find point D in simplex.

GJK Algorithm: Step 1

GJK Algorithm: Step 1

GJK Algorithm: Step 2

GJK Algorithm: Step 2

GJK Algorithm: Step 3

GJK Algorithm: Step 3

GJK Algorithm: Step 4

GJK Algorithm: Step 4

GJK Algorithm: Step 5

GJK Algorithm: Step 5

GJK Algorithm: Step 6

GJK Algorithm: Step 6

GJK Algorithm: Step 7

GJK Algorithm: Step 7

The algorithm provides better complexity than boundary checks.

GJK Algorithm: when the triangle overlaps the origin

GJK Algorithm: when the triangle overlaps the origin

For triangle-point intersection, we calculate its barycentric coordinate and check for negative (if you want some penetration length). Or orientation check if you don't need extra data.

Separating Axis Theorem (SAT): for two convex object A, B, the object is separated if and only if you can find a plane (line, hyperplane) that separates the two object in a projection along the plane. In 3D, there exist a face in object A that separate A, B if A, B do not collide.

Separating Axis Theorem 2D

Separating Axis Theorem 2D

A method for 2D: The main idea is: for each A's segment, you test whether any vertex in B is outside of the line. If so, you have found the line that separates two geometry. Do this for every A's line on B's vertex and every B's line on A's vertex.

Separating Axis Theorem 3D

Separating Axis Theorem 3D

However, for 3D, it is not enough for us to conclude intersection by just testing faces against vertices (think about clipping). You need also test the face that forms by cross product of two edges from both geometry.

When you write the physics engine to detect collision in an animation, you could use the last frame's data as the current frame's initialization heuristic to achieve better amortized performance.

Sometimes Jacobian Matrix is useful here. // QUESTION: why

Collision Resolution

Collision Resolution describes what rules to follow when we detect collisions in physical engine.

Penalty Force: we push object away from each other.

Nobody use penalty force to simulate a real object now, it was a historical method.

Lagrangian's physics, contrast to Newton's physics, describe the movement by solving constraints which is easier to model: the collision constraints include

Put it simply, our input is the original position and velocity, given a certain constraint, we want the new position and velocity.

Directly Apply Penalty Force: The Old Method

Directly Apply Penalty Force: The Old Method

Solving Constraint: The Better Method

Solving Constraint: The Better Method

We solve for a sequential impulse that satisfy the "collision constraints" with semi-implicit integration. Non-linear Gauss-Seidel Method is a stable method commonly used in modern physics engine.

Geometry Query

Geometry Query: Ray Casting

Geometry Query: Ray Casting

Ray Casting Problem:

Sweep: implementing sized projectile

Sweep: implementing sized projectile

Overlap: implementing bomb

Overlap: implementing bomb

To reduce the possible size of queried objects, we usually divide collision geometries into collision-groups:

Improving Efficiency, Accuracy, Determinism

Efficiency

We can divide objects into separated islands that can hardly affect each other.

Islands

Islands

If a ridgid body does not move for a long time, we let the group sleep until some external force act on it.

Islands: sleep

Islands: sleep

Accuracy

When the projectile fly fast, it might go through the barrier.

Tunneling

Tunneling

A common and effective method is simply to make the barrier thicker.

Continuous Collision Detection

Continuous Collision Detection

Continuous Collision Detection: we estimate a safe stepsize such that A, B won't collide. We decrease stepsize as two objects move closer within a threshold.

Determinism

In multiplayer games, physics simulation is usually in the client side. Therefore we need consistency over network latency.

The effect of small error will accumulate and therefore diverge in complex system (Chaos Theory).

Not just network latency, the same program with the same input running on different computer with different framerate can yield different result in physics simulation.

We need to make sure we have: - same frame rate - same order or traversal - same integer and floating point size - same GPU architecture if possible

To deal with network latency, we can synchronize physics input over clients.

Common Ticks:

Table of Content