bitty

Physics Manual

Manual Physics Operations Others

Table of Content

TOP

Fundamental

This module is a Beta feature. There may be unrevealed bugs, and the final API may be different from the current version.

Bitty Engine is integrated with the Chipmunk2D physics library to offer 2D dynamics simulation in Lua. The knowledges of the concepts and programming interfaces in Chipmunk2D are widely applicable to programming it in Bitty Engine.

Reading the official documentations would be helpful to understand and master this module, although the original Chipmunk2D is written in C. You’ll find that almost every interface has its counterpart, i.e. the Lua operations in Bitty Engine Physics.Shape.new(Physics.Shape.Circle, ...), Physics.Body.new(...), body.position = ..., space:addBody(...) are equivalent to the C version cpCircleShapeNew(...), cpBodyNew(...), cpBodySetPosition(...), cpSpaceAddBody(...) in Chipmunk2D.

Why Physics

First of all, this module is just a physics engine. It has nothing to do with graphics, it is only responsible for receiving input data, and outputing calculation result.

If your program doesn’t contain complicated behaviours, then the generic algorithms and solutions would be capable. However, it is worth the time and effort required to learn it, because this module helps you simulate how objects interact with each other in a 2D world.

The physics module encapsuled complex calculations and procedures, exposed necessary interfaces, and runs at a decent speed. It uses some of the generic structures, i.e. Vec2, Rect to represent point, bounding box, etc.

Glossary

Space

Spaces are containers for simulating objects in the physics module. You add bodies, shapes and joints to a space and then update the space as a whole. They control how all the rigid bodies, shapes, and constraints interact together.

Shape

By attaching shapes to bodies, you can define the a body’s shape. You can attach as many shapes to a single body as you need to in order to define a complex shape. Shapes contain the surface properties of an object such as how much friction or elasticity it has.

Body

A rigid body holds the physical properties of an object (mass, position, rotation, velocity, etc.). It does not have a shape until you attach one or more collision shapes to it. Rigid bodies generally tend to have a 1:1 correlation to sprites in a program. You should structure your program so that you use the position and rotation of the rigid body for drawing your sprite.

Constraint

Constraints and joints describe how bodies are attached to each other.

Arbiter

The physics module’s arbiter struct encapsulates a pair of colliding shapes and all of the data about their collision. Arbiters are created when a collision starts, and persist until those shapes are no longer colliding, thus you only get weak references to arbiters in code.

TOP

Physics

All the programming interfaces of the physics module are packed in a named table Physics.

Constants

Static Functions

Space

Constructors

Object Fields

Methods

Available options:

Option Behaviour Return value
“collect” Performs a manual collecting -
“stop” Stops automatic collecting -
“restart” Restarts automatic collecting -
“isrunning” Gets whether automatic collecting is running true for running, otherwise false
“threshold” Gets the automatic collecting threshold The threshold
“limit” Sets the automatic collecting threshold The threshold

Shape

Constants

Constructors

Object Fields

Methods

Body

Constants

Constructors

Object Fields

Methods

When objects in the physics module sleep, they sleep as a group of all objects that are touching or jointed together. When an object is woken up, all of the objects in its group are woken up.

Constraints

Constraint

Constants

Object Fields

Methods

DampedRotarySpring

Constructors

Object Fields

DampedSpring

Constructors

Object Fields

GearJoint

Constructors

Object Fields

GrooveJoint

Constructors

Object Fields

PinJoint

Constructors

Object Fields

PivotJoint

Constructors

Object Fields

RatchetJoint

Constructors

Object Fields

RotaryLimitJoint

Constructors

Object Fields

SimpleMotor

Constructors

Object Fields

SlideJoint

Constructors

Object Fields

Arbiter

Operators

Object Fields

Methods

Transform

Constants

Constructors

Operators

Object Fields

Methods

ShapeFilter

Constructors

Object Fields

Contact

Object Fields

Contacts

Operators

Object Fields

Queries

PointQuery

Object Fields

SegmentQuery

Object Fields

BoundingBoxQuery

Object Fields

ShapeQuery

Operators

Object Fields

TOP