遊戲物理
跳去導覽
跳去搵嘢
例如一隻用牛頓力學(Newtonian mechanics)嘅賽車遊戲,喺玩家撳咗「踩油」嘅掣嗰陣,要改變架車嘅加速度數值,而架車相應嘅速度同位置等變數亦要跟牛頓力學裏面嘅法則作出相應嘅改變[1]。
力學模擬[編輯]
以下呢段用 C 程式語言寫嘅源碼可以攞嚟模擬喺牛頓第二定律(Newton's second law)之下郁動嘅物體[2]:
double t = 0.0;
float dt = 1.0f;
float velocity = 0.0f;
float position = 0.0f;
float force = 10.0f;
float mass = 1.0f;
// 設一大柞變數,包括咗時間點(t)、時間間隔(dt)、速度(velocity)、位置(position)、件物體受嘅力(force)、同件物體嘅質量(mass)。
while ( t <= 10.0 ) // 重複噉計若干次,計到時間點係 10 為止。
{
position = position + velocity * dt;
velocity = velocity + ( force / mass ) * dt; // 用牛頓第二定律計吓件物體受嘅力同佢嘅質量會點影響佢嘅速度。
t += dt;
}
睇埋[編輯]
文獻[編輯]
- Szauer, G. (2017). Game Physics Cookbook (PDF). Packt Publishing Ltd.
攷[編輯]
- ↑ McShaffry, M. (2014). Game coding complete. Nelson Education. Ch. 2.
- ↑ Integration Basics: How to integrate the equations of motion 互聯網檔案館嘅歸檔,歸檔日期2018年10月26號,.. Gaffer on Games.
拎[編輯]
- "Math and Physics". GameDev. Archive. 原著喺February 22, 2011歸檔.
- "Physics Engines List". Database. Digital Rune. Mar 30, 2015 [2010]. 原著喺March 9, 2016歸檔.