Modern Game Engine Course Notes 04

Course from: BoomingTech

Physics System

Basic Concepts

Physics Actors and Shapes

Actor – Summary

Actor Shapes

Actor Shapes

Wrap Objects with Physics Shapes

Shape Properties

Forces

Force

Impulse

Movements

Newton’s 1st Law of Motion

v(t + dt) = v(t), x(t + dt) = x(t) + v(t)dt

Newton’s 2nd Law of Motion

F = ma, a(t) = dv(t)/dt = d^2x(t)/dt^2

Example of Simple Movement

Euler’s Method

Explicit (Forward) Euler’s Method

v(t + dt) = v(t) + F(t)dt / M
x(t + dt) = x(t) + v(t)dt

Pros:

Cons:

Implicit (Backward) Euler’s Method

v(t + dt) = v(t) + F(t + dt)dt / M
x(t + dt) = x(t) + v(t + dt)dt

Pros:

Cons:

Semi-implicit Euler’s Method

v(t + dt) = v(t) + F(t)dt / M
x(t + dt) = x(t) + v(t + dt)dt

Rigid Body Dynamics

Rigid body Dynamics

Rigid body Dynamics

// Orientation:

Matrix
R = [r_xx, r_yx, r_zx
     r_xy, r_yy, r_zy
     r_xz, r_yz, r_zz]
Quaternion
q = (s, v)


// Angular Velocity
omega = (d theta) / dt  = (v x r) / ||r||^2

// Angular Acceleration 
alpha = (d omega) / dt = (a x r) / ||r||^2

// Rotational Inertia
I = R I_0 R^T

// Angular Momentum
L = I omega

// Torque
tau = r x F = dL/dt

Rigid Body Summary

Collision Detection

Collision Detection – Two Phases

Broad Phase

Broad Phase - BVH Collision Detection BVH

Broad Phase - Sort and Sweep

  1. Sorting Stage (Initialize)

For each axis

  1. Sweeping Stage (Update)
    • Only check swapping of bounds
    • temporal coherence
    • local steps from frame to frame - Swapping of min and max indicates add/delete potential overlap pair from overlaps set - Swapping of min and min or max and max does not affect overlaps set

Narrow Phase – Objectives

Narrow Phase – Three approaches

Collision Resolution

Three approaches

Solving Constraints

Approaches:

Characteristics:

Scene Query

Raycast

Sweep

Overlap

Collision Group

Efficiency, Accuracy, and Determinism

Simulation Optimization - Island

Simulation Optimization – Sleeping

Continuous Collision Detection

Deterministic Simulation

Same old states + same inputs = same new states

Requirements:

Applications

Character Controller

Character Controller vs. Rigid Body Dynamics

Legacy Hack in Character Control

Build a Controller in Physics System

Collide with environment

Auto Stepping and its Problem

Slope Limits and Force Sliding Down

Controller Volume Update

Controller Push Objects

Standing on Moving Platform

Ragdoll

Map Skeleton to Rigid Bodies

Importance of Joint Constraints

Carefully Tweaked Constraints

Animating Skeleton by Ragdoll

Blending between Animation and Ragdoll

Powered Ragdoll – Physics-Animation Blending

Clothing

Animation-based Cloth Simulation

Rigid Body-based Cloth Simulation

Mesh-based Cloth Simulation

  1. Render mesh -> Physics mesh
  2. Paint cloth simulation constraints, add maximum radius constraints to each vertex
  3. Set cloth physical material
  4. Cloth Solver - Mass-Spring system:
    • Spring force: F_s = k_spring dx
    • Spring damping force: F_D = -k_damping v

Cloth Solver

Verlet Integration

x(t + dt) = 2x(t) - x(t - dt) + a(t)(dt)^2

Cloth Solver - Position Based Dynamics (Advanced choice)

Self Collision

Destruction

Destruction is Important

Chunk Hierarchy

Connectivity Graph - Construct connectivity graph for chunks at the deepest level

Connectivity Value - The value on each edge in the connectivity graph

Damage Calculation

  1. Calculate damage from impulse at the impact point
    • I : the applied impulse (e.g. by collision)
    • H : the material hardness of the rigid body
    • The damage at the impact point is D = I / H
  2. Damage distribution Damage Distribution

Build Chunks by Voronoi Diagram

Voronoi Cell

Fracturing with Voronoi Diagram - 2D Mesh

Pick N random points within the bounding rect of the mesh

Fracturing with Voronoi Diagram - 3D Mesh

Similar to the 2D situation, but not trivial

Generate triangles for all fracture surfaces

Different Fracture Patterns with Voronoi Diagram

Handle destruction after collision

Make it more realistic - Fracture is not enough

Issues with Destruction

Vehicle

Vehicle Mechanism Modeling

Traction Force Traction Force

Suspensions Force Suspensions Force

Tire Forces Tire Forces

Center of Mass

Weight Transfer

Steering angles

Advanced Physics : PBD/XPBD

Note: only for reference

Position Based Dynamics PBD - Constraints Projection

PBD

Advantages of PBD

Extended Position Based Dynamics (XPBD)