没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
Box2D v2.2.0 User Manual
Copyright © 2007-2011 Erin Catto
Chapter 1 Introduction ............................................................................................................................ 2
Chapter 2 Hello Box2D............................................................................................................................. 8
Chapter 3 Common ............................................................................................................................... 14
Chapter 4 Collision Module ................................................................................................................... 16
Chapter 5 Dynamics Module .................................................................................................................. 27
Chapter 6 Fixtures ................................................................................................................................. 28
Chapter 7 Bodies ................................................................................................................................... 32
Chapter 8 Joints ..................................................................................................................................... 39
Chapter 9 Contacts ................................................................................................................................ 48
Chapter 10 World Class ......................................................................................................................... 56
Chapter 11 Loose Ends .......................................................................................................................... 62
Chapter 12 Debug Drawing .................................................................................................................... 64
Chapter 13 Limitations .......................................................................................................................... 65
Chapter 14 References .......................................................................................................................... 66
Chapter 1 Introduction
1.1 About
Box2D is a 2D rigid body simulation library for games. Programmers can use it in their games to make
objects move in believable ways and make the game world more interactive. From the game engine's
point of view a physics engine is just a system for procedural animation.
Box2D is written in portable C++. Most of the types defined in the engine begin with the b2 prefix.
Hopefully this is sufficient to avoid name clashing with your game engine.
1.2 Prerequisites
In this manual I'll assume you are familiar with basic physics concepts, such as mass, force, torque, and
impulses. If not, please first consult Google search and Wikipedia.
Box2D was created as part of a physics tutorial at the Game Developer Conference. You can get these
tutorials from the download section of box2d.org.
Since Box2D is written in C++, you are expected to be experienced in C++ programming. Box2D should
not be your first C++ programming project. You should be comfortable with compiling, linking, and
debugging.
Caution
Box2D should not be your first C++ project. Please learn C++ programming,
compiling, linking, and debugging before working with Box2D. There are many
resources for this on the net.
1.3 About this Manual
This manual covers the majority of the Box2D API. However, not every aspect is covered. You are
encouraged to look at the testbed included with Box2D to learn more. Also, the Box2D code base has
comments formatted for Doxygen, so it is easy to create a hyper-linked API document.
This manual is only updated with new releases. The version in source control is likely to be out of date.
1.4 Feedback and Reporting Bugs
If you have a question or feedback about Box2D, please leave a comment in the forum. This is also a
great place for community discussion.
Box2D issues are tracked using a Google code project. This is a great way to track issues and ensures
that your issue will not be lost in the depths of the forums.
Please file bugs and feature requests here: http://code.google.com/p/box2d/
You can help to ensure your issue gets fixed if you provide sufficient detail. A testbed example that
reproduces the problem is ideal. You can read about the testbed later in this document.
1.5 Core Concepts
Box2D works with several fundamental objects. We briefly define these objects here and more details
are given later in this document.
shape
A 2D geometrical object, such as a circle or polygon.
rigid body
A chunk of matter that is so strong that the distance between any two bits of matter on the chunk is
constant. They are hard like a diamond. In the following discussion we use body interchangeably with
rigid body.
fixture
A fixture binds a shape to a body and adds material properties such as density, friction, and restitution.
constraint
A constraint is a physical connection that removes degrees of freedom from bodies. In 2D a body has 3
degrees of freedom (two translation coordinates and one rotation coordinate). If we take a body and pin
it to the wall (like a pendulum) we have constrained the body to the wall. At this point the body can only
rotate about the pin, so the constraint has removed 2 degrees of freedom.
contact constraint
A special constraint designed to prevent penetration of rigid bodies and to simulate friction and
restitution. You do not create contact constraints; they are created automatically by Box2D.
joint
This is a constraint used to hold two or more bodies together. Box2D supports several joint types:
revolute, prismatic, distance, and more. Some joints may have limits and motors.
joint limit
A joint limit restricts the range of motion of a joint. For example, the human elbow only allows a certain
range of angles.
joint motor
A joint motor drives the motion of the connected bodies according to the joint's degrees of freedom. For
example, you can use a motor to drive the rotation of an elbow.
world
A physics world is a collection of bodies, fixtures, and constraints that interact together. Box2D supports
the creation of multiple worlds, but this is usually not necessary or desirable.
solver
The physics world has a solver that is used to advance time and to resolve contact and joint constraints.
The Box2D solver is a high performance iterative solver that operates in order N time, where N is the
number of constraints.
continuous collision
The solver advances bodies in time using discrete time steps. Without intervention this can lead to
tunneling.
Box2D contains specialized algorithms to deal with tunneling. First, the collision algorithms can
interpolate the motion of two bodies to find the first time of impace (TOI). Second, there is a sub-
stepping solver that moves bodies to their first time of impact and then resolves the collision.
1.6 Modules
Box2D is composed of three modules: Common, Collision, and Dynamics. The Common module has code
for allocation, math, and settings. The Collision module defines shapes, a broad-phase, and collision
functions/queries. Finally the Dynamics module provides the simulation world, bodies, fixtures, and
joints.
1.7 Units
Box2D works with floating point numbers and tolerances have to be used to make Box2D perform well.
These tolerances have been tuned to work well with meters-kilogram-second (MKS) units. In particular,
Box2D has been tuned to work well with moving objects between 0.1 and 10 meters. So this means
objects between soup cans and buses in size should work well. Static objects may be up to 50 meters big
without too much trouble.
Being a 2D physics engine, it is tempting to use pixels as your units. Unfortunately this will lead to a poor
simulation and possibly weird behavior. An object of length 200 pixels would be seen by Box2D as the
size of a 45 story building.
Caution
Box2D is tuned for MKS units. Keep the size of moving objects roughly between 0.1
and 10 meters. You'll need to use some scaling system when you render your
environment and actors. The Box2D testbed does this by using an OpenGL viewport
transform. DO NOT USE PIXELS.
It is best to think of Box2D bodies as moving billboards upon which you attach your artwork. The
billboard may move in a unit system of meters, but you can convert that to pixel coordinates with a
simple scaling factor. You can then use those pixel coordinates to place your sprites, etc.
Box2D uses radians for angles. The body rotation is stored in radians and may grow unbounded.
Consider normalizing the angle of your bodies if the magnitude of the angle becomes too large (use
b2Body::SetAngle).
剩余65页未读,继续阅读
tsr106
- 粉丝: 10
- 资源: 25
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 数据库管理工具:dbeaver-ce-23.0.3-stable.x86-64.rpm
- 外部中断0计数数码管显示0-9.zip
- xp系统安装.net框架包括镜像和.net4.0安装包
- c语言连接两个字符串.pdf
- 数据库管理工具:dbeaver-ce-23.0.3-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.0.3-macos-aarch64.dmg
- Delphi 12 控件之DEV自动安装程序.exe
- 数据库管理工具:dbeaver-ce-23.0.2-x86-64-setup.exe
- Delphi 12 控件之AnySQL-0.0.9.rar
- 俄罗斯引擎Yandex的进入.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0