Files
2nd/10_Wiki/Topics/Game_Design/Physics.md
T
koriweb 27b2c25e4d feat(wiki): Topic_Blog SEO 지식화 + orphan 연결
- Topic_Blog: 미추적 상태였던 SEO/색인 지식 문서 일괄 추적 추가
  (Google '페이지 색인 생성 보고서' 기반 신규 6종 포함:
   페이지 색인 생성 보고서/색인 생성 유효성 검사/Soft 404/NOINDEX/
   크롤링됨·발견됨-현재 색인 안 됨/SEO를 위한 HTTP 상태 코드).
- orphan 연결: 완전 고립된 지식 문서 9개를 관련 기존 문서와 양방향 링크
  (Game Design 쌍, Aerospace, Apple Vision Pro, 3D_Web_HMI, Stock 3,
   Topics_Biz). append-only, 존재 타깃만 링크(dangling 0).
도구: Datacollect/scripts/wiki_audit.mjs (중복·orphan 감사)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 14:48:16 +09:00

198 lines
6.9 KiB
Markdown

---
id: wiki-2026-0508-physics
title: Physics
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Game Physics, Physics Engine, Rigid Body Simulation]
duplicate_of: none
source_trust_level: A
confidence_score: 0.95
verification_status: applied
tags: [game-design, physics, simulation, rigid-body, collision]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: cpp
framework: rigid-body-physics
---
# Physics
## 매 한 줄
> **"매 Newtonian dynamics 의 discrete-time integration + collision detection + constraint solving 의 trinity"**. Game physics 매 (1) integrator (Euler, Verlet, RK4), (2) broadphase + narrowphase collision, (3) iterative constraint solver (Sequential Impulses, PGS, XPBD) 의 stack. 2026 매 Jolt (Horizon Forbidden West), Rapier (Rust ecosystem), PhysX 5, Bullet 매 dominant.
## 매 핵심
### 매 Three Pillars
- **Integration**: 매 Δt 의 over forces → velocity → position.
- **Collision detection**: 매 broadphase (BVH, sweep-and-prune) → narrowphase (GJK, SAT, MPR).
- **Constraint resolution**: 매 contact, joints, friction 의 iterative solve.
### 매 Integrators
- **Explicit Euler**: 매 simple, unstable, energy gain.
- **Semi-implicit Euler**: 매 game default, stable for most cases.
- **Verlet**: 매 position-based, energy-stable, cloth-friendly.
- **RK4**: 매 accurate, expensive — 매 specialized sims.
### 매 Constraint solvers
- **Sequential Impulses (Erin Catto)**: 매 Box2D / Bullet 의 standard.
- **Projected Gauss-Seidel (PGS)**: 매 PhysX, ODE.
- **XPBD (Extended Position-Based Dynamics)**: 매 Jolt, modern soft-body.
### 매 응용
1. Action games — Jolt + Havok physics for combat impact.
2. Driving sims — multi-body vehicle constraints.
3. Cloth / soft-body — XPBD + Verlet for hair, capes, organic deformation.
## 💻 패턴
### Semi-implicit Euler
```cpp
struct RigidBody {
Vec3 position, velocity;
Quat orientation; Vec3 angularVelocity;
float invMass; Mat3 invInertia;
Vec3 force, torque;
};
void integrate(RigidBody& b, float dt) {
b.velocity += (b.force * b.invMass) * dt; // 매 v_{n+1} 의 first
b.position += b.velocity * dt; // 매 x_{n+1} 의 use new v
b.angularVelocity += (b.invInertia * b.torque) * dt;
Quat dq = 0.5f * Quat(0, b.angularVelocity) * b.orientation;
b.orientation = normalize(b.orientation + dq * dt);
b.force = b.torque = Vec3::Zero;
}
```
### AABB broadphase (sweep-and-prune)
```cpp
struct AABB { Vec3 min, max; int bodyId; };
std::vector<std::pair<int,int>> sap(std::vector<AABB>& boxes, int axis) {
std::sort(boxes.begin(), boxes.end(),
[&](auto& a, auto& b){ return a.min[axis] < b.min[axis]; });
std::vector<std::pair<int,int>> pairs;
for (size_t i = 0; i < boxes.size(); i++) {
for (size_t j = i + 1; j < boxes.size(); j++) {
if (boxes[j].min[axis] > boxes[i].max[axis]) break;
if (overlap(boxes[i], boxes[j])) pairs.emplace_back(boxes[i].bodyId, boxes[j].bodyId);
}
}
return pairs;
}
```
### GJK narrowphase (convex overlap test)
```cpp
bool gjk(const ConvexShape& A, const ConvexShape& B) {
Vec3 d = {1, 0, 0};
std::vector<Vec3> simplex = { support(A, B, d) };
d = -simplex[0];
for (int i = 0; i < 64; i++) {
Vec3 p = support(A, B, d);
if (dot(p, d) < 0) return false; // 매 origin 의 not contained
simplex.push_back(p);
if (doSimplex(simplex, d)) return true;
}
return false;
}
```
### Sequential impulse contact resolution
```cpp
void resolveContact(RigidBody& a, RigidBody& b, const Contact& c, float restitution, float friction) {
Vec3 ra = c.point - a.position;
Vec3 rb = c.point - b.position;
Vec3 relV = (b.velocity + cross(b.angularVelocity, rb))
- (a.velocity + cross(a.angularVelocity, ra));
float vn = dot(relV, c.normal);
if (vn > 0) return; // 매 separating
float effMass = a.invMass + b.invMass
+ dot(c.normal, cross(a.invInertia * cross(ra, c.normal), ra))
+ dot(c.normal, cross(b.invInertia * cross(rb, c.normal), rb));
float j = -(1 + restitution) * vn / effMass;
Vec3 impulse = j * c.normal;
a.velocity -= impulse * a.invMass;
b.velocity += impulse * b.invMass;
a.angularVelocity -= a.invInertia * cross(ra, impulse);
b.angularVelocity += b.invInertia * cross(rb, impulse);
}
```
### XPBD distance constraint
```cpp
void solveDistance(RigidBody& a, RigidBody& b, float restLen, float compliance, float dt) {
Vec3 d = b.position - a.position;
float len = length(d);
Vec3 n = d / len;
float C = len - restLen;
float wSum = a.invMass + b.invMass;
float alpha = compliance / (dt * dt);
float dLambda = -C / (wSum + alpha);
a.position -= n * (dLambda * a.invMass);
b.position += n * (dLambda * b.invMass);
}
```
### Continuous collision (CCD)
```cpp
// 매 high-velocity tunneling 의 prevent
float ccdSphereSphere(Vec3 pa, Vec3 va, float ra, Vec3 pb, Vec3 vb, float rb, float dt) {
Vec3 dp = pb - pa;
Vec3 dv = vb - va;
float r = ra + rb;
float a = dot(dv, dv);
float b = 2 * dot(dp, dv);
float c = dot(dp, dp) - r * r;
float disc = b*b - 4*a*c;
if (disc < 0 || a == 0) return -1;
float t = (-b - std::sqrt(disc)) / (2 * a);
return (t >= 0 && t <= dt) ? t : -1;
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Action / shooter | Jolt + semi-implicit Euler + sequential impulses |
| Cloth / soft-body | XPBD + Verlet |
| Driving sim | Multi-body + RK4 (or sub-stepped semi-implicit) |
| Casual mobile | Box2D / cocos2d-x physics — minimal overhead |
| Multiplayer rollback | Deterministic fixed-point physics (Photon Quantum) |
**기본값**: 매 semi-implicit Euler + sequential impulses + AABB broadphase + GJK narrowphase.
## 🔗 Graph
- 응용: [[Fixed Time Step vs Variable Time Step]] · [[Beat Saber]] · [[가상현실(VR) 자전거 시뮬레이터]]
- Adjacent: [[BVH]]
## 🤖 LLM 활용
**언제**: Solver boilerplate, integrator selection, debugging stuck constraint diagnosis.
**언제 X**: Numerical correctness verification (deterministic test 의 require), shipping-grade tuning.
## ❌ 안티패턴
- **Explicit Euler 의 production**: 매 energy drift → instability.
- **No CCD on bullets**: 매 tunneling 의 inevitable.
- **Single-axis SAP**: 매 worst-case O(N²) 의 degrade.
- **Float-based deterministic netcode**: 매 cross-platform desync.
- **Constraint solver 의 too-few iterations**: 매 stack jitter.
## 🧪 검증 / 중복
- Verified (Erin Catto GDC talks 2006-2024, Jolt physics docs 2024, "Real-Time Collision Detection" Christer Ericson, XPBD paper Macklin et al.).
- 신뢰도 A+.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — integration, collision, constraint trinity + canonical solvers |
<!-- AUTO-CONNECT 2026-06-10 -->
## 🔗 관련 문서 (자동 연결)
- [[Aerospace Flight Simulation]]