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)
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
Properties:
density
center of mass
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.
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.
Example Force:
gravity
drag
friction
impulse
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.
We use the unknown force in the future to calculate current state.
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.
In Semi-Implicit Euler's Method, we modify implicit euler's method:
we assume that next frame's force is the same as this frame's force
we update next frame's velocity using this frame's force
we update next frame's position using next frame's velocity
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.
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}
Inertia Tensor: I
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}
While BVH is fast, axis-aligned bounding box (AABB) provides faster query.
We sort every AABB to two arrays: the object is coliding when both x-axis and y-axis bounding box overlap
all mimimum and maximum values in x direction
all mimimum and maximum values in y direction
When we update dynamic object, Swap-and-sweep only adjust a few moving elements in the array.
Sphere Intersection
Sphere Overlap: |\vec{c_2} - \vec{c_1}| - r_1 - r_2 < 0
Contact Normal: \frac{\vec{c_2} - \vec{c_1}}{|\vec{c_2} - \vec{c_1}|}
Penetration Depth: |\vec{c_2} - \vec{c_1}| - r_1 - r_2
For convax geometry, we use 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.
For convex geometry, we can simplify the sum with infinite series to just a few points. This guarantees the resulting geometry is also convex.
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
The algorithm provides better complexity than boundary checks.
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.
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.
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 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
non-penetration
restitution
friction
Put it simply, our input is the original position and velocity, given a certain constraint, we want the new position and velocity.
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.
Ray Casting Problem:
Multi-hit: please give me every hit point along the ray
Closest-hit: please give me the fist hit along the ray
Any-hit: please tell me whether the ray hit any points
Sweep: whether a geometry travel along a segment will hit other geometries
Overlap: find geometries in the region
To reduce the possible size of queried objects, we usually divide collision geometries into collision-groups:
Pawn: players
Static: obstacles
Dynamic: moving objects
Trigger: trigger box
We can divide objects into separated islands that can hardly affect each other.
If a ridgid body does not move for a long time, we let the group sleep until some external force act on it.
When the projectile fly fast, it might go through the barrier.
A common and effective method is simply to make the barrier thicker.
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.
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:
logic ticks: 15/s~30/s
physics ticks: 30/s
rendering ticks: 30/s~60/s
Table of Content