Documentation
¶
Index ¶
- Constants
- Variables
- func AlwaysCollideFunc(_ *Arbiter, _ *Space, _ any) bool
- func AreaForCircle(r1, r2 float64) float64
- func AreaForPolygon(count int, verts []v.Vec, r float64) float64
- func AreaForSegment(a, b v.Vec, r float64) float64
- func BodyUpdatePosition(body *Body, dt float64)
- func BodyUpdateVelocity(body *Body, gravity v.Vec, damping, dt float64)
- func CachedArbitersFilter(arb *Arbiter, space *Space, shape *Shape, body *Body) bool
- func CentroidForPolygon(count int, verts []v.Vec) v.Vec
- func ComponentActive(root *Body, threshold float64) bool
- func Contains(bodies []*Body, body *Body) bool
- func DebugInfo(space *Space) string
- func DefaultBeginFunc(arb *Arbiter, space *Space, _ any) bool
- func DefaultPostSolveFunc(arb *Arbiter, space *Space, _ any)
- func DefaultPreSolveFunc(arb *Arbiter, space *Space, _ any) bool
- func DefaultSeparateFunc(arb *Arbiter, space *Space, _ any)
- func DefaultSpringForce(spring *DampedSpring, dist float64) float64
- func DoNothingFunc(_ *Arbiter, _ *Space, _ any)
- func DrawConstraint(constraint *Constraint, drawer IDrawer)
- func DrawShape(shape *Shape, drawer IDrawer)
- func DrawSpace(space *Space, drawer IDrawer)
- func MomentForBox(mass, width, height float64) float64
- func MomentForBox2(mass float64, box BB) float64
- func MomentForCircle(mass, d1, d2 float64, offset v.Vec) float64
- func MomentForCircle2(mass, radius float64) float64
- func MomentForPolygon(mass float64, count int, verts []v.Vec, offset v.Vec, r float64) float64
- func MomentForSegment(mass float64, a, b v.Vec, radius float64) float64
- func NewContactBuffer(stamp uint, slice *contactBuffer) *contactBuffer
- func PolyLineCollectSegment(v0, v1 v.Vec, pls *PolyLineSet)
- func PolyToPoly(info *CollisionInfo)
- func PostStepDoNothing(space *Space, key, data any)
- func QHullPartition(verts []v.Vec, count int, a, b v.Vec, tol float64) int
- func QHullReduce(tol float64, verts []v.Vec, count int, a, pivot, b v.Vec, result []v.Vec) int
- func QueryReject(a, b *Shape) bool
- func QueryRejectConstraints(a, b *Body) bool
- func Sharpness(a, b, c v.Vec) float64
- func SpaceArbiterSetFilter(arb *Arbiter, space *Space) bool
- func VoidQueryFunc(obj1 any, obj2 *Shape, collisionId uint32, data any) uint32
- type Arbiter
- func (a *Arbiter) Bodies() (*Body, *Body)
- func (a *Arbiter) CallWildcardBeginA(space *Space) bool
- func (a *Arbiter) CallWildcardBeginB(space *Space) bool
- func (a *Arbiter) CallWildcardPostSolveA(space *Space)
- func (a *Arbiter) CallWildcardPostSolveB(space *Space)
- func (a *Arbiter) CallWildcardPreSolveA(space *Space) bool
- func (a *Arbiter) CallWildcardPreSolveB(space *Space) bool
- func (a *Arbiter) CallWildcardSeparateA(space *Space)
- func (a *Arbiter) CallWildcardSeparateB(space *Space)
- func (a *Arbiter) ContactPointSet() ContactPointSet
- func (a *Arbiter) Count() int
- func (a *Arbiter) Ignore() bool
- func (a *Arbiter) Init(shapeA, shapeB *Shape) *Arbiter
- func (a *Arbiter) IsFirstContact() bool
- func (a *Arbiter) Normal() v.Vec
- func (a *Arbiter) SetContactPointSet(set *ContactPointSet)
- func (a *Arbiter) Shapes() (*Shape, *Shape)
- func (a *Arbiter) TotalImpulse() v.Vec
- type BB
- func (bb BB) Area() float64
- func (bb BB) Center() v.Vec
- func (bb BB) ClampVect(vect v.Vec) v.Vec
- func (bb BB) Contains(other BB) bool
- func (bb BB) ContainsVect(v v.Vec) bool
- func (bb BB) Expand(v v.Vec) BB
- func (bb BB) Intersects(b BB) bool
- func (bb BB) IntersectsSegment(a, b v.Vec) bool
- func (a BB) Merge(b BB) BB
- func (a BB) MergedArea(b BB) float64
- func (bb BB) Offset(vect v.Vec) BB
- func (a BB) Proximity(b BB) float64
- func (bb BB) SegmentQuery(a, b v.Vec) float64
- func (bb BB) String() string
- func (bb BB) WrapVect(vect v.Vec) v.Vec
- type BBQueryContext
- type Body
- func (body *Body) AccumulateMassFromShapes()
- func (body *Body) Activate()
- func (body *Body) ActivateStatic(filter *Shape)
- func (body *Body) Angle() float64
- func (body *Body) AngularVelocity() float64
- func (body *Body) ApplyForceAtLocalPoint(force, point v.Vec)
- func (body *Body) ApplyForceAtWorldPoint(force, point v.Vec)
- func (body *Body) ApplyImpulseAtLocalPoint(impulse, point v.Vec)
- func (body *Body) ApplyImpulseAtWorldPoint(impulse, point v.Vec)
- func (body *Body) AttachShape(shape *Shape)
- func (body Body) CenterOfGravity() v.Vec
- func (root *Body) ComponentAdd(body *Body)
- func (body *Body) ComponentRoot() *Body
- func (body *Body) EachArbiter(f func(*Arbiter))
- func (body *Body) EachConstraint(f func(*Constraint))
- func (body *Body) EachShape(f func(*Shape))
- func (body *Body) Force() v.Vec
- func (b Body) ID() int
- func (body *Body) IdleTime() float64
- func (body *Body) IsSleeping() bool
- func (body *Body) KineticEnergy() float64
- func (body *Body) LocalToWorld(point v.Vec) v.Vec
- func (body *Body) Mass() float64
- func (body Body) Moment() float64
- func (body *Body) Position() v.Vec
- func (body *Body) PushArbiter(arb *Arbiter)
- func (body *Body) RemoveConstraint(constraint *Constraint)
- func (body *Body) RemoveShape(shape *Shape)
- func (body *Body) RemoveShapeAtIndex(index int)
- func (body *Body) Rotation() v.Vec
- func (body *Body) SetAngle(angle float64)
- func (body *Body) SetAngularVelocity(angularVelocity float64)
- func (body *Body) SetForce(force v.Vec)
- func (body *Body) SetMass(mass float64)
- func (body *Body) SetMoment(moment float64)
- func (body *Body) SetPosition(position v.Vec)
- func (body *Body) SetPositionUpdateFunc(f BodyPositionFunc)
- func (body *Body) SetTorque(torque float64)
- func (body *Body) SetTransform(p v.Vec, a float64)
- func (body *Body) SetType(bt BodyType)
- func (body *Body) SetVelocity(x, y float64)
- func (body *Body) SetVelocityUpdateFunc(f BodyVelocityFunc)
- func (body *Body) SetVelocityVector(v v.Vec)
- func (b *Body) ShapeAtIndex(index int) *Shape
- func (b Body) String() string
- func (body *Body) Torque() float64
- func (body *Body) Transform() Transform
- func (body *Body) Type() BodyType
- func (body *Body) UpdateVelocity(gravity v.Vec, damping, dt float64)
- func (body *Body) Velocity() v.Vec
- func (body *Body) VelocityAtLocalPoint(point v.Vec) v.Vec
- func (body *Body) VelocityAtWorldPoint(point v.Vec) v.Vec
- func (body *Body) WorldToLocal(point v.Vec) v.Vec
- type BodyPositionFunc
- type BodyType
- type BodyVelocityFunc
- type Circle
- func (circle *Circle) CacheData(transform Transform) BB
- func (circle *Circle) PointQuery(p v.Vec, info *PointQueryInfo)
- func (circle *Circle) Radius() float64
- func (circle *Circle) SegmentQuery(a, b v.Vec, radius float64, info *SegmentQueryInfo)
- func (circle *Circle) SetRadius(r float64)
- func (circle *Circle) TransformC() v.Vec
- type CollisionBeginFunc
- type CollisionHandler
- type CollisionInfo
- type CollisionPostSolveFunc
- type CollisionPreSolveFunc
- type CollisionSeparateFunc
- type CollisionType
- type Constrainer
- type Constraint
- func FilterConstraints(node *Constraint, body *Body, filter *Constraint) *Constraint
- func NewConstraint(class Constrainer, a, b *Body) *Constraint
- func NewDampedRotarySpring(a, b *Body, restAngle, stiffness, damping float64) *Constraint
- func NewDampedSpring(a, b *Body, anchorA, anchorB v.Vec, restLength, stiffness, damping float64) *Constraint
- func NewGearJoint(a, b *Body, phase, ratio float64) *Constraint
- func NewGrooveJoint(a, b *Body, grooveA, grooveB, anchorB v.Vec) *Constraint
- func NewPinJoint(a, b *Body, anchorA, anchorB v.Vec) *Constraint
- func NewPivotJoint(a, b *Body, pivot v.Vec) *Constraint
- func NewPivotJoint2(a, b *Body, anchorA, anchorB v.Vec) *Constraint
- func NewRatchetJoint(a, b *Body, phase, ratchet float64) *Constraint
- func NewRotaryLimitJoint(a, b *Body, min, max float64) *Constraint
- func NewSimpleMotor(a, b *Body, rate float64) *Constraint
- func NewSlideJoint(a, b *Body, anchorA, anchorB v.Vec, min, max float64) *Constraint
- func (c *Constraint) ActivateBodies()
- func (c *Constraint) BodyA() *Body
- func (c *Constraint) BodyB() *Body
- func (c Constraint) ErrorBias() float64
- func (c Constraint) MaxBias() float64
- func (c Constraint) MaxForce() float64
- func (c *Constraint) Next(body *Body) *Constraint
- func (c *Constraint) SetCollideBodies(collideBodies bool)
- func (c *Constraint) SetErrorBias(errorBias float64)
- func (c *Constraint) SetMaxBias(max float64)
- func (c *Constraint) SetMaxForce(max float64)
- type ConstraintPostSolveFunc
- type ConstraintPreSolveFunc
- type Contact
- type ContactPointSet
- type DampedRotarySpring
- type DampedSpring
- type DampedSpringForceFunc
- type FColor
- type GearJoint
- type GrooveJoint
- type HashSetBin
- type HashValue
- type IDrawer
- type IShape
- type PinJoint
- type PivotJoint
- type PointQueryInfo
- type PolyLine
- func (pl *PolyLine) Enqueue(vect v.Vec) *PolyLine
- func (pl *PolyLine) IsClosed() bool
- func (pl *PolyLine) IsShort(count, start, end int, min float64) bool
- func (pl *PolyLine) Push(v v.Vec) *PolyLine
- func (pl *PolyLine) SimplifyCurves(tol float64) *PolyLine
- func (pl *PolyLine) SimplifyVertexes(tol float64) *PolyLine
- type PolyLineSet
- type Polygon
- func (ps *Polygon) CacheData(transform Transform) BB
- func (ps *Polygon) Count() int
- func (ps *Polygon) PointQuery(p v.Vec, info *PointQueryInfo)
- func (ps *Polygon) SegmentQuery(a, b v.Vec, r2 float64, info *SegmentQueryInfo)
- func (ps *Polygon) SetVerts(count int, verts []v.Vec)
- func (p *Polygon) SetVertsRaw(count int, verts []v.Vec)
- func (ps *Polygon) SetVertsUnsafe(count int, verts []v.Vec, transform Transform)
- func (ps *Polygon) TransformVert(i int) v.Vec
- func (ps *Polygon) Vert(vertIndex int) v.Vec
- type PostStepCallbackFunc
- type RatchetJoint
- type RotaryLimitJoint
- type Segment
- func (seg *Segment) A() v.Vec
- func (seg *Segment) B() v.Vec
- func (seg *Segment) CacheData(transform Transform) BB
- func (seg *Segment) Normal() v.Vec
- func (seg *Segment) PointQuery(p v.Vec, info *PointQueryInfo)
- func (seg *Segment) Radius() float64
- func (seg *Segment) SegmentQuery(a, b v.Vec, r2 float64, info *SegmentQueryInfo)
- func (seg *Segment) SetEndpoints(a, b v.Vec)
- func (seg *Segment) SetRadius(r float64)
- func (seg *Segment) TransformA() v.Vec
- func (seg *Segment) TransformB() v.Vec
- type SegmentQueryContext
- type SegmentQueryInfo
- type Shape
- func NewBox(body *Body, w, h, r float64) *Shape
- func NewBox2(body *Body, bb BB, r float64) *Shape
- func NewCircle(b *Body, r float64, offset v.Vec) *Shape
- func NewPolygon(b *Body, vertices []v.Vec, t Transform, r float64) *Shape
- func NewPolygonRaw(body *Body, count int, verts []v.Vec, roundingRadius float64) *Shape
- func NewSegment(body *Body, a, b v.Vec, r float64) *Shape
- func NewShape(class IShape, body *Body, massInfo *ShapeMassInfo) *Shape
- func (sh *Shape) Area() float64
- func (sh *Shape) CacheBB() BB
- func (sh *Shape) CenterOfGravity() v.Vec
- func (sh *Shape) Density() float64
- func (sh *Shape) HashId() HashValue
- func (sh *Shape) Mass() float64
- func (sh *Shape) Moment() float64
- func (s *Shape) Order() int
- func (sh *Shape) PointQuery(p v.Vec) PointQueryInfo
- func (sh *Shape) SegmentQuery(a, b v.Vec, radius float64, info *SegmentQueryInfo) bool
- func (sh *Shape) SetBody(b *Body)
- func (sh *Shape) SetCollisionType(collisionType CollisionType)
- func (sh *Shape) SetDensity(density float64)
- func (sh *Shape) SetElasticity(e float64)
- func (sh *Shape) SetFriction(u float64)
- func (sh *Shape) SetHashId(hashid HashValue)
- func (sh *Shape) SetMass(mass float64)
- func (sh *Shape) SetSensor(sensor bool)
- func (sh *Shape) SetShapeFilter(filter ShapeFilter)
- func (s Shape) String() string
- func (sh *Shape) Update(transform Transform) BB
- type ShapeFilter
- type ShapeMassInfo
- type ShapePair
- type SimpleMotor
- type SlideJoint
- type Space
- func (s *Space) Activate(body *Body)
- func (s *Space) AddBody(body *Body)
- func (s *Space) AddBodyWithShapes(body *Body)
- func (s *Space) AddCollisionHandler(a, b CollisionType) *CollisionHandler
- func (s *Space) AddCollisionHandler2(handler *CollisionHandler)
- func (s *Space) AddConstraint(constraint *Constraint) *Constraint
- func (s *Space) AddPostStepCallback(f PostStepCallbackFunc, key, data any) bool
- func (s *Space) AddShape(shape *Shape) *Shape
- func (s *Space) AddWildcardCollisionHandler(typeA CollisionType) *CollisionHandler
- func (s *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data any)
- func (s *Space) ContainsBody(body *Body) bool
- func (s *Space) ContainsConstraint(constraint *Constraint) bool
- func (s *Space) ContainsShape(shape *Shape) bool
- func (s *Space) Deactivate(body *Body)
- func (s *Space) DynamicBodyCount() int
- func (s *Space) DynamicShapeCount() int
- func (s *Space) EachBody(f func(b *Body))
- func (s *Space) EachConstraint(f func(*Constraint))
- func (s *Space) EachDynamicBody(f func(b *Body))
- func (s *Space) EachDynamicShape(f func(*Shape))
- func (s *Space) EachShape(f func(*Shape))
- func (s *Space) EachStaticBody(f func(b *Body))
- func (s *Space) EachStaticShape(f func(*Shape))
- func (s *Space) FilterArbiters(body *Body, filter *Shape)
- func (s *Space) IsLocked() bool
- func (s *Space) LookupHandler(a, b CollisionType, defaultHandler *CollisionHandler) *CollisionHandler
- func (s *Space) PointQueryNearest(point v.Vec, maxDistance float64, filter ShapeFilter) *PointQueryInfo
- func (s *Space) PostStepCallback(key any) *postStepCallback
- func (s *Space) ReindexShape(shape *Shape)
- func (s *Space) RemoveBody(body *Body)
- func (s *Space) RemoveBodyWithShapes(body *Body)
- func (s *Space) RemoveConstraint(constraint *Constraint)
- func (s *Space) RemoveShape(shape *Shape)
- func (s *Space) SegmentQuery(start, end v.Vec, radius float64, filter ShapeFilter, f SpaceSegmentQueryFunc, ...)
- func (s *Space) SegmentQueryFirst(start, end v.Vec, radius float64, filter ShapeFilter) SegmentQueryInfo
- func (s *Space) SetGravity(gravity v.Vec)
- func (s *Space) SetStaticBody(body *Body)
- func (s *Space) ShapeCount() int
- func (s *Space) ShapeQuery(shape *Shape, callback func(shape *Shape, points *ContactPointSet)) bool
- func (s *Space) SliceForBodyType(t BodyType) *[]*Body
- func (s *Space) StaticBodyCount() int
- func (s *Space) StaticShapeCount() int
- func (s *Space) Step(dt float64)
- func (s *Space) TimeStep() float64
- func (s *Space) UseSpatialHash(dim float64, count int)
- func (s *Space) UseWildcardDefaultHandler()
- type SpaceBBQueryFunc
- type SpacePointQueryFunc
- type SpaceSegmentQueryFunc
- type SplittingPlane
- type SupportPoint
- type Transform
- func NewTransform(a, c, tx, b, d, ty float64) Transform
- func NewTransformIdentity() Transform
- func NewTransformRigid(translate v.Vec, rotation float64) Transform
- func NewTransformRigidInverse(t Transform) Transform
- func NewTransformRotate(rotation float64) Transform
- func NewTransformScale(scaleX, scaleY float64) Transform
- func NewTransformTranslate(translate v.Vec) Transform
- func NewTransformTranspose(a, c, tx, b, d, ty float64) Transform
- func (t Transform) Apply(p v.Vec) v.Vec
- func (t Transform) ApplyVector(vect v.Vec) v.Vec
- func (t Transform) AxialScale(axis, pivot v.Vec, scale float64) Transform
- func (t Transform) BB(bb BB) BB
- func (t Transform) BoneScale(v0, v1 v.Vec) Transform
- func (t Transform) Inverse() Transform
- func (t Transform) Mult(t2 Transform) Transform
- func (t Transform) Ortho(bb BB) Transform
- func (t *Transform) Scale(x, y float64)
- func (t Transform) Wrap(inner Transform) Transform
Constants ¶
const ( DrawShapes = 1 << 0 DrawConstraints = 1 << 1 DrawCollisionPoints = 1 << 2 )
Draw flags
const ( // Value for group signifying that a shape is in no group. NoGroup uint = 0 // Value for Shape layers signifying that a shape is in every layer. AllCategories uint = ^uint(0) )
const ( MaxContactsPerArbiter int = 2 ContactsBufferSize int = 1024 )
const (
ShapeTypeNum = 3
)
Variables ¶
var CollisionHandlerDefault = CollisionHandler{ Wildcard, Wildcard, DefaultBeginFunc, DefaultPreSolveFunc, DefaultPostSolveFunc, DefaultSeparateFunc, nil, }
var CollisionHandlerDoNothing = CollisionHandler{ Wildcard, Wildcard, AlwaysCollideFunc, AlwaysCollideFunc, DoNothingFunc, DoNothingFunc, nil, }
var ShapeFilterAll = ShapeFilter{NoGroup, AllCategories, AllCategories}
ShapeFilterAll is s collision filter value for a shape that will collide with anything except ShapeFilterNone.
var ShapeFilterNone = ShapeFilter{NoGroup, ^AllCategories, ^AllCategories}
ShapeFilterNone is a collision filter value for a shape that does not collide with anything.
var ShapeVelocityFunc = func(obj any) v.Vec { return obj.(*Shape).Body.velocity }
Functions ¶
func AreaForCircle ¶
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 AreaForPolygon ¶ added in v1.14.9
AreaForPolygon 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 ¶
AreaForSegment calculates the area of a fattened (capsule shaped) line segment.
func BodyUpdatePosition ¶
BodyUpdatePosition is default position integration function.
func BodyUpdateVelocity ¶
BodyUpdateVelocity is default velocity integration function.
func CachedArbitersFilter ¶
func CentroidForPolygon ¶ added in v1.14.9
CentroidForPolygon calculates the natural centroid of a polygon.
func ComponentActive ¶
func DefaultBeginFunc ¶ added in v1.14.8
func DefaultPostSolveFunc ¶ added in v1.14.8
func DefaultPreSolveFunc ¶ added in v1.14.8
func DefaultSeparateFunc ¶ added in v1.14.8
func DefaultSpringForce ¶
func DefaultSpringForce(spring *DampedSpring, dist float64) float64
func DoNothingFunc ¶ added in v1.14.8
func DrawConstraint ¶
func DrawConstraint(constraint *Constraint, drawer IDrawer)
DrawConstraint draws constraints with the drawer implementation
func MomentForBox ¶
MomentForBox calculates the moment of inertia for a solid box.
func MomentForBox2 ¶
MomentForBox2 calculates the moment of inertia for a solid box.
func MomentForCircle ¶
MomentForCircle calculates the moment of inertia for a circle.
d1 and d2 are the inner and outer diameters. A solid circle has an inner diameter (d1) of 0. offset is a v.Vec representing the displacement of the circle's center of mass from the axis of rotation. If the center is not aligned with the axis, the offset increases the moment of inertia.
func MomentForCircle2 ¶ added in v1.10.0
MomentForCircle calculates the moment of inertia for a solid circle with radius and mass
func MomentForPolygon ¶ added in v1.14.9
MomentForPolygon 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 ¶
MomentForSegment calculates the moment of inertia for a line segment.
Beveling radius is not supported.
func NewContactBuffer ¶
func NewContactBuffer(stamp uint, slice *contactBuffer) *contactBuffer
func PolyLineCollectSegment ¶
func PolyLineCollectSegment(v0, v1 v.Vec, 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 PolyToPoly ¶
func PolyToPoly(info *CollisionInfo)
func PostStepDoNothing ¶
func QHullReduce ¶
func QueryReject ¶
QueryReject returns true if shapes a and b reject to collide.
func QueryRejectConstraints ¶
func SpaceArbiterSetFilter ¶
SpaceArbiterSetFilter throws away old arbiters.
Types ¶
type Arbiter ¶
type Arbiter struct {
UserData any
Contacts []Contact // a slice onto the current buffer array of contacts
// 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 (*Arbiter) Bodies ¶
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 ¶
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 ¶
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 (*Arbiter) CallWildcardPostSolveB ¶
func (*Arbiter) CallWildcardPreSolveA ¶
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 ¶
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 (*Arbiter) CallWildcardSeparateB ¶
func (*Arbiter) ContactPointSet ¶
func (a *Arbiter) ContactPointSet() ContactPointSet
ContactPointSet returns ContactPointSet
func (*Arbiter) Ignore ¶
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) IsFirstContact ¶
func (*Arbiter) SetContactPointSet ¶
func (a *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 ¶
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) TotalImpulse ¶
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.
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 NewBBForCircle ¶
NewBBForCircle constructs a BB for a circle with the given position and radius.
func NewBBForExtents ¶
NewBBForExtents constructs a BB centered on a point with the given extents (half sizes).
func (BB) ContainsVect ¶
ContainsVect returns true if bb contains v.
func (BB) Intersects ¶
Intersects returns true if a and b intersect.
func (BB) IntersectsSegment ¶
IntersectsSegment returns true if the bounding box intersects the line segment with ends a and b.
func (BB) MergedArea ¶
MergedArea merges a and b and returns the area of the merged bounding box.
func (BB) SegmentQuery ¶
SegmentQuery returns the fraction along the segment query the BB is hit. Returns cm.INFINITY if it doesn't hit.
type BBQueryContext ¶
type BBQueryContext struct {
// contains filtered or unexported fields
}
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 any
Space *Space
Shapes []*Shape
// contains filtered or unexported fields
}
func NewBody ¶
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) ActivateStatic ¶
ActivateStatic wakes up any sleeping or idle bodies touching this static body.
func (*Body) AngularVelocity ¶
AngularVelocity returns the angular velocity of the body.
func (*Body) ApplyForceAtLocalPoint ¶
ApplyForceAtLocalPoint applies a force at local point.
func (*Body) ApplyForceAtWorldPoint ¶
ApplyForceAtWorldPoint applies a force at world point.
func (*Body) ApplyImpulseAtLocalPoint ¶
ApplyImpulseAtLocalPoint applies impulse at local point
func (*Body) ApplyImpulseAtWorldPoint ¶
ApplyImpulseAtWorldPoint applies impulse at world point
func (*Body) AttachShape ¶ added in v1.10.0
AttachShape adds shape to the body
func (Body) CenterOfGravity ¶
CenterOfGravity returns the offset of the center of gravity in body local coordinates.
func (*Body) ComponentAdd ¶
func (*Body) ComponentRoot ¶
func (*Body) EachArbiter ¶
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) IsSleeping ¶
IsSleeping returns true if the body is sleeping.
func (*Body) KineticEnergy ¶
KineticEnergy returns the kinetic energy of this body.
func (*Body) LocalToWorld ¶
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) PushArbiter ¶
func (*Body) RemoveConstraint ¶
func (body *Body) RemoveConstraint(constraint *Constraint)
RemoveConstraint removes constraint from the body.
func (*Body) RemoveShape ¶
RemoveShape removes collision shape from the body.
func (*Body) RemoveShapeAtIndex ¶ added in v1.10.0
RemoveShapeAtIndex removes collision shape from the body.
func (*Body) Rotation ¶
Rotation returns the rotation vector of the body.
(The x basis vector of it's transform.)
func (*Body) SetAngularVelocity ¶
SetAngularVelocity sets the angular velocity of the body.
func (*Body) SetPosition ¶
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) SetTransform ¶
SetTransform sets transform
func (*Body) SetVelocity ¶
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 ¶
SetVelocityVector sets the velocity of the body
func (*Body) ShapeAtIndex ¶ added in v1.10.0
ShapeAtIndex returns shape at index attached to this body
func (*Body) UpdateVelocity ¶
UpdateVelocity is the default velocity integration function.
func (*Body) VelocityAtLocalPoint ¶
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 ¶
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.
type BodyPositionFunc ¶
BodyPositionFunc is rigid body position update function type.
type BodyType ¶ added in v1.10.0
type BodyType uint8
BodyType for bodies; Dynamic, Kinematic or Static
type BodyVelocityFunc ¶
BodyVelocityFunc is rigid body velocity update function type.
type Circle ¶
type Circle struct {
*Shape
// contains filtered or unexported fields
}
func (*Circle) PointQuery ¶
func (circle *Circle) PointQuery(p v.Vec, info *PointQueryInfo)
func (*Circle) SegmentQuery ¶
func (circle *Circle) SegmentQuery(a, b v.Vec, radius float64, info *SegmentQueryInfo)
func (*Circle) TransformC ¶
type CollisionBeginFunc ¶
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 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 any
}
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 (*CollisionInfo) PushContact ¶
func (info *CollisionInfo) PushContact(p1, p2 v.Vec, hash HashValue)
type CollisionPostSolveFunc ¶
CollisionPostSolveFunc is collision post-solve event function callback type.
type CollisionPreSolveFunc ¶
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 ¶
CollisionSeparateFunc is collision separate event function callback type.
type Constrainer ¶
type Constraint ¶
type Constraint struct {
Class Constrainer
PreSolve ConstraintPreSolveFunc
PostSolve ConstraintPostSolveFunc
UserData any
// contains filtered or unexported fields
}
func FilterConstraints ¶ added in v1.14.8
func FilterConstraints(node *Constraint, body *Body, filter *Constraint) *Constraint
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 v.Vec, 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 v.Vec) *Constraint
func NewPinJoint ¶
func NewPinJoint(a, b *Body, anchorA, anchorB v.Vec) *Constraint
func NewPivotJoint ¶
func NewPivotJoint(a, b *Body, pivot v.Vec) *Constraint
func NewPivotJoint2 ¶
func NewPivotJoint2(a, b *Body, anchorA, anchorB v.Vec) *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 v.Vec, min, max float64) *Constraint
func (*Constraint) ActivateBodies ¶
func (c *Constraint) ActivateBodies()
func (*Constraint) BodyA ¶ added in v1.6.0
func (c *Constraint) BodyA() *Body
func (*Constraint) BodyB ¶ added in v1.6.0
func (c *Constraint) BodyB() *Body
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 ContactPointSet ¶
type ContactPointSet struct {
// Count is the number of contact points in the set.
Count int
// Normal is the normal of the collision.
Normal v.Vec
Points [MaxContactsPerArbiter]struct {
// The position of the contact on the surface of each shape.
PointA, PointB v.Vec
// 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.
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(dtCoef 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 v.Vec
RestLength, Stiffness, Damping float64
SpringForceFunc DampedSpringForceFunc
// contains filtered or unexported fields
}
func (*DampedSpring) ApplyCachedImpulse ¶
func (spring *DampedSpring) ApplyCachedImpulse(dtCoef 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 GearJoint ¶
type GearJoint struct {
*Constraint
// contains filtered or unexported fields
}
func (*GearJoint) ApplyCachedImpulse ¶
func (*GearJoint) ApplyImpulse ¶
func (*GearJoint) GetImpulse ¶
type GrooveJoint ¶
type GrooveJoint struct {
*Constraint
GrooveN, GrooveA, GrooveB v.Vec
AnchorB v.Vec
// contains filtered or unexported fields
}
func (*GrooveJoint) ApplyCachedImpulse ¶
func (joint *GrooveJoint) ApplyCachedImpulse(dtCoef 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 HashSetBin ¶
type HashSetBin[U comparable] struct { // contains filtered or unexported fields }
HashSetBin implements a linked list
type IDrawer ¶ added in v1.9.0
type IDrawer interface {
DrawCircle(pos v.Vec, angle, radius float64, outline, fill FColor, data any)
DrawSegment(a, b v.Vec, fill FColor, data any)
DrawFatSegment(a, b v.Vec, radius float64, outline, fill FColor, data any)
DrawPolygon(count int, verts []v.Vec, radius float64, outline, fill FColor, data any)
DrawDot(size float64, pos v.Vec, fill FColor, data any)
Flags() uint
OutlineColor() FColor
ShapeColor(shape *Shape, data any) FColor
ConstraintColor() FColor
CollisionPointColor() FColor
Data() any
}
type IShape ¶ added in v1.10.0
type IShape interface {
CacheData(transform Transform) BB
PointQuery(p v.Vec, info *PointQueryInfo)
SegmentQuery(a, b v.Vec, radius float64, info *SegmentQueryInfo)
}
type PinJoint ¶
type PinJoint struct {
*Constraint
AnchorA, AnchorB v.Vec
Dist float64
// contains filtered or unexported fields
}
func (*PinJoint) ApplyCachedImpulse ¶
func (*PinJoint) ApplyImpulse ¶
func (*PinJoint) GetImpulse ¶
type PivotJoint ¶
type PivotJoint struct {
*Constraint
AnchorA, AnchorB v.Vec
// contains filtered or unexported fields
}
func (*PivotJoint) ApplyCachedImpulse ¶
func (joint *PivotJoint) ApplyCachedImpulse(dtCoef 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 PointQueryInfo ¶
type PointQueryInfo struct {
// The nearest shape, nil if no shape was within range.
Shape *Shape
// The closest point on the shape's surface. (in world space coordinates)
Point v.Vec
// 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 v.Vec
}
PointQueryInfo is point query info struct.
type PolyLine ¶
func DouglasPeucker ¶
func DouglasPeucker( verts []v.Vec, reduced *PolyLine, length, start, end int, min, tol float64, ) *PolyLine
Recursive function used by PolylineSimplifyCurves().
func (*PolyLine) IsShort ¶
IsShort checks if the total length of a polyline segment is less than 'min'. It iterates from 'start' to 'end', summing the distances between consecutive vertices. If the length exceeds 'min', it returns false, otherwise true.
Parameters: - count: // Total number of vertices in the polyline. - start: // Starting index for the length calculation. - end: // Ending index for the length calculation. - min: // Minimum length threshold.
func (*PolyLine) SimplifyCurves ¶
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 ¶
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 (*PolyLineSet) FindEnds ¶
func (pls *PolyLineSet) FindEnds(v v.Vec) int
Find the polyline that ends with v.
func (*PolyLineSet) FindStarts ¶
func (pls *PolyLineSet) FindStarts(v v.Vec) 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 Polygon ¶ added in v1.14.9
type Polygon struct {
*Shape
Radius float64
// The untransformed Planes are appended at the end of the transformed Planes.
Planes []SplittingPlane
// contains filtered or unexported fields
}
func (*Polygon) PointQuery ¶ added in v1.14.9
func (ps *Polygon) PointQuery(p v.Vec, info *PointQueryInfo)
func (*Polygon) SegmentQuery ¶ added in v1.14.9
func (ps *Polygon) SegmentQuery(a, b v.Vec, r2 float64, info *SegmentQueryInfo)
func (*Polygon) SetVertsRaw ¶ added in v1.14.9
func (*Polygon) SetVertsUnsafe ¶ added in v1.14.9
type PostStepCallbackFunc ¶
type RatchetJoint ¶
type RatchetJoint struct {
*Constraint
Angle, Phase, Ratchet float64
// contains filtered or unexported fields
}
func (*RatchetJoint) ApplyCachedImpulse ¶
func (joint *RatchetJoint) ApplyCachedImpulse(dtCoef 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(dtCoef 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
}
Segment is a segment Shape
func (*Segment) PointQuery ¶
func (seg *Segment) PointQuery(p v.Vec, info *PointQueryInfo)
func (*Segment) SegmentQuery ¶
func (seg *Segment) SegmentQuery(a, b v.Vec, r2 float64, info *SegmentQueryInfo)
func (*Segment) SetEndpoints ¶
func (*Segment) TransformA ¶
func (*Segment) TransformB ¶
type SegmentQueryContext ¶
type SegmentQueryContext struct {
// contains filtered or unexported fields
}
type SegmentQueryInfo ¶
type SegmentQueryInfo struct {
// The shape that was hit, or nil if no collision occurred.
Shape *Shape
// The point of impact.
Point v.Vec
// The normal of the surface hit.
Normal v.Vec
// 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 IShape
Body *Body
Space *Space
UserData any
Filter ShapeFilter
// You can assign types to collision shapes that triggercallbacks when objects
// of certain types touch.
CollisionType CollisionType
// Sensor is a boolean value if this shape is a Sensor or not.
// Sensors only call collision callbacks, and never generate real collisions.
Sensor bool
// The surface velocity of the object. Useful for creating conveyor belts or
// players that move around. This value is only used when calculating friction,
// not resolving the collision.
SurfaceVelocity v.Vec
Elasticity, Friction float64
BB BB
// contains filtered or unexported fields
}
func NewBox ¶
NewBox returns a Box shape with specified width 'w', height 'h', and rounding radius 'roundingRadius'. The shape is attached to the body.
Parameters:
- body: The body to which the shape will be attached.
- w: The width of the box.
- h: The height of the box.
- r: The rounding radius of the box corners.
func NewBox2 ¶
NewBox2 returns a Box shape using a bounding box 'bb' and a rounding radius 'roundingRadius'. The shape is attached to the body.
Parameters:
- body: The body to which the shape will be attached.
- bb: The bounding box defining the shape dimensions.
- r: The rounding radius of the box corners.
func NewCircle ¶
NewCircle returns a Circle shape with a specified radius and offset.
The shape is attached to the given body.
Parameters:
- b: The body to which the shape will be attached.
- r: The radius of the circle.
- offset: The position of the circle's center.
func NewPolygon ¶ added in v1.14.9
NewPolygon returns a Polygon shape with a given vertices.
Parameters:
- b: The body to which the shape will be attached.
- vertices: The list of vertex positions.
- t: The transformation applied to the vertex positions.
- r: The rounding radius of the polygon corners.
func NewPolygonRaw ¶ added in v1.14.9
Initialize a polygon shape with rounded corners. The vertexes must be convex with a counter-clockwise winding.
func NewSegment ¶
NewSegment returns a new Segment shape using two points 'a' and 'b' and rounding radius 'r'. The shape is attached to the given body.
Parameters:
- body: The body to which the shape will be attached.
- a: The first point of the segment.
- b: The second point of the segment.
- r: The radius of the segment shape.
func (*Shape) CenterOfGravity ¶
func (*Shape) Density ¶
Get the density of the shape if you are having Chipmunk calculate mass properties for you.
func (*Shape) PointQuery ¶
func (sh *Shape) PointQuery(p v.Vec) PointQueryInfo
Perform a nearest point query.
It finds the closest point on the surface of shape to a specific point. The value returned is the distance between the points. A negative distance means the point is inside the shape.
func (*Shape) SegmentQuery ¶
Perform a segment query against a shape.
info must be a pointer to a valid SegmentQueryInfo structure.
func (*Shape) SetCollisionType ¶
func (sh *Shape) SetCollisionType(collisionType CollisionType)
SetCollisionType sets collision type.
You can assign types to shapes that trigger callbacks (CollisionHandler) when objects of certain types touch
func (*Shape) SetDensity ¶
Set the density of this shape to have Chipmunk calculate mass properties for you.
func (*Shape) SetElasticity ¶
SetElasticity sets elasticity (0-1 range)
func (*Shape) SetFriction ¶
func (*Shape) SetMass ¶
Set the mass of this shape to have Chipmunk calculate mass properties for you.
func (*Shape) SetSensor ¶
SetSensor wakes up sleeping or idle body then sets Shape.Sensor. sensor is a boolean value if this shape is a sensor or not. Sensors only call collision callbacks, and never generate real collisions.
func (*Shape) SetShapeFilter ¶ added in v1.0.1
func (sh *Shape) SetShapeFilter(filter ShapeFilter)
Set the collision filtering parameters of this shape.
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 (*ShapeFilter) CollideWith ¶ added in v1.14.8
func (sf *ShapeFilter) CollideWith(mask uint)
CollideWith enables collision with the specified category mask.
func (*ShapeFilter) DontCollideWith ¶ added in v1.14.8
func (sf *ShapeFilter) DontCollideWith(mask uint)
DontCollideWith disables collision with the specified category mask.
func (ShapeFilter) Reject ¶
func (sf ShapeFilter) Reject(other ShapeFilter) bool
Reject checks whether two ShapeFilter objects should be considered incompatible. It returns true if the filters should be rejected based on the following conditions: - If both filters belong to the same group (and the group is not 0). - If the category/mask combination of either filter does not match the other.
- Specifically, it checks if the categories of the first filter don't match the mask of the second, or vice versa.
Returns true if the filters are considered incompatible, otherwise false.
type ShapeMassInfo ¶
type ShapeMassInfo struct {
// contains filtered or unexported fields
}
ShapeMassInfo is mass info struct
func CircleShapeMassInfo ¶
func CircleShapeMassInfo(mass, radius float64, center v.Vec) *ShapeMassInfo
func NewSegmentMassInfo ¶
func NewSegmentMassInfo(mass float64, a, b v.Vec, r float64) *ShapeMassInfo
func PolyShapeMassInfo ¶
type SimpleMotor ¶
type SimpleMotor struct {
*Constraint
Rate float64
// contains filtered or unexported fields
}
func (*SimpleMotor) ApplyCachedImpulse ¶
func (motor *SimpleMotor) ApplyCachedImpulse(dtCoef 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 v.Vec
Min, Max float64
// contains filtered or unexported fields
}
func (*SlideJoint) ApplyCachedImpulse ¶
func (joint *SlideJoint) ApplyCachedImpulse(dtCoef 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 {
UserData any
// Iterations is number of iterations to use in the impulse solver to solve
// contacts and other constrain. Must be non-zero.
Iterations uint
// IdleSpeedThreshold is speed threshold for a body to be considered idle.
// The default value of 0 means to let the space guess a good threshold based on gravity.
IdleSpeedThreshold float64
// SleepTimeThreshold is time a group of bodies must remain idle in order to fall asleep.
// Enabling sleeping also implicitly enables the the contact graph.
// The default value of INFINITY disables the sleeping algorithm.
SleepTimeThreshold float64
// StaticBody is the Space provided static body for a given s.
// This is merely provided for convenience and you are not required to use it.
StaticBody *Body
// Gravity to pass to rigid bodies when integrating velocity.
Gravity v.Vec
// Damping rate expressed as the fraction of velocity bodies retain each second.
//
// A value of 0.9 would mean that each body's velocity will drop 10% per second.
// The default value is 1.0, meaning no Damping is applied.
// @note This Damping value is different than those of DampedSpring and DampedRotarySpring.
Damping float64
// CollisionSlop is amount of encouraged penetration between colliding shapes.
//
// Used to reduce oscillating contacts and keep the collision cache warm.
// Defaults to 0.1. If you have poor simulation quality,
// increase this number as much as possible without allowing visible amounts of overlap.
CollisionSlop float64
// CollisionBias determines how fast overlapping shapes are pushed apart.
//
// Expressed as a fraction of the error remaining after each second.
// Defaults to math.Pow(0.9, 60) meaning that Chipmunk fixes 10% of overlap each frame at 60Hz.
CollisionBias float64
// Number of frames that contact information should persist.
// Defaults to 3. There is probably never a reason to change this value.
CollisionPersistence uint
Arbiters []*Arbiter
DynamicBodies []*Body
StaticBodies []*Body
// contains filtered or unexported fields
}
func (*Space) AddBodyWithShapes ¶ added in v1.10.0
AddBodyWithShapes adds body to the space with body's shapes.
Do not add the same Body twice.
func (*Space) AddCollisionHandler ¶ added in v1.13.1
func (s *Space) AddCollisionHandler(a, b CollisionType) *CollisionHandler
AddCollisionHandler adds and returns the CollisionHandler for collisions between objects of type a and b.
Fill the desired collision callback functions, for details see the CollisionHandler object.
Whenever shapes with collision types (Shape.CollisionType) a and b collide, this handler will be used to process the collision events. When a new collision handler is created, the callbacks will all be set to builtin callbacks that perform the default behavior (call the wildcard handlers, and accept all collisions).
func (*Space) AddCollisionHandler2 ¶ added in v1.13.1
func (s *Space) AddCollisionHandler2(handler *CollisionHandler)
AddCollisionHandler adds handler to space, for details see the CollisionHandler{} struct.
func (*Space) AddConstraint ¶
func (s *Space) AddConstraint(constraint *Constraint) *Constraint
func (*Space) AddPostStepCallback ¶
func (s *Space) AddPostStepCallback(f PostStepCallbackFunc, key, data any) bool
AddPostStepCallback defines a callback to be run just before s.Step() finishes.
The main reason you want to define post-step callbacks is to get around the restriction that you cannot call the add/remove methods from a collision handler callback. Post-step callbacks run right before the next (or current) call to s.Step() returns when it is safe to add and remove objects. You can only schedule one post-step callback per key value, this prevents you from accidentally removing an object twice. Registering a second callback for the same key is a no-op.
example: type PostStepCallbackFunc func(space *Space, key any, data any)
func (*Space) AddShape ¶
AddShape adds a collision shape to the simulation.
If the shape is attached to a static body, it will be added as a static shape
func (*Space) AddWildcardCollisionHandler ¶ added in v1.13.1
func (s *Space) AddWildcardCollisionHandler(typeA CollisionType) *CollisionHandler
AddWildcardCollisionHandler sets a collision handler for given collision type. This handler will be used any time an object with this type collides with another object, regardless of its type. A good example is a projectile that should be destroyed the first time it hits anything. There may be a specific collision handler and two wildcard handlers. It’s up to the specific handler to decide if and when to call the wildcard handlers and what to do with their return values. When a new wildcard handler is created, the callbacks will all be set to builtin callbacks that perform the default behavior. (accept all collisions in Begin() and PreSolve(), or do nothing for PostSolve() and Separate().
func (*Space) BBQuery ¶
func (s *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data any)
func (*Space) ContainsBody ¶
func (*Space) ContainsConstraint ¶
func (s *Space) ContainsConstraint(constraint *Constraint) bool
func (*Space) ContainsShape ¶
func (*Space) Deactivate ¶
func (*Space) DynamicBodyCount ¶
DynamicBodyCount returns the total number of dynamic bodies in space
func (*Space) DynamicShapeCount ¶ added in v1.10.0
func (*Space) EachBody ¶
EachBody calls func f for each body in the space
Example:
s.EachBody(func(body *cm.Body) {
fmt.Println(body.Position())
})
func (*Space) EachConstraint ¶
func (s *Space) EachConstraint(f func(*Constraint))
func (*Space) EachDynamicBody ¶ added in v1.7.1
EachDynamicBody calls func f for each dynamic body in the space
func (*Space) EachDynamicShape ¶ added in v1.7.1
EachDynamicShape calls func f for each dynamic shape in the space
func (*Space) EachStaticBody ¶ added in v1.7.1
EachStaticBody calls func f for each static body in the space
func (*Space) EachStaticShape ¶ added in v1.7.1
EachStaticShape calls func f for each static shape in the space
func (*Space) FilterArbiters ¶
func (*Space) IsLocked ¶ added in v1.7.0
IsLocked returns true from inside a callback when objects cannot be added/removed.
func (*Space) LookupHandler ¶
func (s *Space) LookupHandler(a, b CollisionType, defaultHandler *CollisionHandler) *CollisionHandler
LookupHandler finds and returns the matching a/b handler
func (*Space) PointQueryNearest ¶
func (s *Space) PointQueryNearest(point v.Vec, maxDistance float64, filter ShapeFilter) *PointQueryInfo
Query the space at a point and return the nearest shape found. Returns nil if no shapes were found.
func (*Space) PostStepCallback ¶
func (*Space) ReindexShape ¶ added in v1.9.1
ReindexShape re-computes the hash of the shape in both the dynamic and static list.
func (*Space) RemoveBody ¶
RemoveBody removes a body from the simulation
func (*Space) RemoveBodyWithShapes ¶ added in v1.0.1
RemoveBodyWithShapes removes a body and body's shapes from the simulation
func (*Space) RemoveConstraint ¶
func (s *Space) RemoveConstraint(constraint *Constraint)
func (*Space) RemoveShape ¶
RemoveShape removes a collision shape from the simulation.
func (*Space) SegmentQuery ¶
func (s *Space) SegmentQuery(start, end v.Vec, radius float64, filter ShapeFilter, f SpaceSegmentQueryFunc, data any)
func (*Space) SegmentQueryFirst ¶
func (s *Space) SegmentQueryFirst(start, end v.Vec, radius float64, filter ShapeFilter) SegmentQueryInfo
func (*Space) SetGravity ¶
SetGravity sets gravity and wake up all of the sleeping bodies since the gravity changed.
func (*Space) SetStaticBody ¶
func (*Space) ShapeCount ¶ added in v1.10.0
func (*Space) ShapeQuery ¶
func (s *Space) ShapeQuery(shape *Shape, callback func(shape *Shape, points *ContactPointSet)) bool
ShapeQuery queries a space for any shapes overlapping the this shape and call the callback for each shape found.
func (*Space) SliceForBodyType ¶ added in v1.13.1
SliceForBodyType returns bodies of the given type in the space.
func (*Space) StaticBodyCount ¶
StaticBodyCount returns the total number of static bodies in space
func (*Space) StaticShapeCount ¶ added in v1.10.0
func (*Space) UseSpatialHash ¶
func (*Space) UseWildcardDefaultHandler ¶
func (s *Space) UseWildcardDefaultHandler()
type SpaceBBQueryFunc ¶
type SpaceSegmentQueryFunc ¶
type SplittingPlane ¶
type SupportPoint ¶
type SupportPoint struct {
// contains filtered or unexported fields
}
type Transform ¶
type Transform struct {
// contains filtered or unexported fields
}
Transform represents a 2D affine transformation using a 2x3 matrix. This structure can be used to perform various transformations such as translation, rotation, scaling, and shearing of 2D objects.
The transformation matrix is represented as follows:
| a b tx | -> X' = a * X + b * Y + tx | c d ty | -> Y' = c * X + d * Y + ty
Where:
- a: Scaling factor in the X direction and component for rotation.
- b: Shearing factor in the X direction (affects X based on Y).
- c: Shearing factor in the Y direction (affects Y based on X).
- d: Scaling factor in the Y direction and component for rotation.
- tx: Translation in the X direction.
- ty: Translation in the Y direction.
The Transform type can be used to compose multiple transformations, enabling complex transformations by multiplying matrices together.
func NewTransform ¶
NewTransform returns a new transform matrix.
Parameters:
- (a, b) is the x basis vector.
- (c, d) is the y basis vector.
- (tx, ty) is the translation.
func NewTransformIdentity ¶
func NewTransformIdentity() Transform
NewTransformIdentity creates and returns an identity transformation. The identity transformation is a special case of affine transformation that leaves the object's coordinates unchanged.
The identity matrix in 2D transforms points according to the following:
| 1 0 0 | -> X' = 1 * X + 0 * Y + 0 = X | 0 1 0 | -> Y' = 0 * X + 1 * Y + 0 = Y
The identity transform is useful as a starting point for composing transformations, as applying it to any object will yield the same object without any modifications.
func NewTransformRigid ¶
NewTransformRigid creates a new rigid transformation that combines translation and rotation.
Rigid transformation, or rigid motion, refers to a transformation that preserves the shape and size of objects while allowing them to change position and orientation in space. It includes translation, rotation, and reflection, maintaining distances and angles within the object.
Parameters:
- translate: A 2D vector specifying the translation component.
- rotation: The angle of rotation in radians.
Returns:
- A Transform representing the combined translation and rotation.
func NewTransformRigidInverse ¶
NewTransformRigidInverse returns the inverse of a given rigid transformation.
Rigid transformation, or rigid motion, refers to a transformation that preserves the shape and size of objects while allowing them to change position and orientation in space. It includes translation, rotation, and reflection, maintaining distances and angles within the object.
Parameters:
- t: The original Transform to invert.
Returns:
- The inverted Transform.
func NewTransformRotate ¶
NewTransformRotate returns a new rigid transformation with rotation
func NewTransformScale ¶
NewTransformScale returns a new transformation with scaling
func NewTransformTranslate ¶
NewTransformTranslate returns a new transformation matrix with translation
func NewTransformTranspose ¶
NewTransformTranspose returns a new transformation matrix in transposed order.
func (Transform) Apply ¶ added in v1.11.0
Apply applies the transformation to a given abs point `p` and returns the transformed point. This transformation involves scaling, rotation, and translation based on the matrix values.
func (Transform) ApplyVector ¶ added in v1.11.0
ApplyVector applies the transformation matrix (t) to a vector (v). This transformation modifies the vector's direction based on the current transformation without affecting its position.
Parameters:
- vect: the vector (v.Vec) to be transformed, represented by X and Y coordinates.
Returns:
- v.Vec: the transformed vector after applying the matrix transformation.
func (Transform) AxialScale ¶
Creates a transformation matrix for scaling along a given axis.
This function generates a transformation matrix that scales along a specified axis around a pivot point. If the scaling factor (scale) is different from 1.0, the transformation matrix will apply scaling along the direction of the axis.
Parameters:
- axis: A vector representing the axis along which scaling will be applied.
- pivot: The pivot point around which scaling is applied.
- scale: The scaling factor. Values other than 1.0 scale the axis direction accordingly.
Returns:
- Transform: Axial scale transformation matrix.
func (Transform) BB ¶
BB applies the current transformation (t) to a bounding box (BB). It scales and rotates the bounding box around its center to create a transformed bounding box that accounts for the dimensions after transformation.
Parameters:
- bb: the bounding box (BB) to be transformed, defined by its left (L), right (R), top (T), and bottom (B) boundaries.
Returns:
- BB: the transformed bounding box, with dimensions adjusted based on the transformation applied.
func (Transform) BoneScale ¶
BoneScale creates a scaling and rotation transformation matrix based on a bone vector defined by the start and end points v0 and v1. It translates to v0 and scales along the direction to v1.
Parameters: - v0: The starting vector of the bone. - v1: The ending vector of the bone.
Returns: - A Transform that represents the scaling and rotation transformation matrix.
func (Transform) Mult ¶
Mult multiplies this and t2
Parameters:
- t2 - The Transform to be multiplied with the receiver.
Returns:
- A new Transform representing the result of the multiplication.
func (Transform) Ortho ¶
Ortho creates an orthographic transformation matrix based on the given bounding box (bb). It performs scaling and translation to fit coordinates within the bounding box.
Parameters: - bb: A bounding box with left (L), right (R), bottom (B), and top (T) boundaries.
Returns: - A Transform that represents the orthographic projection transformation matrix.
func (Transform) Wrap ¶
Wrap applies the inverse of the current transformation (t) around another transformation (inner). This wraps inner with the inverse of t, then applies t, effectively creating a nested transformation.
Parameters:
- inner: the Transform to wrap with the inverse of the current transformation.
Returns:
- Transform: the resulting transformation after wrapping.
Source Files
¶
- arbiter.go
- bb.go
- bb_tree.go
- body.go
- circle.go
- collision.go
- collision_handler.go
- common.go
- constraint.go
- contact_buffer.go
- damped_rotary_spring.go
- damped_spring.go
- gear_joint.go
- groove_joint.go
- hashset.go
- hashset_arbiter.go
- idrawer.go
- pin_joint.go
- pivot_joint.go
- polygon.go
- polyline.go
- ratchet_joint.go
- rotary_limit_joint.go
- segment.go
- shape.go
- shape_factory.go
- shape_filter.go
- simple_motor.go
- slide_joint.go
- space.go
- space_hash.go
- spatial_index.go
- transform.go