Skip to content

Latest commit

 

History

History
85 lines (81 loc) · 2.88 KB

README.md

File metadata and controls

85 lines (81 loc) · 2.88 KB

2D Game Physics Engine

Dependencies

  • SDL
    • for multi-platform capability

Physics

  • Newtonian physics
    • inertia
    • Force, mass, acceleration
      • $F = ma$
    • Action and reaction
  • Variable Delta-Time
    • delta time changes between frames
    • BUT will result in non-deterministic simulation
    • could use a constant delta time ensure determinism
  • $p = p_0 + v_0t + at^2/2$
    • $p$ is position
  • Newton's dot notation
    • ẋ - $x$ is function of time $t$, the derivative of $x$ with respect to $t$
    • ẍ - second derivative of $x$ with respect to time $t$
  • Euler integration
    • the most basic numerical integration technique
    • only 100% when rate of change is constant
  • Implicit Euler
    • good enough for most game applications
  • Verlet Integration
    • better accuracy than implicit Euler
    • less memory usage when simulating a large number of particles
    • best suited for simulating particles and constraints between particles
  • Runge-Kutta Integration
    • a family of integrators
    • RK4 is the most popular
      • very accurate
  • Drag Force
    • resistive force
    • depends on velocity
  • Friction
    • kinetic friction
    • static friction
  • jerk - rate of change of acceleration
  • Spring Force
  • Angular Velocity
    • theta - angle
    • omega - angular velocity
    • alpha - angular acceleration
  • Initiate angular movement by applying torque
  • Moment of Intertia
    • $I_{solidcircle} = (r^2 / 2) * m$
    • $I_{solidrectangle} = ((w^2 + h^2) / 12) * m$
  • local space vs. world space
  • Collision
    • Steps:
      1. Collision detection - shape-specific
      2. Collision resolution - agnostic to shape
  • Techniques of collision detection
    • broad phase
      • use bounding circles/boxes
    • narrow phase
  • projection method vs. impulse method vs. penalty method
    • projection method: adjust position of the colliding objects
    • impulse method: adjust velocity of colliding objects by apply impulses
    • penalty method: adjust acceleration of colliding objects
  • projection method
    • $d_{a} = depth * (m_b / (m_a + m_b))$
    • $d_{b} = depth * (m_a / (m_a + m_b))$
  • Momentum
    • conservation of momentum
  • Impulse - change in momentum by performing a direct change in velocity
    • $J = F * Δt = ΔP = mv' - mv = mΔv$
    • $Jn$ - impulse vector
  • AABB
  • Separating Axis Theorem (SAT)
    • ONLY works for convex polygons
      • compared to concave polygon
    • one of the most popular collision detection algos for rigid bodies
    • with GJK algorithm
      • works for both convex & concave
  • Oriented Bounding Box (OBB)
    • if there is at least one axis that separates both shapes, then they are not colliding
  • Support Point
    • vertex in the second polygon that is furthest away behind a certain edge of the first polygon