Documentation ¶
Index ¶
- Constants
- Variables
- func AlwaysCollide(_ *Arbiter, _ *Space, _ any) bool
- func AreaForCircle(r1, r2 float64) float64
- func AreaForPoly(count int, verts []vec.Vec2, r float64) float64
- func AreaForSegment(a, b vec.Vec2, r float64) float64
- func BodyUpdatePosition(body *Body, dt float64)
- func BodyUpdateVelocity(body *Body, gravity vec.Vec2, damping, dt float64)
- func CachedArbitersFilter(arb *Arbiter, space *Space, shape *Shape, body *Body) bool
- func CentroidForPoly(count int, verts []vec.Vec2) vec.Vec2
- func CircleSegmentQuery(shape *Shape, center vec.Vec2, r1 float64, a, b vec.Vec2, r2 float64, ...)
- func CircleToCircle(info *CollisionInfo)
- func CircleToPoly(info *CollisionInfo)
- func CircleToSegment(info *CollisionInfo)
- func CollisionError(_ *CollisionInfo)
- func ComponentActive(root *Body, threshold float64) bool
- func ContactPoints(e1, e2 Edge, points ClosestPoints, info *CollisionInfo)
- func Contains(bodies []*Body, body *Body) bool
- func DebugInfo(space *Space) string
- func DefaultBegin(arb *Arbiter, space *Space, _ any) bool
- func DefaultPostSolve(arb *Arbiter, space *Space, _ any)
- func DefaultPreSolve(arb *Arbiter, space *Space, _ any) bool
- func DefaultSeparate(arb *Arbiter, space *Space, _ any)
- func DefaultSpringForce(spring *DampedSpring, dist float64) float64
- func DoNothing(_ *Arbiter, _ *Space, _ any)
- func DrawConstraint(constraint *Constraint, drawer IDrawer)
- func DrawShape(shape *Shape, drawer IDrawer)
- func DrawSpace(space *Space, drawer IDrawer)
- func FloodFillComponent(root *Body, body *Body)
- func MomentForBox(mass, width, height float64) float64
- func MomentForBox2(mass float64, box BB) float64
- func MomentForCircle(mass, d1, d2 float64, offset vec.Vec2) float64
- func MomentForCircle2(mass, radius float64) float64
- func MomentForPoly(mass float64, count int, verts []vec.Vec2, offset vec.Vec2, r float64) float64
- func MomentForSegment(mass float64, a, b vec.Vec2, radius float64) float64
- func NearestPointQueryNearest(obj any, shape *Shape, collisionId uint32, out any) uint32
- func NodeSetA(node, value *Node)
- func NodeSetB(node, value *Node)
- func PolyLineCollectSegment(v0, v1 vec.Vec2, pls *PolyLineSet)
- func PolySupportPointIndex(count int, planes []SplittingPlane, n vec.Vec2) int
- func PolyToPoly(info *CollisionInfo)
- func PostStepDoNothing(space *Space, key, data any)
- func QHullPartition(verts []vec.Vec2, count int, a, b vec.Vec2, tol float64) int
- func QHullReduce(tol float64, verts []vec.Vec2, count int, a, pivot, b vec.Vec2, ...) int
- func QueryReject(a, b *Shape) bool
- func QueryRejectConstraints(a, b *Body) bool
- func SegmentToPoly(info *CollisionInfo)
- func SegmentToSegment(info *CollisionInfo)
- func Sharpness(a, b, c vec.Vec2) float64
- func SpaceArbiterSetFilter(arb *Arbiter, space *Space) bool
- func SpaceCollideShapesFunc(obj any, b *Shape, collisionId uint32, vspace any) uint32
- func VoidQueryFunc(obj1 any, obj2 *Shape, collisionId uint32, data any) uint32
- type Arbiter
- func (arbiter *Arbiter) ApplyCachedImpulse(dtCoef float64)
- func (arbiter *Arbiter) ApplyImpulse()
- func (arb *Arbiter) Bodies() (*Body, *Body)
- func (arb *Arbiter) CallWildcardBeginA(space *Space) bool
- func (arb *Arbiter) CallWildcardBeginB(space *Space) bool
- func (arb *Arbiter) CallWildcardPostSolveA(space *Space)
- func (arb *Arbiter) CallWildcardPostSolveB(space *Space)
- func (arb *Arbiter) CallWildcardPreSolveA(space *Space) bool
- func (arb *Arbiter) CallWildcardPreSolveB(space *Space) bool
- func (arb *Arbiter) CallWildcardSeparateA(space *Space)
- func (arb *Arbiter) CallWildcardSeparateB(space *Space)
- func (arb *Arbiter) ContactPointSet() ContactPointSet
- func (arb *Arbiter) Count() int
- func (arb *Arbiter) Ignore() bool
- func (arbiter *Arbiter) Init(a, b *Shape) *Arbiter
- func (arbiter *Arbiter) IsFirstContact() bool
- func (node *Arbiter) Next(body *Body) *Arbiter
- func (arb *Arbiter) Normal() vec.Vec2
- func (arb *Arbiter) PreStep(dt, slop, bias float64)
- func (arb *Arbiter) SetContactPointSet(set *ContactPointSet)
- func (arb *Arbiter) Shapes() (*Shape, *Shape)
- func (arbiter *Arbiter) ThreadForBody(body *Body) *ArbiterThread
- func (arb *Arbiter) TotalImpulse() vec.Vec2
- func (arbiter *Arbiter) Unthread()
- func (arb *Arbiter) Update(info *CollisionInfo, space *Space)
- type ArbiterThread
- type BB
- func (bb BB) Area() float64
- func (bb BB) Center() vec.Vec2
- func (bb BB) ClampVect(v *vec.Vec2) vec.Vec2
- func (bb BB) Contains(other BB) bool
- func (bb BB) ContainsVect(v vec.Vec2) bool
- func (bb BB) Expand(v vec.Vec2) BB
- func (bb BB) Intersects(b BB) bool
- func (bb BB) IntersectsSegment(a, b vec.Vec2) bool
- func (a BB) Merge(b BB) BB
- func (a BB) MergedArea(b BB) float64
- func (bb BB) Offset(v vec.Vec2) BB
- func (a BB) Proximity(b BB) float64
- func (bb BB) SegmentQuery(a, b vec.Vec2) float64
- func (bb BB) String() string
- func (bb BB) WrapVect(v vec.Vec2) vec.Vec2
- type BBQueryContext
- type BBTree
- func (bbt *BBTree) Contains(obj *Shape, hashId HashValue) bool
- func (bbt *BBTree) Count() int
- func (bbt *BBTree) Each(f SpatialIndexIterator)
- func (bbt *BBTree) GetBB(obj *Shape) BB
- func (tree *BBTree) GetMasterTree() *BBTree
- func (tree *BBTree) IncrementStamp()
- func (bbt *BBTree) Insert(obj *Shape, hashId HashValue)
- func (tree *BBTree) LeafAddPairs(leaf *Node)
- func (tree *BBTree) LeafUpdate(leaf *Node) bool
- func (tree *BBTree) NewLeaf(obj *Shape) *Node
- func (bbt *BBTree) NewNode(a, b *Node) *Node
- func (tree *BBTree) NodeFromPool() *Node
- func (bbt *BBTree) PairFromPool() *Pair
- func (tree *BBTree) PairInsert(a *Node, b *Node)
- func (tree *BBTree) PairsClear(leaf *Node)
- func (bbt *BBTree) Query(obj any, bb BB, f SpatialIndexQuery, data any)
- func (tree *BBTree) RecycleNode(node *Node)
- func (bbt *BBTree) RecyclePair(pair *Pair)
- func (tree *BBTree) Reindex()
- func (bbt *BBTree) ReindexObject(obj *Shape, hashId HashValue)
- func (tree *BBTree) ReindexQuery(f SpatialIndexQuery, data any)
- func (tree *BBTree) Remove(obj *Shape, hashId HashValue)
- func (tree *BBTree) ReplaceChild(parent, child, value *Node)
- func (bbt *BBTree) SegmentQuery(obj any, a, b vec.Vec2, tExit float64, f SpatialIndexSegmentQuery, data any)
- func (bbt *BBTree) SubtreeInsert(subtree *Node, leaf *Node) *Node
- func (tree *BBTree) SubtreeRemove(subtree *Node, leaf *Node) *Node
- type BBTreeVelocityFunc
- 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 vec.Vec2)
- func (body *Body) ApplyForceAtWorldPoint(force, point vec.Vec2)
- func (body *Body) ApplyImpulseAtLocalPoint(impulse, point vec.Vec2)
- func (body *Body) ApplyImpulseAtWorldPoint(impulse, point vec.Vec2)
- func (body *Body) AttachShape(shape *Shape)
- func (body Body) CenterOfGravity() vec.Vec2
- 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() vec.Vec2
- func (body *Body) IdleTime() float64
- func (body *Body) IsSleeping() bool
- func (body *Body) KineticEnergy() float64
- func (body *Body) LocalToWorld(point vec.Vec2) vec.Vec2
- func (body *Body) Mass() float64
- func (body Body) Moment() float64
- func (body *Body) Position() vec.Vec2
- 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() vec.Vec2
- func (body *Body) SetAngle(angle float64)
- func (body *Body) SetAngularVelocity(angularVelocity float64)
- func (body *Body) SetForce(force vec.Vec2)
- func (body *Body) SetMass(mass float64)
- func (body *Body) SetMoment(moment float64)
- func (body *Body) SetPosition(position vec.Vec2)
- func (body *Body) SetPositionUpdateFunc(f BodyPositionFunc)
- func (body *Body) SetTorque(torque float64)
- func (body *Body) SetTransform(p vec.Vec2, 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 vec.Vec2)
- 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 vec.Vec2, damping, dt float64)
- func (body *Body) Velocity() vec.Vec2
- func (body *Body) VelocityAtLocalPoint(point vec.Vec2) vec.Vec2
- func (body *Body) VelocityAtWorldPoint(point vec.Vec2) vec.Vec2
- func (body *Body) WorldToLocal(point vec.Vec2) vec.Vec2
- type BodyPositionFunc
- type BodyType
- type BodyVelocityFunc
- type Children
- type Circle
- func (circle *Circle) CacheData(transform Transform) BB
- func (circle *Circle) PointQuery(p vec.Vec2, info *PointQueryInfo)
- func (circle *Circle) Radius() float64
- func (circle *Circle) SegmentQuery(a, b vec.Vec2, radius float64, info *SegmentQueryInfo)
- func (circle *Circle) SetRadius(r float64)
- func (circle *Circle) TransformC() vec.Vec2
- type ClosestPoints
- func EPA(ctx SupportContext, v0, v1, v2 MinkowskiPoint) ClosestPoints
- func EPARecurse(ctx SupportContext, count int, hull []MinkowskiPoint, iteration int) ClosestPoints
- func GJK(ctx SupportContext, collisionId *uint32) ClosestPoints
- func GJKRecurse(ctx SupportContext, v0, v1 MinkowskiPoint, iteration int) ClosestPoints
- type CollisionBeginFunc
- type CollisionFunc
- type CollisionHandler
- type CollisionInfo
- type CollisionPostSolveFunc
- type CollisionPreSolveFunc
- type CollisionSeparateFunc
- type CollisionType
- type Constrainer
- type 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 vec.Vec2, restLength, stiffness, damping float64) *Constraint
- func NewGearJoint(a, b *Body, phase, ratio float64) *Constraint
- func NewGrooveJoint(a, b *Body, grooveA, grooveB, anchorB vec.Vec2) *Constraint
- func NewPinJoint(a, b *Body, anchorA, anchorB vec.Vec2) *Constraint
- func NewPivotJoint(a, b *Body, pivot vec.Vec2) *Constraint
- func NewPivotJoint2(a, b *Body, anchorA, anchorB vec.Vec2) *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 vec.Vec2, 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 ContactBuffer
- type ContactPointSet
- type DampedRotarySpring
- type DampedSpring
- type DampedSpringForceFunc
- type Edge
- type EdgePoint
- type FColor
- type GearJoint
- type GrooveJoint
- type Handle
- type HashSet
- func (set *HashSet[T, U]) Count() uint
- func (set *HashSet[T, U]) Each(f func(U))
- func (set *HashSet[T, U]) Filter(f func(U) bool)
- func (set *HashSet[T, U]) Find(hash HashValue, ptr T) U
- func (set *HashSet[T, U]) Insert(hash HashValue, ptr T, transform func(obj T) U) U
- func (set *HashSet[T, U]) Remove(hash HashValue, ptr T) U
- type HashSetBin
- type HashValue
- type IDrawer
- type IShape
- type Leaf
- type MarkContext
- type Mat2x2
- type MinkowskiPoint
- type Node
- func (node *Node) IsLeaf() bool
- func (leaf *Node) MarkLeaf(context *MarkContext)
- func (subtree *Node) MarkLeafQuery(leaf *Node, left bool, context *MarkContext)
- func (subtree *Node) MarkSubtree(context *MarkContext)
- func (node *Node) Other(child *Node) *Node
- func (subtree *Node) SubtreeQuery(obj any, bb BB, query SpatialIndexQuery, data any)
- func (subtree *Node) SubtreeSegmentQuery(obj any, a, b vec.Vec2, tExit float64, f SpatialIndexSegmentQuery, data any) float64
- type Pair
- type PinJoint
- type PivotJoint
- type PointQueryContext
- type PointQueryInfo
- type PolyLine
- func (pl *PolyLine) Enqueue(v vec.Vec2) *PolyLine
- func (pl *PolyLine) IsClosed() bool
- func (pl *PolyLine) IsShort(count, start, end int, min float64) bool
- func (pl *PolyLine) Push(v vec.Vec2) *PolyLine
- func (pl *PolyLine) SimplifyCurves(tol float64) *PolyLine
- func (pl *PolyLine) SimplifyVertexes(tol float64) *PolyLine
- type PolyLineSet
- type PolyShape
- func (ps *PolyShape) CacheData(transform Transform) BB
- func (ps *PolyShape) Count() int
- func (ps *PolyShape) PointQuery(p vec.Vec2, info *PointQueryInfo)
- func (ps *PolyShape) SegmentQuery(a, b vec.Vec2, r2 float64, info *SegmentQueryInfo)
- func (ps *PolyShape) SetVerts(count int, verts []vec.Vec2)
- func (p *PolyShape) SetVertsRaw(count int, verts []vec.Vec2)
- func (ps *PolyShape) SetVertsUnsafe(count int, verts []vec.Vec2, transform Transform)
- func (ps *PolyShape) TransformVert(i int) vec.Vec2
- func (ps *PolyShape) Vert(vertIndex int) vec.Vec2
- type PostStepCallback
- type PostStepCallbackFunc
- type RatchetJoint
- type RotaryLimitJoint
- type Segment
- func (seg *Segment) A() vec.Vec2
- func (seg *Segment) B() vec.Vec2
- func (seg *Segment) CacheData(transform Transform) BB
- func (seg *Segment) Normal() vec.Vec2
- func (seg *Segment) PointQuery(p vec.Vec2, info *PointQueryInfo)
- func (seg *Segment) Radius() float64
- func (seg *Segment) SegmentQuery(a, b vec.Vec2, r2 float64, info *SegmentQueryInfo)
- func (seg *Segment) SetEndpoints(a, b vec.Vec2)
- func (seg *Segment) SetRadius(r float64)
- func (seg *Segment) TransformA() vec.Vec2
- func (seg *Segment) TransformB() vec.Vec2
- type SegmentQueryContext
- type SegmentQueryInfo
- type Shape
- func NewBoxShape(body *Body, w, h, r float64) *Shape
- func NewBoxShape2(body *Body, bb BB, r float64) *Shape
- func NewCircleShape(b *Body, r float64, offset vec.Vec2) *Shape
- func NewPolyShape(b *Body, vertices []vec.Vec2, t Transform, r float64) *Shape
- func NewPolyShapeRaw(body *Body, count int, verts []vec.Vec2, roundingRadius float64) *Shape
- func NewSegmentShape(body *Body, a, b vec.Vec2, 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() vec.Vec2
- func (sh *Shape) Density() float64
- func (sh *Shape) HashId() HashValue
- func (sh *Shape) Mass() float64
- func (sh *Shape) MassInfo() *ShapeMassInfo
- func (sh *Shape) Moment() float64
- func (s *Shape) Order() int
- func (sh *Shape) Point(i uint32) SupportPoint
- func (sh *Shape) PointQuery(p vec.Vec2) PointQueryInfo
- func (sh *Shape) SegmentQuery(a, b vec.Vec2, 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) ContactBufferGetArray() []Contact
- 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) Lock()
- func (s *Space) LookupHandler(a, b CollisionType, defaultHandler *CollisionHandler) *CollisionHandler
- func (s *Space) PointQueryNearest(point vec.Vec2, maxDistance float64, filter ShapeFilter) *PointQueryInfo
- func (s *Space) PopContacts(count int)
- func (s *Space) PostStepCallback(key any) *PostStepCallback
- func (s *Space) ProcessComponents(dt float64)
- func (s *Space) PushContacts(count int)
- func (s *Space) PushFreshContactBuffer()
- 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 vec.Vec2, radius float64, filter ShapeFilter, ...)
- func (s *Space) SegmentQueryFirst(start, end vec.Vec2, radius float64, filter ShapeFilter) SegmentQueryInfo
- func (s *Space) SetGravity(gravity vec.Vec2)
- 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) UncacheArbiter(arb *Arbiter)
- func (s *Space) Unlock(runPostStep bool)
- func (s *Space) UseSpatialHash(dim float64, count int)
- func (s *Space) UseWildcardDefaultHandler()
- type SpaceBBQueryFunc
- type SpaceHash
- func (hash *SpaceHash) Contains(obj *Shape, hashId HashValue) bool
- func (hash *SpaceHash) Count() int
- func (hash *SpaceHash) Each(f SpatialIndexIterator)
- func (hash *SpaceHash) Insert(obj *Shape, hashId HashValue)
- func (hash *SpaceHash) Query(obj any, bb BB, f SpatialIndexQuery, data any)
- func (hash *SpaceHash) Reindex()
- func (hash *SpaceHash) ReindexObject(obj *Shape, hashId HashValue)
- func (hash *SpaceHash) ReindexQuery(f SpatialIndexQuery, data any)
- func (hash *SpaceHash) Remove(obj *Shape, hashId HashValue)
- func (hash *SpaceHash) SegmentQuery(obj any, a, b vec.Vec2, tExit float64, f SpatialIndexSegmentQuery, data any)
- type SpaceHashBin
- type SpacePointQueryFunc
- type SpaceSegmentQueryFunc
- type SpatialIndex
- type SpatialIndexBB
- type SpatialIndexIterator
- type SpatialIndexQuery
- type SpatialIndexSegmentQuery
- type SpatialIndexer
- type SplittingPlane
- type SupportContext
- type SupportPoint
- type SupportPointFunc
- type Thread
- type Transform
- func NewTransform(a, c, tx, b, d, ty float64) Transform
- func NewTransformIdentity() Transform
- func NewTransformRigid(translate vec.Vec2, rotation float64) Transform
- func NewTransformRigidInverse(t Transform) Transform
- func NewTransformRotate(rotation float64) Transform
- func NewTransformScale(scaleX, scaleY float64) Transform
- func NewTransformTranslate(translate vec.Vec2) Transform
- func NewTransformTranspose(a, c, tx, b, d, ty float64) Transform
- func (t Transform) Apply(p vec.Vec2) vec.Vec2
- func (t Transform) ApplyVector(v vec.Vec2) vec.Vec2
- func (t Transform) AxialScale(axis, pivot vec.Vec2, scale float64) Transform
- func (t Transform) BB(bb BB) BB
- func (t Transform) BoneScale(v0, v1 vec.Vec2) 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 ( // Arbiter is active and its the first collision. ArbiterStateFirstCollision = iota // Arbiter is active and its not the first collision. ArbiterStateNormal // Collision has been explicitly ignored. Either by returning false from a // begin collision handler or calling ArbiterIgnore(). ArbiterStateIgnore // Collison is no longer active. A space will cache an arbiter for up to Space. // CollisionPersistence more steps. ArbiterStateCached // Collison arbiter is invalid because one of the shapes was removed. ArbiterStateInvalidated )
Arbiter states
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 ( DrawShapes = 1 << 0 DrawConstraints = 1 << 1 DrawCollisionPoints = 1 << 2 )
Draw flags
const ( MaxContactsPerArbiter int = 2 ContactsBufferSize int = 1024 )
const (
ShapeTypeNum = 3
)
Variables ¶
var BuiltinCollisionFuncs = [9]CollisionFunc{ CircleToCircle, CollisionError, CollisionError, CircleToSegment, SegmentToSegment, CollisionError, CircleToPoly, SegmentToPoly, PolyToPoly, }
var CollisionHandlerDefault = CollisionHandler{ WildcardCollisionType, WildcardCollisionType, DefaultBegin, DefaultPreSolve, DefaultPostSolve, DefaultSeparate, nil, }
var CollisionHandlerDoNothing = CollisionHandler{ WildcardCollisionType, WildcardCollisionType, AlwaysCollide, AlwaysCollide, DoNothing, DoNothing, 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 ShapeUpdateFunc = func(shape *Shape) {
shape.CacheBB()
}
var ShapeVelocityFunc = func(obj any) vec.Vec2 { 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 AreaForPoly ¶
AreaForPoly calculates the signed area of a polygon.
A Clockwise winding gives positive area. This is probably backwards from what you expect, but matches Chipmunk's the winding for poly shapes.
func AreaForSegment ¶
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 CentroidForPoly ¶
CentroidForPoly calculates the natural centroid of a polygon.
func CircleSegmentQuery ¶
func CircleToCircle ¶
func CircleToCircle(info *CollisionInfo)
func CircleToPoly ¶
func CircleToPoly(info *CollisionInfo)
func CircleToSegment ¶
func CircleToSegment(info *CollisionInfo)
func CollisionError ¶
func CollisionError(_ *CollisionInfo)
func ComponentActive ¶
func ContactPoints ¶
func ContactPoints(e1, e2 Edge, points ClosestPoints, info *CollisionInfo)
ContactPoints finds contact point pairs on two support edges' surfaces
func DefaultPostSolve ¶
func DefaultSeparate ¶
func DefaultSpringForce ¶
func DefaultSpringForce(spring *DampedSpring, dist float64) float64
func DrawConstraint ¶
func DrawConstraint(constraint *Constraint, drawer IDrawer)
DrawConstraint draws constraints with the drawer implementation
func FloodFillComponent ¶
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 Vec2 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 MomentForPoly ¶
MomentForPoly calculates the moment of inertia for a solid polygon shape assuming it's center of gravity is at it's centroid.
The offset is added to each vertex.
func MomentForSegment ¶
MomentForSegment calculates the moment of inertia for a line segment.
Beveling radius is not supported.
func PolyLineCollectSegment ¶
func PolyLineCollectSegment(v0, v1 vec.Vec2, 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 vec.Vec2) int
func PolyToPoly ¶
func PolyToPoly(info *CollisionInfo)
func PostStepDoNothing ¶
func QHullPartition ¶
func QHullReduce ¶
func QueryReject ¶
QueryReject returns true if shapes a and b reject to collide.
func QueryRejectConstraints ¶
func SegmentToPoly ¶
func SegmentToPoly(info *CollisionInfo)
func SegmentToSegment ¶
func SegmentToSegment(info *CollisionInfo)
func SpaceArbiterSetFilter ¶
SpaceArbiterSetFilter throws away old arbiters.
func SpaceCollideShapesFunc ¶
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) ApplyCachedImpulse ¶
func (*Arbiter) ApplyImpulse ¶
func (arbiter *Arbiter) ApplyImpulse()
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 (arb *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 (arb *Arbiter) SetContactPointSet(set *ContactPointSet)
SetContactPointSet replaces the contact point set.
This can be a very powerful feature, but use it with caution!
func (*Arbiter) Shapes ¶
Shapes return the colliding shapes involved for this arbiter. The order of their space.CollisionType values will match the order set when the collision handler was registered.
func (*Arbiter) ThreadForBody ¶
func (arbiter *Arbiter) ThreadForBody(body *Body) *ArbiterThread
func (*Arbiter) TotalImpulse ¶
TotalImpulse calculates the total impulse including the friction that was applied by this arbiter.
This function should only be called from a post-solve, post-step or EachArbiter callback.
func (*Arbiter) Update ¶
func (arb *Arbiter) Update(info *CollisionInfo, space *Space)
type ArbiterThread ¶
type ArbiterThread struct {
// contains filtered or unexported fields
}
type BB ¶
type BB struct {
L, B, R, T float64
}
BB is Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)
func 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 ShapeGetBB ¶
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 BBTree ¶
type BBTree struct {
// contains filtered or unexported fields
}
BBTree represents a bounding box tree used for spatial indexing and collision detection.
func (*BBTree) Each ¶
func (bbt *BBTree) Each(f SpatialIndexIterator)
func (*BBTree) GetMasterTree ¶
func (*BBTree) IncrementStamp ¶
func (tree *BBTree) IncrementStamp()
func (*BBTree) LeafAddPairs ¶
func (*BBTree) LeafUpdate ¶
func (*BBTree) NodeFromPool ¶
func (*BBTree) PairFromPool ¶
func (*BBTree) PairInsert ¶
func (*BBTree) PairsClear ¶
func (*BBTree) RecycleNode ¶
func (*BBTree) RecyclePair ¶
func (*BBTree) ReindexObject ¶
func (*BBTree) ReindexQuery ¶
func (tree *BBTree) ReindexQuery(f SpatialIndexQuery, data any)
func (*BBTree) ReplaceChild ¶
func (*BBTree) SegmentQuery ¶
type BBTreeVelocityFunc ¶
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 vec.Vec2, info *PointQueryInfo)
func (*Circle) SegmentQuery ¶
func (circle *Circle) SegmentQuery(a, b vec.Vec2, radius float64, info *SegmentQueryInfo)
func (*Circle) TransformC ¶
type ClosestPoints ¶
type ClosestPoints struct {
// contains filtered or unexported fields
}
func EPA ¶
func EPA(ctx SupportContext, v0, v1, v2 MinkowskiPoint) ClosestPoints
EPA is called from GJK when two shapes overlap. Finds the closest points on the surface of two overlapping shapes using the EPA algorithm. This is a moderately expensive step! Avoid it by adding radii to your shapes so their inner polygons won't overlap.
func EPARecurse ¶
func EPARecurse(ctx SupportContext, count int, hull []MinkowskiPoint, iteration int) ClosestPoints
EPARecurse implementation of the EPA loop. Each recursion adds a point to the convex hull until it's known that we have the closest point on the surface.
func GJK ¶
func GJK(ctx SupportContext, collisionId *uint32) ClosestPoints
GJK finds the closest points between two shapes using the GJK algorithm.
func GJKRecurse ¶
func GJKRecurse(ctx SupportContext, v0, v1 MinkowskiPoint, iteration int) ClosestPoints
GJKRecurse implementation of the GJK loop.
type CollisionBeginFunc ¶
CollisionBeginFunc is collision begin event function callback type. Returning false from a begin callback causes the collision to be ignored until the the separate callback is called when the objects stop colliding.
type CollisionFunc ¶
type CollisionFunc func(info *CollisionInfo)
type CollisionHandler ¶
type CollisionHandler struct { // Collision type identifier of the first shape that this handler recognizes. // In the collision handler callback, the shape with this type will be the first argument. Read only. TypeA CollisionType // Collision type identifier of the second shape that this handler recognizes. // In the collision handler callback, the shape with this type will be the second argument. Read only. TypeB CollisionType // This function is called when two shapes with types that match this collision handler begin colliding. BeginFunc CollisionBeginFunc // This function is called each step when two shapes with types that match this collision handler are colliding. // It's called before the collision solver runs so that you can affect a collision's outcome. PreSolveFunc CollisionPreSolveFunc // This function is called each step when two shapes with types that match this collision handler are colliding. // It's called after the collision solver runs so that you can read back information about the collision to trigger events in your game. PostSolveFunc CollisionPostSolveFunc // This function is called when two shapes with types that match this collision handler stop colliding. SeparateFunc CollisionSeparateFunc // This is a user definable context pointer that is passed to all of the collision handler functions. UserData 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 Collide ¶
func Collide(a, b *Shape, collisionID uint32, contacts []Contact) CollisionInfo
Collide performs a collision between two shapes
func (*CollisionInfo) PushContact ¶
func (info *CollisionInfo) PushContact(p1, p2 vec.Vec2, 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 CollisionType ¶
type CollisionType uintptr
const WildcardCollisionType CollisionType = ^CollisionType(0)
type Constrainer ¶
type Constraint ¶
type Constraint struct { Class Constrainer PreSolve ConstraintPreSolveFunc PostSolve ConstraintPostSolveFunc UserData any // 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 vec.Vec2, 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 vec.Vec2) *Constraint
func NewPinJoint ¶
func NewPinJoint(a, b *Body, anchorA, anchorB vec.Vec2) *Constraint
func NewPivotJoint ¶
func NewPivotJoint(a, b *Body, pivot vec.Vec2) *Constraint
func NewPivotJoint2 ¶
func NewPivotJoint2(a, b *Body, anchorA, anchorB vec.Vec2) *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 vec.Vec2, 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 ContactBuffer ¶
type ContactBuffer struct {
// contains filtered or unexported fields
}
func NewContactBuffer ¶
func NewContactBuffer(stamp uint, slice *ContactBuffer) *ContactBuffer
func (*ContactBuffer) InitHeader ¶
func (c *ContactBuffer) InitHeader(stamp uint, splice *ContactBuffer) *ContactBuffer
type ContactPointSet ¶
type ContactPointSet struct { // Count is the number of contact points in the set. Count int // Normal is the normal of the collision. Normal vec.Vec2 Points [MaxContactsPerArbiter]struct { // The position of the contact on the surface of each shape. PointA, PointB vec.Vec2 // Distance is penetration distance of the two shapes. Overlapping means it will be negative. // // This value is calculated as p2.Sub(p1).Dot(n) and is ignored by Arbiter.SetContactPointSet(). Distance float64 } }
ContactPointSet wraps up the important collision data for an arbiter.
func ShapesCollideInfo ¶ added in v1.11.0
func ShapesCollideInfo(a, b *Shape) ContactPointSet
Return contact information about two shapes.
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 vec.Vec2 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 vec.Vec2 AnchorB vec.Vec2 // 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 HashSet ¶
type HashSet[T, U comparable] struct { // contains filtered or unexported fields }
HashSet implements a hash set
func NewHashSet ¶
func NewHashSet[T, U comparable](isEqual func(ptr T, elt U) bool) *HashSet[T, U]
NewHashSet is a HashSet constructor
func (*HashSet[T, U]) Each ¶
func (set *HashSet[T, U]) Each(f func(U))
Each calls f for every U in the HashSet.
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 vec.Vec2, angle, radius float64, outline, fill FColor, data any) DrawSegment(a, b vec.Vec2, fill FColor, data any) DrawFatSegment(a, b vec.Vec2, radius float64, outline, fill FColor, data any) DrawPolygon(count int, verts []vec.Vec2, radius float64, outline, fill FColor, data any) DrawDot(size float64, pos vec.Vec2, 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 vec.Vec2, info *PointQueryInfo) SegmentQuery(a, b vec.Vec2, radius float64, info *SegmentQueryInfo) }
type MarkContext ¶
type MarkContext struct {
// contains filtered or unexported fields
}
type Mat2x2 ¶
type Mat2x2 struct {
// contains filtered or unexported fields
}
Mat2x2 is a 2x2 matrix type used for tensors and such.
type MinkowskiPoint ¶
type MinkowskiPoint struct {
// contains filtered or unexported fields
}
MinkowskiPoint is a point on the surface of two shapes' minkowski difference.
func NewMinkowskiPoint ¶
func NewMinkowskiPoint(a, b SupportPoint) MinkowskiPoint
func (MinkowskiPoint) ClosestPoints ¶
func (v0 MinkowskiPoint) ClosestPoints(v1 MinkowskiPoint) ClosestPoints
ClosestPoints calculates the closest points on two shapes given the closest edge on their minkowski difference to (0, 0)
type Node ¶
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) SubtreeQuery ¶
func (subtree *Node) SubtreeQuery(obj any, bb BB, query SpatialIndexQuery, data any)
func (*Node) SubtreeSegmentQuery ¶
type PinJoint ¶
type PinJoint struct { *Constraint AnchorA, AnchorB vec.Vec2 Dist float64 // contains filtered or unexported fields }
func (*PinJoint) ApplyCachedImpulse ¶
func (*PinJoint) ApplyImpulse ¶
func (*PinJoint) GetImpulse ¶
type PivotJoint ¶
type PivotJoint struct { *Constraint AnchorA, AnchorB vec.Vec2 // 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 PointQueryContext ¶
type PointQueryContext struct {
// contains filtered or unexported fields
}
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 vec.Vec2 // 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 vec.Vec2 }
PointQueryInfo is point query info struct.
type PolyLine ¶
func DouglasPeucker ¶
func DouglasPeucker( verts []vec.Vec2, 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 vec.Vec2) int
Find the polyline that ends with v.
func (*PolyLineSet) FindStarts ¶
func (pls *PolyLineSet) FindStarts(v vec.Vec2) int
Find the polyline that starts with v.
func (*PolyLineSet) Join ¶
func (pls *PolyLineSet) Join(before, after int)
this may deletion could be slow? https://yourbasic.org/golang/delete-element-slice/
func (*PolyLineSet) Push ¶
func (pls *PolyLineSet) Push(v *PolyLine)
Add a new polyline to a polyline set.
type PolyShape ¶
type PolyShape struct { *Shape Radius float64 // The untransformed Planes are appended at the end of the transformed Planes. Planes []SplittingPlane // contains filtered or unexported fields }
func (*PolyShape) PointQuery ¶
func (ps *PolyShape) PointQuery(p vec.Vec2, info *PointQueryInfo)
func (*PolyShape) SegmentQuery ¶
func (ps *PolyShape) SegmentQuery(a, b vec.Vec2, r2 float64, info *SegmentQueryInfo)
func (*PolyShape) SetVertsUnsafe ¶
type PostStepCallback ¶
type PostStepCallback struct {
// contains filtered or unexported fields
}
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 vec.Vec2, info *PointQueryInfo)
func (*Segment) SegmentQuery ¶
func (seg *Segment) SegmentQuery(a, b vec.Vec2, 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 vec.Vec2 // The normal of the surface hit. Normal vec.Vec2 // 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 vec.Vec2 Elasticity, Friction float64 BB BB // contains filtered or unexported fields }
func NewBoxShape ¶ added in v1.11.0
NewBoxShape 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 NewBoxShape2 ¶ added in v1.11.0
NewBoxShape2 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 NewCircleShape ¶ added in v1.11.0
NewCircleShape 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 NewPolyShape ¶
NewPolyShape 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 NewPolyShapeRaw ¶
Initialize a polygon shape with rounded corners. The vertexes must be convex with a counter-clockwise winding.
func NewSegmentShape ¶ added in v1.11.0
NewSegmentShape 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) MassInfo ¶
func (sh *Shape) MassInfo() *ShapeMassInfo
func (*Shape) Point ¶
func (sh *Shape) Point(i uint32) SupportPoint
func (*Shape) PointQuery ¶
func (sh *Shape) PointQuery(p vec.Vec2) 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 ¶
func (*Shape) SetElasticity ¶
SetElasticity sets elasticity (0-1 range)
func (*Shape) SetFriction ¶
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)
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) 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 vec.Vec2) *ShapeMassInfo
func NewSegmentMassInfo ¶
func NewSegmentMassInfo(mass float64, a, b vec.Vec2, 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 vec.Vec2 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 vec.Vec2 // 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 PostStepCallbacks []*PostStepCallback // 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) ContactBufferGetArray ¶
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 vec.Vec2, 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) PopContacts ¶
func (*Space) PostStepCallback ¶
func (s *Space) PostStepCallback(key any) *PostStepCallback
func (*Space) ProcessComponents ¶
func (*Space) PushContacts ¶
func (*Space) PushFreshContactBuffer ¶
func (s *Space) PushFreshContactBuffer()
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 vec.Vec2, radius float64, filter ShapeFilter, f SpaceSegmentQueryFunc, data any)
func (*Space) SegmentQueryFirst ¶
func (s *Space) SegmentQueryFirst(start, end vec.Vec2, 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) UncacheArbiter ¶
func (*Space) UseSpatialHash ¶
func (*Space) UseWildcardDefaultHandler ¶
func (s *Space) UseWildcardDefaultHandler()
type SpaceBBQueryFunc ¶
type SpaceHash ¶
type SpaceHash struct { *SpatialIndex // contains filtered or unexported fields }
func (*SpaceHash) Each ¶
func (hash *SpaceHash) Each(f SpatialIndexIterator)
func (*SpaceHash) Query ¶
func (hash *SpaceHash) Query(obj any, bb BB, f SpatialIndexQuery, data any)
func (*SpaceHash) ReindexObject ¶
func (*SpaceHash) ReindexQuery ¶
func (hash *SpaceHash) ReindexQuery(f SpatialIndexQuery, data any)
func (*SpaceHash) SegmentQuery ¶
func (hash *SpaceHash) SegmentQuery(obj any, a, b vec.Vec2, tExit float64, f SpatialIndexSegmentQuery, data any)
modified from http://playtechs.blogspot.com/2007/03/raytracing-on-grid.html
type SpaceHashBin ¶
type SpaceHashBin struct {
// contains filtered or unexported fields
}
type SpaceSegmentQueryFunc ¶
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 any)
func (*SpatialIndex) GetRootIfTree ¶
func (index *SpatialIndex) GetRootIfTree() *Node
func (*SpatialIndex) GetTree ¶
func (index *SpatialIndex) GetTree() *BBTree
type SpatialIndexBB ¶
type SpatialIndexIterator ¶
type SpatialIndexIterator func(obj *Shape)
type SpatialIndexQuery ¶
type SpatialIndexer ¶
type SpatialIndexer interface { // Count returns the number of objects currently stored in the index. Count() int // Each iterates over all objects in the spatial index, applying // the provided iterator function `f` to each object. Each(f SpatialIndexIterator) // Contains checks if a given object `obj` with the specified // `hashId` exists in the spatial index. Contains(obj *Shape, hashId HashValue) bool // Insert adds a new object `obj` with the specified `hashId` to // the spatial index. Insert(obj *Shape, hashId HashValue) // Remove deletes the object `obj` with the specified `hashId` // from the spatial index, if it exists. Remove(obj *Shape, hashId HashValue) // Reindex rebuilds the spatial index from the existing objects // to optimize query performance. Reindex() // ReindexObject updates the spatial position of the given object // `obj` in the index using the specified `hashId`. ReindexObject(obj *Shape, hashId HashValue) // ReindexQuery performs a reindexing query using the given // spatial query function `f` and additional `data`. ReindexQuery(f SpatialIndexQuery, data any) // Query allows querying the spatial index for objects that intersect // or are contained within the bounding box `bb` using the provided // query function `f` and additional `data`. Query(obj any, bb BB, f SpatialIndexQuery, data any) // SegmentQuery performs a segment-based query using the line segment // defined by points `a` and `b`. It allows querying objects affected // by the segment based on the `tExit` parameter, applying the // provided segment query function `f` and additional `data`. SegmentQuery(obj any, a, b vec.Vec2, tExit float64, f SpatialIndexSegmentQuery, data any) }
SpatialIndexer is an interface for spatial indexing that provides methods to manage spatial objects efficiently. It is implemented by a BBTree structure, which organizes objects in a bounding volume tree.
type SplittingPlane ¶
type SupportContext ¶
type SupportContext struct {
// contains filtered or unexported fields
}
func (*SupportContext) Support ¶
func (ctx *SupportContext) Support(n vec.Vec2) MinkowskiPoint
Support calculates the maximal point on the minkowski difference of two shapes along a particular axis.
type SupportPoint ¶
type SupportPoint struct {
// contains filtered or unexported fields
}
func CircleSupportPoint ¶
func CircleSupportPoint(shape *Shape, _ vec.Vec2) SupportPoint
func NewSupportPoint ¶
func NewSupportPoint(p vec.Vec2, index uint32) SupportPoint
func PolySupportPoint ¶
func PolySupportPoint(shape *Shape, n vec.Vec2) SupportPoint
func SegmentSupportPoint ¶
func SegmentSupportPoint(shape *Shape, n vec.Vec2) SupportPoint
type SupportPointFunc ¶
type SupportPointFunc func(shape *Shape, n vec.Vec2) SupportPoint
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:
- v: the vector (Vec2) to be transformed, represented by X and Y coordinates.
Returns:
- Vec2: 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
- constraint.go
- contact_buffer.go
- damped_rotary_spring.go
- damped_spring.go
- everything.go
- gear_joint.go
- groove_joint.go
- hashset.go
- hashset_arbiter.go
- idrawer.go
- pin_joint.go
- pivot_joint.go
- polyline.go
- polyshape.go
- ratchet_joint.go
- rotary_limit_joint.go
- segment.go
- shape.go
- shape_factory.go
- simple_motor.go
- slide_joint.go
- space.go
- space_hash.go
- spatial_index.go
- transform.go