cp

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 5 Imported by: 28

README

cp

GoDoc Sourcegraph

Go port of Chipmunk2D physics library.

import "github.com/jakecoffman/cp/v2"

Project status

Stable -- most features are implemented and the demos are very close to Chipmunk2D demos.

Examples

Documentation

The official chipmunk docs are a really good place to start: https://chipmunk-physics.net/release/ChipmunkLatest-Docs/

Features

Same features as Chipmunk2D:

  • Designed specifically for 2D video games.
  • Circle, convex polygon, and beveled line segment collision primitives.
  • Multiple collision primitives can be attached to a single rigid body.
  • Fast broad phase collision detection by using a bounding box tree with great temporal coherence or a spatial hash.
  • Extremely fast impulse solving by utilizing Erin Catto’s contact persistence algorithm.
  • Supports sleeping objects that have come to rest to reduce the CPU load.
  • Support for collision event callbacks based on user definable object types types.
  • Flexible collision filtering system with layers, exclusion groups and callbacks.
  • Can be used to create all sorts of effects like one way platforms or buoyancy areas. (Examples included)
  • Supports nearest point, segment (raycasting), shape and bounding box queries to the collision detection system.
  • Collision impulses amounts can be retrieved for gameplay effects, sound effects, etc.
  • Large variety of joints – easily make vehicles, ragdolls, and more.
  • Joint callbacks.
  • Can be used to easily implement breakable or animated joints. (Examples included)
  • Maintains a contact graph of all colliding objects.
  • No external dependencies.
  • Many language bindings available.
  • Simple, read the documentation and see!
  • Unrestrictive MIT license

Documentation

Index

Constants

View Source
const (
	BODY_DYNAMIC = iota
	BODY_KINEMATIC
	BODY_STATIC
)

Body types

View Source
const (
	DRAW_SHAPES           = 1 << 0
	DRAW_CONSTRAINTS      = 1 << 1
	DRAW_COLLISION_POINTS = 1 << 2
)

Draw flags

View Source
const (
	INFINITY      = math.MaxFloat64
	MAGIC_EPSILON = 1e-5

	RadianConst = math.Pi / 180
	DegreeConst = 180 / math.Pi

	POOLED_BUFFER_SIZE = 1024
)
View Source
const (
	// Arbiter is active and its the first collision.
	CP_ARBITER_STATE_FIRST_COLLISION = iota
	// Arbiter is active and its not the first collision.
	CP_ARBITER_STATE_NORMAL
	// Collision has been explicitly ignored.
	// Either by returning false from a begin collision handler or calling cpArbiterIgnore().
	CP_ARBITER_STATE_IGNORE
	// Collison is no longer active. A space will cache an arbiter for up to cpSpace.collisionPersistence more steps.
	CP_ARBITER_STATE_CACHED
	// Collison arbiter is invalid because one of the shapes was removed.
	CP_ARBITER_STATE_INVALIDATED
)

Arbiter states

View Source
const CONTACTS_BUFFER_SIZE = 1024
View Source
const MAX_CONTACTS_PER_ARBITER = 2
View Source
const (
	SHAPE_TYPE_NUM = 3
)

Variables

View Source
var (
	NO_GROUP       uint = 0        // Value for group signifying that a shape is in no group.
	ALL_CATEGORIES uint = ^uint(0) // Value for Shape layers signifying that a shape is in every layer.
)

SHAPE_FILTER_ALL is s collision filter value for a shape that will collide with anything except SHAPE_FILTER_NONE.

SHAPE_FILTER_NONE is a collision filter value for a shape that does not collide with anything.

View Source
var ShapeUpdateFunc = func(shape *Shape) {
	shape.CacheBB()
}
View Source
var ShapeVelocityFunc = func(obj interface{}) Vector {
	return obj.(*Shape).body.v
}

Functions

func AlwaysCollide

func AlwaysCollide(_ *Arbiter, _ *Space, _ interface{}) bool

func AreaForCircle

func AreaForCircle(r1, r2 float64) float64

AreaForCircle returns 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(count int, verts []Vector, r float64) float64

AreaForPoly calculates 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 Vector, r float64) float64

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

func BodyUpdatePosition

func BodyUpdatePosition(body *Body, dt float64)

BodyUpdatePosition is default position integration function.

func BodyUpdateVelocity

func BodyUpdateVelocity(body *Body, gravity Vector, damping, dt float64)

BodyUpdateVelocity is default velocity integration function.

func CachedArbitersFilter

func CachedArbitersFilter(arb *Arbiter, space *Space, shape *Shape, body *Body) bool

func CircleSegmentQuery

func CircleSegmentQuery(shape *Shape, center Vector, r1 float64, a, b Vector, r2 float64, info *SegmentQueryInfo)

func CircleToCircle

func CircleToCircle(info *CollisionInfo)

func CircleToPoly

func CircleToPoly(info *CollisionInfo)

func CircleToSegment

func CircleToSegment(info *CollisionInfo)

func Clamp

func Clamp(f, min, max float64) float64

func Clamp01

func Clamp01(f float64) float64

func CollisionError

func CollisionError(_ *CollisionInfo)

func ComponentActive

func ComponentActive(root *Body, threshold float64) bool

func ContactPoints

func ContactPoints(e1, e2 Edge, points ClosestPoints, info *CollisionInfo)

ContactPoints finds contact point pairs on two support edges' surfaces

func Contains

func Contains(bodies []*Body, body *Body) bool

func ConvexHull

func ConvexHull(count int, verts []Vector, first *int, tol float64) int

QuickHull seemed like a neat algorithm, and efficient-ish for large input sets. My implementation performs an in place reduction using the result array as scratch space.

func DebugInfo

func DebugInfo(space *Space) string

DebugInfo returns info of space

func DefaultBegin

func DefaultBegin(arb *Arbiter, space *Space, _ interface{}) bool

func DefaultPostSolve

func DefaultPostSolve(arb *Arbiter, space *Space, _ interface{})

func DefaultPreSolve

func DefaultPreSolve(arb *Arbiter, space *Space, _ interface{}) bool

func DefaultSeparate

func DefaultSeparate(arb *Arbiter, space *Space, _ interface{})

func DefaultSpringForce

func DefaultSpringForce(spring *DampedSpring, dist float64) float64

func DoNothing

func DoNothing(_ *Arbiter, _ *Space, _ interface{})

func DrawConstraint

func DrawConstraint(constraint *Constraint, options Drawer)

func DrawShape

func DrawShape(shape *Shape, options Drawer)

func DrawSpace

func DrawSpace(space *Space, options Drawer)

func FloodFillComponent

func FloodFillComponent(root *Body, body *Body)

func Lerp

func Lerp(f1, f2, t float64) float64

func LerpConst

func LerpConst(f1, f2, d float64) float64

func LoopIndexes

func LoopIndexes(verts []Vector, count int) (int, int)

func MarchCellHard

func MarchCellHard(t, a, b, c, d, x0, x1, y0, y1 float64, marchSegment MarchSegmentFunc, segmentData *PolyLineSet)

func MarchCellSoft

func MarchCellSoft(t, a, b, c, d, x0, x1, y0, y1 float64, marchSegment MarchSegmentFunc, segmentData *PolyLineSet)

func MomentForBox

func MomentForBox(mass, width, height float64) float64

MomentForBox calculates the moment of inertia for a solid box.

func MomentForBox2

func MomentForBox2(mass float64, box BB) float64

MomentForBox2 calculates the moment of inertia for a solid box.

func MomentForCircle

func MomentForCircle(mass, r1, r2 float64, offset Vector) float64

MomentForCircle calculates 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(mass float64, count int, verts []Vector, offset Vector, r float64) float64

MomentForPoly calculates 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(mass float64, a, b Vector, r float64) float64

MomentForSegment calculates the moment of inertia for a line segment.

Beveling radius is not supported.

func NearestPointQueryNearest

func NearestPointQueryNearest(obj interface{}, shape *Shape, collisionId uint32, out interface{}) uint32

func Next

func Next(i, count int) int

func NodeSetA

func NodeSetA(node, value *Node)

func NodeSetB

func NodeSetB(node, value *Node)

func PolyLineCollectSegment

func PolyLineCollectSegment(v0, v1 Vector, pls *PolyLineSet)

Add a segment to a polyline set. A segment will either start a new polyline, join two others, or add to or loop an existing polyline.

func PolySupportPointIndex

func PolySupportPointIndex(count int, planes []SplittingPlane, n Vector) int

func PolyToPoly

func PolyToPoly(info *CollisionInfo)

func PostStepDoNothing

func PostStepDoNothing(space *Space, key, data interface{})

func QHullPartition

func QHullPartition(verts []Vector, count int, a, b Vector, tol float64) int

func QHullReduce

func QHullReduce(tol float64, verts []Vector, count int, a, pivot, b Vector, result []Vector) int

func QueryReject

func QueryReject(a, b *Shape) bool

func QueryRejectConstraints

func QueryRejectConstraints(a, b *Body) bool

func SegmentToPoly

func SegmentToPoly(info *CollisionInfo)

func SegmentToSegment

func SegmentToSegment(info *CollisionInfo)

func Sharpness

func Sharpness(a, b, c Vector) float64

func SpaceArbiterSetFilter

func SpaceArbiterSetFilter(arb *Arbiter, space *Space) bool

SpaceArbiterSetFilter throws away old arbiters.

func SpaceCollideShapesFunc

func SpaceCollideShapesFunc(obj interface{}, b *Shape, collisionId uint32, vspace interface{}) uint32

func VoidQueryFunc

func VoidQueryFunc(obj1 interface{}, obj2 *Shape, collisionId uint32, data interface{}) uint32

Types

type Arbiter

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

Arbiter struct tracks pairs of colliding shapes.

They are also used in conjuction with collision handler callbacks allowing you to retrieve information on the collision or change it. A unique arbiter value is used for each pair of colliding objects. It persists until the shapes separate.

func ArbiterNext

func ArbiterNext(arb *Arbiter, body *Body) *Arbiter

func (*Arbiter) ApplyCachedImpulse

func (arbiter *Arbiter) ApplyCachedImpulse(dt_coef float64)

func (*Arbiter) ApplyImpulse

func (arbiter *Arbiter) ApplyImpulse()

func (*Arbiter) Bodies

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

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

func (*Arbiter) CallWildcardBeginA

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

CallWildcardBeginA if you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.

You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.

func (*Arbiter) CallWildcardBeginB

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

CallWildcardBeginB If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.

func (*Arbiter) CallWildcardPostSolveA

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

func (*Arbiter) CallWildcardPostSolveB

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

func (*Arbiter) CallWildcardPreSolveA

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

CallWildcardPreSolveA If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.

func (*Arbiter) CallWildcardPreSolveB

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

CallWildcardPreSolveB If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.

func (*Arbiter) CallWildcardSeparateA

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

func (*Arbiter) CallWildcardSeparateB

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

func (*Arbiter) ContactPointSet

func (arb *Arbiter) ContactPointSet() ContactPointSet

ContactPointSet returns ContactPointSet

func (*Arbiter) Count

func (arb *Arbiter) Count() int

func (*Arbiter) Ignore

func (arb *Arbiter) Ignore() bool

Ignore marks a collision pair to be ignored until the two objects separate.

Pre-solve and post-solve callbacks will not be called, but the separate callback will be called.

func (*Arbiter) Init

func (arbiter *Arbiter) Init(a, b *Shape) *Arbiter

Init initializes and returns Arbiter

func (*Arbiter) IsFirstContact

func (arbiter *Arbiter) IsFirstContact() bool

func (*Arbiter) Next

func (node *Arbiter) Next(body *Body) *Arbiter

func (*Arbiter) Normal

func (arb *Arbiter) Normal() Vector

func (*Arbiter) PreStep

func (arb *Arbiter) PreStep(dt, slop, bias float64)

func (*Arbiter) SetContactPointSet

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

SetContactPointSet replaces the contact point set.

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

func (*Arbiter) Shapes

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

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

func (*Arbiter) ThreadForBody

func (arbiter *Arbiter) ThreadForBody(body *Body) *ArbiterThread

func (*Arbiter) TotalImpulse

func (arb *Arbiter) TotalImpulse() Vector

TotalImpulse calculates 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 EachArbiter callback.

func (*Arbiter) Unthread

func (arbiter *Arbiter) Unthread()

func (*Arbiter) Update

func (arb *Arbiter) Update(info *CollisionInfo, space *Space)

type ArbiterThread

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

type BB

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

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

func NewBB

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

NewBB is convenience constructor for BB structs.

func NewBBForCircle

func NewBBForCircle(p Vector, r float64) BB

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

func NewBBForExtents

func NewBBForExtents(c Vector, hw, hh float64) BB

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

func ShapeGetBB

func ShapeGetBB(obj *Shape) BB

func (BB) Area

func (bb BB) Area() float64

Area returns the area of the bounding box.

func (BB) Center

func (bb BB) Center() Vector

Center returns the center of a bounding box.

func (BB) ClampVect

func (bb BB) ClampVect(v *Vector) Vector

ClampVect clamps a vector to bounding box.

func (BB) Contains

func (bb BB) Contains(other BB) bool

Contains returns true if other lies completely within bb.

func (BB) ContainsVect

func (bb BB) ContainsVect(v Vector) bool

ContainsVect returns true if bb contains v.

func (BB) Expand

func (bb BB) Expand(v Vector) BB

Expand returns a bounding box that holds both bb and v.

func (BB) Intersects

func (a BB) Intersects(b BB) bool

Intersects returns true if a and b intersect.

func (BB) IntersectsSegment

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

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

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 a and b and returns the area of the merged bounding box.

func (BB) Offset

func (bb BB) Offset(v Vector) BB

Offset returns a bounding box offseted by v.

func (BB) Proximity

func (a BB) Proximity(b BB) float64

func (BB) SegmentQuery

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

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

func (BB) String

func (bb BB) String() string

func (BB) WrapVect

func (bb BB) WrapVect(v Vector) Vector

WrapVect wraps a vector to bounding box.

type BBQueryContext

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

type BBTree

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

func (*BBTree) Contains

func (tree *BBTree) Contains(obj *Shape, hashId HashValue) bool

func (*BBTree) Count

func (tree *BBTree) Count() int

func (*BBTree) Each

func (tree *BBTree) Each(f SpatialIndexIterator)

func (*BBTree) GetBB

func (tree *BBTree) GetBB(obj *Shape) BB

func (*BBTree) GetMasterTree

func (tree *BBTree) GetMasterTree() *BBTree

func (*BBTree) IncrementStamp

func (tree *BBTree) IncrementStamp()

func (*BBTree) Insert

func (tree *BBTree) Insert(obj *Shape, hashId HashValue)

func (*BBTree) LeafAddPairs

func (tree *BBTree) LeafAddPairs(leaf *Node)

func (*BBTree) LeafUpdate

func (tree *BBTree) LeafUpdate(leaf *Node) bool

func (*BBTree) NewLeaf

func (tree *BBTree) NewLeaf(obj *Shape) *Node

func (*BBTree) NewNode

func (tree *BBTree) NewNode(a, b *Node) *Node

func (*BBTree) NodeFromPool

func (tree *BBTree) NodeFromPool() *Node

func (*BBTree) PairFromPool

func (subtree *BBTree) PairFromPool() *Pair

func (*BBTree) PairInsert

func (tree *BBTree) PairInsert(a *Node, b *Node)

func (*BBTree) PairsClear

func (tree *BBTree) PairsClear(leaf *Node)

func (*BBTree) Query

func (tree *BBTree) Query(obj interface{}, bb BB, f SpatialIndexQuery, data interface{})

func (*BBTree) RecycleNode

func (tree *BBTree) RecycleNode(node *Node)

func (*BBTree) RecyclePair

func (tree *BBTree) RecyclePair(pair *Pair)

func (*BBTree) Reindex

func (tree *BBTree) Reindex()

func (*BBTree) ReindexObject

func (tree *BBTree) ReindexObject(obj *Shape, hashId HashValue)

func (*BBTree) ReindexQuery

func (tree *BBTree) ReindexQuery(f SpatialIndexQuery, data interface{})

func (*BBTree) Remove

func (tree *BBTree) Remove(obj *Shape, hashId HashValue)

func (*BBTree) ReplaceChild

func (tree *BBTree) ReplaceChild(parent, child, value *Node)

func (*BBTree) SegmentQuery

func (tree *BBTree) SegmentQuery(obj interface{}, a, b Vector, t_exit float64, f SpatialIndexSegmentQuery, data interface{})

func (*BBTree) SubtreeInsert

func (tree *BBTree) SubtreeInsert(subtree *Node, leaf *Node) *Node

func (*BBTree) SubtreeRemove

func (tree *BBTree) SubtreeRemove(subtree *Node, leaf *Node) *Node

type BBTreeVelocityFunc

type BBTreeVelocityFunc func(obj interface{}) Vector

type Body

type Body struct {
	// UserData is an object that this constraint is associated with.
	//
	// You can use this get a reference to your game object or controller object from within callbacks.
	UserData interface{}
	// contains filtered or unexported fields
}

func NewBody

func NewBody(mass, moment float64) *Body

NewBody Initializes a rigid body with the given mass and moment of inertia.

Guessing the moment of inertia is usually a bad idea. Use the moment estimation functions MomentFor*().

func NewKinematicBody

func NewKinematicBody() *Body

NewKinematicBody allocates and initializes a Body, and set it as a kinematic body.

func NewStaticBody

func NewStaticBody() *Body

NewStaticBody allocates and initializes a Body, and set it as a static body.

func (*Body) AccumulateMassFromShapes

func (body *Body) AccumulateMassFromShapes()

AccumulateMassFromShapes should *only* be called when shapes with mass info are modified, added or removed.

func (*Body) Activate

func (body *Body) Activate()

Activate wakes up a sleeping or idle body.

func (*Body) ActivateStatic

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

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

func (*Body) AddShape

func (body *Body) AddShape(shape *Shape) *Shape

AddShape adds shape to the body and returns added shape

func (*Body) Angle

func (body *Body) Angle() float64

Angle returns the angle of the body.

func (*Body) AngularVelocity

func (body *Body) AngularVelocity() float64

AngularVelocity returns the angular velocity of the body.

func (*Body) ApplyForceAtLocalPoint

func (body *Body) ApplyForceAtLocalPoint(force, point Vector)

ApplyForceAtLocalPoint applies a force at local point.

func (*Body) ApplyForceAtWorldPoint

func (body *Body) ApplyForceAtWorldPoint(force, point Vector)

ApplyForceAtWorldPoint applies a force at world point.

func (*Body) ApplyImpulseAtLocalPoint

func (body *Body) ApplyImpulseAtLocalPoint(impulse, point Vector)

ApplyImpulseAtLocalPoint applies impulse at local point

func (*Body) ApplyImpulseAtWorldPoint

func (body *Body) ApplyImpulseAtWorldPoint(impulse, point Vector)

ApplyImpulseAtWorldPoint applies impulse at world point

func (Body) CenterOfGravity

func (body Body) CenterOfGravity() Vector

CenterOfGravity returns the offset of the center of gravity in body local coordinates.

func (*Body) ComponentAdd

func (root *Body) ComponentAdd(body *Body)

func (*Body) ComponentRoot

func (body *Body) ComponentRoot() *Body

func (*Body) EachArbiter

func (body *Body) EachArbiter(f func(*Arbiter))

EachArbiter calls f once for each arbiter that is currently active on the body.

func (*Body) EachConstraint

func (body *Body) EachConstraint(f func(*Constraint))

EachConstraint calls f once for each constraint attached to this body

func (*Body) EachShape

func (body *Body) EachShape(f func(*Shape))

EachShape calls f once for each shape attached to this body

func (*Body) Force

func (body *Body) Force() Vector

Force returns the force applied to the body for the next time step.

func (*Body) GetType

func (body *Body) GetType() int

GetType returns the type of the body.

func (*Body) IdleTime

func (body *Body) IdleTime() float64

IdleTime returns sleeping idle time of the body

func (*Body) IsSleeping

func (body *Body) IsSleeping() bool

IsSleeping returns true if the body is sleeping.

func (*Body) KineticEnergy

func (body *Body) KineticEnergy() float64

KineticEnergy returns the kinetic energy of this body.

func (*Body) LocalToWorld

func (body *Body) LocalToWorld(point Vector) Vector

LocalToWorld converts from body local to world coordinates.

Convert a point in world (absolute) coordinates to body local coordinates affected by the position and rotation of the rigid body.

func (*Body) Mass

func (body *Body) Mass() float64

Mass returns mass of the body

func (Body) Moment

func (body Body) Moment() float64

Moment returns moment of inertia of the body.

func (*Body) Position

func (body *Body) Position() Vector

Position returns the position of the body.

func (*Body) PushArbiter

func (body *Body) PushArbiter(arb *Arbiter)

func (*Body) RemoveConstraint

func (body *Body) RemoveConstraint(constraint *Constraint)

RemoveConstraint removes constraint from the body.

func (*Body) RemoveShape

func (body *Body) RemoveShape(shape *Shape)

RemoveShape removes collision shape from the body.

func (*Body) Rotation

func (body *Body) Rotation() Vector

Rotation returns the rotation vector of the body.

(The x basis vector of it's transform.)

func (*Body) SetAngle

func (body *Body) SetAngle(angle float64)

SetAngle sets the angle of body.

func (*Body) SetAngularVelocity

func (body *Body) SetAngularVelocity(angularVelocity float64)

SetAngularVelocity sets the angular velocity of the body.

func (*Body) SetForce

func (body *Body) SetForce(force Vector)

SetForce sets the force applied to the body for the next time step.

func (*Body) SetMass

func (body *Body) SetMass(mass float64)

SetMass sets mass of the body

func (*Body) SetMoment

func (body *Body) SetMoment(moment float64)

SetMoment sets moment of inertia of the body.

func (*Body) SetPosition

func (body *Body) SetPosition(position Vector)

SetPosition sets the position of the body.

func (*Body) SetPositionUpdateFunc

func (body *Body) SetPositionUpdateFunc(f BodyPositionFunc)

SetPositionUpdateFunc sets the callback used to update a body's position.

func (*Body) SetTorque

func (body *Body) SetTorque(torque float64)

SetTorque sets the torque applied to the body for the next time step.

func (*Body) SetTransform

func (body *Body) SetTransform(p Vector, a float64)

SetTransform sets transform

func (*Body) SetType

func (body *Body) SetType(newType int)

SetType sets the type of the body.

func (*Body) SetVelocity

func (body *Body) SetVelocity(x, y float64)

SetVelocity sets the velocity of the body.

Shorthand for Body.SetVelocityVector()

func (*Body) SetVelocityUpdateFunc

func (body *Body) SetVelocityUpdateFunc(f BodyVelocityFunc)

SetVelocityUpdateFunc sets the callback used to update a body's velocity.

func (*Body) SetVelocityVector

func (body *Body) SetVelocityVector(v Vector)

SetVelocityVector sets the velocity of the body

func (Body) String

func (b Body) String() string

String returns body id as string

func (*Body) Torque

func (body *Body) Torque() float64

Torque returns the torque applied to the body for the next time step.

func (*Body) UpdateVelocity

func (body *Body) UpdateVelocity(gravity Vector, damping, dt float64)

UpdateVelocity is the default velocity integration function.

func (*Body) Velocity

func (body *Body) Velocity() Vector

Velocity returns the velocity of the body.

func (*Body) VelocityAtLocalPoint

func (body *Body) VelocityAtLocalPoint(point Vector) Vector

VelocityAtLocalPoint returns the velocity of a point on a body.

Get the world (absolute) velocity of a point on a rigid body specified in body local coordinates.

func (*Body) VelocityAtWorldPoint

func (body *Body) VelocityAtWorldPoint(point Vector) Vector

VelocityAtWorldPoint returns the velocity of a point on a body.

Get the world (absolute) velocity of a point on a rigid body specified in world coordinates.

func (*Body) WorldToLocal

func (body *Body) WorldToLocal(point Vector) Vector

WorldToLocal converts from world to body local Coordinates.

Convert a point in body local coordinates to world (absolute) coordinates.

type BodyPositionFunc

type BodyPositionFunc func(body *Body, dt float64)

BodyPositionFunc is rigid body position update function type.

type BodyVelocityFunc

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

BodyVelocityFunc is rigid body velocity update function type.

type Children

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

type Circle

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

func (*Circle) CacheData

func (circle *Circle) CacheData(transform Transform) BB

func (*Circle) PointQuery

func (circle *Circle) PointQuery(p Vector, info *PointQueryInfo)

func (*Circle) Radius

func (circle *Circle) Radius() float64

func (*Circle) SegmentQuery

func (circle *Circle) SegmentQuery(a, b Vector, radius float64, info *SegmentQueryInfo)

func (*Circle) SetRadius

func (circle *Circle) SetRadius(r float64)

func (*Circle) TransformC

func (circle *Circle) TransformC() Vector

type ClosestPoints

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

func EPA

func EPA(ctx SupportContext, v0, v1, v2 MinkowskiPoint) ClosestPoints

EPA is called from GJK when two shapes overlap. Finds the closest points on the surface of two overlapping shapes using the EPA algorithm. This is a moderately expensive step! Avoid it by adding radii to your shapes so their inner polygons won't overlap.

func EPARecurse

func EPARecurse(ctx SupportContext, count int, hull []MinkowskiPoint, iteration int) ClosestPoints

EPARecurse implementation of the EPA loop. Each recursion adds a point to the convex hull until it's known that we have the closest point on the surface.

func GJK

func GJK(ctx SupportContext, collisionId *uint32) ClosestPoints

GJK finds the closest points between two shapes using the GJK algorithm.

func GJKRecurse

func GJKRecurse(ctx SupportContext, v0, v1 MinkowskiPoint, iteration int) ClosestPoints

GJKRecurse implementation of the GJK loop.

type CollisionBeginFunc

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

CollisionBeginFunc is 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 CollisionFunc

type CollisionFunc func(info *CollisionInfo)

type CollisionHandler

type CollisionHandler struct {
	// Collision type identifier of the first shape that this handler recognizes.
	// In the collision handler callback, the shape with this type will be the first argument. Read only.
	TypeA CollisionType
	// Collision type identifier of the second shape that this handler recognizes.
	// In the collision handler callback, the shape with this type will be the second argument. Read only.
	TypeB CollisionType
	// This function is called when two shapes with types that match this collision handler begin colliding.
	BeginFunc CollisionBeginFunc
	// This function is called each step when two shapes with types that match this collision handler are colliding.
	// It's called before the collision solver runs so that you can affect a collision's outcome.
	PreSolveFunc CollisionPreSolveFunc
	// This function is called each step when two shapes with types that match this collision handler are colliding.
	// It's called after the collision solver runs so that you can read back information about the collision to trigger events in your game.
	PostSolveFunc CollisionPostSolveFunc
	// This function is called when two shapes with types that match this collision handler stop colliding.
	SeparateFunc CollisionSeparateFunc
	// This is a user definable context pointer that is passed to all of the collision handler functions.
	UserData interface{}
}

CollisionHandler is struct that holds function callback pointers to configure custom collision handling. Collision handlers have a pair of types; when a collision occurs between two shapes that have these types, the collision handler functions are triggered.

type CollisionInfo

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

CollisionInfo collision info struct

func Collide

func Collide(a, b *Shape, collisionID uint32, contacts []Contact) CollisionInfo

Collide performs a collision between two shapes

func (*CollisionInfo) PushContact

func (info *CollisionInfo) PushContact(p1, p2 Vector, hash HashValue)

type CollisionPostSolveFunc

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

CollisionPostSolveFunc is collision post-solve event function callback type.

type CollisionPreSolveFunc

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

CollisionPreSolveFunc is 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{})

CollisionSeparateFunc is collision separate event function callback type.

type CollisionType

type CollisionType uintptr
var WILDCARD_COLLISION_TYPE CollisionType = ^CollisionType(0)

type Constrainer

type Constrainer interface {
	PreStep(dt float64)
	ApplyCachedImpulse(dt_coef float64)
	ApplyImpulse(dt float64)
	GetImpulse() float64
}

type Constraint

type Constraint struct {
	Class Constrainer

	PreSolve  ConstraintPreSolveFunc
	PostSolve ConstraintPostSolveFunc

	UserData interface{}
	// contains filtered or unexported fields
}

func NewConstraint

func NewConstraint(class Constrainer, a, b *Body) *Constraint

func NewDampedRotarySpring

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

func NewDampedSpring

func NewDampedSpring(a, b *Body, anchorA, anchorB Vector, restLength, stiffness, damping float64) *Constraint

func NewGearJoint

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

func NewGrooveJoint

func NewGrooveJoint(a, b *Body, grooveA, grooveB, anchorB Vector) *Constraint

func NewPinJoint

func NewPinJoint(a, b *Body, anchorA, anchorB Vector) *Constraint

func NewPivotJoint

func NewPivotJoint(a, b *Body, pivot Vector) *Constraint

func NewPivotJoint2

func NewPivotJoint2(a, b *Body, anchorA, anchorB Vector) *Constraint

func NewRatchetJoint

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

func NewRotaryLimitJoint

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

func NewSimpleMotor

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

func NewSlideJoint

func NewSlideJoint(a, b *Body, anchorA, anchorB Vector, min, max float64) *Constraint

func (*Constraint) ActivateBodies

func (c *Constraint) ActivateBodies()

func (Constraint) ErrorBias

func (c Constraint) ErrorBias() float64

func (Constraint) MaxBias

func (c Constraint) MaxBias() float64

func (Constraint) MaxForce

func (c Constraint) MaxForce() float64

func (*Constraint) Next

func (c *Constraint) Next(body *Body) *Constraint

func (*Constraint) SetCollideBodies

func (c *Constraint) SetCollideBodies(collideBodies bool)

func (*Constraint) SetErrorBias

func (c *Constraint) SetErrorBias(errorBias float64)

func (*Constraint) SetMaxBias

func (c *Constraint) SetMaxBias(max float64)

func (*Constraint) SetMaxForce

func (c *Constraint) SetMaxForce(max float64)

type ConstraintPostSolveFunc

type ConstraintPostSolveFunc func(*Constraint, *Space)

type ConstraintPreSolveFunc

type ConstraintPreSolveFunc func(*Constraint, *Space)

type Contact

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

func (*Contact) Clone

func (c *Contact) Clone() Contact

type ContactBuffer

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

func NewContactBuffer

func NewContactBuffer(stamp uint, slice *ContactBuffer) *ContactBuffer

func (*ContactBuffer) InitHeader

func (c *ContactBuffer) InitHeader(stamp uint, splice *ContactBuffer) *ContactBuffer

type ContactPointSet

type ContactPointSet struct {
	// Count is the number of contact points in the set.
	Count int
	// Normal is the normal of the collision.
	Normal Vector

	Points [MAX_CONTACTS_PER_ARBITER]struct {
		// The position of the contact on the surface of each shape.
		PointA, PointB Vector
		// Distance is penetration distance of the two shapes. Overlapping means it will be negative.
		//
		// This value is calculated as p2.Sub(p1).Dot(n) and is ignored by Arbiter.SetContactPointSet().
		Distance float64
	}
}

ContactPointSet wraps up the important collision data for an arbiter.

func ShapesCollide

func ShapesCollide(a, b *Shape) ContactPointSet

type DampedRotarySpring

type DampedRotarySpring struct {
	*Constraint

	RestAngle, Stiffness, Damping float64
	SpringTorqueFunc              func(spring *DampedRotarySpring, relativeAngle float64) float64
	// contains filtered or unexported fields
}

func (*DampedRotarySpring) ApplyCachedImpulse

func (joint *DampedRotarySpring) ApplyCachedImpulse(dt_coef float64)

func (*DampedRotarySpring) ApplyImpulse

func (spring *DampedRotarySpring) ApplyImpulse(dt float64)

func (*DampedRotarySpring) GetImpulse

func (joint *DampedRotarySpring) GetImpulse() float64

func (*DampedRotarySpring) PreStep

func (spring *DampedRotarySpring) PreStep(dt float64)

type DampedSpring

type DampedSpring struct {
	*Constraint

	AnchorA, AnchorB               Vector
	RestLength, Stiffness, Damping float64
	SpringForceFunc                DampedSpringForceFunc
	// contains filtered or unexported fields
}

func (*DampedSpring) ApplyCachedImpulse

func (spring *DampedSpring) ApplyCachedImpulse(dt_coef float64)

func (*DampedSpring) ApplyImpulse

func (spring *DampedSpring) ApplyImpulse(dt float64)

func (*DampedSpring) GetImpulse

func (spring *DampedSpring) GetImpulse() float64

func (*DampedSpring) PreStep

func (spring *DampedSpring) PreStep(dt float64)

type DampedSpringForceFunc

type DampedSpringForceFunc func(spring *DampedSpring, dist float64) float64

type Drawer

type Drawer interface {
	DrawCircle(pos Vector, angle, radius float64, outline, fill FColor, data interface{})
	DrawSegment(a, b Vector, fill FColor, data interface{})
	DrawFatSegment(a, b Vector, radius float64, outline, fill FColor, data interface{})
	DrawPolygon(count int, verts []Vector, radius float64, outline, fill FColor, data interface{})
	DrawDot(size float64, pos Vector, fill FColor, data interface{})

	Flags() uint
	OutlineColor() FColor
	ShapeColor(shape *Shape, data interface{}) FColor
	ConstraintColor() FColor
	CollisionPointColor() FColor
	Data() interface{}
}

type Edge

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

func SupportEdgeForPoly

func SupportEdgeForPoly(poly *PolyShape, n Vector) Edge

func SupportEdgeForSegment

func SupportEdgeForSegment(seg *Segment, n Vector) Edge

type EdgePoint

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

type FColor

type FColor struct {
	R, G, B, A float32
}

16 bytes

type GearJoint

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

func (*GearJoint) ApplyCachedImpulse

func (joint *GearJoint) ApplyCachedImpulse(dt_coef float64)

func (*GearJoint) ApplyImpulse

func (joint *GearJoint) ApplyImpulse(dt float64)

func (*GearJoint) GetImpulse

func (joint *GearJoint) GetImpulse() float64

func (*GearJoint) PreStep

func (joint *GearJoint) PreStep(dt float64)

type GrooveJoint

type GrooveJoint struct {
	*Constraint

	GrooveN, GrooveA, GrooveB Vector
	AnchorB                   Vector
	// contains filtered or unexported fields
}

func (*GrooveJoint) ApplyCachedImpulse

func (joint *GrooveJoint) ApplyCachedImpulse(dt_coef float64)

func (*GrooveJoint) ApplyImpulse

func (joint *GrooveJoint) ApplyImpulse(dt float64)

func (*GrooveJoint) GetImpulse

func (joint *GrooveJoint) GetImpulse() float64

func (*GrooveJoint) PreStep

func (joint *GrooveJoint) PreStep(dt float64)

type Handle

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

func (*Handle) Init

func (hand *Handle) Init(obj *Shape)

type HashSet

type HashSet[T, U comparable] struct {
	// contains filtered or unexported fields
}

HashSet implements a hash set

func NewHashSet

func NewHashSet[T, U comparable](isEqual func(ptr T, elt U) bool) *HashSet[T, U]

NewHashSet is a HashSet constructor

func (*HashSet[T, U]) Count

func (set *HashSet[T, U]) Count() uint

Count returns the number of entries

func (*HashSet[T, U]) Each

func (set *HashSet[T, U]) Each(f func(U))

Each calls f for every U in the HashSet.

func (*HashSet[T, U]) Filter

func (set *HashSet[T, U]) Filter(f func(U) bool)

Filter removes elements if f returns false

func (*HashSet[T, U]) Find

func (set *HashSet[T, U]) Find(hash HashValue, ptr T) U

Find returns the U the T is in, or nil.

func (*HashSet[T, U]) Insert

func (set *HashSet[T, U]) Insert(hash HashValue, ptr T, transform func(obj T) U) U

Insert returns the U the T is in, or inserts a new U and returns it.

func (*HashSet[T, U]) Remove

func (set *HashSet[T, U]) Remove(hash HashValue, ptr T) U

Remove removes the T from the HashSet, returning the U it was in.

type HashSetBin

type HashSetBin[U comparable] struct {
	// contains filtered or unexported fields
}

HashSetBin implements a linked list

type HashValue

type HashValue uintptr

func HashPair

func HashPair(a, b HashValue) HashValue

type Leaf

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

type MarchCellFunc

type MarchCellFunc func(t, a, b, c, d, x0, x1, y0, y1 float64, marchSegment MarchSegmentFunc, segmentData *PolyLineSet)

type MarchSampleFunc

type MarchSampleFunc func(point Vector) float64

This is a user defined function that gets passed every single point from the bounding box the user passes into the March process - you can use this to sample an image and check for alpha values or really any 2d matrix you define like a tile map. NOTE: I could not determine a use case for the sample_data pointer from the original code so I removed it here - open to adding it back in if there is a reason.

type MarchSegmentFunc

type MarchSegmentFunc func(v0 Vector, v1 Vector, segmentData *PolyLineSet)

This is a user defined function that gets passed in to the Marching process the user establishes a PolyLineSet, passes a pointer to their function, and they populate it. In most cases you want to use PolyLineCollectSegment instead of defining your own

type MarkContext

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

type Mat2x2

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

Mat2x2 is a 2x2 matrix type used for tensors and such.

func (*Mat2x2) Transform

func (m *Mat2x2) Transform(v Vector) Vector

Transform transforms Vector v

type MinkowskiPoint

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

MinkowskiPoint is a point on the surface of two shapes' minkowski difference.

func NewMinkowskiPoint

func NewMinkowskiPoint(a, b SupportPoint) MinkowskiPoint

func (MinkowskiPoint) ClosestPoints

func (v0 MinkowskiPoint) ClosestPoints(v1 MinkowskiPoint) ClosestPoints

ClosestPoints calculates the closest points on two shapes given the closest edge on their minkowski difference to (0, 0)

type Node

type Node struct {
	Children
	Leaf
	// contains filtered or unexported fields
}

func (*Node) IsLeaf

func (node *Node) IsLeaf() bool

func (*Node) MarkLeaf

func (leaf *Node) MarkLeaf(context *MarkContext)

func (*Node) MarkLeafQuery

func (subtree *Node) MarkLeafQuery(leaf *Node, left bool, context *MarkContext)

func (*Node) MarkSubtree

func (subtree *Node) MarkSubtree(context *MarkContext)

func (*Node) Other

func (node *Node) Other(child *Node) *Node

func (*Node) SubtreeQuery

func (subtree *Node) SubtreeQuery(obj interface{}, bb BB, query SpatialIndexQuery, data interface{})

func (*Node) SubtreeSegmentQuery

func (subtree *Node) SubtreeSegmentQuery(obj interface{}, a, b Vector, t_exit float64, f SpatialIndexSegmentQuery, data interface{}) float64

type Pair

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

type PinJoint

type PinJoint struct {
	*Constraint
	AnchorA, AnchorB Vector
	Dist             float64
	// contains filtered or unexported fields
}

func (*PinJoint) ApplyCachedImpulse

func (joint *PinJoint) ApplyCachedImpulse(dt_coef float64)

func (*PinJoint) ApplyImpulse

func (joint *PinJoint) ApplyImpulse(dt float64)

func (*PinJoint) GetImpulse

func (joint *PinJoint) GetImpulse() float64

func (*PinJoint) PreStep

func (joint *PinJoint) PreStep(dt float64)

type PivotJoint

type PivotJoint struct {
	*Constraint
	AnchorA, AnchorB Vector
	// contains filtered or unexported fields
}

func (*PivotJoint) ApplyCachedImpulse

func (joint *PivotJoint) ApplyCachedImpulse(dt_coef float64)

func (*PivotJoint) ApplyImpulse

func (joint *PivotJoint) ApplyImpulse(dt float64)

func (*PivotJoint) GetImpulse

func (joint *PivotJoint) GetImpulse() float64

func (*PivotJoint) PreStep

func (joint *PivotJoint) PreStep(dt float64)

type PointQueryContext

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

type PointQueryInfo

type PointQueryInfo struct {
	// The nearest shape, NULL if no shape was within range.
	Shape *Shape
	// The closest point on the shape's surface. (in world space coordinates)
	Point Vector
	// 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 value should be similar to info.p/info.d, but accurate even for very small values of info.d.
	Gradient Vector
}

PointQueryInfo is point query info struct.

type PolyLine

type PolyLine struct {
	Verts []Vector
}

func DouglasPeucker

func DouglasPeucker(verts []Vector, reduced *PolyLine, length, start, end int, min, tol float64) *PolyLine

Recursive function used by cpPolylineSimplifyCurves().

func (*PolyLine) Enqueue

func (pl *PolyLine) Enqueue(v Vector) *PolyLine

func (*PolyLine) IsClosed

func (pl *PolyLine) IsClosed() bool

func (*PolyLine) IsShort

func (pl *PolyLine) IsShort(count, start, end int, min float64) bool

func (*PolyLine) Push

func (pl *PolyLine) Push(v Vector) *PolyLine

func (*PolyLine) SimplifyCurves

func (pl *PolyLine) SimplifyCurves(tol float64) *PolyLine

Recursively reduce the vertex count on a polyline. Works best for smooth shapes. 'tol' is the maximum error for the reduction. The reduced polyline will never be farther than this distance from the original polyline.

func (*PolyLine) SimplifyVertexes

func (pl *PolyLine) SimplifyVertexes(tol float64) *PolyLine

Join similar adjacent line segments together. Works well for hard edged shapes. 'tol' is the minimum anglular difference in radians of a vertex.

type PolyLineSet

type PolyLineSet struct {
	Lines []*PolyLine
}

func MarchCells

func MarchCells(bb BB, xSamples int64, ySamples int64, t float64, marchSegment MarchSegmentFunc, marchSample MarchSampleFunc, marchCell MarchCellFunc) *PolyLineSet

The looping and sample caching code is shared between cpMarchHard() and cpMarchSoft().

func MarchHard

func MarchHard(bb BB, xSamples, ySamples int64, t float64, marchSegment MarchSegmentFunc, marchSample MarchSampleFunc) *PolyLineSet

Trace an aliased curve of an image along a particular threshold. The given number of samples will be taken and spread across the bounding box area using the sampling function and context. The segment function will be called for each segment detected that lies along the density contour for @c threshold.

func MarchSoft

func MarchSoft(bb BB, xSamples, ySamples int64, t float64, marchSegment MarchSegmentFunc, marchSample MarchSampleFunc) *PolyLineSet

Trace an anti-aliased contour of an image along a particular threshold. The given number of samples will be taken and spread across the bounding box area using the sampling function and context. The segment function will be called for each segment detected that lies along the density contour for @c threshold.

func (*PolyLineSet) FindEnds

func (pls *PolyLineSet) FindEnds(v Vector) int

Find the polyline that ends with v.

func (*PolyLineSet) FindStarts

func (pls *PolyLineSet) FindStarts(v Vector) int

Find the polyline that starts with v.

func (*PolyLineSet) Join

func (pls *PolyLineSet) Join(before, after int)

this may deletion could be slow? https://yourbasic.org/golang/delete-element-slice/

func (*PolyLineSet) Push

func (pls *PolyLineSet) Push(v *PolyLine)

Add a new polyline to a polyline set.

type PolyShape

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

func (*PolyShape) CacheData

func (poly *PolyShape) CacheData(transform Transform) BB

func (PolyShape) Count

func (poly PolyShape) Count() int

func (*PolyShape) PointQuery

func (poly *PolyShape) PointQuery(p Vector, info *PointQueryInfo)

func (PolyShape) Radius

func (poly PolyShape) Radius() float64

func (*PolyShape) SegmentQuery

func (poly *PolyShape) SegmentQuery(a, b Vector, r2 float64, info *SegmentQueryInfo)

func (*PolyShape) SetRadius

func (poly *PolyShape) SetRadius(r float64)

func (*PolyShape) SetVerts

func (p *PolyShape) SetVerts(count int, verts []Vector)

func (*PolyShape) SetVertsRaw

func (p *PolyShape) SetVertsRaw(count int, verts []Vector)

func (*PolyShape) SetVertsUnsafe

func (p *PolyShape) SetVertsUnsafe(count int, verts []Vector, transform Transform)

func (PolyShape) TransformVert

func (poly PolyShape) TransformVert(i int) Vector

func (PolyShape) Vert

func (poly PolyShape) Vert(i int) Vector

type PostStepCallback

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

type PostStepCallbackFunc

type PostStepCallbackFunc func(space *Space, key interface{}, data interface{})

type RatchetJoint

type RatchetJoint struct {
	*Constraint

	Angle, Phase, Ratchet float64
	// contains filtered or unexported fields
}

func (*RatchetJoint) ApplyCachedImpulse

func (joint *RatchetJoint) ApplyCachedImpulse(dt_coef float64)

func (*RatchetJoint) ApplyImpulse

func (joint *RatchetJoint) ApplyImpulse(dt float64)

func (*RatchetJoint) GetImpulse

func (joint *RatchetJoint) GetImpulse() float64

func (*RatchetJoint) PreStep

func (joint *RatchetJoint) PreStep(dt float64)

type RotaryLimitJoint

type RotaryLimitJoint struct {
	*Constraint

	Min, Max float64
	// contains filtered or unexported fields
}

func (*RotaryLimitJoint) ApplyCachedImpulse

func (joint *RotaryLimitJoint) ApplyCachedImpulse(dt_coef float64)

func (*RotaryLimitJoint) ApplyImpulse

func (joint *RotaryLimitJoint) ApplyImpulse(dt float64)

func (*RotaryLimitJoint) GetImpulse

func (joint *RotaryLimitJoint) GetImpulse() float64

func (*RotaryLimitJoint) PreStep

func (joint *RotaryLimitJoint) PreStep(dt float64)

type Segment

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

func (*Segment) A

func (seg *Segment) A() Vector

func (*Segment) B

func (seg *Segment) B() Vector

func (*Segment) CacheData

func (seg *Segment) CacheData(transform Transform) BB

func (*Segment) Normal

func (seg *Segment) Normal() Vector

func (*Segment) PointQuery

func (seg *Segment) PointQuery(p Vector, info *PointQueryInfo)

func (*Segment) Radius

func (seg *Segment) Radius() float64

func (*Segment) SegmentQuery

func (seg *Segment) SegmentQuery(a, b Vector, r2 float64, info *SegmentQueryInfo)

func (*Segment) SetEndpoints

func (seg *Segment) SetEndpoints(a, b Vector)

func (*Segment) SetRadius

func (seg *Segment) SetRadius(r float64)

func (*Segment) TransformA

func (seg *Segment) TransformA() Vector

func (*Segment) TransformB

func (seg *Segment) TransformB() Vector

type SegmentQueryContext

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

type SegmentQueryInfo

type SegmentQueryInfo struct {
	// The shape that was hit, or NULL if no collision occurred.
	Shape *Shape
	// The point of impact.
	Point Vector
	// The normal of the surface hit.
	Normal Vector
	// The normalized distance along the query segment in the range [0, 1].
	Alpha float64
}

SegmentQueryInfo is segment query info struct.

type Shape

type Shape struct {
	Class ShapeClass

	UserData interface{}

	Filter ShapeFilter
	// contains filtered or unexported fields
}

func NewBox

func NewBox(body *Body, w, h, r float64) *Shape

func NewBox2

func NewBox2(body *Body, bb BB, r float64) *Shape

func NewCircle

func NewCircle(body *Body, radius float64, offset Vector) *Shape

func NewPolyShape

func NewPolyShape(body *Body, vectCount int, verts []Vector, transform Transform, radius float64) *Shape

func NewPolyShapeRaw

func NewPolyShapeRaw(body *Body, count int, verts []Vector, radius float64) *Shape

func NewSegment

func NewSegment(body *Body, a, b Vector, r float64) *Shape

func NewShape

func NewShape(class ShapeClass, body *Body, massInfo *ShapeMassInfo) *Shape

func (*Shape) Area

func (s *Shape) Area() float64

func (*Shape) BB

func (s *Shape) BB() BB

func (*Shape) Body

func (s *Shape) Body() *Body

func (*Shape) CacheBB

func (s *Shape) CacheBB() BB

func (*Shape) CenterOfGravity

func (s *Shape) CenterOfGravity() Vector

func (*Shape) Density

func (s *Shape) Density() float64

func (*Shape) Elasticity

func (s *Shape) Elasticity() float64

func (*Shape) Friction

func (s *Shape) Friction() float64

func (*Shape) HashId

func (s *Shape) HashId() HashValue

func (*Shape) Mass

func (s *Shape) Mass() float64

func (*Shape) MassInfo

func (s *Shape) MassInfo() *ShapeMassInfo

func (*Shape) Moment

func (s *Shape) Moment() float64

func (*Shape) Order

func (s *Shape) Order() int

func (*Shape) Point

func (s *Shape) Point(i uint32) SupportPoint

func (*Shape) PointQuery

func (s *Shape) PointQuery(p Vector) PointQueryInfo

func (*Shape) SegmentQuery

func (shape *Shape) SegmentQuery(a, b Vector, radius float64, info *SegmentQueryInfo) bool

func (*Shape) Sensor

func (s *Shape) Sensor() bool

func (*Shape) SetBB

func (s *Shape) SetBB(bb BB)

func (*Shape) SetCollisionType

func (s *Shape) SetCollisionType(collisionType CollisionType)

func (*Shape) SetDensity

func (s *Shape) SetDensity(density float64)

func (*Shape) SetElasticity

func (s *Shape) SetElasticity(e float64)

func (*Shape) SetFilter

func (s *Shape) SetFilter(filter ShapeFilter)

func (*Shape) SetFriction

func (s *Shape) SetFriction(u float64)

func (*Shape) SetHashId

func (s *Shape) SetHashId(hashid HashValue)

func (*Shape) SetMass

func (s *Shape) SetMass(mass float64)

func (*Shape) SetSensor

func (s *Shape) SetSensor(sensor bool)

func (*Shape) SetSpace

func (s *Shape) SetSpace(space *Space)

func (*Shape) SetSurfaceV

func (s *Shape) SetSurfaceV(surfaceV Vector)

func (*Shape) Space

func (s *Shape) Space() *Space

func (Shape) String

func (s Shape) String() string

func (*Shape) Update

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

type ShapeClass

type ShapeClass interface {
	CacheData(transform Transform) BB
	PointQuery(p Vector, info *PointQueryInfo)
	SegmentQuery(a, b Vector, radius float64, info *SegmentQueryInfo)
}

type ShapeFilter

type ShapeFilter struct {
	// Two objects with the same non-zero group value do not collide.
	// This is generally used to group objects in a composite object together to disable self collisions.
	Group uint
	// A bitmask of user definable categories that this object belongs to.
	// The category/mask combinations of both objects in a collision must agree for a collision to occur.
	Categories uint
	// A bitmask of user definable category types that this object object collides with.
	// The category/mask combinations of both objects in a collision must agree for a collision to occur.
	Mask uint
}

ShapeFilter is fast collision filtering type that is used to determine if two objects collide before calling collision or query callbacks.

func NewShapeFilter

func NewShapeFilter(group, categories, mask uint) ShapeFilter

NewShapeFilter creates a new collision filter.

func (ShapeFilter) Reject

func (a ShapeFilter) Reject(b ShapeFilter) bool

type ShapeMassInfo

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

ShapeMassInfo is mass info struct

func CircleShapeMassInfo

func CircleShapeMassInfo(mass, radius float64, center Vector) *ShapeMassInfo

func NewSegmentMassInfo

func NewSegmentMassInfo(mass float64, a, b Vector, r float64) *ShapeMassInfo

func PolyShapeMassInfo

func PolyShapeMassInfo(mass float64, count int, verts []Vector, r float64) *ShapeMassInfo

type ShapePair

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

type Shaper

type Shaper interface {
	Body() *Body
	MassInfo() *ShapeMassInfo
	HashId() HashValue
	SetHashId(HashValue)
	SetSpace(*Space)
	BB() BB
	SetBB(BB)
}

type SimpleMotor

type SimpleMotor struct {
	*Constraint

	Rate float64
	// contains filtered or unexported fields
}

func (*SimpleMotor) ApplyCachedImpulse

func (motor *SimpleMotor) ApplyCachedImpulse(dt_coef float64)

func (*SimpleMotor) ApplyImpulse

func (motor *SimpleMotor) ApplyImpulse(dt float64)

func (*SimpleMotor) GetImpulse

func (motor *SimpleMotor) GetImpulse() float64

func (*SimpleMotor) PreStep

func (motor *SimpleMotor) PreStep(dt float64)

type SlideJoint

type SlideJoint struct {
	*Constraint

	AnchorA, AnchorB Vector
	Min, Max         float64
	// contains filtered or unexported fields
}

func (*SlideJoint) ApplyCachedImpulse

func (joint *SlideJoint) ApplyCachedImpulse(dt_coef float64)

func (*SlideJoint) ApplyImpulse

func (joint *SlideJoint) ApplyImpulse(dt float64)

func (*SlideJoint) GetImpulse

func (joint *SlideJoint) GetImpulse() float64

func (*SlideJoint) PreStep

func (joint *SlideJoint) PreStep(dt float64)

type Space

type Space struct {
	Iterations uint // must be non-zero

	IdleSpeedThreshold float64
	SleepTimeThreshold float64

	StaticBody *Body
	// contains filtered or unexported fields
}

func NewSpace

func NewSpace() *Space

func (*Space) Activate

func (space *Space) Activate(body *Body)

func (*Space) AddBody

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

func (*Space) AddConstraint

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

func (*Space) AddPostStepCallback

func (space *Space) AddPostStepCallback(f PostStepCallbackFunc, key, data interface{}) bool

func (*Space) AddShape

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

func (*Space) ArrayForBodyType

func (space *Space) ArrayForBodyType(bodyType int) *[]*Body

func (*Space) BBQuery

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

func (*Space) ContactBufferGetArray

func (space *Space) ContactBufferGetArray() []Contact

func (*Space) ContainsBody

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

func (*Space) ContainsConstraint

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

func (*Space) ContainsShape

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

func (*Space) Damping

func (space *Space) Damping() float64

func (*Space) Deactivate

func (space *Space) Deactivate(body *Body)

func (*Space) EachBody

func (space *Space) EachBody(f func(body *Body))

func (*Space) EachConstraint

func (space *Space) EachConstraint(f func(*Constraint))

func (*Space) EachShape

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

func (*Space) FilterArbiters

func (space *Space) FilterArbiters(body *Body, filter *Shape)

func (*Space) Gravity

func (space *Space) Gravity() Vector

func (*Space) Lock

func (space *Space) Lock()

func (*Space) LookupHandler

func (space *Space) LookupHandler(a, b CollisionType, defaultHandler *CollisionHandler) *CollisionHandler

func (*Space) NewCollisionHandler

func (space *Space) NewCollisionHandler(collisionTypeA, collisionTypeB CollisionType) *CollisionHandler

func (*Space) NewWildcardCollisionHandler

func (space *Space) NewWildcardCollisionHandler(collisionType CollisionType) *CollisionHandler

func (*Space) PointQueryNearest

func (space *Space) PointQueryNearest(point Vector, maxDistance float64, filter ShapeFilter) *PointQueryInfo

func (*Space) PopContacts

func (space *Space) PopContacts(count int)

func (*Space) PostStepCallback

func (space *Space) PostStepCallback(key interface{}) *PostStepCallback

func (*Space) ProcessComponents

func (space *Space) ProcessComponents(dt float64)

func (*Space) PushContacts

func (space *Space) PushContacts(count int)

func (*Space) PushFreshContactBuffer

func (space *Space) PushFreshContactBuffer()

func (*Space) RemoveBody

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

func (*Space) RemoveConstraint

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

func (*Space) RemoveShape

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

func (*Space) SegmentQuery

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

func (*Space) SegmentQueryFirst

func (space *Space) SegmentQueryFirst(start, end Vector, radius float64, filter ShapeFilter) SegmentQueryInfo

func (*Space) SetCollisionSlop

func (space *Space) SetCollisionSlop(slop float64)

func (*Space) SetDamping

func (space *Space) SetDamping(damping float64)

func (*Space) SetGravity

func (space *Space) SetGravity(gravity Vector)

func (*Space) SetStaticBody

func (space *Space) SetStaticBody(body *Body)

func (*Space) ShapeQuery

func (space *Space) ShapeQuery(shape *Shape, callback func(shape *Shape, points *ContactPointSet)) bool

ShapeQuery queries a space for any shapes overlapping the given shape and call the callback for each shape found.

func (*Space) Step

func (space *Space) Step(dt float64)

func (*Space) TimeStep

func (space *Space) TimeStep() float64

func (*Space) UncacheArbiter

func (space *Space) UncacheArbiter(arb *Arbiter)

func (*Space) Unlock

func (space *Space) Unlock(runPostStep bool)

func (*Space) UseSpatialHash

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

func (*Space) UseWildcardDefaultHandler

func (space *Space) UseWildcardDefaultHandler()

type SpaceBBQueryFunc

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

type SpaceHash

type SpaceHash struct {
	*SpatialIndex
	// contains filtered or unexported fields
}

func (*SpaceHash) Contains

func (hash *SpaceHash) Contains(obj *Shape, hashId HashValue) bool

func (*SpaceHash) Count

func (hash *SpaceHash) Count() int

func (*SpaceHash) Each

func (hash *SpaceHash) Each(f SpatialIndexIterator)

func (*SpaceHash) Insert

func (hash *SpaceHash) Insert(obj *Shape, hashId HashValue)

func (*SpaceHash) Query

func (hash *SpaceHash) Query(obj interface{}, bb BB, f SpatialIndexQuery, data interface{})

func (*SpaceHash) Reindex

func (hash *SpaceHash) Reindex()

func (*SpaceHash) ReindexObject

func (hash *SpaceHash) ReindexObject(obj *Shape, hashId HashValue)

func (*SpaceHash) ReindexQuery

func (hash *SpaceHash) ReindexQuery(f SpatialIndexQuery, data interface{})

func (*SpaceHash) Remove

func (hash *SpaceHash) Remove(obj *Shape, hashId HashValue)

func (*SpaceHash) SegmentQuery

func (hash *SpaceHash) SegmentQuery(obj interface{}, a, b Vector, t_exit float64, f SpatialIndexSegmentQuery, data interface{})

modified from http://playtechs.blogspot.com/2007/03/raytracing-on-grid.html

type SpaceHashBin

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

type SpacePointQueryFunc

type SpacePointQueryFunc func(*Shape, Vector, float64, Vector, interface{})

type SpaceSegmentQueryFunc

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

type SpatialIndex

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

func NewBBTree

func NewBBTree(bbfunc SpatialIndexBB, staticIndex *SpatialIndex) *SpatialIndex

func NewSpaceHash

func NewSpaceHash(celldim float64, num int, bbfunc SpatialIndexBB, staticIndex *SpatialIndex) *SpatialIndex

func NewSpatialIndex

func NewSpatialIndex(klass SpatialIndexer, bbfunc SpatialIndexBB, staticIndex *SpatialIndex) *SpatialIndex

func (*SpatialIndex) CollideStatic

func (dynamicIndex *SpatialIndex) CollideStatic(staticIndex *SpatialIndex, f SpatialIndexQuery, data interface{})

func (*SpatialIndex) GetRootIfTree

func (index *SpatialIndex) GetRootIfTree() *Node

func (*SpatialIndex) GetTree

func (index *SpatialIndex) GetTree() *BBTree

type SpatialIndexBB

type SpatialIndexBB func(obj *Shape) BB

type SpatialIndexIterator

type SpatialIndexIterator func(obj *Shape)

type SpatialIndexQuery

type SpatialIndexQuery func(obj1 interface{}, obj2 *Shape, collisionId uint32, data interface{}) uint32

type SpatialIndexSegmentQuery

type SpatialIndexSegmentQuery func(obj1 interface{}, obj2 *Shape, data interface{}) float64

type SpatialIndexer

type SpatialIndexer interface {
	Count() int
	Each(f SpatialIndexIterator)
	Contains(obj *Shape, hashId HashValue) bool
	Insert(obj *Shape, hashId HashValue)
	Remove(obj *Shape, hashId HashValue)
	Reindex()
	ReindexObject(obj *Shape, hashId HashValue)
	ReindexQuery(f SpatialIndexQuery, data interface{})
	Query(obj interface{}, bb BB, f SpatialIndexQuery, data interface{})
	SegmentQuery(obj interface{}, a, b Vector, t_exit float64, f SpatialIndexSegmentQuery, data interface{})
}

SpatialIndexer implemented by BBTree

type SplittingPlane

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

type SupportContext

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

func (*SupportContext) Support

func (ctx *SupportContext) Support(n Vector) MinkowskiPoint

Support calculates the maximal point on the minkowski difference of two shapes along a particular axis.

type SupportPoint

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

func CircleSupportPoint

func CircleSupportPoint(shape *Shape, _ Vector) SupportPoint

func NewSupportPoint

func NewSupportPoint(p Vector, index uint32) SupportPoint

func PolySupportPoint

func PolySupportPoint(shape *Shape, n Vector) SupportPoint

func SegmentSupportPoint

func SegmentSupportPoint(shape *Shape, n Vector) SupportPoint

type SupportPointFunc

type SupportPointFunc func(shape *Shape, n Vector) SupportPoint

type Thread

type Thread struct {
	// contains filtered or unexported fields
}
func (thread *Thread) Unlink()

type Transform

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

func NewTransform

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

func NewTransformIdentity

func NewTransformIdentity() Transform

func NewTransformRigid

func NewTransformRigid(translate Vector, radians float64) Transform

func NewTransformRigidInverse

func NewTransformRigidInverse(t Transform) Transform

func NewTransformRotate

func NewTransformRotate(radians float64) Transform

func NewTransformScale

func NewTransformScale(scaleX, scaleY float64) Transform

func NewTransformTranslate

func NewTransformTranslate(translate Vector) Transform

func NewTransformTranspose

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

func (Transform) AxialScale

func (t Transform) AxialScale(axis, pivot Vector, scale float64) Transform

func (Transform) BB

func (t Transform) BB(bb BB) BB

func (Transform) BoneScale

func (t Transform) BoneScale(v0, v1 Vector) Transform

func (Transform) Inverse

func (t Transform) Inverse() Transform

func (Transform) Mult

func (t Transform) Mult(t2 Transform) Transform

func (Transform) Ortho

func (t Transform) Ortho(bb BB) Transform

func (Transform) Point

func (t Transform) Point(p Vector) Vector

func (Transform) Vect

func (t Transform) Vect(v Vector) Vector

func (Transform) Wrap

func (t Transform) Wrap(inner Transform) Transform

type Vector

type Vector struct {
	X, Y float64
}

func CentroidForPoly

func CentroidForPoly(count int, verts []Vector) Vector

CentroidForPoly calculates the natural centroid of a polygon.

func ForAngle

func ForAngle(a float64) Vector

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

func (Vector) Add

func (v Vector) Add(other Vector) Vector

func (Vector) CheckAxis

func (v Vector) CheckAxis(v1, p, n Vector) bool

func (Vector) Clamp

func (v Vector) Clamp(length float64) Vector

func (Vector) Clone

func (v Vector) Clone() Vector

func (Vector) ClosestDist

func (v Vector) ClosestDist(v1 Vector) float64

func (Vector) ClosestPointOnSegment

func (v Vector) ClosestPointOnSegment(a, b Vector) Vector

func (Vector) ClosestT

func (v Vector) ClosestT(b Vector) float64

func (Vector) Cross

func (v Vector) Cross(other Vector) float64

Cross calculates the 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 (Vector) Distance

func (v Vector) Distance(other Vector) float64

func (Vector) DistanceSq

func (v Vector) DistanceSq(other Vector) float64

func (Vector) Dot

func (v Vector) Dot(other Vector) float64

func (Vector) Equal

func (v Vector) Equal(other Vector) bool

func (Vector) Length

func (v Vector) Length() float64

func (Vector) LengthSq

func (v Vector) LengthSq() float64

func (Vector) Lerp

func (v Vector) Lerp(other Vector, t float64) Vector

func (Vector) LerpConst

func (v Vector) LerpConst(other Vector, d float64) Vector

func (Vector) LerpT

func (v Vector) LerpT(b Vector, t float64) Vector

func (Vector) Mult

func (v Vector) Mult(s float64) Vector

func (Vector) Near

func (v Vector) Near(other Vector, d float64) bool

func (Vector) Neg

func (v Vector) Neg() Vector

func (Vector) Normalize

func (v Vector) Normalize() Vector

func (Vector) Perp

func (v Vector) Perp() Vector

func (Vector) PointGreater

func (v Vector) PointGreater(b, c Vector) bool

func (Vector) Project

func (v Vector) Project(other Vector) Vector

func (Vector) ReversePerp

func (v Vector) ReversePerp() Vector

func (Vector) Rotate

func (v Vector) Rotate(other Vector) Vector

func (Vector) SLerp

func (v Vector) SLerp(other Vector, t float64) Vector

func (Vector) SlerpConst

func (v Vector) SlerpConst(other Vector, a float64) Vector

func (Vector) String

func (v Vector) String() string

func (Vector) Sub

func (v Vector) Sub(other Vector) Vector

func (Vector) ToAngle

func (v Vector) ToAngle() float64

func (Vector) Unrotate

func (v Vector) Unrotate(other Vector) Vector

Jump to

Keyboard shortcuts

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