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 ¶
- func AddForce(body *Body, force raylib.Vector2)
- func AddTorque(body *Body, amount float32)
- func Close()
- func DestroyBody(index int)
- func GetBodiesCount() int
- func GetShapeVertex(body *Body, vertex int) raylib.Vector2
- func GetShapeVerticesCount(index int) int
- func Init()
- func Reset()
- func SetBodyRotation(body *Body, radians float32)
- func SetGravity(x, y float32)
- func Shatter(body *Body, position raylib.Vector2, force float32)
- func Step(delta float32)
- type Body
- type Manifold
- type PolygonData
- type Shape
- type ShapeType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBodiesCount ¶
func GetBodiesCount() int
GetBodiesCount - Returns the current amount of created physics bodies
func GetShapeVertex ¶
GetShapeVertex - Returns transformed position of a body shape (body position + vertex transformed position)
func GetShapeVerticesCount ¶
GetShapeVerticesCount - Returns the amount of vertices of a physics body shape
func Reset ¶
func Reset()
Reset - Destroys created physics bodies and manifolds and resets global values
func SetBodyRotation ¶
SetBodyRotation - Sets physics body shape transform based on radians parameter
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 ¶
CreateBodyCircle - Creates a new circle physics body with generic parameters
func CreateBodyPolygon ¶
CreateBodyPolygon - Creates a new polygon physics body with generic parameters
func CreateBodyRectangle ¶
CreateBodyRectangle - Creates a new rectangle physics body with generic parameters
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