物理引擎的工作原理 Burak Kanber

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/DanielDingshengli/article/details/82226345

计算一个物体的motion(运动过程)
The process for simulating an object’s motion goes something like this:
Figure out what the forces are on an object //第一步:受力分析
Add those forces up to get a single “resultant” or “net” force//第二步:平行四边形法则得出合力
Use F = ma to calculate the object’s acceleration due to those forces//合力产生的加速度
Use the object’s acceleration to calculate the object’s velocity//利用加速度算物体速度
Use the object’s velocity to calculate the object’s position//利用速度去算物体的位置
Since the forces on the object may change from moment to moment, repeat this process from #1, forever.//不断重复上述过程
That’s pretty easy! Six straightforward steps is all it takes to model a simple object translating in any number of dimensions.

#

More importantly, we can work backwards. If we know an object’s acceleration, we can figure out how much the velocity is supposed to change every second. And if we know the velocity, we can figure out how much the position is supposed to change every second. This technique is called “integration”.
//更重要的,我们可以往后推。如果我们知道物体的加速度,我们可以知道它的速度每秒的变化。如果我们知道速度,我们可以知道位置每秒的变化。这个技术叫做积分,

#

Game engines sometimes have the graphics engine running at 30 fps and the physics engine at 60 fps–in that case, the numerical integration is using a timestep of 1/60 seconds (16 milliseconds).
//游戏引擎的图像处理引擎每秒刷新30次,物理引擎每秒工作60次,数值积分的时间步长为16毫秒。

欧拉算法:
acceleration = force / mass
velocity += acceleration * time_step
position += velocity * time_step
改进算法:
last_acceleration = acceleration
position += velocity * time_step + ( 0.5 * last_acceleration * time_step^2 )
new_acceleration = force / mass 
avg_acceleration = ( last_acceleration + new_acceleration ) / 2
velocity += avg_acceleration * time_step

这里写图片描述

#

Modeling something with shape adds a whole degree of complexity to our work, because things with shape should be able to rotate. This puts us in the realm of “rigid body physics.” Rigid bodies have a shape and orientation. They can rotate, and they can collide with each other.
有形状的物体要考虑旋转和碰撞,这就复杂了
collision 考里忍

#

moment of inertia is a property of an object that resists angular acceleration
//转动惯量是物体阻止角加速度的属性
Torque is a force that has a tendency to rotate an object.
//力矩是让物体有旋转趋势的力
//重写牛顿第二定律
T=Ja

链接:http://buildnewgames.com/gamephysics/
里面的代码实现是用网页页面三件套,待日后再看

物理引擎的工作原理说白了就是把物理规则转换成代码表示,积分和求导可以结合步长去算。

猜你喜欢

转载自blog.csdn.net/DanielDingshengli/article/details/82226345