Documentation
¶
Overview ¶
Package physics - 2D Physics library for videogames
A port of Victor Fisac's physac engine (https://github.com/raysan5/raylib/blob/master/src/physac.h)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DestroyBody ¶
DestroyBody - Unitializes and destroys a physics body
func GetBodiesCount ¶
func GetBodiesCount() int
GetBodiesCount - Returns the current amount of created physics bodies
func GetShapeVerticesCount ¶
GetShapeVerticesCount - Returns the amount of vertices of a physics body shape
func SetPhysicsTimeStep ¶
func SetPhysicsTimeStep(delta float32)
Sets physics fixed time step in milliseconds. 1.666666 by default
Types ¶
type Body ¶
type Body struct {
// Enabled dynamics state (collisions are calculated anyway)
Enabled bool
// Physics body shape pivot
Position rl.Vector2
// Current linear velocity applied to position
Velocity rl.Vector2
// Current linear force (reset to 0 every step)
Force rl.Vector2
// Current angular velocity applied to orient
AngularVelocity float32
// Current angular force (reset to 0 every step)
Torque float32
// Rotation in radians
Orient float32
// Moment of inertia
Inertia float32
// Inverse value of inertia
InverseInertia float32
// Physics body mass
Mass float32
// Inverse value of mass
InverseMass float32
// Friction when the body has not movement (0 to 1)
StaticFriction float32
// Friction when the body has movement (0 to 1)
DynamicFriction float32
// Restitution coefficient of the body (0 to 1)
Restitution float32
// Apply gravity force to dynamics
UseGravity bool
// Physics grounded on other body state
IsGrounded bool
// Physics rotation constraint
FreezeOrient bool
// Physics body shape information (type, radius, vertices, normals)
Shape Shape
}
Body type
func NewBodyCircle ¶
NewBodyCircle - Creates a new circle physics body with generic parameters
func NewBodyPolygon ¶
NewBodyPolygon - Creates a new polygon physics body with generic parameters
func NewBodyRectangle ¶
NewBodyRectangle - Creates a new rectangle physics body with generic parameters
func (*Body) AddForce ¶
func (b *Body) AddForce(force rl.Vector2)
AddForce - Adds a force to a physics body
func (*Body) GetShapeVertex ¶
GetShapeVertex - Returns transformed position of a body shape (body position + vertex transformed position)
func (*Body) SetRotation ¶
SetRotation - Sets physics body shape transform based on radians parameter
type Polygon ¶
type Polygon struct {
// Current used vertex and normals count
VertexCount int
// Polygon vertex positions vectors
Vertices [maxVertices]rl.Vector2
// Polygon vertex normals vectors
Normals [maxVertices]rl.Vector2
// Vertices transform matrix 2x2
Transform rl.Mat2
}
Polygon type
type Shape ¶
type Shape struct {
// Physics shape type (circle or polygon)
Type ShapeType
// Shape physics body reference
Body *Body
// Circle shape radius (used for circle shapes)
Radius float32
// Polygon shape vertices position and normals data (just used for polygon shapes)
VertexData Polygon
}
Shape type