cp

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: MIT Imports: 4 Imported by: 171

README

cp

GoDoc Sourcegraph

Chipmunk2D ported to Go

project status

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

examples

https://github.com/jakecoffman/cp-examples contains the port of all of the Chipmunk2D demos.

https://github.com/hajimehoshi/ebiten/blob/master/examples/chipmunk/main.go is an example using Ebiten

https://github.com/gen2brain/raylib-go/blob/master/examples/physics/chipmunk/main.go is an example with raylib's Go port

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 (
	MAX_GJK_ITERATIONS  = 30
	MAX_EPA_ITERATIONS  = 30
	WARN_GJK_ITERATIONS = 20
	WARN_EPA_ITERATIONS = 20
)
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 HASH_COEF = 3344921057
View Source
const MAX_CONTACTS_PER_ARBITER = 2
View Source
const (
	SHAPE_TYPE_NUM = 3
)

Variables

View Source
var (
	NO_GROUP       uint = 0
	ALL_CATEGORIES uint = ^uint(0)
)
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

func AreaForPoly

func AreaForPoly(count int, verts []Vector, r float64) float64

func AreaForSegment

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

func BodyUpdatePosition

func BodyUpdatePosition(body *Body, dt float64)

func BodyUpdateVelocity

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

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(info *CollisionInfo)

func ComponentActive

func ComponentActive(root *Body, threshold float64) bool

func ContactPoints

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

Given two support edges, find contact point pairs on their 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

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 added in v1.2.0

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

func MarchCellSoft added in v1.2.0

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

func MomentForBox

func MomentForBox(m, width, height float64) float64

func MomentForBox2

func MomentForBox2(m float64, box BB) float64

func MomentForCircle

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

func MomentForPoly

func MomentForPoly(m float64, count int, verts []Vector, offset Vector, r float64) float64

func MomentForSegment

func MomentForSegment(m float64, a, b Vector, r float64) float64

func NearestPointQueryNearest

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

func Next added in v1.2.0

func Next(i, count int) int

func NodeSetA

func NodeSetA(node, value *Node)

func NodeSetB

func NodeSetB(node, value *Node)

func PolyLineCollectSegment added in v1.2.0

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 added in v1.2.0

func Sharpness(a, b, c Vector) float64

func SpaceArbiterSetFilter

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

Hashset filter func to throw 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
}

func ArbiterNext

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

func SpaceArbiterSetTrans

func SpaceArbiterSetTrans(shapes ShapePair, space *Space) *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)

func (*Arbiter) CallWildcardBeginA

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

func (*Arbiter) CallWildcardBeginB

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

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

func (*Arbiter) CallWildcardPreSolveB

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

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

func (*Arbiter) Count

func (arb *Arbiter) Count() int

func (*Arbiter) Ignore

func (arb *Arbiter) Ignore() bool

func (*Arbiter) Init

func (arbiter *Arbiter) Init(a, b *Shape) *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)

func (*Arbiter) Shapes

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

func (*Arbiter) ThreadForBody

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

func (*Arbiter) TotalImpulse

func (arb *Arbiter) TotalImpulse() Vector

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
}

func NewBBForCircle

func NewBBForCircle(p Vector, r float64) BB

func NewBBForExtents

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

func ShapeGetBB

func ShapeGetBB(obj *Shape) BB

func (BB) Area

func (bb BB) Area() float64

func (BB) Center

func (bb BB) Center() Vector

func (BB) ClampVect

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

func (BB) Contains

func (bb BB) Contains(other BB) bool

func (BB) ContainsVect

func (bb BB) ContainsVect(v Vector) bool

func (BB) Expand

func (bb BB) Expand(v Vector) BB

func (BB) Intersects

func (a BB) Intersects(b BB) bool

func (BB) IntersectsSegment

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

func (BB) Merge

func (a BB) Merge(b BB) BB

func (BB) MergedArea

func (a BB) MergedArea(b BB) float64

func (BB) Offset

func (bb BB) Offset(v Vector) BB

func (BB) Proximity

func (a BB) Proximity(b BB) float64

func (BB) SegmentQuery

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

func (BB) String

func (bb BB) String() string

func (BB) WrapVect

func (bb BB) WrapVect(v Vector) Vector

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 interface{}
	// contains filtered or unexported fields
}

func NewBody

func NewBody(mass, moment float64) *Body

func NewKinematicBody

func NewKinematicBody() *Body

func NewStaticBody

func NewStaticBody() *Body

func (*Body) AccumulateMassFromShapes

func (body *Body) AccumulateMassFromShapes()

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

func (*Body) Activate

func (body *Body) Activate()

func (*Body) ActivateStatic

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

func (*Body) AddShape

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

func (*Body) Angle

func (body *Body) Angle() float64

func (*Body) AngularVelocity

func (body *Body) AngularVelocity() float64

func (*Body) ApplyForceAtLocalPoint

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

func (*Body) ApplyForceAtWorldPoint

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

func (*Body) ApplyImpulseAtLocalPoint

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

func (*Body) ApplyImpulseAtWorldPoint

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

func (Body) CenterOfGravity

func (body Body) CenterOfGravity() Vector

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

func (*Body) EachConstraint

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

func (*Body) EachShape

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

func (*Body) Force

func (body *Body) Force() Vector

func (*Body) GetType

func (body *Body) GetType() int

func (*Body) IdleTime

func (body *Body) IdleTime() float64

func (*Body) IsSleeping

func (body *Body) IsSleeping() bool

func (*Body) KineticEnergy

func (body *Body) KineticEnergy() float64

func (*Body) LocalToWorld

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

func (*Body) Mass

func (body *Body) Mass() float64

func (Body) Moment

func (body Body) Moment() float64

func (*Body) Position

func (body *Body) Position() Vector

func (*Body) PushArbiter

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

func (*Body) RemoveConstraint

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

func (*Body) RemoveShape

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

func (*Body) Rotation

func (body *Body) Rotation() Vector

func (*Body) SetAngle

func (body *Body) SetAngle(angle float64)

func (*Body) SetAngularVelocity

func (body *Body) SetAngularVelocity(angularVelocity float64)

func (*Body) SetForce

func (body *Body) SetForce(force Vector)

func (*Body) SetMass

func (body *Body) SetMass(mass float64)

func (*Body) SetMoment

func (body *Body) SetMoment(moment float64)

func (*Body) SetPosition

func (body *Body) SetPosition(position Vector)

func (*Body) SetPositionUpdateFunc

func (body *Body) SetPositionUpdateFunc(f BodyPositionFunc)

func (*Body) SetTorque added in v1.1.0

func (body *Body) SetTorque(torque float64)

func (*Body) SetTransform

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

func (*Body) SetType

func (body *Body) SetType(newType int)

func (*Body) SetVelocity

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

func (*Body) SetVelocityUpdateFunc

func (body *Body) SetVelocityUpdateFunc(f BodyVelocityFunc)

func (*Body) SetVelocityVector

func (body *Body) SetVelocityVector(v Vector)

func (Body) String

func (b Body) String() string

func (*Body) Torque added in v1.1.0

func (body *Body) Torque() float64

func (*Body) UpdateVelocity

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

func (*Body) Velocity

func (body *Body) Velocity() Vector

func (*Body) VelocityAtLocalPoint

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

func (*Body) VelocityAtWorldPoint

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

func (*Body) WorldToLocal

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

type BodyPositionFunc

type BodyPositionFunc func(body *Body, dt float64)

/ Rigid body position update function type.

type BodyVelocityFunc

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

/ 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

Find the closest points on the surface of two overlapping shapes using the EPA algorithm. EPA is called from GJK when two shapes overlap. 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

Recursive 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

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

func GJKRecurse

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

Recursive implementation of the GJK loop.

type CollisionBeginFunc

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

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{}
}

/ 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
}

func Collide added in v1.2.0

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

Collide performs a collision between two shapes

func (*CollisionInfo) Collide

func (info *CollisionInfo) Collide(a, b *Shape)

Collide performs a collision between two shapes Deprecated - use Collide below

func (*CollisionInfo) PushContact

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

type CollisionPostSolveFunc

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

type CollisionPreSolveFunc

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

type CollisionSeparateFunc

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

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
	// 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  int
	Normal Vector

	Points [MAX_CONTACTS_PER_ARBITER]struct {
		/// The position of the contact on the surface of each shape.
		PointA, PointB Vector
		/// Penetration distance of the two shapes. Overlapping means it will be negative.
		/// This value is calculated as cpvdot(cpvsub(point2, point1), normal) and is ignored by cpArbiterSetContactPointSet().
		Distance float64
	}
}

func ShapesCollide added in v1.2.0

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 struct {
	// contains filtered or unexported fields
}

func NewHashSet

func NewHashSet(eql HashSetEqual) *HashSet

func (*HashSet) Count

func (set *HashSet) Count() uint

func (*HashSet) Each

func (set *HashSet) Each(f HashSetIterator)

func (*HashSet) Filter

func (set *HashSet) Filter(f HashSetFilter, data interface{})

func (*HashSet) Find

func (set *HashSet) Find(hash HashValue, ptr interface{}) interface{}

func (*HashSet) Free

func (set *HashSet) Free()

func (*HashSet) GetUnusedBin

func (set *HashSet) GetUnusedBin() *HashSetBin

func (*HashSet) Insert

func (set *HashSet) Insert(hash HashValue, ptr interface{}, trans HashSetTrans, data interface{}) interface{}

func (*HashSet) Recycle

func (set *HashSet) Recycle(bin *HashSetBin)

func (*HashSet) Remove

func (set *HashSet) Remove(hash HashValue, ptr interface{}) interface{}

func (*HashSet) Resize

func (set *HashSet) Resize()

type HashSetArbiter

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

func NewHashSetArbiter

func NewHashSetArbiter(eql HashSetEqualArbiter) *HashSetArbiter

func (*HashSetArbiter) Count

func (set *HashSetArbiter) Count() uint

func (*HashSetArbiter) Each

func (*HashSetArbiter) Filter

func (set *HashSetArbiter) Filter(filter func(arb *Arbiter) bool)

func (*HashSetArbiter) Find

func (set *HashSetArbiter) Find(hash HashValue, ptr ShapePair) interface{}

func (*HashSetArbiter) Free

func (set *HashSetArbiter) Free()

func (*HashSetArbiter) GetUnusedBin

func (set *HashSetArbiter) GetUnusedBin() *HashSetBinArbiter

func (*HashSetArbiter) Insert

func (set *HashSetArbiter) Insert(hash HashValue, ptr ShapePair, trans HashSetTransArbiter, space *Space) *Arbiter

func (*HashSetArbiter) InsertArb

func (set *HashSetArbiter) InsertArb(hash HashValue, ptr ShapePair, arb *Arbiter) interface{}

func (*HashSetArbiter) Recycle

func (set *HashSetArbiter) Recycle(bin *HashSetBinArbiter)

func (*HashSetArbiter) Remove

func (set *HashSetArbiter) Remove(hash HashValue, ptr ShapePair) *Arbiter

func (*HashSetArbiter) Resize

func (set *HashSetArbiter) Resize()

type HashSetBin

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

type HashSetBinArbiter

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

type HashSetBinCollisionHandler

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

type HashSetBinHandle

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

type HashSetCollisionHandler

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

func NewHashSetCollisionHandler

func NewHashSetCollisionHandler() *HashSetCollisionHandler

func (*HashSetCollisionHandler) Count

func (set *HashSetCollisionHandler) Count() uint

func (*HashSetCollisionHandler) Each

func (*HashSetCollisionHandler) Find

func (*HashSetCollisionHandler) Insert

func (*HashSetCollisionHandler) Resize

func (set *HashSetCollisionHandler) Resize()

type HashSetEqual

type HashSetEqual func(ptr, elt interface{}) bool

type HashSetEqualArbiter

type HashSetEqualArbiter func(ptr ShapePair, elt *Arbiter) bool

type HashSetEqualCollisionHandler

type HashSetEqualCollisionHandler func(ptr, elt interface{}) bool

type HashSetEqualHandle

type HashSetEqualHandle func(ptr *Shape, elt *Handle) bool

type HashSetFilter

type HashSetFilter func(elt, data interface{}) bool

type HashSetFilterArbiter

type HashSetFilterArbiter func(arb *Arbiter, space *Space) bool

type HashSetFilterCollisionHandler

type HashSetFilterCollisionHandler func(elt, data interface{}) bool

type HashSetFilterHandle

type HashSetFilterHandle func(arb *Handle, space *Space) bool

type HashSetHandle

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

func NewHashSetHandle

func NewHashSetHandle(eql HashSetEqualHandle) *HashSetHandle

func (*HashSetHandle) Count

func (set *HashSetHandle) Count() uint

func (*HashSetHandle) Each

func (set *HashSetHandle) Each(f HashSetIteratorHandle)

func (*HashSetHandle) Find

func (set *HashSetHandle) Find(hash HashValue, ptr *Shape) interface{}

func (*HashSetHandle) Free

func (set *HashSetHandle) Free()

func (*HashSetHandle) GetUnusedBin

func (set *HashSetHandle) GetUnusedBin() *HashSetBinHandle

func (*HashSetHandle) Insert

func (set *HashSetHandle) Insert(hash HashValue, ptr *Shape, trans HashSetTransHandle, spaceHash *SpaceHash) *Handle

func (*HashSetHandle) InsertArb

func (set *HashSetHandle) InsertArb(hash HashValue, ptr *Shape, arb *Handle) interface{}

func (*HashSetHandle) Recycle

func (set *HashSetHandle) Recycle(bin *HashSetBinHandle)

func (*HashSetHandle) Remove

func (set *HashSetHandle) Remove(hash HashValue, ptr *Shape) *Handle

func (*HashSetHandle) Resize

func (set *HashSetHandle) Resize()

type HashSetIterator

type HashSetIterator func(elt interface{})

type HashSetIteratorArbiter

type HashSetIteratorArbiter func(elt *Arbiter)

type HashSetIteratorCollisionHandler

type HashSetIteratorCollisionHandler func(elt interface{})

type HashSetIteratorHandle

type HashSetIteratorHandle func(elt *Handle)

type HashSetTrans

type HashSetTrans func(ptr, data interface{}) interface{}

type HashSetTransArbiter

type HashSetTransArbiter func(ptr ShapePair, space *Space) *Arbiter

type HashSetTransCollisionHandler

type HashSetTransCollisionHandler func(ptr, data interface{}) interface{}

type HashSetTransHandle

type HashSetTransHandle func(ptr *Shape, hash *SpaceHash) *Handle

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 added in v1.2.0

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

type MarchSampleFunc added in v1.2.0

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 added in v1.2.0

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
}

func (*Mat2x2) Transform

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

type MinkowskiPoint

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

A point on the surface of two shape's minkowski difference.

func NewMinkowskiPoint

func NewMinkowskiPoint(a, b SupportPoint) MinkowskiPoint

func (MinkowskiPoint) ClosestPoints

func (v0 MinkowskiPoint) ClosestPoints(v1 MinkowskiPoint) ClosestPoints

Calculate 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
}

type PolyLine added in v1.2.0

type PolyLine struct {
	Verts []Vector
}

func DouglasPeucker added in v1.2.0

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

Recursive function used by cpPolylineSimplifyCurves().

func (*PolyLine) Enqueue added in v1.2.0

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

func (*PolyLine) IsClosed added in v1.2.0

func (pl *PolyLine) IsClosed() bool

func (*PolyLine) IsShort added in v1.2.0

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

func (*PolyLine) Push added in v1.2.0

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

func (*PolyLine) SimplifyCurves added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

type PolyLineSet struct {
	Lines []*PolyLine
}

func MarchCells added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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

Find the polyline that ends with v.

func (*PolyLineSet) FindStarts added in v1.2.0

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

Find the polyline that starts with v.

func (*PolyLineSet) Join added in v1.2.0

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

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

func (*PolyLineSet) Push added in v1.2.0

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
}

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 added in v1.1.0

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 added in v1.1.0

func (s *Shape) CenterOfGravity() Vector

func (*Shape) Density added in v1.1.0

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 added in v1.1.0

func (s *Shape) Mass() float64

func (*Shape) MassInfo

func (s *Shape) MassInfo() *ShapeMassInfo

func (*Shape) Moment added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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
}

func NewShapeFilter

func NewShapeFilter(group, categories, mask uint) ShapeFilter

func (ShapeFilter) Reject

func (a ShapeFilter) Reject(b ShapeFilter) bool

type ShapeMassInfo

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

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 added in v1.2.0

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

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

Calculate 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, n 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 (outer Transform) AxialScale(axis, pivot Vector, scale float64) Transform

func (Transform) BB

func (t Transform) BB(bb BB) BB

func (Transform) BoneScale

func (outer 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 (outer 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 (outer Transform) Wrap(inner Transform) Transform

type Vector

type Vector struct {
	X, Y float64
}

func CentroidForPoly

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

func ForAngle

func ForAngle(a float64) Vector

/ 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 (v0 Vector) CheckAxis(v1, p, n Vector) bool

func (Vector) Clamp

func (v Vector) Clamp(length float64) Vector

func (Vector) Clone

func (p Vector) Clone() Vector

func (Vector) ClosestDist

func (v0 Vector) ClosestDist(v1 Vector) float64

func (Vector) ClosestPointOnSegment

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

func (Vector) ClosestT

func (a Vector) ClosestT(b Vector) float64

func (Vector) Cross

func (v Vector) Cross(other Vector) 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 (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 (a 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 (a 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