physics

package
v0.0.0-...-2c0b272 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2018 License: Zlib Imports: 4 Imported by: 0

README

physics GoDoc

2D Physics library for videogames.

A port of Victor Fisac's physac engine.

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 AddForce

func AddForce(body *Body, force raylib.Vector2)

AddForce - Adds a force to a physics body

func AddTorque

func AddTorque(body *Body, amount float32)

AddTorque - Adds an angular force to a physics body

func Close

func Close()

Close - Unitializes physics pointers

func DestroyBody

func DestroyBody(index int)

DestroyBody - Unitializes and destroy a physics body

func GetBodiesCount

func GetBodiesCount() int

GetBodiesCount - Returns the current amount of created physics bodies

func GetShapeVertex

func GetShapeVertex(body *Body, vertex int) raylib.Vector2

GetShapeVertex - Returns transformed position of a body shape (body position + vertex transformed position)

func GetShapeVerticesCount

func GetShapeVerticesCount(index int) int

GetShapeVerticesCount - Returns the amount of vertices of a physics body shape

func Init

func Init()

Init - initializes physics values

func Reset

func Reset()

Reset - Destroys created physics bodies and manifolds and resets global values

func SetBodyRotation

func SetBodyRotation(body *Body, radians float32)

SetBodyRotation - Sets physics body shape transform based on radians parameter

func SetGravity

func SetGravity(x, y float32)

SetGravity - Sets physics global gravity force

func Shatter

func Shatter(body *Body, position raylib.Vector2, force float32)

Shatter - Shatters a polygon shape physics body to little physics bodies with explosion force

func Step

func Step(delta float32)

Step - Physics steps calculations (dynamics, collisions and position corrections)

Types

type Body

type Body struct {
	// Enabled dynamics state (collisions are calculated anyway)
	Enabled bool
	// Physics body shape pivot
	Position raylib.Vector2
	// Current linear velocity applied to position
	Velocity raylib.Vector2
	// Current linear force (reset to 0 every step)
	Force raylib.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 CreateBodyCircle

func CreateBodyCircle(pos raylib.Vector2, radius, density float32) *Body

CreateBodyCircle - Creates a new circle physics body with generic parameters

func CreateBodyPolygon

func CreateBodyPolygon(pos raylib.Vector2, radius float32, sides int32, density float32) *Body

CreateBodyPolygon - Creates a new polygon physics body with generic parameters

func CreateBodyRectangle

func CreateBodyRectangle(pos raylib.Vector2, width, height, density float32) *Body

CreateBodyRectangle - Creates a new rectangle physics body with generic parameters

func GetBody

func GetBody(index int) *Body

GetBody - Returns a physics body of the bodies pool at a specific index

type Manifold

type Manifold struct {
	// Manifold first physics body reference
	BodyA *Body
	// Manifold second physics body reference
	BodyB *Body
	// Depth of penetration from collision
	Penetration float32
	// Normal direction vector from 'a' to 'b'
	Normal raylib.Vector2
	// Points of contact during collision
	Contacts [2]raylib.Vector2
	// Current collision number of contacts
	ContactsCount int
	// Mixed restitution during collision
	Restitution float32
	// Mixed dynamic friction during collision
	DynamicFriction float32
	// Mixed static friction during collision
	StaticFriction float32
}

Manifold type

type PolygonData

type PolygonData struct {
	// Current used vertex and normals count
	VertexCount int
	// Polygon vertex positions vectors
	Vertices [maxVertices]raylib.Vector2
	// Polygon vertex normals vectors
	Normals [maxVertices]raylib.Vector2
	// Vertices transform matrix 2x2
	Transform raylib.Mat2
}

PolygonData 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 *PolygonData
}

Shape type

type ShapeType

type ShapeType int

Physics shape type

const (
	// Circle type
	Circle ShapeType = 1
	// Polygon type
	Polygon ShapeType = 2
)

Physics shape types

func GetShapeType

func GetShapeType(index int) ShapeType

GetShapeType - Returns the physics body shape type (Circle or Polygon)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL