cp

package
v0.0.0-...-793ea6c Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package cp is a wrapper for the Chipmunk 2D Physics Engine.

More information about Chipmunk can be found at:

http://chipmunk-physics.net/

This package uses the Chipmunk library, and as such it is also bound by it's license which can be found at:

https://github.com/slembcke/Chipmunk2D/blob/master/LICENSE.txt

Index

Constants

View Source
const (
	// Value for cpShape.group signifying that a shape is in no group.
	NO_GROUP = C.CP_NO_GROUP

	// Value for cpShape.layers signifying that a shape is in every layer.
	ALL_CATEGORIES = C.CP_ALL_CATEGORIES

	// cpCollisionType value internally reserved for hashing wildcard handlers.
	WILDCARD_COLLISION_TYPE = C.CP_WILDCARD_COLLISION_TYPE
)
View Source
const (
	MAX_CONTACTS_PER_ARBITER = C.CP_MAX_CONTACTS_PER_ARBITER
)

Variables

View Source
var (
	SHAPE_FILTER_ALL  = ShapeFilter{NO_GROUP, ALL_CATEGORIES, ALL_CATEGORIES}
	SHAPE_FILTER_NONE = ShapeFilter{NO_GROUP, 0 &^ ALL_CATEGORIES, 0 &^ ALL_CATEGORIES}
)
View Source
var (
	TransformIdentity = Transform{1, 0, 0, 1, 0, 0}
)

Identity transform matrix.

View Source
var (
	// Version string.
	VersionString = C.GoString(C.cpVersionString)
)
View Source
var (
	// The zero vector.
	Vzero = Vect{0, 0}
)

Functions

func AreaForCircle

func AreaForCircle(r1, r2 float64) float64

Calculate area of a hollow circle.

r1 and r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.

func AreaForPoly

func AreaForPoly(verts []Vect, radius float64) float64

Calculate 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, radius float64) float64

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

func BodyUpdatePosition

func BodyUpdatePosition(b *Body, dt float64)

Default position integration function.

func BodyUpdateVelocity

func BodyUpdateVelocity(b *Body, gravity Vect, damping, dt float64)

Default velocity integration function..

func ConvexHull

func ConvexHull(count int, verts, result *Vect, first *int, tol float64) int

Calculate the convex hull of a given set of points. Returns the count of points in the hull.

result must be a pointer to a  cpVect array with at least  count elements.
If  verts ==  result, then  verts will be reduced inplace.

first is an optional pointer to an integer to store where the first vertex
in the hull came from (i.e. verts[first] == result[0])

tol is the allowed amount to shrink the hull when simplifying it. A
tolerance of 0.0 creates an exact hull.

func Fabs

func Fabs(f float64) float64

Return the absolute value of a cpFloat.

func Fclamp

func Fclamp(f, min, max float64) float64

Clamp f to be between min and max.

func Fclamp01

func Fclamp01(f float64) float64

Clamp f to be between 0 and 1.

func Flerp

func Flerp(f1, f2, t float64) float64

Linearly interpolate (or extrapolate) between f1 and f2 by t percent.

func Flerpconst

func Flerpconst(f1, f2, d float64) float64

Linearly interpolate from f1 to f2 by no more than d.

func Fmax

func Fmax(a, b float64) float64

Return the max of two cpFloats.

func Fmin

func Fmin(a, b float64) float64

Return the min of two cpFloats.

func MomentForBox

func MomentForBox(m, width, height float64) float64

Calculate the moment of inertia for a solid box.

func MomentForBox2

func MomentForBox2(m float64, box BB) float64

Calculate the moment of inertia for a solid box.

func MomentForCircle

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

Calculate the moment of inertia for a circle.

r1 and r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.

func MomentForPoly

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

Calculate 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, radius float64) float64

Calculate the moment of inertia for a line segment.

Beveling radius is not supported.

func Vcross

func Vcross(v1, v2 Vect) float64

2D vector cross product analog.

The cross product of 2D vectors results in a 3D vector with only a z component.

This function returns the magnitude of the z value.

func Vdist

func Vdist(v1, v2 Vect) float64

Returns the distance between v1 and v2.

func Vdistsq

func Vdistsq(v1, v2 Vect) float64

Returns the squared distance between v1 and v2. Faster than cpvdist() when you only need to compare distances.

func Veql

func Veql(v1, v2 Vect) bool

Check if two vectors are equal. (Be careful when comparing floating point numbers!)

func Vlength

func Vlength(v Vect) float64

Returns the length of v.

func Vlengthsq

func Vlengthsq(v Vect) float64

Returns the squared length of v. Faster than cpvlength() when you only need to compare lengths.

func Vnear

func Vnear(v1, v2 Vect, dist float64) bool

Returns true if the distance between v1 and v2 is less than dist.

func Vtoangle

func Vtoangle(v Vect) float64

Returns the angular direction v is pointing in (in radians).

Types

type Arbiter

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

The Arbiter struct controls pairs of colliding shapes.

They are also used in conjuction with collision handler callbacks allowing you to retrieve information on the collision and control it.

func (*Arbiter) CallWildcardBeginA

func (a *Arbiter) CallWildcardBeginA(space *Space) bool

func (*Arbiter) CallWildcardBeginB

func (a *Arbiter) CallWildcardBeginB(space *Space) bool

func (*Arbiter) CallWildcardPostSolveA

func (a *Arbiter) CallWildcardPostSolveA(space *Space)

func (*Arbiter) CallWildcardPostSolveB

func (a *Arbiter) CallWildcardPostSolveB(space *Space)

func (*Arbiter) CallWildcardPreSolveA

func (a *Arbiter) CallWildcardPreSolveA(space *Space) bool

func (*Arbiter) CallWildcardPreSolveB

func (a *Arbiter) CallWildcardPreSolveB(space *Space) bool

func (*Arbiter) CallWildcardSeparateA

func (a *Arbiter) CallWildcardSeparateA(space *Space)

func (*Arbiter) CallWildcardSeparateB

func (a *Arbiter) CallWildcardSeparateB(space *Space)

func (*Arbiter) ContactPointSet

func (a *Arbiter) ContactPointSet() *ContactPointSet

Return a contact set from an arbiter.

func (*Arbiter) Count

func (a *Arbiter) Count() int

Get the number of contact points for this arbiter.

func (*Arbiter) Depth

func (a *Arbiter) Depth(i int) float64

Get the depth of the ith contact point.

func (*Arbiter) Friction

func (a *Arbiter) Friction() float64

func (*Arbiter) GetNormal

func (a *Arbiter) GetNormal() Vect

Get the normal of the collision.

func (*Arbiter) Ignore

func (a *Arbiter) Ignore() bool

func (*Arbiter) IsFirstContact

func (a *Arbiter) IsFirstContact() bool

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

func (*Arbiter) IsRemoval

func (a *Arbiter) IsRemoval() bool

Returns true if in separate callback due to a shape being removed from the space.

func (*Arbiter) Point1

func (a *Arbiter) Point1(i int) Vect

Get the position of the ith contact point on the surface of the first shape.

func (*Arbiter) Point2

func (a *Arbiter) Point2(i int) Vect

Get the position of the ith contact point on the surface of the second shape.

func (*Arbiter) Restitution

func (a *Arbiter) Restitution() float64

func (*Arbiter) SetContactPointSet

func (a *Arbiter) SetContactPointSet(set *ContactPointSet)

Replace the contact point set for an arbiter.

This can be a very powerful feature, but use it with caution!

func (*Arbiter) SetFriction

func (a *Arbiter) SetFriction(friction float64)

func (*Arbiter) SetRestitution

func (a *Arbiter) SetRestitution(restitution float64)

func (*Arbiter) SetSurfaceVelocity

func (a *Arbiter) SetSurfaceVelocity(vr Vect)

Override the relative surface velocity of the two shapes in contact.

By default this is calculated to be the difference of the two surface velocities clamped to the tangent plane.

func (*Arbiter) SetUserData

func (a *Arbiter) SetUserData(i interface{})

func (*Arbiter) Shapes

func (arb *Arbiter) Shapes() (a, b *Shape)

Return the colliding shapes involved for this arbiter.

The order of their cpSpace.collision_type values will match the order set when the collision handler was registered.

func (*Arbiter) SurfaceVelocity

func (a *Arbiter) SurfaceVelocity() Vect

Get the relative surface velocity of the two shapes in contact.

func (*Arbiter) TotalImpulse

func (a *Arbiter) TotalImpulse() Vect

Calculate 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 cpBodyEachArbiter callback.

func (*Arbiter) TotalKE

func (a *Arbiter) TotalKE() float64

Calculate 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 cpBodyEachArbiter callback.

func (*Arbiter) UserData

func (a *Arbiter) UserData() interface{}

type Array

type Array C.cpArray

type BB

type BB struct {
	L float64
	B float64
	R float64
	T float64
}

Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)

func BBNew

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

Convenience constructor for BB structs.

func BBNewForCircle

func BBNewForCircle(p Vect, r float64) BB

Constructs a BB for a circle with the given position and radius.

func BBNewForExtents

func BBNewForExtents(c Vect, hw, hh float64) BB

Constructs a BB centered on a point with the given extents (half sizes).

func (BB) Area

func (bb BB) Area() float64

Returns the area of the bounding box.

func (BB) Center

func (bb BB) Center() Vect

Returns the center of a bounding box.

func (BB) ClampVect

func (bb BB) ClampVect(v Vect) Vect

Clamp a vector to a bounding box.

func (BB) ContainsBB

func (bb BB) ContainsBB(other BB) bool

Returns true if other lies completely within bb.

func (BB) ContainsVect

func (bb BB) ContainsVect(v Vect) bool

Returns true if bb contains v.

func (BB) Expand

func (bb BB) Expand(v Vect) BB

Returns a bounding box that holds both bb and v.

func (BB) Intersects

func (a BB) Intersects(b BB) bool

Returns true if a and b intersect.

func (BB) IntersectsSegment

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

Return true if the bounding box intersects the line segment with ends a and b.

func (BB) Merge

func (a BB) Merge(b BB) BB

Returns a bounding box that holds both bounding boxes.

func (BB) MergedArea

func (a BB) MergedArea(b BB) float64

Merges a and b and returns the area of the merged bounding box.

func (BB) SegmentQuery

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

Returns the fraction along the segment query the BB is hit. Returns INFINITY if it doesn't hit.

func (BB) WrapVect

func (bb BB) WrapVect(v Vect) Vect

Wrap a vector to a bounding box.

type Bitmask

type Bitmask uint32

type Body

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

func BodyNew

func BodyNew(mass, moment float64) *Body

Allocate and initialize a Body.

func BodyNewKinematic

func BodyNewKinematic() *Body

Allocate and initialize a Body, and set it as a kinematic body.

func BodyNewStatic

func BodyNewStatic() *Body

Allocate and initialize a cpBody, and set it as a static body.

func (*Body) Activate

func (b *Body) Activate()

Wake up a sleeping or idle body.

func (*Body) ActivateStatic

func (b *Body) ActivateStatic(filter *Shape)

Wake up any sleeping or idle bodies touching a static body.

func (*Body) Angle

func (b *Body) Angle() float64

Get the angle of the body.

func (*Body) AngularVelocity

func (b *Body) AngularVelocity() float64

Get the angular velocity of the body.

func (*Body) ApplyForceAtLocalPoint

func (b *Body) ApplyForceAtLocalPoint(force, point Vect)

Apply a force to a body. Both the force and point are expressed in body local coordinates.

func (*Body) ApplyForceAtWorldPoint

func (b *Body) ApplyForceAtWorldPoint(force, point Vect)

Apply a force to a body. Both the force and point are expressed in world coordinates.

func (*Body) ApplyImpulseAtLocalPoint

func (b *Body) ApplyImpulseAtLocalPoint(impulse, point Vect)

Apply an impulse to a body. Both the impulse and point are expressed in body local coordinates.

func (*Body) ApplyImpulseAtWorldPoint

func (b *Body) ApplyImpulseAtWorldPoint(impulse, point Vect)

Apply an impulse to a body. Both the impulse and point are expressed in world coordinates.

func (*Body) BoxShapeNew

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

Allocate and initialize a box shaped polygon shape.

func (*Body) BoxShapeNew2

func (b *Body) BoxShapeNew2(box BB, radius float64) *Shape

Allocate and initialize an offset box shaped polygon shape.

func (*Body) CenterOfGravity

func (b *Body) CenterOfGravity() Vect

Get the offset of the center of gravity in body local coordinates.

func (*Body) CircleShapeNew

func (b *Body) CircleShapeNew(radius float64, offset Vect) *Shape

Allocate and initialize a circle shape.

func (*Body) EachArbiter

func (b *Body) EachArbiter(f func(b *Body, a *Arbiter))

Returns a slice of all arbiters that are currently active on the body.

func (*Body) EachConstraint

func (b *Body) EachConstraint(f func(b *Body, c *Constraint))

Returns a slice of all contraints attached to the body and added to the space.

func (*Body) EachShape

func (b *Body) EachShape(f func(b *Body, s *Shape))

Returns a slice of all shapes attached to the body and added to the space.

func (*Body) Force

func (b *Body) Force() Vect

Get the force applied to the body for the next time step.

func (*Body) Free

func (b *Body) Free()

Free is deprecated. Do not use it, it is no-op.

func (*Body) IsSleeping

func (b *Body) IsSleeping() bool

Returns true if the body is sleeping.

func (*Body) KineticEnergy

func (b *Body) KineticEnergy() float64

Get the amount of kinetic energy contained by the body.

func (*Body) LocalToWorld

func (b *Body) LocalToWorld(point Vect) Vect

Convert body relative/local coordinates to absolute/world coordinates.

func (*Body) Mass

func (b *Body) Mass() float64

Get the mass of the body.

func (*Body) Moment

func (b *Body) Moment() float64

Get the moment of inertia of the body.

func (*Body) PolyShapeNew

func (b *Body) PolyShapeNew(verts []Vect, transform Transform, radius float64) *Shape

Allocate and initialize a polygon shape with rounded corners.

A convex hull will be created from the vertexes.

func (*Body) Position

func (b *Body) Position() Vect

Get the position of a body.

func (*Body) Rotation

func (b *Body) Rotation() Vect

Get the rotation vector of the body. (The x basis vector of it's transform.)

func (*Body) SegmentShapeNew

func (bd *Body) SegmentShapeNew(a, b Vect, radius float64) *Shape

Allocate and initialize a segment shape.

func (*Body) SetAngle

func (b *Body) SetAngle(a float64)

Set the angle of a body.

func (*Body) SetAngularVelocity

func (b *Body) SetAngularVelocity(angularVelocity float64)

Set the angular velocity of the body.

func (*Body) SetCenterOfGravity

func (b *Body) SetCenterOfGravity(cog Vect)

Set the offset of the center of gravity in body local coordinates.

func (*Body) SetForce

func (b *Body) SetForce(force Vect)

Set the force applied to the body for the next time step.

func (*Body) SetMass

func (b *Body) SetMass(m float64)

Set the mass of the body.

func (*Body) SetMoment

func (b *Body) SetMoment(i float64)

Set the moment of inertia of the body.

func (*Body) SetPosition

func (b *Body) SetPosition(pos Vect)

Set the position of the body.

func (*Body) SetPositionUpdateFunc

func (b *Body) SetPositionUpdateFunc(f BodyPositionFunc)

Set the callback used to update a body's position.

NOTE: It's not generally recommended to override this.

func (*Body) SetTorque

func (b *Body) SetTorque(torque float64)

Set the torque applied to the body for the next time step.

func (*Body) SetType

func (b *Body) SetType(t BodyType)

Set the type of the body.

func (*Body) SetUserData

func (b *Body) SetUserData(userData interface{})

Set the user data interface assigned to the body.

func (*Body) SetVelocity

func (b *Body) SetVelocity(velocity Vect)

Set the velocity of the body.

func (*Body) SetVelocityUpdateFunc

func (b *Body) SetVelocityUpdateFunc(f BodyVelocityFunc)

Set the callback used to update a body's velocity.

func (*Body) Sleep

func (b *Body) Sleep()

Force a body to fall asleep immediately.

func (*Body) SleepWithGroup

func (b *Body) SleepWithGroup(group *Body)

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

func (*Body) Space

func (b *Body) Space() *Space

Get the space this body is added to.

func (*Body) Torque

func (b *Body) Torque() float64

Get the torque applied to the body for the next time step.

func (*Body) Type

func (b *Body) Type() BodyType

Get the type of the body.

func (*Body) UserData

func (b *Body) UserData() interface{}

Get the user data interface assigned to the body.

func (*Body) Velocity

func (b *Body) Velocity() Vect

Get the velocity of the body.

func (*Body) VelocityAtLocalPoint

func (b *Body) VelocityAtLocalPoint(point Vect) Vect

Get 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

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

func (*Body) WorldToLocal

func (b *Body) WorldToLocal(point Vect) Vect

Convert body absolute/world coordinates to relative/local coordinates.

type BodyPositionFunc

type BodyPositionFunc func(body *Body, dt float64)

Rigid body position update function type.

type BodyType

type BodyType int

Chipmunk's rigid body type. Rigid bodies hold the physical properties of an object like it's mass, and position and velocity of it's center of gravity. They don't have an shape on their own. They are given a shape by creating collision shapes (cpShape) that point to the body.

const (
	BODY_TYPE_DYNAMIC   BodyType = C.CP_BODY_TYPE_DYNAMIC
	BODY_TYPE_KINEMATIC BodyType = C.CP_BODY_TYPE_KINEMATIC
	BODY_TYPE_STATIC    BodyType = C.CP_BODY_TYPE_STATIC
)

type BodyVelocityFunc

type BodyVelocityFunc func(body *Body, gravity Vect, damping, dt float64)

Rigid body velocity update function type.

type CircleShape

type CircleShape C.cpCircleShape

type CollisionBeginFunc

type CollisionBeginFunc func(arb *Arbiter, space *Space, userData interface{}) bool

Collision begin event function callback type.

Returning false from a begin callback causes the collision to be ignored until the the separate callback is called when the objects stop colliding.

type CollisionHandler

type CollisionHandler struct {
	TypeA, TypeB  CollisionType
	BeginFunc     CollisionBeginFunc
	PreSolveFunc  CollisionPreSolveFunc
	PostSolveFunc CollisionPostSolveFunc
	SeparateFunc  CollisionSeparateFunc
	UserData      interface{}
}

type CollisionID

type CollisionID uint32

type CollisionPostSolveFunc

type CollisionPostSolveFunc func(arb *Arbiter, space *Space, userData interface{})

Collision post-solve event function callback type.

type CollisionPreSolveFunc

type CollisionPreSolveFunc func(arb *Arbiter, space *Space, userData interface{}) bool

Collision pre-solve event function callback type.

Returning false from a pre-step callback causes the collision to be ignored until the next step.

type CollisionSeparateFunc

type CollisionSeparateFunc func(arb *Arbiter, space *Space, userData interface{})

Collision separate event function callback type.

type CollisionType

type CollisionType uint64

type Constraint

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

func DampedRotarySpringNew

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

Allocate and initialize a damped rotary spring.

func DampedSpringNew

func DampedSpringNew(a, b *Body, anchorA, anchorB Vect, restLength, stiffness, damping float64) *Constraint

Allocate and initialize a damped spring.

func GearJointNew

func GearJointNew(a, b *Body, phase, ratio float64) *Constraint

Allocate and initialize a gear joint.

func GrooveJointNew

func GrooveJointNew(a, b *Body, grooveA, grooveB, anchorB Vect) *Constraint

Allocate and initialize a groove joint.

func PinJointNew

func PinJointNew(a, b *Body, anchorA, anchorB Vect) *Constraint

Allocate and initialize a pin joint.

func PivotJointNew

func PivotJointNew(a, b *Body, pivot Vect) *Constraint

Allocate and initialize a pivot joint.

func PivotJointNew2

func PivotJointNew2(a, b *Body, anchorA, anchorB Vect) *Constraint

Allocate and initialize a pivot joint with specific anchors.

func RatchetJointNew

func RatchetJointNew(a, b *Body, phase, ratchet float64) *Constraint

Allocate and initialize a ratchet joint.

func RotaryLimitJointNew

func RotaryLimitJointNew(a, b *Body, min, max float64) *Constraint

Allocate and initialize a damped rotary limit joint.

func SimpleMotorNew

func SimpleMotorNew(a, b *Body, rate float64) *Constraint

Allocate and initialize a simple motor.

func SlideJointNew

func SlideJointNew(a, b *Body, anchorA, anchorB Vect, min, max float64) *Constraint

Allocate and initialize a slide joint.

func (*Constraint) BodyA

func (c *Constraint) BodyA() *Body

Get the first body the constraint is attached to.

func (*Constraint) BodyB

func (c *Constraint) BodyB() *Body

Get the second body the constraint is attached to.

func (*Constraint) CollideBodies

func (c *Constraint) CollideBodies() bool

Get if the two bodies connected by the constraint are allowed to collide or not.

func (*Constraint) DampedRotarySpringDamping

func (c *Constraint) DampedRotarySpringDamping() float64

Get the damping of the spring.

func (*Constraint) DampedRotarySpringRestAngle

func (c *Constraint) DampedRotarySpringRestAngle() float64

Get the rest length of the spring.

func (*Constraint) DampedRotarySpringSetDamping

func (c *Constraint) DampedRotarySpringSetDamping(damping float64)

Set the damping of the spring.

func (*Constraint) DampedRotarySpringSetStiffness

func (c *Constraint) DampedRotarySpringSetStiffness(stiffness float64)

Set the stiffness of the spring in force/distance.

func (*Constraint) DampedRotarySpringSetTorqueFunc

func (c *Constraint) DampedRotarySpringSetTorqueFunc(f func(spring *Constraint, relativeAngle float64) float64)

Set the damping rotary spring torque callback function.

func (*Constraint) DampedRotarySpringStiffness

func (c *Constraint) DampedRotarySpringStiffness() float64

Get the stiffness of the spring in force/distance.

func (*Constraint) DampedRotarySpringTorqueFunc

func (c *Constraint) DampedRotarySpringTorqueFunc() func(spring *Constraint, relativeAngle float64) float64

Get the damping rotary spring torque callback function.

func (*Constraint) DampedSpringAnchorA

func (c *Constraint) DampedSpringAnchorA() Vect

Get the location of the first anchor relative to the first body.

func (*Constraint) DampedSpringAnchorB

func (c *Constraint) DampedSpringAnchorB() Vect

Get the location of the second anchor relative to the second body.

func (*Constraint) DampedSpringDamping

func (c *Constraint) DampedSpringDamping() float64

Get the damping of the spring.

func (*Constraint) DampedSpringForceFunc

func (c *Constraint) DampedSpringForceFunc() func(spring *Constraint, dist float64) float64

Get the damping rotary spring torque callback function.

func (*Constraint) DampedSpringRestLength

func (c *Constraint) DampedSpringRestLength() float64

Get the rest length of the spring.

func (*Constraint) DampedSpringSetAnchorA

func (c *Constraint) DampedSpringSetAnchorA(anchorA Vect)

Set the location of the first anchor relative to the first body.

func (*Constraint) DampedSpringSetAnchorB

func (c *Constraint) DampedSpringSetAnchorB(anchorA Vect)

Set the location of the second anchor relative to the second body.

func (*Constraint) DampedSpringSetDamping

func (c *Constraint) DampedSpringSetDamping(damping float64)

Set the damping of the spring.

func (*Constraint) DampedSpringSetForceFunc

func (c *Constraint) DampedSpringSetForceFunc(f func(spring *Constraint, dist float64) float64)

Set the damping spring force callback function.

func (*Constraint) DampedSpringSetRestLength

func (c *Constraint) DampedSpringSetRestLength(restLength float64)

Set the rest length of the spring.

func (*Constraint) DampedSpringSetStiffness

func (c *Constraint) DampedSpringSetStiffness(stiffness float64)

Set the stiffness of the spring in force/distance.

func (*Constraint) DampedSpringStiffness

func (c *Constraint) DampedSpringStiffness() float64

Get the stiffness of the spring in force/distance.

func (*Constraint) ErrorBias

func (c *Constraint) ErrorBias() float64

Get rate at which joint error is corrected.

func (*Constraint) Free

func (c *Constraint) Free()

Free is deprecated. Do not use it, it is no-op.

func (*Constraint) GearJointPhase

func (c *Constraint) GearJointPhase() float64

Get the phase offset of the gears.

func (*Constraint) GearJointRatio

func (c *Constraint) GearJointRatio() float64

Get the angular distance of each ratchet.

func (*Constraint) GearJointSetPhase

func (c *Constraint) GearJointSetPhase(phase float64)

Set the phase offset of the gears.

func (*Constraint) GearJointSetRatio

func (c *Constraint) GearJointSetRatio(ratio float64)

Set the ratio of a gear joint.

func (*Constraint) GrooveJointAnchorB

func (c *Constraint) GrooveJointAnchorB() Vect

Get the location of the second anchor relative to the second body.

func (*Constraint) GrooveJointGrooveA

func (c *Constraint) GrooveJointGrooveA() Vect

Get the first endpoint of the groove relative to the first body.

func (*Constraint) GrooveJointGrooveB

func (c *Constraint) GrooveJointGrooveB() Vect

Get the first endpoint of the groove relative to the first body.

func (*Constraint) GrooveJointSetAnchorB

func (c *Constraint) GrooveJointSetAnchorB(grooveB Vect)

Set the location of the second anchor relative to the second body.

func (*Constraint) GrooveJointSetGrooveA

func (c *Constraint) GrooveJointSetGrooveA(grooveA Vect)

Set the first endpoint of the groove relative to the first body.

func (*Constraint) GrooveJointSetGrooveB

func (c *Constraint) GrooveJointSetGrooveB(grooveB Vect)

Set the first endpoint of the groove relative to the first body.

func (*Constraint) Impulse

func (c *Constraint) Impulse() float64

Get the last impulse applied by this constraint.

func (*Constraint) IsDampedRotarySpring

func (c *Constraint) IsDampedRotarySpring() bool

Check if a constraint is a damped rotary spring.

func (*Constraint) IsDampedSpring

func (c *Constraint) IsDampedSpring() bool

Check if a constraint is a damped spring.

func (*Constraint) IsGearJoint

func (c *Constraint) IsGearJoint() bool

Check if a constraint is a ratchet joint.

func (*Constraint) IsGrooveJoint

func (c *Constraint) IsGrooveJoint() bool

Check if a constraint is a groove joint.

func (*Constraint) IsPinJoint

func (c *Constraint) IsPinJoint() bool

Check if a constraint is a pin joint.

func (*Constraint) IsPivotJoint

func (c *Constraint) IsPivotJoint() bool

Check if a constraint is a pivot joint.

func (*Constraint) IsRatchetJoint

func (c *Constraint) IsRatchetJoint() bool

Check if a constraint is a ratchet joint.

func (*Constraint) IsRotaryLimitJoint

func (c *Constraint) IsRotaryLimitJoint() bool

Check if a constraint is a rotary limit joint.

func (*Constraint) IsSimpleMotor

func (c *Constraint) IsSimpleMotor() bool

Check if a constraint is a simple motor.

func (*Constraint) IsSlideJoint

func (c *Constraint) IsSlideJoint() bool

Check if a constraint is a slide joint.

func (*Constraint) MaxBias

func (c *Constraint) MaxBias() float64

Get the maximum rate at which joint error is corrected.

func (*Constraint) MaxForce

func (c *Constraint) MaxForce() float64

Get the maximum force that this constraint is allowed to use.

func (*Constraint) PinJointAnchorA

func (c *Constraint) PinJointAnchorA() Vect

Get the location of the first anchor relative to the first body.

func (*Constraint) PinJointAnchorB

func (c *Constraint) PinJointAnchorB() Vect

Get the location of the second anchor relative to the second body.

func (*Constraint) PinJointDist

func (c *Constraint) PinJointDist() float64

Get the distance the joint will maintain between the two anchors.

func (*Constraint) PinJointSetAnchorA

func (c *Constraint) PinJointSetAnchorA(anchorA Vect)

Set the location of the first anchor relative to the first body.

func (*Constraint) PinJointSetAnchorB

func (c *Constraint) PinJointSetAnchorB(anchorB Vect)

Set the location of the second anchor relative to the second body.

func (*Constraint) PinJointSetDist

func (c *Constraint) PinJointSetDist(dist float64)

Set the distance the joint will maintain between the two anchors.

func (*Constraint) PivotJointAnchorA

func (c *Constraint) PivotJointAnchorA() Vect

Get the location of the first anchor relative to the first body.

func (*Constraint) PivotJointAnchorB

func (c *Constraint) PivotJointAnchorB() Vect

Get the location of the second anchor relative to the second body.

func (*Constraint) PivotJointSetAnchorA

func (c *Constraint) PivotJointSetAnchorA(anchorA Vect)

Set the location of the first anchor relative to the first body.

func (*Constraint) PivotJointSetAnchorB

func (c *Constraint) PivotJointSetAnchorB(anchorB Vect)

Set the location of the second anchor relative to the second body.

func (*Constraint) PostSolveFunc

func (c *Constraint) PostSolveFunc() func(*Constraint, *Space)

Get the post-solve function that is called before the solver runs.

func (*Constraint) PreSolveFunc

func (c *Constraint) PreSolveFunc() func(*Constraint, *Space)

Get the pre-solve function that is called before the solver runs.

func (*Constraint) RatchetJointAngle

func (c *Constraint) RatchetJointAngle() float64

Get the angle of the current ratchet tooth.

func (*Constraint) RatchetJointPhase

func (c *Constraint) RatchetJointPhase() float64

Get the phase offset of the ratchet.

func (*Constraint) RatchetJointRatchet

func (c *Constraint) RatchetJointRatchet() float64

Get the angular distance of each ratchet.

func (*Constraint) RatchetJointSetAngle

func (c *Constraint) RatchetJointSetAngle(angle float64)

Set the angle of the current ratchet tooth.

func (*Constraint) RatchetJointSetPhase

func (c *Constraint) RatchetJointSetPhase(phase float64)

Get the phase offset of the ratchet.

func (*Constraint) RatchetJointSetRatchet

func (c *Constraint) RatchetJointSetRatchet(ratchet float64)

Set the angular distance of each ratchet.

func (*Constraint) RotaryLimitJointMax

func (c *Constraint) RotaryLimitJointMax() float64

Get the maximum distance the joint will maintain between the two anchors.

func (*Constraint) RotaryLimitJointMin

func (c *Constraint) RotaryLimitJointMin() float64

Get the minimum distance the joint will maintain between the two anchors.

func (*Constraint) RotaryLimitJointSetMax

func (c *Constraint) RotaryLimitJointSetMax(max float64)

Set the maximum distance the joint will maintain between the two anchors.

func (*Constraint) RotaryLimitJointSetMin

func (c *Constraint) RotaryLimitJointSetMin(min float64)

Set the minimum distance the joint will maintain between the two anchors.

func (*Constraint) RotarySpringSetRestAngle

func (c *Constraint) RotarySpringSetRestAngle(restAngle float64)

Set the rest length of the spring.

func (*Constraint) SetCollideBodies

func (c *Constraint) SetCollideBodies(collideBodies bool)

Set if the two bodies connected by the constraint are allowed to collide or not. (defaults to cpFalse)

func (*Constraint) SetErrorBias

func (c *Constraint) SetErrorBias(errorBias float64)

Set rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

func (*Constraint) SetMaxBias

func (c *Constraint) SetMaxBias(maxBias float64)

Set the maximum rate at which joint error is corrected. (defaults to INFINITY)

func (*Constraint) SetMaxForce

func (c *Constraint) SetMaxForce(maxForce float64)

Set the maximum force that this constraint is allowed to use. (defaults to INFINITY)

func (*Constraint) SetPostSolveFunc

func (c *Constraint) SetPostSolveFunc(f func(*Constraint, *Space))

Set the post-solve function that is called before the solver runs.

func (*Constraint) SetPreSolveFunc

func (c *Constraint) SetPreSolveFunc(f func(*Constraint, *Space))

Set the pre-solve function that is called before the solver runs.

func (*Constraint) SetUserData

func (c *Constraint) SetUserData(i interface{})

Set the user definable data pointer for this constraint

func (*Constraint) SimpleMotorRate

func (c *Constraint) SimpleMotorRate() float64

Get the rate of the motor.

func (*Constraint) SimpleMotorSetRate

func (c *Constraint) SimpleMotorSetRate(rate float64)

Set the rate of the motor.

func (*Constraint) SlideJointAnchorA

func (c *Constraint) SlideJointAnchorA() Vect

Get the location of the first anchor relative to the first body.

func (*Constraint) SlideJointAnchorB

func (c *Constraint) SlideJointAnchorB() Vect

Get the location of the second anchor relative to the second body.

func (*Constraint) SlideJointMax

func (c *Constraint) SlideJointMax() float64

Get the maximum distance the joint will maintain between the two anchors.

func (*Constraint) SlideJointMin

func (c *Constraint) SlideJointMin() float64

Get the minimum distance the joint will maintain between the two anchors.

func (*Constraint) SlideJointSetAnchorA

func (c *Constraint) SlideJointSetAnchorA(anchorA Vect)

Set the location of the first anchor relative to the first body.

func (*Constraint) SlideJointSetAnchorB

func (c *Constraint) SlideJointSetAnchorB(anchorB Vect)

Set the location of the second anchor relative to the second body.

func (*Constraint) SlideJointSetMax

func (c *Constraint) SlideJointSetMax(max float64)

Set the maximum distance the joint will maintain between the two anchors.

func (*Constraint) SlideJointSetMin

func (c *Constraint) SlideJointSetMin(min float64)

Set the minimum distance the joint will maintain between the two anchors.

func (*Constraint) Space

func (c *Constraint) Space() *Space

Get the Space this constraint is added to.

func (*Constraint) UserData

func (c *Constraint) UserData() interface{}

Get the user definable data pointer for this constraint

type ConstraintPostSolveFunc

type ConstraintPostSolveFunc func(c *Constraint, space *Space)

Callback function type that gets called after solving a joint.

type ConstraintPreSolveFunc

type ConstraintPreSolveFunc func(c *Constraint, space *Space)

Callback function type that gets called before solving a joint.

type ContactBufferHeader

type ContactBufferHeader C.cpContactBufferHeader

type ContactPoint

type ContactPoint struct {
	// The position of the contact on the surface of each shape.
	Point1, Point2 Vect

	// Penetration distance of the two shapes. Overlapping means it will be
	// negative.
	//
	// This value is calculated as Vdot(Vsub(point2, point1), normal) and is
	// ignored by arbiter.SetContactPointSet().
	Distance float64
}

type ContactPointSet

type ContactPointSet struct {
	// The number of contact points in the set.
	Count Int

	// The normal of the collision.
	Normal Vect

	// The array of contact points.
	Points [MAX_CONTACTS_PER_ARBITER]ContactPoint
}

A struct that wraps up the important collision data for an arbiter.

type DampedRotarySpring

type DampedRotarySpring C.cpDampedRotarySpring

type DampedSpring

type DampedSpring C.cpDampedSpring

type DataPointer

type DataPointer unsafe.Pointer

type GearJoint

type GearJoint C.cpGearJoint

type GrooveJoint

type GrooveJoint C.cpGrooveJoint

type Group

type Group uint64

type HashSet

type HashSet C.cpHashSet

type HashValue

type HashValue uint64

type Int

type Int C.int

type Mat2x2

type Mat2x2 struct {
	A float64
	B float64
	C float64
	D float64
}

Row major [[a, b][c, d]]

func Mat2x2New

func Mat2x2New(a, b, c, d float64) Mat2x2

func (Mat2x2) Transform

func (m Mat2x2) Transform(v Vect) Vect

type PinJoint

type PinJoint C.cpPinJoint

type PivotJoint

type PivotJoint C.cpPivotJoint

type PointQueryInfo

type PointQueryInfo struct {
	// The nearest shape, nil if no shape was within range.
	Shape *Shape

	// The closest point on the shape's surface. (in world space coordinates)
	Point Vect

	// The distance to the point. The distance is negative if the point is
	// inside the shape.
	Distance float64

	// The gradient of the signed distance function.
	//
	// The same as info.p/info.d, but accurate even for very small values of
	// info.d.
	Gradient Vect
}

Nearest point query info struct.

type PolyShape

type PolyShape C.cpPolyShape

type RatchetJoint

type RatchetJoint C.cpRatchetJoint

type RotaryLimitJoint

type RotaryLimitJoint C.cpRotaryLimitJoint

type SegmentQueryInfo

type SegmentQueryInfo struct {
	// The shape that was hit, nil if no collision occured.
	Shape *Shape

	// The point of impact.
	Point Vect

	// The normal of the surface hit.
	Normal Vect

	// The normalized distance along the query segment in the range [0, 1].
	Alpha float64
}

Segment query info struct.

type SegmentShape

type SegmentShape C.cpSegmentShape

type Shape

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

The Shape struct defines the shape of a rigid body.

func (*Shape) Area

func (s *Shape) Area() float64

Get the calculated area of this shape.

func (*Shape) BB

func (s *Shape) BB() BB

Get the bounding box that contains the shape given it's current position and angle.

func (*Shape) Body

func (s *Shape) Body() *Body

The cpBody this shape is connected to.

func (*Shape) CacheBB

func (s *Shape) CacheBB() BB

Update, cache and return the bounding box of a shape based on the body it's attached to.

func (*Shape) CenterOfGravity

func (s *Shape) CenterOfGravity() Vect

Get the centroid of this shape.

func (*Shape) CircleOffset

func (s *Shape) CircleOffset() Vect

Get the offset of a circle shape.

func (*Shape) CircleRadius

func (s *Shape) CircleRadius() float64

Get the radius of a circle shape.

func (*Shape) CircleShapeSetOffset

func (shape *Shape) CircleShapeSetOffset(offset Vect)

Set the offset of a circle shape.

This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.

func (*Shape) CircleShapeSetRadius

func (shape *Shape) CircleShapeSetRadius(radius float64)

Set the radius of a circle shape.

This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.

func (*Shape) CollisionType

func (s *Shape) CollisionType() CollisionType

Get the collision type of this shape.

func (*Shape) Density

func (s *Shape) Density() float64

Get the density of the shape if you are having Chipmunk calculate mass properties for you.

func (*Shape) Elasticity

func (s *Shape) Elasticity() float64

Get the elasticity of this shape.

func (*Shape) Filter

func (s *Shape) Filter() ShapeFilter

Get the collision filtering parameters of this shape.

func (*Shape) Free

func (s *Shape) Free()

Free is deprecated. Do not use it, it is no-op.

func (*Shape) Friction

func (s *Shape) Friction() float64

Get the friction of this shape.

func (*Shape) Mass

func (s *Shape) Mass() float64

Get the mass of the shape if you are having Chipmunk calculate mass properties for you.

func (*Shape) Moment

func (s *Shape) Moment() float64

Get the calculated moment of inertia for this shape.

func (*Shape) PointQuery

func (s *Shape) PointQuery(p Vect) (out *PointQueryInfo, d float64)

Perform a nearest point query. It finds the closest point on the surface of shape to a specific point.

The value returned is the distance between the points. A negative distance means the point is inside the shape.

func (*Shape) PolyCount

func (s *Shape) PolyCount() int

Get the number of verts in a polygon shape.

func (*Shape) PolyRadius

func (s *Shape) PolyRadius() float64

Get the radius of a polygon shape.

func (*Shape) PolyShapeSetRadius

func (shape *Shape) PolyShapeSetRadius(radius float64)

Set the radius of a poly shape.

This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.

func (*Shape) PolyShapeSetVerts

func (shape *Shape) PolyShapeSetVerts(verts []Vect, transform Transform)

Set the vertexes of a poly shape.

This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.

func (*Shape) PolyShapeSetVertsRaw

func (shape *Shape) PolyShapeSetVertsRaw(verts []Vect)

Set the vertexes of a poly shape.

This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.

func (*Shape) PolyVert

func (s *Shape) PolyVert(index int) Vect

Get the ith vertex of a polygon shape.

func (*Shape) SegmentA

func (s *Shape) SegmentA() Vect

Get the first endpoint of a segment shape.

func (*Shape) SegmentB

func (s *Shape) SegmentB() Vect

Get the second endpoint of a segment shape.

func (*Shape) SegmentNormal

func (s *Shape) SegmentNormal() Vect

Get the normal of a segment shape.

func (*Shape) SegmentQuery

func (s *Shape) SegmentQuery(a, b Vect, radius float64) (info *SegmentQueryInfo, ret bool)

Perform a segment query against a shape.

func (*Shape) SegmentRadius

func (s *Shape) SegmentRadius() float64

Get the first endpoint of a segment shape.

func (*Shape) SegmentSetNeighbors

func (s *Shape) SegmentSetNeighbors(prev, next Vect)

Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps.

func (*Shape) SegmentShapeSetEndpoints

func (shape *Shape) SegmentShapeSetEndpoints(a, b Vect)

Set the endpoints of a segment shape.

This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.

func (*Shape) SegmentShapeSetRadius

func (shape *Shape) SegmentShapeSetRadius(radius float64)

Set the radius of a segment shape.

This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.

func (*Shape) Sensor

func (s *Shape) Sensor() bool

Get if the shape is set to be a sensor or not.

func (*Shape) SetBody

func (s *Shape) SetBody(b *Body)

Set the cpBody this shape is connected to.

Can only be used if the shape is not currently added to a space.

func (*Shape) SetCollisionType

func (s *Shape) SetCollisionType(collisionType CollisionType)

Set the collision type of this shape.

func (*Shape) SetDensity

func (s *Shape) SetDensity(density float64)

Set the density of this shape to have Chipmunk calculate mass properties for you.

func (*Shape) SetElasticity

func (s *Shape) SetElasticity(elasticity float64)

Set the elasticity of this shape.

func (*Shape) SetFilter

func (s *Shape) SetFilter(filter ShapeFilter)

Set the collision filtering parameters of this shape.

func (*Shape) SetFriction

func (s *Shape) SetFriction(friction float64)

Set the friction of this shape.

func (*Shape) SetMass

func (s *Shape) SetMass(mass float64)

Set the mass of this shape to have Chipmunk calculate mass properties for you.

func (*Shape) SetSensor

func (s *Shape) SetSensor(sensor bool)

Set if the shape is a sensor or not.

func (*Shape) SetSurfaceVelocity

func (s *Shape) SetSurfaceVelocity(surfaceVelocity Vect)

Set the surface velocity of this shape.

func (*Shape) SetUserData

func (s *Shape) SetUserData(i interface{})

Set the user definable data pointer of this shape.

func (*Shape) ShapesCollide

func (a *Shape) ShapesCollide(b *Shape) ContactPointSet

Return contact information about two shapes.

func (*Shape) Space

func (s *Shape) Space() *Space

The cpSpace this body is added to.

func (*Shape) SurfaceVelocity

func (s *Shape) SurfaceVelocity() Vect

Get the surface velocity of this shape.

func (*Shape) Update

func (s *Shape) Update(transform Transform) BB

Update, cache and return the bounding box of a shape with an explicit transformation.

func (*Shape) UserData

func (s *Shape) UserData() interface{}

Get the user definable data interface of this shape.

type ShapeFilter

type ShapeFilter struct {
	Group      Group
	Categories Bitmask
	Mask       Bitmask
}

func ShapeFilterNew

func ShapeFilterNew(group Group, categories, mask Bitmask) ShapeFilter

type SimpleMotorJoint

type SimpleMotorJoint C.cpSimpleMotorJoint

type SlideJoint

type SlideJoint C.cpSlideJoint

type Space

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

func SpaceNew

func SpaceNew() *Space

Allocate and initialize a cpSpace.

func (*Space) AddBody

func (s *Space) AddBody(body *Body) *Body

Add a rigid body to the simulation.

func (*Space) AddCollisionHandler

func (s *Space) AddCollisionHandler(a, b CollisionType, handler *CollisionHandler)

func (*Space) AddConstraint

func (s *Space) AddConstraint(constraint *Constraint) *Constraint

Add a constraint to the simulation.

func (*Space) AddDefaultCollisionHandler

func (s *Space) AddDefaultCollisionHandler()

func (*Space) AddPostStepCallback

func (s *Space) AddPostStepCallback(f func())

Schedule a post-step callback to be called when space.Step() finishes.

func (*Space) AddShape

func (s *Space) AddShape(shape *Shape) *Shape

Add 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) AddWildcardHandler

func (s *Space) AddWildcardHandler(t CollisionType, handler *CollisionHandler)

func (*Space) BBQuery

func (s *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data interface{})

Perform a fast rectangle query on the space calling func 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

Determines 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) CollisionPersistence

func (s *Space) CollisionPersistence() Timestamp

Number of frames that contact information should persist.

Defaults to 3. There is probably never a reason to change this value.

func (*Space) CollisionSlop

func (s *Space) CollisionSlop() float64

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) ContainsBody

func (s *Space) ContainsBody(body *Body) bool

Test if a rigid body has been added to the space.

func (*Space) ContainsConstraint

func (s *Space) ContainsConstraint(constraint *Constraint) bool

Test if a constraint has been added to the space.

func (*Space) ContainsShape

func (s *Space) ContainsShape(shape *Shape) bool

Test if a collision shape has been added to the space.

func (*Space) CurrentTimeStep

func (s *Space) CurrentTimeStep() float64

Returns the current (or most recent) time step used with the given space. Useful from callbacks if your time step is not a compile-time global.

func (*Space) Damping

func (s *Space) Damping() float64

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.

This damping value is different than those of cpDampedSpring and cpDampedRotarySpring.

func (*Space) DebugDraw

func (s *Space) DebugDraw(options *SpaceDebugDrawOptions)

DebugDraw draws the space using the debug draw options (which includes callbacks for performing the actual drawing). All options fields are entirely optional (callbacks may be nil, etc).

options.Data is arbitrary user data fed into the callbacks (this is just for a 1:1 mapping of chipmunks API, in Go you can just use a closure and access the data itself not storing it inside options.Data).

func (*Space) EachBody

func (s *Space) EachBody(space *Space, f func(b *Body))

Space/body iterator callback function type.

func (*Space) EachConstraint

func (s *Space) EachConstraint(space *Space, f func(c *Constraint))

Call f for each shape in the space.

func (*Space) EachShape

func (s *Space) EachShape(space *Space, f func(s *Shape))

Call f for each shape in the space.

func (*Space) Free

func (s *Space) Free()

Free is deprecated. Do not use it, it is no-op.

func (*Space) Gravity

func (s *Space) Gravity() Vect

Gravity to pass to rigid bodies when integrating velocity.

func (*Space) IdleSpeedThreshold

func (s *Space) IdleSpeedThreshold() float64

Speed threshold for a body to be considered idle.

The default value of 0 means to let the space guess a good threshold based on gravity.

func (*Space) IsLocked

func (s *Space) IsLocked() bool

returns true from inside a callback when objects cannot be added/removed.

func (*Space) Iterations

func (s *Space) Iterations() int

Number of iterations to use in the impulse solver to solve contacts and other constraints.

func (*Space) PointQuery

func (s *Space) PointQuery(point Vect, maxDistance float64, filter ShapeFilter, f SpacePointQueryFunc, data interface{})

Query the space at a point and call f for each shape found.

func (*Space) PointQueryNearest

func (s *Space) PointQueryNearest(point Vect, maxDistance float64, filter ShapeFilter) (shape *Shape, out *PointQueryInfo)

Query the space at a point and return the nearest shape found. Returns NULL if no shapes were found.

func (*Space) ReindexShape

func (s *Space) ReindexShape(shape *Shape)

Update the collision detection data for a specific shape in the space.

func (*Space) ReindexShapesForBody

func (s *Space) ReindexShapesForBody(body *Body)

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

func (*Space) ReindexStatic

func (s *Space) ReindexStatic()

Update the collision detection info for the static shapes in the space.

func (*Space) RemoveBody

func (s *Space) RemoveBody(body *Body)

Remove a rigid body from the simulation.

func (*Space) RemoveConstraint

func (s *Space) RemoveConstraint(constraint *Constraint)

Remove a constraint from the simulation.

func (*Space) RemoveShape

func (s *Space) RemoveShape(shape *Shape)

Remove a collision shape from the simulation.

func (*Space) SegmentQuery

func (s *Space) SegmentQuery(start, end Vect, radius float64, filter ShapeFilter, f SpaceSegmentQueryFunc, data interface{})

Perform a directed line segment query (like a raycast) against the space calling f for each shape intersected.

func (*Space) SegmentQueryFirst

func (s *Space) SegmentQueryFirst(start, end Vect, radius float64, filter ShapeFilter) (shape *Shape, out *SegmentQueryInfo)

Perform a directed line segment query (like a raycast) against the space and return the first shape hit. Returns NULL if no shapes were hit.

func (*Space) SetCollisionBias

func (s *Space) SetCollisionBias(collisionBias float64)

func (*Space) SetCollisionPersistence

func (s *Space) SetCollisionPersistence(collisionPersistence Timestamp)

func (*Space) SetCollisionSlop

func (s *Space) SetCollisionSlop(collisionSlop float64)

func (*Space) SetDamping

func (s *Space) SetDamping(damping float64)

func (*Space) SetGravity

func (s *Space) SetGravity(gravity Vect)

func (*Space) SetIdleSpeedThreshold

func (s *Space) SetIdleSpeedThreshold(idleSpeedThreshold float64)

func (*Space) SetIterations

func (s *Space) SetIterations(iterations int)

func (*Space) SetSleepTimeThreshold

func (s *Space) SetSleepTimeThreshold(sleepTimeThreshold float64)

func (*Space) SetUserData

func (s *Space) SetUserData(i interface{})

func (*Space) ShapeQuery

func (s *Space) ShapeQuery(shape *Shape, f SpaceShapeQueryFunc, data interface{}) bool

Query a space for any shapes overlapping the given shape and call func for each shape found.

func (*Space) SleepTimeThreshold

func (s *Space) SleepTimeThreshold() float64

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 INFINITY disables the sleeping algorithm.

func (*Space) StaticBody

func (s *Space) StaticBody() *Body

The Space provided static body for a given cpSpace.

This is merely provided for convenience and you are not required to use it.

func (*Space) Step

func (s *Space) Step(dt float64)

Step the space forward in time by dt.

func (*Space) UseSpatialHash

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

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

func (*Space) UserData

func (s *Space) UserData() interface{}

User definable data interface.

Generally this points to your game's controller or game state class so you can access it when given a cpSpace reference in a callback.

type SpaceArbiterApplyImpulseFunc

type SpaceArbiterApplyImpulseFunc func(arb *Arbiter)

type SpaceBBQueryFunc

type SpaceBBQueryFunc func(shape *Shape, data interface{})

Rectangle Query callback function type.

type SpaceDebugColor

type SpaceDebugColor struct {
	R float32
	G float32
	B float32
	A float32
}

type SpaceDebugDrawCircleImpl

type SpaceDebugDrawCircleImpl func(pos Vect, angle, radius float64, outlineColor, fillColor SpaceDebugColor, data interface{})

type SpaceDebugDrawColorForShapeImpl

type SpaceDebugDrawColorForShapeImpl func(shape *Shape, data interface{}) SpaceDebugColor

type SpaceDebugDrawDotImpl

type SpaceDebugDrawDotImpl func(size float64, pos Vect, color SpaceDebugColor, data interface{})

type SpaceDebugDrawFatSegmentImpl

type SpaceDebugDrawFatSegmentImpl func(a, b Vect, radius float64, outlineColor, fillColor SpaceDebugColor, data interface{})

type SpaceDebugDrawFlags

type SpaceDebugDrawFlags int
const (
	SPACE_DEBUG_DRAW_SHAPES           SpaceDebugDrawFlags = C.CP_SPACE_DEBUG_DRAW_SHAPES
	SPACE_DEBUG_DRAW_CONSTRAINTS      SpaceDebugDrawFlags = C.CP_SPACE_DEBUG_DRAW_CONSTRAINTS
	SPACE_DEBUG_DRAW_COLLISION_POINTS SpaceDebugDrawFlags = C.CP_SPACE_DEBUG_DRAW_COLLISION_POINTS
)

type SpaceDebugDrawOptions

type SpaceDebugDrawOptions struct {
	DrawCircle     SpaceDebugDrawCircleImpl
	DrawSegment    SpaceDebugDrawSegmentImpl
	DrawFatSegment SpaceDebugDrawFatSegmentImpl
	DrawPolygon    SpaceDebugDrawPolygonImpl
	DrawDot        SpaceDebugDrawDotImpl

	ColorForShape SpaceDebugDrawColorForShapeImpl

	Flags               SpaceDebugDrawFlags
	ShapeOutlineColor   SpaceDebugColor
	ConstraintColor     SpaceDebugColor
	CollisionPointColor SpaceDebugColor

	Data interface{}
}

type SpaceDebugDrawPolygonImpl

type SpaceDebugDrawPolygonImpl func(verts []Vect, radius float64, outlineColor, fillColor SpaceDebugColor, data interface{})

type SpaceDebugDrawSegmentImpl

type SpaceDebugDrawSegmentImpl func(a, b Vect, color SpaceDebugColor, data interface{})

type SpacePointQueryFunc

type SpacePointQueryFunc func(shape *Shape, point Vect, distance float64, gradient Vect, data interface{})

Nearest point query callback function type.

type SpaceSegmentQueryFunc

type SpaceSegmentQueryFunc func(shape *Shape, point, normal Vect, alpha float64, data interface{})

Nearest point query callback function type.

type SpaceShapeQueryFunc

type SpaceShapeQueryFunc func(shape *Shape, points *ContactPointSet, data interface{})

Shape query callback function type.

type Timestamp

type Timestamp uint32

type Transform

type Transform struct {
	A  float64
	B  float64
	C  float64
	D  float64
	Tx float64
	Ty float64
}

Column major affine transform.

func TransformAxialScale

func TransformAxialScale(axis, pivot Vect, scale float64) Transform

func TransformBoneScale

func TransformBoneScale(v0, v1 Vect) Transform

func TransformNew

func TransformNew(a, b, c, d, tx, ty float64) Transform

Construct a new transform matrix.

(a, b) is the x basis vector.

(c, d) is the y basis vector.

(tx, ty) is the translation.

func TransformNewTranspose

func TransformNewTranspose(a, c, tx, b, d, ty float64) Transform

Construct a new transform matrix in transposed order.

func TransformOrtho

func TransformOrtho(bb BB) Transform

func TransformRigid

func TransformRigid(translate Vect, radians float64) Transform

Create a rigid transformation matrix. (translation + rotation)

func TransformRotate

func TransformRotate(radians float64) Transform

Create a rotation matrix.

func TransformScale

func TransformScale(scaleX, scaleY float64) Transform

Create a scale matrix.

func TransformTranslate

func TransformTranslate(translate Vect) Transform

Create a translation matrix.

func (Transform) BB

func (t Transform) BB(bb BB) BB

Transform a BB.

func (Transform) Inverse

func (t Transform) Inverse() Transform

Get the inverse of a transform matrix.

func (Transform) Mult

func (t1 Transform) Mult(t2 Transform) Transform

Multiply two transformation matrices.

func (Transform) Point

func (t Transform) Point(p Vect) Vect

Transform an absolute point. (i.e. a vertex)

func (Transform) RigidInverse

func (t Transform) RigidInverse() Transform

Fast inverse of a rigid transformation matrix.

func (Transform) Vect

func (t Transform) Vect(v Vect) Vect

Transform a vector (i.e. a normal)

func (Transform) Wrap

func (outer Transform) Wrap(inner Transform) Transform

func (Transform) WrapInverse

func (outer Transform) WrapInverse(inner Transform) Transform

type Vect

type Vect struct {
	X float64
	Y float64
}

Chipmunk's 2D vector type.

func CentroidForPoly

func CentroidForPoly(verts []Vect) Vect

Calculate the natural centroid of a polygon.

func ClosetPointOnSegment

func ClosetPointOnSegment(p, a, b Vect) Vect

Returns the closest point on the line segment ab, to the point p.

func V

func V(x, y float64) Vect

Convenience constructor for cpVect structs.

func Vadd

func Vadd(v1, v2 Vect) Vect

Add two vectors

func Vdot

func Vdot(v1, v2 Vect) Vect

Vector dot product.

func Vforangle

func Vforangle(a float64) Vect

Returns the unit length vector for the given angle (in radians).

func Vlerp

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

Linearly interpolate between v1 and v2.

func Vlerpconst

func Vlerpconst(v1, v2 Vect, d float64) Vect

Linearly interpolate between v1 towards v2 by distance d.

func Vmult

func Vmult(v Vect, s float64) Vect

Scalar multiplication.

func Vneg

func Vneg(v Vect) Vect

Negate a vector.

func Vnormalize

func Vnormalize(v Vect) Vect

Returns a normalized copy of v.

func Vperp

func Vperp(v Vect) Vect

Returns a perpendicular vector. (90 degree rotation)

func Vproject

func Vproject(v1, v2 Vect) Vect

Returns the vector projection of v1 onto v2.

func Vrotate

func Vrotate(v1, v2 Vect) Vect

Uses complex number multiplication to rotate v1 by v2. Scaling will occur if v1 is not a unit vector.

func Vrperp

func Vrperp(v Vect) Vect

Returns a perpendicular vector. (-90 degree rotation)

func Vslerp

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

Spherical linearly interpolate between v1 and v2.

func Vslerpconst

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

Spherical linearly interpolate between v1 towards v2 by no more than angle a radians

func Vsub

func Vsub(v1, v2 Vect) Vect

Subtract two vectors.

func Vunrotate

func Vunrotate(v1, v2 Vect) Vect

Inverse of Vrotate().

Jump to

Keyboard shortcuts

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