chipmunk

package module
v0.0.0-...-377ead8 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2014 License: MIT Imports: 5 Imported by: 1

README

Chipmunk Physics bindings for Go

WIP

Installation

$ go get github.com/ftrvxmtrx/gochipmunk/chipmunk

Documentation

gochipmunk on go.pkgdoc.org

Usage

import (
  . "github.com/ftrvxmtrx/gochipmunk/chipmunk"
)

Demo

$ go get github.com/ftrvxmtrx/gochipmunk/chipmunk-demo
$ go install github.com/ftrvxmtrx/gochipmunk/chipmunk-demo
$ chipmunk-demo

Documentation

Overview

Package chipmunk is an interface to Chipmunk Physics library.

Usage example: https://github.com/ftrvxmtrx/gochipmunk/blob/master/chipmunk-demo/main.go

Index

Constants

View Source
const (
	// NoGroup is a value for Shape.Group signifying that a shape is in no group.
	NoGroup = Group(0)
	// AllLayers is a value for Shape.Layers signifying that a shape is in every layer.
	AllLayers = Layers(0)
)
View Source
const (
	VersionMajor   = int(C.CP_VERSION_MAJOR)
	VersionMinor   = int(C.CP_VERSION_MINOR)
	VersionRelease = int(C.CP_VERSION_RELEASE)
)

Chipmunk version.

Variables

This section is empty.

Functions

func AreaForCircle

func AreaForCircle(r1, r2 float64) float64

AreaForCircle returns the area of a hollow circle.

func AreaForPoly

func AreaForPoly(verts []Vect) float64

AreaForPoly returns the signed area of a polygon. A Clockwise winding gives positive area. This is probably backwards from what you expect, but matches Chipmunk's the winding for poly shapes.

func AreaForSegment

func AreaForSegment(a, b Vect, r float64) float64

AreaForSegment returns the area of a fattened (capsule shaped) line segment.

func MomentForBox

func MomentForBox(m, width, height float64) float64

MomentForBox returns the moment of inertia for a solid box.

func MomentForBox2

func MomentForBox2(m float64, box BB) float64

MomentForBox2 returns the moment of inertia for a solid box.

func MomentForCircle

func MomentForCircle(m, r1, r2 float64, offset Vect) float64

MomentForCircle returns the moment of inertia for a circle.

func MomentForPoly

func MomentForPoly(m float64, verts []Vect, offset Vect) float64

MomentForPoly returns the moment of inertia for a solid polygon shape assuming it's center of gravity is at it's centroid. The offset is added to each vertex.

func MomentForSegment

func MomentForSegment(m float64, a, b Vect) float64

MomentForSegment returns the moment of inertia for a line segment.

func PolyValidate

func PolyValidate(verts []Vect) bool

PolyValidate returns true if a set of vertexes is convex and has a clockwise winding.

func RecenterPoly

func RecenterPoly(verts []Vect)

RecenterPoly centers the polygon on the origin (subtracts the centroid of the polygon from each vertex).

func ResetShapeIDCounter

func ResetShapeIDCounter()

ResetShapeIDCounter is used to reset the shape ID counter when recreating a space. When initializing a shape, it's hash value comes from a counter. Because the hash value may affect iteration order, you can reset the shape ID counter when recreating a space. This will make the simulation be deterministic.

func Version

func Version() string

Version returns Chipmunk version string.

func VertsEqual

func VertsEqual(a, b []Vect) bool

VertsEqual returns a boolean reporting whether a == b.

Types

type Arbiter

type Arbiter uintptr

Arbiter is a type of colliding pair of shapes.

func (Arbiter) Bodies

func (arb Arbiter) Bodies() (Body, Body)

Bodies returns the colliding bodies involved for this arbiter. The order of the CollisionType the bodies are associated with values will match the order set when the collision handler was registered.

func (Arbiter) ContactPoints

func (a Arbiter) ContactPoints() []ContactPoint

ContactPoints returns a contact set from an arbiter.

func (Arbiter) Count

func (a Arbiter) Count() int

Count returns the number of contact points for this arbiter.

func (Arbiter) Depth

func (a Arbiter) Depth(i int) float64

Depth returns the depth of specific contact point.

func (Arbiter) Elasticity

func (a Arbiter) Elasticity() float64

Elasticity returns a calculated value to use for the elasticity coefficient. Override in a pre-solve collision handler for custom behavior.

func (Arbiter) Friction

func (a Arbiter) Friction() float64

Friction returns a calculated value to use for the friction coefficient. Override in a pre-solve collision handler for custom behavior.

func (Arbiter) Ignore

func (a Arbiter) Ignore()

Ignore causes a collision pair to be ignored as if you returned false from a begin callback. If called from a pre-step callback, you will still need to return false if you want it to be ignored in the current step.

func (Arbiter) IsFirstContact

func (a Arbiter) IsFirstContact() bool

IsFirstContact returns true if this is the first step a pair of objects started colliding.

func (Arbiter) Normal

func (a Arbiter) Normal(i int) Vect

Normal returns the normal of specific contact point.

func (Arbiter) Point

func (a Arbiter) Point(i int) Vect

Point returns the position of specific contact point.

func (Arbiter) SetContactPoints

func (a Arbiter) SetContactPoints(cp []ContactPoint)

SetContactPoints replaces the contact point set for an arbiter. This can be a very powerful feature, but use it with caution!

func (Arbiter) SetElasticity

func (a Arbiter) SetElasticity(e float64)

SetElasticity sets elasticity coefficient.

func (Arbiter) SetFriction

func (a Arbiter) SetFriction(f float64)

SetFriction sets friction coefficient.

func (Arbiter) SetSurfaceVelocity

func (a Arbiter) SetSurfaceVelocity(v Vect)

SetSurfaceVelocity sets calculated value to use for applying surface velocities.

func (Arbiter) Shapes

func (arb Arbiter) Shapes() (Shape, Shape)

Shapes returns the colliding shapes involved for this arbiter. The order of their CollisionType values will match the order set when the collision handler was registered.

func (Arbiter) String

func (a Arbiter) String() string

String converts an arbiter to a human-readable string.

func (Arbiter) SurfaceVelocity

func (a Arbiter) SurfaceVelocity() Vect

SurfaceVelocity returns a calculated value to use for applying surface velocities. Override in a pre-solve collision handler for custom behavior.

func (Arbiter) TotalImpulse

func (a Arbiter) TotalImpulse() Vect

TotalImpulse returns the total impulse that was applied by this arbiter. This function should only be called from a post-solve, post-step or body.EachArbiter callback.

func (Arbiter) TotalImpulseWithFriction

func (a Arbiter) TotalImpulseWithFriction() Vect

TotalImpulseWithFriction returns the total impulse including the friction that was applied by this arbiter. This function should only be called from a post-solve, post-step or body.EachArbiter callback.

func (Arbiter) TotalKE

func (a Arbiter) TotalKE() float64

TotalKE returns the amount of energy lost in a collision including static, but not dynamic friction. This function should only be called from a post-solve, post-step or body.EachArbiter callback.

type BB

type BB struct {
	// contains filtered or unexported fields
}

BB is an axis-aligned 2D bounding box type (left, bottom, right, top).

func BBNew

func BBNew(l, b, r, t float64) BB

BBNew creates a 2D bounding box.

func BBNewForCircle

func BBNewForCircle(p Vect, r float64) BB

BBNewForCircle constructs a BB for a circle with the given position and radius.

func (BB) Area

func (b BB) Area() float64

Area returns the area of the bounding box.

func (BB) Center

func (bb BB) Center() Vect

Center returns the center of the bounding box

func (BB) ClampVect

func (bb BB) ClampVect(v Vect) Vect

ClampVect clamps a vector to a bounding box.

func (BB) Contains

func (b BB) Contains(other BB) bool

Contains returns true if other bounding box lies completely within.

func (BB) ContainsVect

func (b BB) ContainsVect(v Vect) bool

ContainsVect returns true if the bounding box contains a vector.

func (BB) Expand

func (b BB) Expand(v Vect) BB

Expand returns a bounding box that holds both bounding box and a vector.

func (BB) Intersects

func (a BB) Intersects(b BB) bool

Intersects returns true if two bounding boxes intersect.

func (BB) IntersectsSegment

func (bb BB) IntersectsSegment(a, b Vect) bool

IntersectsSegment returns true if the bounding box intersects the line segment defined using two points.

func (BB) Merge

func (a BB) Merge(b BB) BB

Merge returns a bounding box that holds both bounding boxes.

func (BB) MergedArea

func (a BB) MergedArea(b BB) float64

MergedArea merges two bounding boxes and returns the area of the merged bounding box.

func (BB) SegmentQuery

func (bb BB) SegmentQuery(a, b Vect) float64

SegmentQuery returns the fraction along the segment query the BB is hit. Returns math.Inf(1) if it doesn't hit.

func (BB) String

func (b BB) String() string

String converts a BB to a human-readable string.

func (BB) WrapVect

func (bb BB) WrapVect(v Vect) Vect

WrapVect wraps a vector to a bounding box.

type BBQuery

type BBQuery func(s Shape)

BBQuery is a rectangle query callback function type.

type Body

type Body uintptr

Body is a rigid body struct.

func BodyNew

func BodyNew(m, i float64) Body

BodyNew creates a new body.

func BodyStaticNew

func BodyStaticNew() Body

BodyStaticNew creates a new static body.

func (Body) Activate

func (b Body) Activate()

Activate wakes up a sleeping or idle body.

func (Body) ActivateStatic

func (b Body) ActivateStatic(s Shape)

ActivateStatic wakes up any sleeping or idle bodies touching a static body.

func (Body) Angle

func (b Body) Angle() float64

Angle returns the rotation of the body around it's center of gravity in radians.

func (Body) AngularVelocity

func (b Body) AngularVelocity() float64

AngularVelocity returns the angular velocity of the body around it's center of gravity in radians/second.

func (Body) AngularVelocityLimit

func (b Body) AngularVelocityLimit() float64

AngularVelocityLimit returns the maximum rotational rate (in radians/second) allowed when updating the angular velocity.

func (Body) ApplyForce

func (b Body) ApplyForce(f, r Vect)

ApplyForce applies a force (in world coordinates) to the body at a point relative to the center of gravity (also in world coordinates).

func (Body) ApplyImpulse

func (b Body) ApplyImpulse(j, r Vect)

ApplyImpulse applies an impulse (in world coordinates) to the body at a point relative to the center of gravity (also in world coordinates).

func (Body) EachArbiter

func (b Body) EachArbiter(iter func(Body, Arbiter))

EachArbiter calls a callback function once for each arbiter which is currently active on the body.

func (Body) EachConstraint

func (b Body) EachConstraint(iter func(Body, Constraint))

EachConstraint calls a callback function once for each constraint attached to the body and added to the space.

func (Body) EachShape

func (b Body) EachShape(iter func(Body, Shape))

EachShape calls a callback function once for each shape attached to the body and added to the space.

func (Body) Force

func (b Body) Force() Vect

Force returns the force acting on the rigid body's center of gravity.

func (Body) Free

func (b Body) Free()

Free removes a body.

func (Body) IsRogue

func (b Body) IsRogue() bool

IsRogue returns true if the body has not been added to a space.

func (Body) IsSleeping

func (b Body) IsSleeping() bool

IsSleeping returns true if the body is sleeping.

func (Body) IsStatic

func (b Body) IsStatic() bool

IsStatic returns true if the body is static.

func (Body) KineticEnergy

func (b Body) KineticEnergy() float64

KineticEnergy returns the kinetic energy of a body.

func (Body) LocalToWorld

func (b Body) LocalToWorld(v Vect) Vect

LocalToWorld converts body relative/local coordinates to absolute/world coordinates.

func (Body) Mass

func (b Body) Mass() float64

Mass returns the mass of the body.

func (Body) Moment

func (b Body) Moment() float64

Moment returns a moment of intertia of the body.

func (Body) Position

func (b Body) Position() Vect

Position returns the position of the rigid body's center of gravity.

func (Body) ResetForces

func (b Body) ResetForces()

ResetForces sets the forces and torque of a body to zero.

func (Body) Rotation

func (b Body) Rotation() Vect

Rotation returns the cached unit length vector representing the angle of the body.

func (Body) SetAngle

func (b Body) SetAngle(angle float64)

SetAngle sets the rotation of the body around it's center of gravity in radians.

func (Body) SetAngularVelocity

func (b Body) SetAngularVelocity(vel float64)

SetAngularVelocity sets the angular velocity of the body around it's center of gravity in radians/second.

func (Body) SetAngularVelocityLimit

func (b Body) SetAngularVelocityLimit(limit float64)

SetAngularVelocityLimit sets the maximum rotational rate (in radians/second) allowed when updating the angular velocity.

func (Body) SetForce

func (b Body) SetForce(force Vect)

SetForce sets the force acting on the rigid body's center of gravity.

func (Body) SetMass

func (b Body) SetMass(mass float64)

SetMass sets the mass of the body.

func (Body) SetMoment

func (b Body) SetMoment(moment float64)

SetMoment sets the moment of the body.

func (Body) SetPosition

func (b Body) SetPosition(pos Vect)

SetPosition sets the position of the body.

func (Body) SetPositionFunc

func (b Body) SetPositionFunc(f func(b Body, dt float64))

SetPositionFunc sets a function that is called to integrate the body's position.

func (Body) SetTorque

func (b Body) SetTorque(torq float64)

SetTorque sets the torque applied to the body around it's center of gravity.

func (Body) SetUserData

func (b Body) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Body reference in a callback.

func (Body) SetVelocity

func (b Body) SetVelocity(vel Vect)

SetVelocity sets the velocity of the body.

func (Body) SetVelocityFunc

func (b Body) SetVelocityFunc(f func(b Body, gravity Vect, damping, dt float64))

SetVelocityFunc sets a function that is called to integrate the body's velocity.

func (Body) SetVelocityLimit

func (b Body) SetVelocityLimit(limit float64)

SetVelocityLimit sets the maximum velocity allowed when updating the velocity.

func (Body) Sleep

func (b Body) Sleep()

Sleep forces a body to fall asleep immediately.

func (Body) SleepWithGroup

func (b Body) SleepWithGroup(g Body)

SleepWithGroup forces a body to fall asleep immediately along with other bodies in a group.

func (Body) Space

func (b Body) Space() Space

Space returns space the body was added to or 0 if the body doesn't belong to any space.

func (Body) String

func (b Body) String() string

String converts a body to a human-readable string.

func (Body) Torque

func (b Body) Torque() float64

Torque returns the torque applied to the body around it's center of gravity.

func (Body) UpdatePosition

func (b Body) UpdatePosition(dt float64)

UpdatePosition is a default function that is called to integrate the body's position.

func (Body) UpdateVelocity

func (b Body) UpdateVelocity(gravity Vect, damping float64, dt float64)

UpdateVelocity is a default function that is called to integrate the body's velocity.

func (Body) UserData

func (b Body) UserData() interface{}

UserData returns user defined data.

func (Body) Velocity

func (b Body) Velocity() Vect

Velocity returns the velocity of the rigid body's center of gravity.

func (Body) VelocityAtLocalPoint

func (b Body) VelocityAtLocalPoint(point Vect) Vect

VelocityAtLocalPoint returns the velocity on a body (in world units) at a point on the body in local coordinates.

func (Body) VelocityAtWorldPoint

func (b Body) VelocityAtWorldPoint(point Vect) Vect

VelocityAtWorldPoint returns the velocity on a body (in world units) at a point on the body in world coordinates.

func (Body) VelocityLimit

func (b Body) VelocityLimit() float64

VelocityLimit returns the maximum velocity allowed when updating the velocity.

func (Body) WorldToLocal

func (b Body) WorldToLocal(v Vect) Vect

WorldToLocal converts body absolute/world coordinates to relative/local coordinates.

type CircleShape

type CircleShape struct {
	// contains filtered or unexported fields
}

CircleShape is a circle shape type.

func CircleShapeNew

func CircleShapeNew(body Body, radius float64, offset Vect) CircleShape

CircleShapeNew creates a new circle shape.

func (CircleShape) BB

func (s CircleShape) BB() BB

BB returns current bounding box of the shape.

func (CircleShape) Body

func (s CircleShape) Body() Body

Body returns the rigid body this collision shape is attached to.

func (CircleShape) CacheBB

func (s CircleShape) CacheBB() BB

CacheBB updates, caches and returns the bounding box of a shape based on the body it's attached to.

func (CircleShape) Center

func (s CircleShape) Center() Vect

Center returns the center of the circle shape (world coordinates).

func (CircleShape) CollisionType

func (s CircleShape) CollisionType() CollisionType

CollisionType returns collision type of the shape used when picking collision handlers.

func (CircleShape) Elasticity

func (s CircleShape) Elasticity() float64

Elasticity returns shape's coefficient of restitution.

func (CircleShape) Free

func (s CircleShape) Free()

Free removes a shape.

func (CircleShape) Friction

func (s CircleShape) Friction() float64

Friction returns shape's coefficient of friction.

func (CircleShape) Group

func (s CircleShape) Group() Group

Group returns a group of the shape. Shapes in the same group don't collide.

func (CircleShape) Layers

func (s CircleShape) Layers() Layers

Layers returns layers bitmask of the shape. Shapes collide only if bitwise of their layers is non-zero.

func (CircleShape) NearestPointQuery

func (s CircleShape) NearestPointQuery(p Vect) (float64, NearestPointQueryInfo)

NearestPointQuery finds the closest point on the surface of shape to a specific point. The first returned value is the distance between the points. A negative distance means the point is inside the shape.

func (CircleShape) Offset

func (s CircleShape) Offset() Vect

Offset returns the offset from the center of gravity.

func (CircleShape) PointQuery

func (s CircleShape) PointQuery(p Vect) bool

PointQuery returns true if a point lies within a shape.

func (CircleShape) Radius

func (s CircleShape) Radius() float64

Radius returns the radius of the circle.

func (CircleShape) SegmentQuery

func (s CircleShape) SegmentQuery(a, b Vect) (bool, SegmentQueryInfo)

SegmentQuery performs a segment query against a shape.

func (CircleShape) Sensor

func (s CircleShape) Sensor() bool

Sensor returns true when shape is "sensor" one, i.e. does not produce collisions.

func (CircleShape) SetBody

func (s CircleShape) SetBody(b Body)

SetBody sets the rigid body this collision shape is attached to.

func (CircleShape) SetCollisionType

func (s CircleShape) SetCollisionType(t CollisionType)

SetCollisionType sets collision type of the shape used when picking collision handlers.

func (CircleShape) SetElasticity

func (s CircleShape) SetElasticity(e float64)

SetElasticity sets coefficient of restitution.

func (CircleShape) SetFriction

func (s CircleShape) SetFriction(f float64)

SetFriction sets coefficient of friction.

func (CircleShape) SetGroup

func (s CircleShape) SetGroup(g Group)

SetGroup sets a group of the shape. Shapes in the same group don't collide.

func (CircleShape) SetLayers

func (s CircleShape) SetLayers(l Layers)

SetLayers sets layers bitmask of the shape. Shapes collide only if bitwise of their layers is non-zero.

func (CircleShape) SetOffset

func (s CircleShape) SetOffset(offset Vect)

SetOffset sets the offset from the center of gravity. NOTE: this is unsafe function.

func (CircleShape) SetRadius

func (s CircleShape) SetRadius(radius float64)

SetRadius sets the radius of the circle. NOTE: this is unsafe function.

func (CircleShape) SetSensor

func (s CircleShape) SetSensor(b bool)

SetSensor sets if the shape is "sensor" one, i.e. does not produce collisions, but still calls collision callbacks.

func (CircleShape) SetSurfaceVelocity

func (s CircleShape) SetSurfaceVelocity(v Vect)

SetSurfaceVelocity sets surface velocity used when solving friction.

func (CircleShape) SetUserData

func (s CircleShape) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Shape reference in a callback.

func (CircleShape) Space

func (s CircleShape) Space() Space

Space returns space the body was added to or nil if the body doesn't belong to any space.

func (CircleShape) String

func (s CircleShape) String() string

String converts a circle shape to a human-readable string.

func (CircleShape) SurfaceVelocity

func (s CircleShape) SurfaceVelocity() Vect

SurfaceVelocity returns surface velocity used when solving friction.

func (CircleShape) Update

func (s CircleShape) Update(pos, rot Vect) BB

Update updates, caches and returns the bounding box of a shape with an explicit transformation.

func (CircleShape) UserData

func (s CircleShape) UserData() interface{}

UserData returns user defined data.

type CollisionType

type CollisionType C.cpCollisionType

CollisionType is a type used for Space.CollisionType.

type Constraint

type Constraint interface {
	A() Body
	ActivateBodies()
	B() Body
	ErrorBias() float64
	Free()
	Impulse() float64
	MaxBias() float64
	MaxForce() float64
	SetErrorBias(float64)
	SetMaxBias(float64)
	SetMaxForce(float64)
	SetUserData(interface{})
	Space() Space
	UserData() interface{}
	// contains filtered or unexported methods
}

Constraint is a type of object which is used to connect two bodies together.

type ContactPoint

type ContactPoint struct {
	// Point is position normal of the contact point.
	Point Vect
	// Normal is the normal of the contact point.
	Normal Vect
	// Dist is the depth of the contact point.
	Dist float64
}

ContactPoint is a contact point type of collision.

type DampedRotarySpring

type DampedRotarySpring struct {
	// contains filtered or unexported fields
}

DampedRotarySpring is like a DampedSpring, but operates in a rotational fashion.

func DampedRotarySpringNew

func DampedRotarySpringNew(a, b Body, restAngle, stiffness, damping float64) DampedRotarySpring

DampedRotarySpringNew creates a new damped rotary spring.

func (DampedRotarySpring) A

func (c DampedRotarySpring) A() Body

A returns the first body the constraint controls.

func (DampedRotarySpring) ActivateBodies

func (c DampedRotarySpring) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (DampedRotarySpring) B

func (c DampedRotarySpring) B() Body

B returns the second body the constraint controls.

func (DampedRotarySpring) Damping

func (c DampedRotarySpring) Damping() float64

Damping returns the amount of viscous damping to apply.

func (DampedRotarySpring) ErrorBias

func (c DampedRotarySpring) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (DampedRotarySpring) Free

func (c DampedRotarySpring) Free()

Free frees the constraint.

func (DampedRotarySpring) Impulse

func (c DampedRotarySpring) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (DampedRotarySpring) MaxBias

func (c DampedRotarySpring) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (DampedRotarySpring) MaxForce

func (c DampedRotarySpring) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (DampedRotarySpring) RestAngle

func (c DampedRotarySpring) RestAngle() float64

RestAngle returns the angular offset in radians the spring attempts to keep between the two bodies.

func (DampedRotarySpring) SetDamping

func (c DampedRotarySpring) SetDamping(damping float64)

SetDamping sets the amount of viscous damping to apply.

func (DampedRotarySpring) SetErrorBias

func (c DampedRotarySpring) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (DampedRotarySpring) SetMaxBias

func (c DampedRotarySpring) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (DampedRotarySpring) SetMaxForce

func (c DampedRotarySpring) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (DampedRotarySpring) SetPostSolveFunc

func (c DampedRotarySpring) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (DampedRotarySpring) SetPreSolveFunc

func (c DampedRotarySpring) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (DampedRotarySpring) SetRestAngle

func (c DampedRotarySpring) SetRestAngle(restAngle float64)

SetRestAngle sets the angular offset in radians the spring attempts to keep between the two bodies.

func (DampedRotarySpring) SetStiffness

func (c DampedRotarySpring) SetStiffness(stiffness float64)

SetStiffness sets the young's modulus of the spring.

func (DampedRotarySpring) SetUserData

func (c DampedRotarySpring) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (DampedRotarySpring) Space

func (c DampedRotarySpring) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (DampedRotarySpring) Stiffness

func (c DampedRotarySpring) Stiffness() float64

Stiffness returns the young's modulus of the spring.

func (DampedRotarySpring) UserData

func (c DampedRotarySpring) UserData() interface{}

UserData returns user defined data.

type DampedSpring

type DampedSpring struct {
	// contains filtered or unexported fields
}

DampedSpring is a spring with a damper. While a spring is not technically a constraint, the damper is. The spring forces are simply a convenience.

func DampedSpringNew

func DampedSpringNew(a, b Body, anchr1, anchr2 Vect,
	restLength, stiffness, damping float64) DampedSpring

DampedSpringNew creates a new damped spring.

func (DampedSpring) A

func (c DampedSpring) A() Body

A returns the first body the constraint controls.

func (DampedSpring) ActivateBodies

func (c DampedSpring) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (DampedSpring) Anchr1

func (c DampedSpring) Anchr1() Vect

Anchr1 returns the anchor point on the first body.

func (DampedSpring) Anchr2

func (c DampedSpring) Anchr2() Vect

Anchr2 returns the anchor point on the second body.

func (DampedSpring) B

func (c DampedSpring) B() Body

B returns the second body the constraint controls.

func (DampedSpring) Damping

func (c DampedSpring) Damping() float64

Damping returns the amount of viscous damping to apply.

func (DampedSpring) ErrorBias

func (c DampedSpring) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (DampedSpring) Free

func (c DampedSpring) Free()

Free frees the constraint.

func (DampedSpring) Impulse

func (c DampedSpring) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (DampedSpring) MaxBias

func (c DampedSpring) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (DampedSpring) MaxForce

func (c DampedSpring) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (DampedSpring) RestLength

func (c DampedSpring) RestLength() float64

RestLength returns the length the spring wants to contract or expand to.

func (DampedSpring) SetAnchr1

func (c DampedSpring) SetAnchr1(v Vect)

SetAnchr1 sets the anchor point on the first body.

func (DampedSpring) SetAnchr2

func (c DampedSpring) SetAnchr2(v Vect)

SetAnchr2 sets the anchor point on the second body.

func (DampedSpring) SetDamping

func (c DampedSpring) SetDamping(damping float64)

SetDamping sets the amount of viscous damping to apply.

func (DampedSpring) SetErrorBias

func (c DampedSpring) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (DampedSpring) SetMaxBias

func (c DampedSpring) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (DampedSpring) SetMaxForce

func (c DampedSpring) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (DampedSpring) SetPostSolveFunc

func (c DampedSpring) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (DampedSpring) SetPreSolveFunc

func (c DampedSpring) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (DampedSpring) SetRestLength

func (c DampedSpring) SetRestLength(restLength float64)

SetRestLength sets the length the spring wants to contract or expand to.

func (DampedSpring) SetStiffness

func (c DampedSpring) SetStiffness(stiffness float64)

SetStiffness sets the young's modulus of the spring.

func (DampedSpring) SetUserData

func (c DampedSpring) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (DampedSpring) Space

func (c DampedSpring) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (DampedSpring) Stiffness

func (c DampedSpring) Stiffness() float64

Stiffness returns the young's modulus of the spring.

func (DampedSpring) UserData

func (c DampedSpring) UserData() interface{}

UserData returns user defined data.

type GearJoint

type GearJoint struct {
	// contains filtered or unexported fields
}

GearJoint constrains the rotational speed of one body to another. A ratio of 1.0 will lock the rotation of two bodies together, and negative ratios will cause them to spin in opposite directions. You can also use gear joints as rotary servos by setting MaxForce and MaxBias to finite values and changing the Phase property.

func GearJointNew

func GearJointNew(a, b Body, phase, ratio float64) GearJoint

GearJointNew creates a new gear joint.

func (GearJoint) A

func (c GearJoint) A() Body

A returns the first body the constraint controls.

func (GearJoint) ActivateBodies

func (c GearJoint) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (GearJoint) B

func (c GearJoint) B() Body

B returns the second body the constraint controls.

func (GearJoint) ErrorBias

func (c GearJoint) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (GearJoint) Free

func (c GearJoint) Free()

Free frees the constraint.

func (GearJoint) Impulse

func (c GearJoint) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (GearJoint) MaxBias

func (c GearJoint) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (GearJoint) MaxForce

func (c GearJoint) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (GearJoint) Phase

func (c GearJoint) Phase() float64

Phase returns the angular offset in radians.

func (GearJoint) Ratio

func (c GearJoint) Ratio() float64

Ratio returns the ratio of the rotational speeds.

func (GearJoint) SetErrorBias

func (c GearJoint) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (GearJoint) SetMaxBias

func (c GearJoint) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (GearJoint) SetMaxForce

func (c GearJoint) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (GearJoint) SetPhase

func (c GearJoint) SetPhase(m float64)

SetPhase sets the angular offset in radians.

func (GearJoint) SetPostSolveFunc

func (c GearJoint) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (GearJoint) SetPreSolveFunc

func (c GearJoint) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (GearJoint) SetRatio

func (c GearJoint) SetRatio(m float64)

SetRatio sets the ratio of the rotational speeds.

func (GearJoint) SetUserData

func (c GearJoint) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (GearJoint) Space

func (c GearJoint) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (GearJoint) UserData

func (c GearJoint) UserData() interface{}

UserData returns user defined data.

type GrooveJoint

type GrooveJoint struct {
	// contains filtered or unexported fields
}

GrooveJoint holds a pivot point on one body to line along a line segment on another like a pin in a groove.

func GrooveJointNew

func GrooveJointNew(a, b Body, grooveA, grooveB, anchr2 Vect) GrooveJoint

GrooveJointNew creates a new groove joint. Make sure you have the bodies in the right place as the joint will snap into shape as soon as you start simulating the space.

func (GrooveJoint) A

func (c GrooveJoint) A() Body

A returns the first body the constraint controls.

func (GrooveJoint) ActivateBodies

func (c GrooveJoint) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (GrooveJoint) Anchr2

func (c GrooveJoint) Anchr2() Vect

Anchr2 returns the anchor point on the second body that is held to the line segment on the first.

func (GrooveJoint) B

func (c GrooveJoint) B() Body

B returns the second body the constraint controls.

func (GrooveJoint) ErrorBias

func (c GrooveJoint) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (GrooveJoint) Free

func (c GrooveJoint) Free()

Free frees the constraint.

func (GrooveJoint) GrooveA

func (c GrooveJoint) GrooveA() Vect

GrooveA returns the start of the line segment on the first body.

func (GrooveJoint) GrooveB

func (c GrooveJoint) GrooveB() Vect

GrooveB returns the end of the line segment on the first body.

func (GrooveJoint) Impulse

func (c GrooveJoint) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (GrooveJoint) MaxBias

func (c GrooveJoint) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (GrooveJoint) MaxForce

func (c GrooveJoint) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (GrooveJoint) SetAnchr2

func (c GrooveJoint) SetAnchr2(v Vect)

SetAnchr2 sets the anchor point on the second body that is held to the line segment on the first.

func (GrooveJoint) SetErrorBias

func (c GrooveJoint) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (GrooveJoint) SetGrooveA

func (c GrooveJoint) SetGrooveA(v Vect)

SetGrooveA sets the start of the line segment on the first body.

func (GrooveJoint) SetGrooveB

func (c GrooveJoint) SetGrooveB(v Vect)

SetGrooveB sets the end of the line segment on the first body.

func (GrooveJoint) SetMaxBias

func (c GrooveJoint) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (GrooveJoint) SetMaxForce

func (c GrooveJoint) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (GrooveJoint) SetPostSolveFunc

func (c GrooveJoint) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (GrooveJoint) SetPreSolveFunc

func (c GrooveJoint) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (GrooveJoint) SetUserData

func (c GrooveJoint) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (GrooveJoint) Space

func (c GrooveJoint) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (GrooveJoint) UserData

func (c GrooveJoint) UserData() interface{}

UserData returns user defined data.

type Group

type Group C.cpGroup

Group is a type used for Shape.Group.

func (Group) String

func (g Group) String() string

String converts Group to a human-readable string.

type Layers

type Layers uint

Layers is a type used for Shape.Layers.

func (Layers) String

func (l Layers) String() string

String converts Layers to a human-readable string.

type NearestPointQuery

type NearestPointQuery func(s Shape, distance float64, point Vect)

NearestPointQuery is a callback function type for NearestPointQuery function.

type NearestPointQueryInfo

type NearestPointQueryInfo struct {
	// Shape is the nearest shape. nil if no shape was within range.
	Shape
	// P is the closest point on the shape's surface (world space coordinates).
	P Vect
	// D is the distance to the point. Negative if the point is inside the shape.
	D float64
	// G is the gradient of the signed distance field for the shape.
	G Vect
}

NearestPointQueryInfo is a nearest point query struct.

type PinJoint

type PinJoint struct {
	// contains filtered or unexported fields
}

PinJoint holds a set distance between points on two bodies. Think of them as connecting a solid pin or rod between the two anchor points.

func PinJointNew

func PinJointNew(a, b Body, anchr1, anchr2 Vect) PinJoint

PinJointNew creates a new pin joint.

func (PinJoint) A

func (c PinJoint) A() Body

A returns the first body the constraint controls.

func (PinJoint) ActivateBodies

func (c PinJoint) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (PinJoint) Anchr1

func (c PinJoint) Anchr1() Vect

Anchr1 returns the anchor point on the first body.

func (PinJoint) Anchr2

func (c PinJoint) Anchr2() Vect

Anchr2 returns the anchor point on the second body.

func (PinJoint) B

func (c PinJoint) B() Body

B returns the second body the constraint controls.

func (PinJoint) Dist

func (c PinJoint) Dist() float64

Dist returns the distance between the two anchor points that the joint keeps.

func (PinJoint) ErrorBias

func (c PinJoint) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (PinJoint) Free

func (c PinJoint) Free()

Free frees the constraint.

func (PinJoint) Impulse

func (c PinJoint) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (PinJoint) MaxBias

func (c PinJoint) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (PinJoint) MaxForce

func (c PinJoint) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (PinJoint) SetAnchr1

func (c PinJoint) SetAnchr1(v Vect)

SetAnchr1 sets the anchor point on the first body.

func (PinJoint) SetAnchr2

func (c PinJoint) SetAnchr2(v Vect)

SetAnchr2 sets the anchor point on the second body.

func (PinJoint) SetDist

func (c PinJoint) SetDist(d float64)

SetDist sets the distance between the two anchor points that the joint keeps.

func (PinJoint) SetErrorBias

func (c PinJoint) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (PinJoint) SetMaxBias

func (c PinJoint) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (PinJoint) SetMaxForce

func (c PinJoint) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (PinJoint) SetPostSolveFunc

func (c PinJoint) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (PinJoint) SetPreSolveFunc

func (c PinJoint) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (PinJoint) SetUserData

func (c PinJoint) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (PinJoint) Space

func (c PinJoint) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (PinJoint) UserData

func (c PinJoint) UserData() interface{}

UserData returns user defined data.

type PivotJoint

type PivotJoint struct {
	// contains filtered or unexported fields
}

PivotJoint holds two points on two bodies together allowing them to rotate freely around the pivot.

func PivotJointNew

func PivotJointNew(a, b Body, pivot Vect) PivotJoint

PivotJointNew creates a new pivot joint.

func PivotJointNew2

func PivotJointNew2(a, b Body, anchr1, anchr2 Vect) PivotJoint

PivotJointNew2 creates a new pivot joint with the two anchor points.

func (PivotJoint) A

func (c PivotJoint) A() Body

A returns the first body the constraint controls.

func (PivotJoint) ActivateBodies

func (c PivotJoint) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (PivotJoint) Anchr1

func (c PivotJoint) Anchr1() Vect

Anchr1 returns the anchor point on the first body.

func (PivotJoint) Anchr2

func (c PivotJoint) Anchr2() Vect

Anchr2 returns the anchor point on the second body.

func (PivotJoint) B

func (c PivotJoint) B() Body

B returns the second body the constraint controls.

func (PivotJoint) ErrorBias

func (c PivotJoint) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (PivotJoint) Free

func (c PivotJoint) Free()

Free frees the constraint.

func (PivotJoint) Impulse

func (c PivotJoint) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (PivotJoint) MaxBias

func (c PivotJoint) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (PivotJoint) MaxForce

func (c PivotJoint) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (PivotJoint) SetAnchr1

func (c PivotJoint) SetAnchr1(v Vect)

SetAnchr1 sets the anchor point on the first body.

func (PivotJoint) SetAnchr2

func (c PivotJoint) SetAnchr2(v Vect)

SetAnchr2 sets the anchor point on the second body.

func (PivotJoint) SetErrorBias

func (c PivotJoint) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (PivotJoint) SetMaxBias

func (c PivotJoint) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (PivotJoint) SetMaxForce

func (c PivotJoint) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (PivotJoint) SetPostSolveFunc

func (c PivotJoint) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (PivotJoint) SetPreSolveFunc

func (c PivotJoint) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (PivotJoint) SetUserData

func (c PivotJoint) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (PivotJoint) Space

func (c PivotJoint) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (PivotJoint) UserData

func (c PivotJoint) UserData() interface{}

UserData returns user defined data.

type PointQuery

type PointQuery func(s Shape)

PointQuery is a callback function type for PointQuery function.

type PolyShape

type PolyShape struct {
	// contains filtered or unexported fields
}

PolyShape is a polygon shape type.

func PolyShapeNew

func PolyShapeNew(b Body, verts []Vect, offset Vect) PolyShape

PolyShapeNew creates a new polygon shape.

func PolyShapeNew2

func PolyShapeNew2(b Body, verts []Vect, offset Vect, radius float64) PolyShape

PolyShapeNew2 creates a new polygon shape.

func (PolyShape) BB

func (s PolyShape) BB() BB

BB returns current bounding box of the shape.

func (PolyShape) Body

func (s PolyShape) Body() Body

Body returns the rigid body this collision shape is attached to.

func (PolyShape) CacheBB

func (s PolyShape) CacheBB() BB

CacheBB updates, caches and returns the bounding box of a shape based on the body it's attached to.

func (PolyShape) CollisionType

func (s PolyShape) CollisionType() CollisionType

CollisionType returns collision type of the shape used when picking collision handlers.

func (PolyShape) Elasticity

func (s PolyShape) Elasticity() float64

Elasticity returns shape's coefficient of restitution.

func (PolyShape) Free

func (s PolyShape) Free()

Free removes a shape.

func (PolyShape) Friction

func (s PolyShape) Friction() float64

Friction returns shape's coefficient of friction.

func (PolyShape) Group

func (s PolyShape) Group() Group

Group returns a group of the shape. Shapes in the same group don't collide.

func (PolyShape) Layers

func (s PolyShape) Layers() Layers

Layers returns layers bitmask of the shape. Shapes collide only if bitwise of their layers is non-zero.

func (PolyShape) NearestPointQuery

func (s PolyShape) NearestPointQuery(p Vect) (float64, NearestPointQueryInfo)

NearestPointQuery finds the closest point on the surface of shape to a specific point. The first returned value is the distance between the points. A negative distance means the point is inside the shape.

func (PolyShape) NumVerts

func (s PolyShape) NumVerts() int

NumVerts returns the number of vertices in a polygon shape.

func (PolyShape) PointQuery

func (s PolyShape) PointQuery(p Vect) bool

PointQuery returns true if a point lies within a shape.

func (PolyShape) Radius

func (s PolyShape) Radius() float64

Radius returns the vertex radius.

func (PolyShape) SegmentQuery

func (s PolyShape) SegmentQuery(a, b Vect) (bool, SegmentQueryInfo)

SegmentQuery performs a segment query against a shape.

func (PolyShape) Sensor

func (s PolyShape) Sensor() bool

Sensor returns true when shape is "sensor" one, i.e. does not produce collisions.

func (PolyShape) SetBody

func (s PolyShape) SetBody(b Body)

SetBody sets the rigid body this collision shape is attached to.

func (PolyShape) SetCollisionType

func (s PolyShape) SetCollisionType(t CollisionType)

SetCollisionType sets collision type of the shape used when picking collision handlers.

func (PolyShape) SetElasticity

func (s PolyShape) SetElasticity(e float64)

SetElasticity sets coefficient of restitution.

func (PolyShape) SetFriction

func (s PolyShape) SetFriction(f float64)

SetFriction sets coefficient of friction.

func (PolyShape) SetGroup

func (s PolyShape) SetGroup(g Group)

SetGroup sets a group of the shape. Shapes in the same group don't collide.

func (PolyShape) SetLayers

func (s PolyShape) SetLayers(l Layers)

SetLayers sets layers bitmask of the shape. Shapes collide only if bitwise of their layers is non-zero.

func (PolyShape) SetRadius

func (s PolyShape) SetRadius(radius float64)

SetRadius sets the vertex radius.

func (PolyShape) SetSensor

func (s PolyShape) SetSensor(b bool)

SetSensor sets if the shape is "sensor" one, i.e. does not produce collisions, but still calls collision callbacks.

func (PolyShape) SetSurfaceVelocity

func (s PolyShape) SetSurfaceVelocity(v Vect)

SetSurfaceVelocity sets surface velocity used when solving friction.

func (PolyShape) SetUserData

func (s PolyShape) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Shape reference in a callback.

func (PolyShape) SetVerts

func (s PolyShape) SetVerts(verts []Vect, offset Vect)

SetVerts sets the vertexes of a poly shape.

func (PolyShape) Space

func (s PolyShape) Space() Space

Space returns space the body was added to or nil if the body doesn't belong to any space.

func (PolyShape) String

func (s PolyShape) String() string

String converts a polygon shape to a human-readable string.

func (PolyShape) SurfaceVelocity

func (s PolyShape) SurfaceVelocity() Vect

SurfaceVelocity returns surface velocity used when solving friction.

func (PolyShape) Update

func (s PolyShape) Update(pos, rot Vect) BB

Update updates, caches and returns the bounding box of a shape with an explicit transformation.

func (PolyShape) UserData

func (s PolyShape) UserData() interface{}

UserData returns user defined data.

func (PolyShape) VertLocal

func (s PolyShape) VertLocal(idx int) Vect

VertLocal returns a specific vertex of a polygon shape (local coordinates).

func (PolyShape) VertsWorld

func (s PolyShape) VertsWorld() []Vect

VertsWorld returns vertex positions (world coordinates).

func (PolyShape) VertsWorldFloat64

func (s PolyShape) VertsWorldFloat64() []float64

VertsWorldFloat64 returns vertex positions (world coordinates) as array of float64 values.

type RatchetJoint

type RatchetJoint struct {
	// contains filtered or unexported fields
}

RatchetJoint creates rotary ratches similar to a socket wrench.

func RatchetJointNew

func RatchetJointNew(a, b Body, phase, ratchet float64) RatchetJoint

RatchetJointNew creates a new ratchet joint.

func (RatchetJoint) A

func (c RatchetJoint) A() Body

A returns the first body the constraint controls.

func (RatchetJoint) ActivateBodies

func (c RatchetJoint) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (RatchetJoint) Angle

func (c RatchetJoint) Angle() float64

Angle returns the current ratchet position in radians.

func (RatchetJoint) B

func (c RatchetJoint) B() Body

B returns the second body the constraint controls.

func (RatchetJoint) ErrorBias

func (c RatchetJoint) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (RatchetJoint) Free

func (c RatchetJoint) Free()

Free frees the constraint.

func (RatchetJoint) Impulse

func (c RatchetJoint) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (RatchetJoint) MaxBias

func (c RatchetJoint) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (RatchetJoint) MaxForce

func (c RatchetJoint) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (RatchetJoint) Phase

func (c RatchetJoint) Phase() float64

Phase returns the angular offset of the ratchet positions in radians.

func (RatchetJoint) Ratchet

func (c RatchetJoint) Ratchet() float64

Ratchet returns the angle in radians of each ratchet position.

func (RatchetJoint) SetAngle

func (c RatchetJoint) SetAngle(m float64)

SetAngle sets the ratchet position in radians.

func (RatchetJoint) SetErrorBias

func (c RatchetJoint) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (RatchetJoint) SetMaxBias

func (c RatchetJoint) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (RatchetJoint) SetMaxForce

func (c RatchetJoint) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (RatchetJoint) SetPhase

func (c RatchetJoint) SetPhase(m float64)

SetPhase sets the angular offset of the ratchet positions in radians.

func (RatchetJoint) SetPostSolveFunc

func (c RatchetJoint) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (RatchetJoint) SetPreSolveFunc

func (c RatchetJoint) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (RatchetJoint) SetRatchet

func (c RatchetJoint) SetRatchet(m float64)

SetRatchet sets the angle in radians of each ratchet position. Negative values cause the ratchet to operate in the opposite direction.

func (RatchetJoint) SetUserData

func (c RatchetJoint) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (RatchetJoint) Space

func (c RatchetJoint) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (RatchetJoint) UserData

func (c RatchetJoint) UserData() interface{}

UserData returns user defined data.

type RotaryLimitJoint

type RotaryLimitJoint struct {
	// contains filtered or unexported fields
}

RotaryLimitJoint constrains the angle between two bodies. This joint is often used in conjuction with a separate PivotJoint in order to limit the rotation around the pivot.

func RotaryLimitJointNew

func RotaryLimitJointNew(a, b Body, min, max float64) RotaryLimitJoint

RotaryLimitJointNew creates a new rotary limit joint.

func (RotaryLimitJoint) A

func (c RotaryLimitJoint) A() Body

A returns the first body the constraint controls.

func (RotaryLimitJoint) ActivateBodies

func (c RotaryLimitJoint) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (RotaryLimitJoint) B

func (c RotaryLimitJoint) B() Body

B returns the second body the constraint controls.

func (RotaryLimitJoint) ErrorBias

func (c RotaryLimitJoint) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (RotaryLimitJoint) Free

func (c RotaryLimitJoint) Free()

Free frees the constraint.

func (RotaryLimitJoint) Impulse

func (c RotaryLimitJoint) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (RotaryLimitJoint) Max

func (c RotaryLimitJoint) Max() float64

Max returns the maximum angular delta of the joint in radians.

func (RotaryLimitJoint) MaxBias

func (c RotaryLimitJoint) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (RotaryLimitJoint) MaxForce

func (c RotaryLimitJoint) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (RotaryLimitJoint) Min

func (c RotaryLimitJoint) Min() float64

Min returns the minimum angular delta of the joint in radians.

func (RotaryLimitJoint) SetErrorBias

func (c RotaryLimitJoint) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (RotaryLimitJoint) SetMax

func (c RotaryLimitJoint) SetMax(m float64)

SetMax sets the maximum angular delta of the joint in radians.

func (RotaryLimitJoint) SetMaxBias

func (c RotaryLimitJoint) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (RotaryLimitJoint) SetMaxForce

func (c RotaryLimitJoint) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (RotaryLimitJoint) SetMin

func (c RotaryLimitJoint) SetMin(m float64)

SetMin sets the minimum angular delta of the joint in radians.

func (RotaryLimitJoint) SetPostSolveFunc

func (c RotaryLimitJoint) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (RotaryLimitJoint) SetPreSolveFunc

func (c RotaryLimitJoint) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (RotaryLimitJoint) SetUserData

func (c RotaryLimitJoint) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (RotaryLimitJoint) Space

func (c RotaryLimitJoint) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (RotaryLimitJoint) UserData

func (c RotaryLimitJoint) UserData() interface{}

UserData returns user defined data.

type SegmentQuery

type SegmentQuery func(s Shape, t float64, n Vect)

SegmentQuery is a query callback function type.

type SegmentQueryInfo

type SegmentQueryInfo struct {
	// Shape is the one that was hit. nil if no collision occured.
	Shape
	// Normalized distance along the query segment in the range [0;1].
	T float64
	// Normal of the surface hit.
	N Vect
}

SegmentQueryInfo holds the result of SegmentQuery.

func (SegmentQueryInfo) HitDistance

func (s SegmentQueryInfo) HitDistance(start, end Vect) float64

HitDistance returns the hit distance for a segment query.

func (SegmentQueryInfo) HitPoint

func (s SegmentQueryInfo) HitPoint(start, end Vect) Vect

HitPoint returns the hit point for a segment query.

type SegmentShape

type SegmentShape struct {
	// contains filtered or unexported fields
}

SegmentShape is a a beveled (rounded) segment shape.

func SegmentShapeNew

func SegmentShapeNew(body Body, a, b Vect, radius float64) SegmentShape

SegmentShapeNew creates a new segment shape.

func (SegmentShape) A

func (s SegmentShape) A() Vect

A returns the start of the segment shape.

func (SegmentShape) B

func (s SegmentShape) B() Vect

B returns the end of the segment shape.

func (SegmentShape) BB

func (s SegmentShape) BB() BB

BB returns current bounding box of the shape.

func (SegmentShape) Body

func (s SegmentShape) Body() Body

Body returns the rigid body this collision shape is attached to.

func (SegmentShape) CacheBB

func (s SegmentShape) CacheBB() BB

CacheBB updates, caches and returns the bounding box of a shape based on the body it's attached to.

func (SegmentShape) CollisionType

func (s SegmentShape) CollisionType() CollisionType

CollisionType returns collision type of the shape used when picking collision handlers.

func (SegmentShape) Elasticity

func (s SegmentShape) Elasticity() float64

Elasticity returns shape's coefficient of restitution.

func (SegmentShape) Free

func (s SegmentShape) Free()

Free removes a shape.

func (SegmentShape) Friction

func (s SegmentShape) Friction() float64

Friction returns shape's coefficient of friction.

func (SegmentShape) Group

func (s SegmentShape) Group() Group

Group returns a group of the shape. Shapes in the same group don't collide.

func (SegmentShape) Layers

func (s SegmentShape) Layers() Layers

Layers returns layers bitmask of the shape. Shapes collide only if bitwise of their layers is non-zero.

func (SegmentShape) NearestPointQuery

func (s SegmentShape) NearestPointQuery(p Vect) (float64, NearestPointQueryInfo)

NearestPointQuery finds the closest point on the surface of shape to a specific point. The first returned value is the distance between the points. A negative distance means the point is inside the shape.

func (SegmentShape) Normal

func (s SegmentShape) Normal() Vect

Normal returns the normal of the segment shape.

func (SegmentShape) PointQuery

func (s SegmentShape) PointQuery(p Vect) bool

PointQuery returns true if a point lies within a shape.

func (SegmentShape) Radius

func (s SegmentShape) Radius() float64

Radius returns the beveling radius of the segment shape.

func (SegmentShape) SegmentQuery

func (s SegmentShape) SegmentQuery(a, b Vect) (bool, SegmentQueryInfo)

SegmentQuery performs a segment query against a shape.

func (SegmentShape) Sensor

func (s SegmentShape) Sensor() bool

Sensor returns true when shape is "sensor" one, i.e. does not produce collisions.

func (SegmentShape) SetBody

func (s SegmentShape) SetBody(b Body)

SetBody sets the rigid body this collision shape is attached to.

func (SegmentShape) SetCollisionType

func (s SegmentShape) SetCollisionType(t CollisionType)

SetCollisionType sets collision type of the shape used when picking collision handlers.

func (SegmentShape) SetElasticity

func (s SegmentShape) SetElasticity(e float64)

SetElasticity sets coefficient of restitution.

func (SegmentShape) SetEndpoints

func (s SegmentShape) SetEndpoints(a, b Vect)

SetEndpoints sets the endpoints of a segment shape. NOTE: this is unsafe function.

func (SegmentShape) SetFriction

func (s SegmentShape) SetFriction(f float64)

SetFriction sets coefficient of friction.

func (SegmentShape) SetGroup

func (s SegmentShape) SetGroup(g Group)

SetGroup sets a group of the shape. Shapes in the same group don't collide.

func (SegmentShape) SetLayers

func (s SegmentShape) SetLayers(l Layers)

SetLayers sets layers bitmask of the shape. Shapes collide only if bitwise of their layers is non-zero.

func (SegmentShape) SetNeighbors

func (s SegmentShape) SetNeighbors(prev, next Vect)

SetNeighbors FIXME TODO OMG WTF

func (SegmentShape) SetRadius

func (s SegmentShape) SetRadius(radius float64)

SetRadius sets the radius of a segment shape. NOTE: this is unsafe function.

func (SegmentShape) SetSensor

func (s SegmentShape) SetSensor(b bool)

SetSensor sets if the shape is "sensor" one, i.e. does not produce collisions, but still calls collision callbacks.

func (SegmentShape) SetSurfaceVelocity

func (s SegmentShape) SetSurfaceVelocity(v Vect)

SetSurfaceVelocity sets surface velocity used when solving friction.

func (SegmentShape) SetUserData

func (s SegmentShape) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Shape reference in a callback.

func (SegmentShape) Space

func (s SegmentShape) Space() Space

Space returns space the body was added to or nil if the body doesn't belong to any space.

func (SegmentShape) String

func (s SegmentShape) String() string

String converts a segment shape to a human-readable string.

func (SegmentShape) SurfaceVelocity

func (s SegmentShape) SurfaceVelocity() Vect

SurfaceVelocity returns surface velocity used when solving friction.

func (SegmentShape) Update

func (s SegmentShape) Update(pos, rot Vect) BB

Update updates, caches and returns the bounding box of a shape with an explicit transformation.

func (SegmentShape) UserData

func (s SegmentShape) UserData() interface{}

UserData returns user defined data.

type Shape

type Shape interface {
	BB() BB
	Body() Body
	CacheBB() BB
	CollisionType() CollisionType
	Elasticity() float64
	Free()
	Friction() float64
	Group() Group
	Layers() Layers
	NearestPointQuery(Vect) (float64, NearestPointQueryInfo)
	PointQuery(Vect) bool
	SegmentQuery(Vect, Vect) (bool, SegmentQueryInfo)
	Sensor() bool
	SetBody(Body)
	SetCollisionType(CollisionType)
	SetElasticity(float64)
	SetFriction(float64)
	SetGroup(Group)
	SetLayers(Layers)
	SetSensor(bool)
	SetSurfaceVelocity(Vect)
	String() string
	SurfaceVelocity() Vect
	Update(Vect, Vect) BB
	// contains filtered or unexported methods
}

Shape is an opaque collision shape struct.

func BoxShapeNew

func BoxShapeNew(b Body, width, height float64) Shape

BoxShapeNew creates a new box shape.

func BoxShapeNew2

func BoxShapeNew2(b Body, box BB) Shape

BoxShapeNew2 creates a new box shape.

func BoxShapeNew3

func BoxShapeNew3(b Body, box BB, radius float64) Shape

BoxShapeNew3 creates a new box shape.

type SimpleMotor

type SimpleMotor struct {
	// contains filtered or unexported fields
}

SimpleMotor makes two objects spin relative to each other. They are most often used with the MaxForce property set to a finite value.

func SimpleMotorNew

func SimpleMotorNew(a, b Body, rate float64) SimpleMotor

SimpleMotorNew creates a new simple motor.

func (SimpleMotor) A

func (c SimpleMotor) A() Body

A returns the first body the constraint controls.

func (SimpleMotor) ActivateBodies

func (c SimpleMotor) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (SimpleMotor) B

func (c SimpleMotor) B() Body

B returns the second body the constraint controls.

func (SimpleMotor) ErrorBias

func (c SimpleMotor) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (SimpleMotor) Free

func (c SimpleMotor) Free()

Free frees the constraint.

func (SimpleMotor) Impulse

func (c SimpleMotor) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (SimpleMotor) MaxBias

func (c SimpleMotor) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (SimpleMotor) MaxForce

func (c SimpleMotor) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (SimpleMotor) Rate

func (c SimpleMotor) Rate() float64

Rate returns the relative rotation speed of the two bodies in radians per second.

func (SimpleMotor) SetErrorBias

func (c SimpleMotor) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (SimpleMotor) SetMaxBias

func (c SimpleMotor) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (SimpleMotor) SetMaxForce

func (c SimpleMotor) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (SimpleMotor) SetPostSolveFunc

func (c SimpleMotor) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (SimpleMotor) SetPreSolveFunc

func (c SimpleMotor) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (SimpleMotor) SetRate

func (c SimpleMotor) SetRate(m float64)

SetRate sets the relative rotation speed of the two bodies in radians per second.

func (SimpleMotor) SetUserData

func (c SimpleMotor) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (SimpleMotor) Space

func (c SimpleMotor) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (SimpleMotor) UserData

func (c SimpleMotor) UserData() interface{}

UserData returns user defined data.

type SlideJoint

type SlideJoint struct {
	// contains filtered or unexported fields
}

SlideJoint holds the distance between points on two bodies between a minimum and a maximum. Think of them as a telescoping PinJoint.

func SlideJointNew

func SlideJointNew(a, b Body, anchr1, anchr2 Vect, min, max float64) SlideJoint

SlideJointNew creates a new slide joint.

func (SlideJoint) A

func (c SlideJoint) A() Body

A returns the first body the constraint controls.

func (SlideJoint) ActivateBodies

func (c SlideJoint) ActivateBodies()

ActivateBodies calls Activate() on bodies the constraint controls.

func (SlideJoint) Anchr1

func (c SlideJoint) Anchr1() Vect

Anchr1 returns the anchor point on the first body.

func (SlideJoint) Anchr2

func (c SlideJoint) Anchr2() Vect

Anchr2 returns the anchor point on the second body.

func (SlideJoint) B

func (c SlideJoint) B() Body

B returns the second body the constraint controls.

func (SlideJoint) ErrorBias

func (c SlideJoint) ErrorBias() float64

ErrorBias returns the rate at which joint error is corrected.

func (SlideJoint) Free

func (c SlideJoint) Free()

Free frees the constraint.

func (SlideJoint) Impulse

func (c SlideJoint) Impulse() float64

Impulse returns the last impulse applied by this constraint.

func (SlideJoint) Max

func (c SlideJoint) Max() float64

Max returns the maximum allowed distance between anchor points.

func (SlideJoint) MaxBias

func (c SlideJoint) MaxBias() float64

MaxBias returns the maximum rate (speed) that a joint can be corrected at.

func (SlideJoint) MaxForce

func (c SlideJoint) MaxForce() float64

MaxForce returns the maximum force this constraint is allowed to use.

func (SlideJoint) Min

func (c SlideJoint) Min() float64

Min returns the minimum allowed distance between anchor points.

func (SlideJoint) SetAnchr1

func (c SlideJoint) SetAnchr1(v Vect)

SetAnchr1 sets the anchor point on the first body.

func (SlideJoint) SetAnchr2

func (c SlideJoint) SetAnchr2(v Vect)

SetAnchr2 sets the anchor point on the second body.

func (SlideJoint) SetErrorBias

func (c SlideJoint) SetErrorBias(b float64)

SetErrorBias sets the rate at which joint error is corrected. Defaults to math.Pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (SlideJoint) SetMax

func (c SlideJoint) SetMax(m float64)

SetMax sets the maximum allowed distance between anchor points.

func (SlideJoint) SetMaxBias

func (c SlideJoint) SetMaxBias(b float64)

SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).

func (SlideJoint) SetMaxForce

func (c SlideJoint) SetMaxForce(f float64)

SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity). This allows joints to be pulled apart if too much force is applied to them. It also allows you to use constraints as force or friction generators for controlling bodies.

func (SlideJoint) SetMin

func (c SlideJoint) SetMin(m float64)

SetMin sets the minimum allowed distance between anchor points.

func (SlideJoint) SetPostSolveFunc

func (c SlideJoint) SetPostSolveFunc(f func(c Constraint, s Space))

SetPostSolveFunc sets a callback function type that gets called after solving a joint. Use the applied impulse to perform effects like breakable joints.

func (SlideJoint) SetPreSolveFunc

func (c SlideJoint) SetPreSolveFunc(f func(c Constraint, s Space))

SetPreSolveFunc sets a callback function type that gets called before solving a joint. Animate your joint anchors, update your motor torque, etc.

func (SlideJoint) SetUserData

func (c SlideJoint) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your the game object so you can access it when given a Constraint reference in a callback.

func (SlideJoint) Space

func (c SlideJoint) Space() Space

Space returns space the constraint was added to or 0 if the constraint doesn't belong to any space.

func (SlideJoint) UserData

func (c SlideJoint) UserData() interface{}

UserData returns user defined data.

type Space

type Space uintptr

Space is a basic unit of simulation in Chipmunk.

func SpaceNew

func SpaceNew() Space

SpaceNew creates a new space.

func (Space) ActivateShapesTouchingShape

func (s Space) ActivateShapesTouchingShape(sh Shape)

ActivateShapesTouchingShape activates body (calls Activate()) of any shape that overlaps the given shape.

func (Space) Add

func (s Space) Add(obj SpaceObject) SpaceObject

Add an object to space.

func (Space) AddBody

func (s Space) AddBody(b Body) Body

AddBody adds a rigid body to the simulation.

func (Space) AddCollisionHandler

func (s Space) AddCollisionHandler(a, b CollisionType,
	beginFunc, preSolveFunc func(Space, Arbiter, interface{}) bool,
	postStepFunc, separateFunc func(Space, Arbiter, interface{}), data interface{})

AddCollisionHandler sets a collision handler to be used whenever the two shapes with the given collision types collide

func (Space) AddConstraint

func (s Space) AddConstraint(c Constraint) Constraint

AddConstraint adds a constraint to the simulation.

func (Space) AddPostStepCallback

func (s Space) AddPostStepCallback(f func(Space, interface{}), key interface{}) bool

AddPostStepCallback schedules a post-step callback to be called when Space.Step() finishes. You can only register one callback per unique value for key. Returns true only if the key has never been scheduled before.

func (Space) AddShape

func (s Space) AddShape(sh Shape) Shape

AddShape adds a collision shape to the simulation. If the shape is attached to a static body, it will be added as a static shape.

func (Space) AddStaticShape

func (s Space) AddStaticShape(sh Shape) Shape

AddStaticShape explicity adds a shape as a static shape to the simulation.

func (Space) BBQuery

func (s Space) BBQuery(bb BB, layers Layers, group Group, f BBQuery)

BBQuery performs a fast rectangle query on the space calling a callback function for each shape found. Only the shape's bounding boxes are checked for overlap, not their full shape.

func (Space) CollisionBias

func (s Space) CollisionBias() float64

CollisionBias returns the speed of how fast overlapping shapes are pushed apart.

func (Space) CollisionPersistence

func (s Space) CollisionPersistence() Timestamp

CollisionPersistence returns the number of frames that contact information should persist.

func (Space) CollisionSlop

func (s Space) CollisionSlop() float64

CollisionSlop returns amount of encouraged penetration between colliding shapes.

func (Space) Contains

func (s Space) Contains(obj SpaceObject) bool

Contains tests if a collision shape, rigid body or a constraint has been added to the space.

func (Space) ConvertBodyToDynamic

func (s Space) ConvertBodyToDynamic(b Body, m, i float64)

ConvertBodyToDynamic converts a body to a dynamic rogue body. This will convert any static shapes attached to the body into regular ones. If you want the body to be active after the transition, you must add it to the space also.

func (Space) ConvertBodyToStatic

func (s Space) ConvertBodyToStatic(b Body)

ConvertBodyToStatic converts a dynamic rogue body to a static one. This will convert any shapes attached to the body into static shapes, but does not handle constra ints. If the body is active, you must remove it from the space first.

func (Space) CurrentTimeStep

func (s Space) CurrentTimeStep() float64

CurrentTimeStep returns the current (if you are in a callback from SpaceStep()) or most recent (outside of a SpaceStep() call) timestep.

func (Space) Damping

func (s Space) Damping() float64

Damping returns the damping rate expressed as the fraction of velocity bodies retain each second.

func (Space) Each

func (s Space) Each(iter interface{})

Each calls a callback function on each object of specific type (according to iterator) in the space.

func (Space) EachBody

func (s Space) EachBody(iter func(Body))

EachBody calls a callback function on each body in the space.

func (Space) EachConstraint

func (s Space) EachConstraint(iter func(Constraint))

EachConstraint calls a callback function on each constraint in the space.

func (Space) EachShape

func (s Space) EachShape(iter func(Shape))

EachShape calls a callback function on each shape in the space.

func (Space) EnableContactGraph

func (s Space) EnableContactGraph() bool

EnableContactGraph returns true if rebuild of the contact graph during each step is enabled.

func (Space) Free

func (s Space) Free()

Free removes a space.

func (Space) FreeChildren

func (s Space) FreeChildren()

FreeChildren frees all bodies, constraints and shapes in the space.

func (Space) Gravity

func (s Space) Gravity() Vect

Gravity returns current gravity used when integrating velocity for rigid bodies.

func (Space) IdleSpeedThreshold

func (s Space) IdleSpeedThreshold() float64

IdleSpeedThreshold returns speed threshold for a body to be considered idle.

func (Space) IsLocked

func (s Space) IsLocked() bool

IsLocked returns true if objects cannot be added/removed inside a callback.

func (Space) Iterations

func (s Space) Iterations() int

Iterations returns the number of iterations to use in the impulse solver (to solve contacts).

func (Space) NearestPointQuery

func (s Space) NearestPointQuery(point Vect, maxDistance float64, layers Layers, group Group,
	f NearestPointQuery)

NearestPointQuery queries the space at a point and calls a callback function for each shape found.

func (Space) PointQuery

func (s Space) PointQuery(point Vect, layers Layers, group Group, f PointQuery)

PointQuery queries the space at a point and calls a callback function for each shape found.

func (Space) PointQueryFirst

func (s Space) PointQueryFirst(point Vect, layers Layers, group Group) Shape

PointQueryFirst queries the space at a point and returns the first shape found. Returns nil if no shapes were found.

func (Space) ReindexShape

func (s Space) ReindexShape(sh Shape)

ReindexShape updates the collision detection data for a specific shape in the space.

func (Space) ReindexShapesForBody

func (s Space) ReindexShapesForBody(b Body)

ReindexShapesForBody updates the collision detection data for all shapes attached to a body.

func (Space) ReindexStatic

func (s Space) ReindexStatic()

ReindexStatic updates the collision detection info for the static shape in the space.

func (Space) Remove

func (s Space) Remove(obj SpaceObject)

Remove an object from space.

func (Space) RemoveBody

func (s Space) RemoveBody(b Body)

RemoveBody removes a rigid body from the simulation.

func (Space) RemoveCollisionHandler

func (s Space) RemoveCollisionHandler(a CollisionType, b CollisionType)

RemoveCollisionHandler unsets a collision handler.

func (Space) RemoveConstraint

func (s Space) RemoveConstraint(c Constraint)

RemoveConstraint removes a constraint from the simulation.

func (Space) RemoveShape

func (s Space) RemoveShape(sh Shape)

RemoveShape removes a collision shape from the simulation.

func (Space) RemoveStaticShape

func (s Space) RemoveStaticShape(sh Shape)

RemoveStaticShape removes a collision shape added using AddStaticShape() from the simulation.

func (Space) SegmentQuery

func (s Space) SegmentQuery(start, end Vect, layers Layers, group Group, f SegmentQuery)

SegmentQuery performs a directed line segment query (like a raycast) against the space calling a callback function for each shape intersected.

func (Space) SetCollisionBias

func (s Space) SetCollisionBias(b float64)

SetCollisionBias sets the speed of how fast overlapping shapes are pushed apart. Expressed as a fraction of the error remaining after each second. Defaults to pow(1.0 - 0.1, 60.0) meaning that Chipmunk fixes 10% of overlap each frame at 60Hz.

func (Space) SetCollisionPersistence

func (s Space) SetCollisionPersistence(p Timestamp)

SetCollisionPersistence sets the number of frames that contact information should persist. Defaults to 3. There is probably never a reason to change this value.

func (Space) SetCollisionSlop

func (s Space) SetCollisionSlop(sl float64)

SetCollisionSlop sets amount of encouraged penetration between colliding shapes. Used to reduce oscillating contacts and keep the collision cache warm. Defaults to 0.1. If you have poor simulation quality, increase this number as much as possible without allowing visible amounts of overlap.

func (Space) SetDamping

func (s Space) SetDamping(d float64)

SetDamping sets the damping rate expressed as the fraction of velocity bodies retain each second. A value of 0.9 would mean that each body's velocity will drop 10% per second. The default value is 1.0, meaning no damping is applied. Note this damping value is different than those of DampedSpring and DampedRotarySpring.

func (Space) SetDefaultCollisionHandler

func (s Space) SetDefaultCollisionHandler(beginFunc, preSolveFunc func(Space, Arbiter, interface{}) bool,
	postStepFunc, separateFunc func(Space, Arbiter, interface{}), data interface{})

SetDefaultCollisionHandler sets a default collision handler for this space. The default collision handler is invoked for each colliding pair of shapes that isn't explicitly handled by a specific collision handler. You can pass NULL for any function you don't want to implement.

func (Space) SetEnableContactGraph

func (s Space) SetEnableContactGraph(cg bool)

SetEnableContactGraph enables a rebuild of the contact graph during each step. Must be enabled to use the EachArbiter() method of Body. Disabled by default for a small performance boost. Enabled implicitly when the sleeping feature is enabled.

func (Space) SetGravity

func (s Space) SetGravity(g Vect)

SetGravity sets the gravity to pass to rigid bodies when integrating velocity.

func (Space) SetIdleSpeedThreshold

func (s Space) SetIdleSpeedThreshold(t float64)

SetIdleSpeedThreshold sets the speed threshold for a body to be considered idle. The default value of 0.0 means to let the space guess a good threshold based on gravity.

func (Space) SetIterations

func (s Space) SetIterations(i int)

SetIterations sets the number of iterations to use in the impulse solver to solve contacts.

func (Space) SetSleepTimeThreshold

func (s Space) SetSleepTimeThreshold(t float64)

SetSleepTimeThreshold sets the time a group of bodies must remain idle in order to fall asleep. Enabling sleeping also implicitly enables the the contact graph. The default value of math.Inf(1) disables the sleeping algorithm.

func (Space) SetUserData

func (s Space) SetUserData(data interface{})

SetUserData sets user definable data pointer. Generally this points to your game's controller or game state so you can access it when given a Space reference in a callback.

func (Space) SleepTimeThreshold

func (s Space) SleepTimeThreshold() float64

SleepTimeThreshold returns the time a groups of bodies must remain idle in order to "fall asleep".

func (Space) StaticBody

func (s Space) StaticBody() Body

StaticBody returns a dedicated static body for the space. You don't have to use it, but because it's memory is managed automatically with the space it's very convenient. You can set its user data pointer to something helpful if you want for callbacks.

func (Space) Step

func (s Space) Step(dt float64)

Step makes the space step forward in time by dt seconds.

func (Space) String

func (s Space) String() string

String converts a space to a human-readable string.

func (Space) UseSpatialHash

func (s Space) UseSpatialHash(dim float64, count int)

UseSpatialHash switches the space to use a spatial has as it's spatial index.

func (Space) UserData

func (s Space) UserData() interface{}

UserData returns user defined data.

type SpaceObject

type SpaceObject interface {
	Free()
	// contains filtered or unexported methods
}

SpaceObject is an interface every space object must implement.

type Timestamp

type Timestamp uint

Timestamp is type used for various timestamps.

type Vect

type Vect struct {
	X, Y float64
}

Vect is a 2D vector type.

func CentroidForPoly

func CentroidForPoly(verts []Vect) Vect

CentroidForPoly returns the natural centroid of a polygon.

func ConvexHull

func ConvexHull(verts []Vect, tolerance float64) ([]Vect, int)

ConvexHull calculates the convex hull of a given set of points. Returns the points and index of the first vertex in the hull came from the input. Tolerance is the allowed amount to shrink the hull when simplifying it. A tolerance of 0.0 creates an exact hull.

func Origin

func Origin() Vect

Origin returns zero vector.

func VectForAngle

func VectForAngle(a float64) Vect

VectForAngle returns the unit length vector for the given angle (radians).

func VectNew

func VectNew(x, y float64) Vect

VectNew returns a new 2D vector.

func (Vect) Add

func (a Vect) Add(b Vect) Vect

Add adds one vector to another.

func (Vect) Dist

func (a Vect) Dist(b Vect) float64

Dist returns distance between two vectors.

func (Vect) Div

func (v Vect) Div(x float64) Vect

Div divides vector by a value thus shrinking it.

func (Vect) Dot

func (v1 Vect) Dot(v2 Vect) float64

Dot returns a dot product of two vectors.

func (Vect) Length

func (v Vect) Length() float64

Length returns the length of vector.

func (Vect) Lerp

func (v1 Vect) Lerp(v2 Vect, t float64) Vect

Lerp does a spherical linear interpolation between two vectors.

func (Vect) LerpConst

func (v1 Vect) LerpConst(v2 Vect, a float64) Vect

LerpConst does a spherical linear interpolation between two vectors by no more than specific angle (radians).

func (Vect) Mul

func (v Vect) Mul(x float64) Vect

Mul multiples vector by a value thus scaling it.

func (Vect) Neg

func (v Vect) Neg() Vect

Neg negates vector.

func (Vect) String

func (v Vect) String() string

String converts a vector to a human-readable string.

func (Vect) Sub

func (a Vect) Sub(b Vect) Vect

Sub subtracts one vector from another.

func (Vect) ToAngle

func (v Vect) ToAngle() float64

ToAngle returns the angular direction vector is pointing in (radians).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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