跳到正文
This is Oscar
返回

Box2D--Physics Engine

Demo

Box2D是一个强大的物理引擎(Physics Engine),有c++, java, js等多种版本。当前流行的Angry birds游戏就使用它作为物理引擎。Wikipedia中给出的定义是:

physics engine is computer software that provides an approximate simulation of certain simple physical systems, such as rigid body dynamics(including collision detection), soft body dynamics, and fluid dynamics, of use in the domains of computer graphicsvideo games and film. Their main uses are in video games (typically as middleware), in which case the simulations are in real-time. The term is sometimes used more generally to describe any software system for simulating physical phenomena, such as high-performance scientific simulation.

近期为了给Tankcraft做spike,实现了一个简单的坦克,包括的功能有:

其中关键技术点包括:

Body:

在Box2D中,整个界面成为一个World,World中可以创建多个不同的Body,Body可以具有质量,摩擦力,位置,形状等等属性。例如上图中坦克的底座,操作舱,轮子,炮筒,炮弹,斜坡,四周方框都是Body。Body共有三种:

Body Joint:

多个Body之间可能毫无关系,也可能紧密结合,Body Joint就是用来处理不同Body之间关系的一个对象。共有9种Joint:

有一篇blog对joint讲解的非常详细:,这里不再详述每种joint的适用场景。只简单列举用到的两种:

以下是一些有用的链接:


分享到:

上一篇
Box2D-Post Collision Detection
下一篇
Validation Refactor -- Command Pattern