Documentation ¶
Overview ¶
Package cp is a wrapper for the Chipmunk 2D Physics Engine.
More information about Chipmunk can be found at:
http://chipmunk-physics.net/
This package uses the Chipmunk library, and as such it is also bound by it's license which can be found at:
https://github.com/slembcke/Chipmunk2D/blob/master/LICENSE.txt
Index ¶
- Constants
- Variables
- func AreaForCircle(r1, r2 float64) float64
- func AreaForPoly(verts []Vect, radius float64) float64
- func AreaForSegment(a, b Vect, radius float64) float64
- func BodyUpdatePosition(b *Body, dt float64)
- func BodyUpdateVelocity(b *Body, gravity Vect, damping, dt float64)
- func ConvexHull(count int, verts, result *Vect, first *int, tol float64) int
- func Fabs(f float64) float64
- func Fclamp(f, min, max float64) float64
- func Fclamp01(f float64) float64
- func Flerp(f1, f2, t float64) float64
- func Flerpconst(f1, f2, d float64) float64
- func Fmax(a, b float64) float64
- func Fmin(a, b float64) float64
- func MomentForBox(m, width, height float64) float64
- func MomentForBox2(m float64, box BB) float64
- func MomentForCircle(m, r1, r2 float64, offset Vect) float64
- func MomentForPoly(m float64, verts []Vect, offset Vect, radius float64) float64
- func MomentForSegment(m float64, a, b Vect, radius float64) float64
- func Vcross(v1, v2 Vect) float64
- func Vdist(v1, v2 Vect) float64
- func Vdistsq(v1, v2 Vect) float64
- func Veql(v1, v2 Vect) bool
- func Vlength(v Vect) float64
- func Vlengthsq(v Vect) float64
- func Vnear(v1, v2 Vect, dist float64) bool
- func Vtoangle(v Vect) float64
- type Arbiter
- 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) Depth(i int) float64
- func (a *Arbiter) Friction() float64
- func (a *Arbiter) GetNormal() Vect
- func (a *Arbiter) Ignore() bool
- func (a *Arbiter) IsFirstContact() bool
- func (a *Arbiter) IsRemoval() bool
- func (a *Arbiter) Point1(i int) Vect
- func (a *Arbiter) Point2(i int) Vect
- func (a *Arbiter) Restitution() float64
- func (a *Arbiter) SetContactPointSet(set *ContactPointSet)
- func (a *Arbiter) SetFriction(friction float64)
- func (a *Arbiter) SetRestitution(restitution float64)
- func (a *Arbiter) SetSurfaceVelocity(vr Vect)
- func (a *Arbiter) SetUserData(i interface{})
- func (arb *Arbiter) Shapes() (a, b *Shape)
- func (a *Arbiter) SurfaceVelocity() Vect
- func (a *Arbiter) TotalImpulse() Vect
- func (a *Arbiter) TotalKE() float64
- func (a *Arbiter) UserData() interface{}
- type Array
- type BB
- func (bb BB) Area() float64
- func (bb BB) Center() Vect
- func (bb BB) ClampVect(v Vect) Vect
- func (bb BB) ContainsBB(other BB) bool
- func (bb BB) ContainsVect(v Vect) bool
- func (bb BB) Expand(v Vect) BB
- func (a BB) Intersects(b BB) bool
- func (bb BB) IntersectsSegment(a, b Vect) bool
- func (a BB) Merge(b BB) BB
- func (a BB) MergedArea(b BB) float64
- func (bb BB) SegmentQuery(a, b Vect) float64
- func (bb BB) WrapVect(v Vect) Vect
- type Bitmask
- type Body
- func (b *Body) Activate()
- func (b *Body) ActivateStatic(filter *Shape)
- func (b *Body) Angle() float64
- func (b *Body) AngularVelocity() float64
- func (b *Body) ApplyForceAtLocalPoint(force, point Vect)
- func (b *Body) ApplyForceAtWorldPoint(force, point Vect)
- func (b *Body) ApplyImpulseAtLocalPoint(impulse, point Vect)
- func (b *Body) ApplyImpulseAtWorldPoint(impulse, point Vect)
- func (b *Body) BoxShapeNew(width, height, radius float64) *Shape
- func (b *Body) BoxShapeNew2(box BB, radius float64) *Shape
- func (b *Body) CenterOfGravity() Vect
- func (b *Body) CircleShapeNew(radius float64, offset Vect) *Shape
- func (b *Body) EachArbiter(f func(b *Body, a *Arbiter))
- func (b *Body) EachConstraint(f func(b *Body, c *Constraint))
- func (b *Body) EachShape(f func(b *Body, s *Shape))
- func (b *Body) Force() Vect
- func (b *Body) Free()
- func (b *Body) IsSleeping() bool
- func (b *Body) KineticEnergy() float64
- func (b *Body) LocalToWorld(point Vect) Vect
- func (b *Body) Mass() float64
- func (b *Body) Moment() float64
- func (b *Body) PolyShapeNew(verts []Vect, transform Transform, radius float64) *Shape
- func (b *Body) Position() Vect
- func (b *Body) Rotation() Vect
- func (bd *Body) SegmentShapeNew(a, b Vect, radius float64) *Shape
- func (b *Body) SetAngle(a float64)
- func (b *Body) SetAngularVelocity(angularVelocity float64)
- func (b *Body) SetCenterOfGravity(cog Vect)
- func (b *Body) SetForce(force Vect)
- func (b *Body) SetMass(m float64)
- func (b *Body) SetMoment(i float64)
- func (b *Body) SetPosition(pos Vect)
- func (b *Body) SetPositionUpdateFunc(f BodyPositionFunc)
- func (b *Body) SetTorque(torque float64)
- func (b *Body) SetType(t BodyType)
- func (b *Body) SetUserData(userData interface{})
- func (b *Body) SetVelocity(velocity Vect)
- func (b *Body) SetVelocityUpdateFunc(f BodyVelocityFunc)
- func (b *Body) Sleep()
- func (b *Body) SleepWithGroup(group *Body)
- func (b *Body) Space() *Space
- func (b *Body) Torque() float64
- func (b *Body) Type() BodyType
- func (b *Body) UserData() interface{}
- func (b *Body) Velocity() Vect
- func (b *Body) VelocityAtLocalPoint(point Vect) Vect
- func (b *Body) VelocityAtWorldPoint(point Vect) Vect
- func (b *Body) WorldToLocal(point Vect) Vect
- type BodyPositionFunc
- type BodyType
- type BodyVelocityFunc
- type CircleShape
- type CollisionBeginFunc
- type CollisionHandler
- type CollisionID
- type CollisionPostSolveFunc
- type CollisionPreSolveFunc
- type CollisionSeparateFunc
- type CollisionType
- type Constraint
- func DampedRotarySpringNew(a, b *Body, restAngle, stiffness, damping float64) *Constraint
- func DampedSpringNew(a, b *Body, anchorA, anchorB Vect, restLength, stiffness, damping float64) *Constraint
- func GearJointNew(a, b *Body, phase, ratio float64) *Constraint
- func GrooveJointNew(a, b *Body, grooveA, grooveB, anchorB Vect) *Constraint
- func PinJointNew(a, b *Body, anchorA, anchorB Vect) *Constraint
- func PivotJointNew(a, b *Body, pivot Vect) *Constraint
- func PivotJointNew2(a, b *Body, anchorA, anchorB Vect) *Constraint
- func RatchetJointNew(a, b *Body, phase, ratchet float64) *Constraint
- func RotaryLimitJointNew(a, b *Body, min, max float64) *Constraint
- func SimpleMotorNew(a, b *Body, rate float64) *Constraint
- func SlideJointNew(a, b *Body, anchorA, anchorB Vect, min, max float64) *Constraint
- func (c *Constraint) BodyA() *Body
- func (c *Constraint) BodyB() *Body
- func (c *Constraint) CollideBodies() bool
- func (c *Constraint) DampedRotarySpringDamping() float64
- func (c *Constraint) DampedRotarySpringRestAngle() float64
- func (c *Constraint) DampedRotarySpringSetDamping(damping float64)
- func (c *Constraint) DampedRotarySpringSetStiffness(stiffness float64)
- func (c *Constraint) DampedRotarySpringSetTorqueFunc(f func(spring *Constraint, relativeAngle float64) float64)
- func (c *Constraint) DampedRotarySpringStiffness() float64
- func (c *Constraint) DampedRotarySpringTorqueFunc() func(spring *Constraint, relativeAngle float64) float64
- func (c *Constraint) DampedSpringAnchorA() Vect
- func (c *Constraint) DampedSpringAnchorB() Vect
- func (c *Constraint) DampedSpringDamping() float64
- func (c *Constraint) DampedSpringForceFunc() func(spring *Constraint, dist float64) float64
- func (c *Constraint) DampedSpringRestLength() float64
- func (c *Constraint) DampedSpringSetAnchorA(anchorA Vect)
- func (c *Constraint) DampedSpringSetAnchorB(anchorA Vect)
- func (c *Constraint) DampedSpringSetDamping(damping float64)
- func (c *Constraint) DampedSpringSetForceFunc(f func(spring *Constraint, dist float64) float64)
- func (c *Constraint) DampedSpringSetRestLength(restLength float64)
- func (c *Constraint) DampedSpringSetStiffness(stiffness float64)
- func (c *Constraint) DampedSpringStiffness() float64
- func (c *Constraint) ErrorBias() float64
- func (c *Constraint) Free()
- func (c *Constraint) GearJointPhase() float64
- func (c *Constraint) GearJointRatio() float64
- func (c *Constraint) GearJointSetPhase(phase float64)
- func (c *Constraint) GearJointSetRatio(ratio float64)
- func (c *Constraint) GrooveJointAnchorB() Vect
- func (c *Constraint) GrooveJointGrooveA() Vect
- func (c *Constraint) GrooveJointGrooveB() Vect
- func (c *Constraint) GrooveJointSetAnchorB(grooveB Vect)
- func (c *Constraint) GrooveJointSetGrooveA(grooveA Vect)
- func (c *Constraint) GrooveJointSetGrooveB(grooveB Vect)
- func (c *Constraint) Impulse() float64
- func (c *Constraint) IsDampedRotarySpring() bool
- func (c *Constraint) IsDampedSpring() bool
- func (c *Constraint) IsGearJoint() bool
- func (c *Constraint) IsGrooveJoint() bool
- func (c *Constraint) IsPinJoint() bool
- func (c *Constraint) IsPivotJoint() bool
- func (c *Constraint) IsRatchetJoint() bool
- func (c *Constraint) IsRotaryLimitJoint() bool
- func (c *Constraint) IsSimpleMotor() bool
- func (c *Constraint) IsSlideJoint() bool
- func (c *Constraint) MaxBias() float64
- func (c *Constraint) MaxForce() float64
- func (c *Constraint) PinJointAnchorA() Vect
- func (c *Constraint) PinJointAnchorB() Vect
- func (c *Constraint) PinJointDist() float64
- func (c *Constraint) PinJointSetAnchorA(anchorA Vect)
- func (c *Constraint) PinJointSetAnchorB(anchorB Vect)
- func (c *Constraint) PinJointSetDist(dist float64)
- func (c *Constraint) PivotJointAnchorA() Vect
- func (c *Constraint) PivotJointAnchorB() Vect
- func (c *Constraint) PivotJointSetAnchorA(anchorA Vect)
- func (c *Constraint) PivotJointSetAnchorB(anchorB Vect)
- func (c *Constraint) PostSolveFunc() func(*Constraint, *Space)
- func (c *Constraint) PreSolveFunc() func(*Constraint, *Space)
- func (c *Constraint) RatchetJointAngle() float64
- func (c *Constraint) RatchetJointPhase() float64
- func (c *Constraint) RatchetJointRatchet() float64
- func (c *Constraint) RatchetJointSetAngle(angle float64)
- func (c *Constraint) RatchetJointSetPhase(phase float64)
- func (c *Constraint) RatchetJointSetRatchet(ratchet float64)
- func (c *Constraint) RotaryLimitJointMax() float64
- func (c *Constraint) RotaryLimitJointMin() float64
- func (c *Constraint) RotaryLimitJointSetMax(max float64)
- func (c *Constraint) RotaryLimitJointSetMin(min float64)
- func (c *Constraint) RotarySpringSetRestAngle(restAngle float64)
- func (c *Constraint) SetCollideBodies(collideBodies bool)
- func (c *Constraint) SetErrorBias(errorBias float64)
- func (c *Constraint) SetMaxBias(maxBias float64)
- func (c *Constraint) SetMaxForce(maxForce float64)
- func (c *Constraint) SetPostSolveFunc(f func(*Constraint, *Space))
- func (c *Constraint) SetPreSolveFunc(f func(*Constraint, *Space))
- func (c *Constraint) SetUserData(i interface{})
- func (c *Constraint) SimpleMotorRate() float64
- func (c *Constraint) SimpleMotorSetRate(rate float64)
- func (c *Constraint) SlideJointAnchorA() Vect
- func (c *Constraint) SlideJointAnchorB() Vect
- func (c *Constraint) SlideJointMax() float64
- func (c *Constraint) SlideJointMin() float64
- func (c *Constraint) SlideJointSetAnchorA(anchorA Vect)
- func (c *Constraint) SlideJointSetAnchorB(anchorB Vect)
- func (c *Constraint) SlideJointSetMax(max float64)
- func (c *Constraint) SlideJointSetMin(min float64)
- func (c *Constraint) Space() *Space
- func (c *Constraint) UserData() interface{}
- type ConstraintPostSolveFunc
- type ConstraintPreSolveFunc
- type ContactBufferHeader
- type ContactPoint
- type ContactPointSet
- type DampedRotarySpring
- type DampedSpring
- type DataPointer
- type GearJoint
- type GrooveJoint
- type Group
- type HashSet
- type HashValue
- type Int
- type Mat2x2
- type PinJoint
- type PivotJoint
- type PointQueryInfo
- type PolyShape
- type RatchetJoint
- type RotaryLimitJoint
- type SegmentQueryInfo
- type SegmentShape
- type Shape
- func (s *Shape) Area() float64
- func (s *Shape) BB() BB
- func (s *Shape) Body() *Body
- func (s *Shape) CacheBB() BB
- func (s *Shape) CenterOfGravity() Vect
- func (s *Shape) CircleOffset() Vect
- func (s *Shape) CircleRadius() float64
- func (shape *Shape) CircleShapeSetOffset(offset Vect)
- func (shape *Shape) CircleShapeSetRadius(radius float64)
- func (s *Shape) CollisionType() CollisionType
- func (s *Shape) Density() float64
- func (s *Shape) Elasticity() float64
- func (s *Shape) Filter() ShapeFilter
- func (s *Shape) Free()
- func (s *Shape) Friction() float64
- func (s *Shape) Mass() float64
- func (s *Shape) Moment() float64
- func (s *Shape) PointQuery(p Vect) (out *PointQueryInfo, d float64)
- func (s *Shape) PolyCount() int
- func (s *Shape) PolyRadius() float64
- func (shape *Shape) PolyShapeSetRadius(radius float64)
- func (shape *Shape) PolyShapeSetVerts(verts []Vect, transform Transform)
- func (shape *Shape) PolyShapeSetVertsRaw(verts []Vect)
- func (s *Shape) PolyVert(index int) Vect
- func (s *Shape) SegmentA() Vect
- func (s *Shape) SegmentB() Vect
- func (s *Shape) SegmentNormal() Vect
- func (s *Shape) SegmentQuery(a, b Vect, radius float64) (info *SegmentQueryInfo, ret bool)
- func (s *Shape) SegmentRadius() float64
- func (s *Shape) SegmentSetNeighbors(prev, next Vect)
- func (shape *Shape) SegmentShapeSetEndpoints(a, b Vect)
- func (shape *Shape) SegmentShapeSetRadius(radius float64)
- func (s *Shape) Sensor() bool
- func (s *Shape) SetBody(b *Body)
- func (s *Shape) SetCollisionType(collisionType CollisionType)
- func (s *Shape) SetDensity(density float64)
- func (s *Shape) SetElasticity(elasticity float64)
- func (s *Shape) SetFilter(filter ShapeFilter)
- func (s *Shape) SetFriction(friction float64)
- func (s *Shape) SetMass(mass float64)
- func (s *Shape) SetSensor(sensor bool)
- func (s *Shape) SetSurfaceVelocity(surfaceVelocity Vect)
- func (s *Shape) SetUserData(i interface{})
- func (a *Shape) ShapesCollide(b *Shape) ContactPointSet
- func (s *Shape) Space() *Space
- func (s *Shape) SurfaceVelocity() Vect
- func (s *Shape) Update(transform Transform) BB
- func (s *Shape) UserData() interface{}
- type ShapeFilter
- type SimpleMotorJoint
- type SlideJoint
- type Space
- func (s *Space) AddBody(body *Body) *Body
- func (s *Space) AddCollisionHandler(a, b CollisionType, handler *CollisionHandler)
- func (s *Space) AddConstraint(constraint *Constraint) *Constraint
- func (s *Space) AddDefaultCollisionHandler()
- func (s *Space) AddPostStepCallback(f func())
- func (s *Space) AddShape(shape *Shape) *Shape
- func (s *Space) AddWildcardHandler(t CollisionType, handler *CollisionHandler)
- func (s *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data interface{})
- func (s *Space) CollisionBias() float64
- func (s *Space) CollisionPersistence() Timestamp
- func (s *Space) CollisionSlop() float64
- func (s *Space) ContainsBody(body *Body) bool
- func (s *Space) ContainsConstraint(constraint *Constraint) bool
- func (s *Space) ContainsShape(shape *Shape) bool
- func (s *Space) CurrentTimeStep() float64
- func (s *Space) Damping() float64
- func (s *Space) DebugDraw(options *SpaceDebugDrawOptions)
- func (s *Space) EachBody(space *Space, f func(b *Body))
- func (s *Space) EachConstraint(space *Space, f func(c *Constraint))
- func (s *Space) EachShape(space *Space, f func(s *Shape))
- func (s *Space) Free()
- func (s *Space) Gravity() Vect
- func (s *Space) IdleSpeedThreshold() float64
- func (s *Space) IsLocked() bool
- func (s *Space) Iterations() int
- func (s *Space) PointQuery(point Vect, maxDistance float64, filter ShapeFilter, f SpacePointQueryFunc, ...)
- func (s *Space) PointQueryNearest(point Vect, maxDistance float64, filter ShapeFilter) (shape *Shape, out *PointQueryInfo)
- func (s *Space) ReindexShape(shape *Shape)
- func (s *Space) ReindexShapesForBody(body *Body)
- func (s *Space) ReindexStatic()
- func (s *Space) RemoveBody(body *Body)
- func (s *Space) RemoveConstraint(constraint *Constraint)
- func (s *Space) RemoveShape(shape *Shape)
- func (s *Space) SegmentQuery(start, end Vect, radius float64, filter ShapeFilter, f SpaceSegmentQueryFunc, ...)
- func (s *Space) SegmentQueryFirst(start, end Vect, radius float64, filter ShapeFilter) (shape *Shape, out *SegmentQueryInfo)
- func (s *Space) SetCollisionBias(collisionBias float64)
- func (s *Space) SetCollisionPersistence(collisionPersistence Timestamp)
- func (s *Space) SetCollisionSlop(collisionSlop float64)
- func (s *Space) SetDamping(damping float64)
- func (s *Space) SetGravity(gravity Vect)
- func (s *Space) SetIdleSpeedThreshold(idleSpeedThreshold float64)
- func (s *Space) SetIterations(iterations int)
- func (s *Space) SetSleepTimeThreshold(sleepTimeThreshold float64)
- func (s *Space) SetUserData(i interface{})
- func (s *Space) ShapeQuery(shape *Shape, f SpaceShapeQueryFunc, data interface{}) bool
- func (s *Space) SleepTimeThreshold() float64
- func (s *Space) StaticBody() *Body
- func (s *Space) Step(dt float64)
- func (s *Space) UseSpatialHash(dim float64, count int)
- func (s *Space) UserData() interface{}
- type SpaceArbiterApplyImpulseFunc
- type SpaceBBQueryFunc
- type SpaceDebugColor
- type SpaceDebugDrawCircleImpl
- type SpaceDebugDrawColorForShapeImpl
- type SpaceDebugDrawDotImpl
- type SpaceDebugDrawFatSegmentImpl
- type SpaceDebugDrawFlags
- type SpaceDebugDrawOptions
- type SpaceDebugDrawPolygonImpl
- type SpaceDebugDrawSegmentImpl
- type SpacePointQueryFunc
- type SpaceSegmentQueryFunc
- type SpaceShapeQueryFunc
- type Timestamp
- type Transform
- func TransformAxialScale(axis, pivot Vect, scale float64) Transform
- func TransformBoneScale(v0, v1 Vect) Transform
- func TransformNew(a, b, c, d, tx, ty float64) Transform
- func TransformNewTranspose(a, c, tx, b, d, ty float64) Transform
- func TransformOrtho(bb BB) Transform
- func TransformRigid(translate Vect, radians float64) Transform
- func TransformRotate(radians float64) Transform
- func TransformScale(scaleX, scaleY float64) Transform
- func TransformTranslate(translate Vect) Transform
- func (t Transform) BB(bb BB) BB
- func (t Transform) Inverse() Transform
- func (t1 Transform) Mult(t2 Transform) Transform
- func (t Transform) Point(p Vect) Vect
- func (t Transform) RigidInverse() Transform
- func (t Transform) Vect(v Vect) Vect
- func (outer Transform) Wrap(inner Transform) Transform
- func (outer Transform) WrapInverse(inner Transform) Transform
- type Vect
- func CentroidForPoly(verts []Vect) Vect
- func ClosetPointOnSegment(p, a, b Vect) Vect
- func V(x, y float64) Vect
- func Vadd(v1, v2 Vect) Vect
- func Vdot(v1, v2 Vect) Vect
- func Vforangle(a float64) Vect
- func Vlerp(v1, v2 Vect, t float64) Vect
- func Vlerpconst(v1, v2 Vect, d float64) Vect
- func Vmult(v Vect, s float64) Vect
- func Vneg(v Vect) Vect
- func Vnormalize(v Vect) Vect
- func Vperp(v Vect) Vect
- func Vproject(v1, v2 Vect) Vect
- func Vrotate(v1, v2 Vect) Vect
- func Vrperp(v Vect) Vect
- func Vslerp(v1, v2 Vect, t float64) Vect
- func Vslerpconst(v1, v2 Vect, a float64) Vect
- func Vsub(v1, v2 Vect) Vect
- func Vunrotate(v1, v2 Vect) Vect
Constants ¶
const ( // Value for cpShape.group signifying that a shape is in no group. NO_GROUP = C.CP_NO_GROUP // Value for cpShape.layers signifying that a shape is in every layer. ALL_CATEGORIES = C.CP_ALL_CATEGORIES // cpCollisionType value internally reserved for hashing wildcard handlers. WILDCARD_COLLISION_TYPE = C.CP_WILDCARD_COLLISION_TYPE )
const (
MAX_CONTACTS_PER_ARBITER = C.CP_MAX_CONTACTS_PER_ARBITER
)
Variables ¶
var ( SHAPE_FILTER_ALL = ShapeFilter{NO_GROUP, ALL_CATEGORIES, ALL_CATEGORIES} SHAPE_FILTER_NONE = ShapeFilter{NO_GROUP, 0 &^ ALL_CATEGORIES, 0 &^ ALL_CATEGORIES} )
var (
TransformIdentity = Transform{1, 0, 0, 1, 0, 0}
)
Identity transform matrix.
var ( // Version string. VersionString = C.GoString(C.cpVersionString) )
var ( // The zero vector. Vzero = Vect{0, 0} )
Functions ¶
func AreaForCircle ¶
Calculate area of a hollow circle.
r1 and r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
func AreaForPoly ¶
Calculate the signed area of a polygon. A Clockwise winding gives positive area.
This is probably backwards from what you expect, but matches Chipmunk's the winding for poly shapes.
func AreaForSegment ¶
Calculate the area of a fattened (capsule shaped) line segment.
func BodyUpdatePosition ¶
Default position integration function.
func BodyUpdateVelocity ¶
Default velocity integration function..
func ConvexHull ¶
Calculate the convex hull of a given set of points. Returns the count of points in the hull.
result must be a pointer to a cpVect array with at least count elements. If verts == result, then verts will be reduced inplace. first is an optional pointer to an integer to store where the first vertex in the hull came from (i.e. verts[first] == result[0]) tol is the allowed amount to shrink the hull when simplifying it. A tolerance of 0.0 creates an exact hull.
func Flerpconst ¶
Linearly interpolate from f1 to f2 by no more than d.
func MomentForBox ¶
Calculate the moment of inertia for a solid box.
func MomentForBox2 ¶
Calculate the moment of inertia for a solid box.
func MomentForCircle ¶
Calculate the moment of inertia for a circle.
r1 and r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
func MomentForPoly ¶
Calculate the moment of inertia for a solid polygon shape assuming it's center of gravity is at it's centroid. The offset is added to each vertex.
func MomentForSegment ¶
Calculate the moment of inertia for a line segment.
Beveling radius is not supported.
func Vcross ¶
2D vector cross product analog.
The cross product of 2D vectors results in a 3D vector with only a z component.
This function returns the magnitude of the z value.
func Vdistsq ¶
Returns the squared distance between v1 and v2. Faster than cpvdist() when you only need to compare distances.
func Vlengthsq ¶
Returns the squared length of v. Faster than cpvlength() when you only need to compare lengths.
Types ¶
type Arbiter ¶
type Arbiter struct {
// contains filtered or unexported fields
}
The Arbiter struct controls pairs of colliding shapes.
They are also used in conjuction with collision handler callbacks allowing you to retrieve information on the collision and control it.
func (*Arbiter) CallWildcardBeginA ¶
func (*Arbiter) CallWildcardBeginB ¶
func (*Arbiter) CallWildcardPostSolveA ¶
func (*Arbiter) CallWildcardPostSolveB ¶
func (*Arbiter) CallWildcardPreSolveA ¶
func (*Arbiter) CallWildcardPreSolveB ¶
func (*Arbiter) CallWildcardSeparateA ¶
func (*Arbiter) CallWildcardSeparateB ¶
func (*Arbiter) ContactPointSet ¶
func (a *Arbiter) ContactPointSet() *ContactPointSet
Return a contact set from an arbiter.
func (*Arbiter) IsFirstContact ¶
Returns true if this is the first step a pair of objects started colliding.
func (*Arbiter) IsRemoval ¶
Returns true if in separate callback due to a shape being removed from the space.
func (*Arbiter) Point1 ¶
Get the position of the ith contact point on the surface of the first shape.
func (*Arbiter) Point2 ¶
Get the position of the ith contact point on the surface of the second shape.
func (*Arbiter) Restitution ¶
func (*Arbiter) SetContactPointSet ¶
func (a *Arbiter) SetContactPointSet(set *ContactPointSet)
Replace the contact point set for an arbiter.
This can be a very powerful feature, but use it with caution!
func (*Arbiter) SetFriction ¶
func (*Arbiter) SetRestitution ¶
func (*Arbiter) SetSurfaceVelocity ¶
Override the relative surface velocity of the two shapes in contact.
By default this is calculated to be the difference of the two surface velocities clamped to the tangent plane.
func (*Arbiter) SetUserData ¶
func (a *Arbiter) SetUserData(i interface{})
func (*Arbiter) Shapes ¶
Return the colliding shapes involved for this arbiter.
The order of their cpSpace.collision_type values will match the order set when the collision handler was registered.
func (*Arbiter) SurfaceVelocity ¶
Get the relative surface velocity of the two shapes in contact.
func (*Arbiter) TotalImpulse ¶
Calculate the total impulse including the friction that was applied by this arbiter. This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
type BB ¶
Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)
func BBNewForCircle ¶
Constructs a BB for a circle with the given position and radius.
func BBNewForExtents ¶
Constructs a BB centered on a point with the given extents (half sizes).
func (BB) ContainsBB ¶
Returns true if other lies completely within bb.
func (BB) IntersectsSegment ¶
Return true if the bounding box intersects the line segment with ends a and b.
func (BB) MergedArea ¶
Merges a and b and returns the area of the merged bounding box.
func (BB) SegmentQuery ¶
Returns the fraction along the segment query the BB is hit. Returns INFINITY if it doesn't hit.
type Body ¶
type Body struct {
// contains filtered or unexported fields
}
func BodyNewKinematic ¶
func BodyNewKinematic() *Body
Allocate and initialize a Body, and set it as a kinematic body.
func BodyNewStatic ¶
func BodyNewStatic() *Body
Allocate and initialize a cpBody, and set it as a static body.
func (*Body) ActivateStatic ¶
Wake up any sleeping or idle bodies touching a static body.
func (*Body) AngularVelocity ¶
Get the angular velocity of the body.
func (*Body) ApplyForceAtLocalPoint ¶
Apply a force to a body. Both the force and point are expressed in body local coordinates.
func (*Body) ApplyForceAtWorldPoint ¶
Apply a force to a body. Both the force and point are expressed in world coordinates.
func (*Body) ApplyImpulseAtLocalPoint ¶
Apply an impulse to a body. Both the impulse and point are expressed in body local coordinates.
func (*Body) ApplyImpulseAtWorldPoint ¶
Apply an impulse to a body. Both the impulse and point are expressed in world coordinates.
func (*Body) BoxShapeNew ¶
Allocate and initialize a box shaped polygon shape.
func (*Body) BoxShapeNew2 ¶
Allocate and initialize an offset box shaped polygon shape.
func (*Body) CenterOfGravity ¶
Get the offset of the center of gravity in body local coordinates.
func (*Body) CircleShapeNew ¶
Allocate and initialize a circle shape.
func (*Body) EachArbiter ¶
Returns a slice of all arbiters that are currently active on the body.
func (*Body) EachConstraint ¶
func (b *Body) EachConstraint(f func(b *Body, c *Constraint))
Returns a slice of all contraints attached to the body and added to the space.
func (*Body) KineticEnergy ¶
Get the amount of kinetic energy contained by the body.
func (*Body) LocalToWorld ¶
Convert body relative/local coordinates to absolute/world coordinates.
func (*Body) PolyShapeNew ¶
Allocate and initialize a polygon shape with rounded corners.
A convex hull will be created from the vertexes.
func (*Body) Rotation ¶
Get the rotation vector of the body. (The x basis vector of it's transform.)
func (*Body) SegmentShapeNew ¶
Allocate and initialize a segment shape.
func (*Body) SetAngularVelocity ¶
Set the angular velocity of the body.
func (*Body) SetCenterOfGravity ¶
Set the offset of the center of gravity in body local coordinates.
func (*Body) SetPositionUpdateFunc ¶
func (b *Body) SetPositionUpdateFunc(f BodyPositionFunc)
Set the callback used to update a body's position.
NOTE: It's not generally recommended to override this.
func (*Body) SetUserData ¶
func (b *Body) SetUserData(userData interface{})
Set the user data interface assigned to the body.
func (*Body) SetVelocityUpdateFunc ¶
func (b *Body) SetVelocityUpdateFunc(f BodyVelocityFunc)
Set the callback used to update a body's velocity.
func (*Body) SleepWithGroup ¶
Force a body to fall asleep immediately along with other bodies in a group.
func (*Body) UserData ¶
func (b *Body) UserData() interface{}
Get the user data interface assigned to the body.
func (*Body) VelocityAtLocalPoint ¶
Get the velocity on a body (in world units) at a point on the body in local coordinates.
func (*Body) VelocityAtWorldPoint ¶
Get the velocity on a body (in world units) at a point on the body in world coordinates.
func (*Body) WorldToLocal ¶
Convert body absolute/world coordinates to relative/local coordinates.
type BodyPositionFunc ¶
Rigid body position update function type.
type BodyType ¶
type BodyType int
Chipmunk's rigid body type. Rigid bodies hold the physical properties of an object like it's mass, and position and velocity of it's center of gravity. They don't have an shape on their own. They are given a shape by creating collision shapes (cpShape) that point to the body.
const ( BODY_TYPE_DYNAMIC BodyType = C.CP_BODY_TYPE_DYNAMIC BODY_TYPE_KINEMATIC BodyType = C.CP_BODY_TYPE_KINEMATIC BODY_TYPE_STATIC BodyType = C.CP_BODY_TYPE_STATIC )
type BodyVelocityFunc ¶
Rigid body velocity update function type.
type CircleShape ¶
type CircleShape C.cpCircleShape
type CollisionBeginFunc ¶
Collision begin event function callback type.
Returning false from a begin callback causes the collision to be ignored until the the separate callback is called when the objects stop colliding.
type CollisionHandler ¶
type CollisionHandler struct {
TypeA, TypeB CollisionType
BeginFunc CollisionBeginFunc
PreSolveFunc CollisionPreSolveFunc
PostSolveFunc CollisionPostSolveFunc
SeparateFunc CollisionSeparateFunc
UserData interface{}
}
type CollisionID ¶
type CollisionID uint32
type CollisionPostSolveFunc ¶
Collision post-solve event function callback type.
type CollisionPreSolveFunc ¶
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 ¶
Collision separate event function callback type.
type CollisionType ¶
type CollisionType uint64
type Constraint ¶
type Constraint struct {
// contains filtered or unexported fields
}
func DampedRotarySpringNew ¶
func DampedRotarySpringNew(a, b *Body, restAngle, stiffness, damping float64) *Constraint
Allocate and initialize a damped rotary spring.
func DampedSpringNew ¶
func DampedSpringNew(a, b *Body, anchorA, anchorB Vect, restLength, stiffness, damping float64) *Constraint
Allocate and initialize a damped spring.
func GearJointNew ¶
func GearJointNew(a, b *Body, phase, ratio float64) *Constraint
Allocate and initialize a gear joint.
func GrooveJointNew ¶
func GrooveJointNew(a, b *Body, grooveA, grooveB, anchorB Vect) *Constraint
Allocate and initialize a groove joint.
func PinJointNew ¶
func PinJointNew(a, b *Body, anchorA, anchorB Vect) *Constraint
Allocate and initialize a pin joint.
func PivotJointNew ¶
func PivotJointNew(a, b *Body, pivot Vect) *Constraint
Allocate and initialize a pivot joint.
func PivotJointNew2 ¶
func PivotJointNew2(a, b *Body, anchorA, anchorB Vect) *Constraint
Allocate and initialize a pivot joint with specific anchors.
func RatchetJointNew ¶
func RatchetJointNew(a, b *Body, phase, ratchet float64) *Constraint
Allocate and initialize a ratchet joint.
func RotaryLimitJointNew ¶
func RotaryLimitJointNew(a, b *Body, min, max float64) *Constraint
Allocate and initialize a damped rotary limit joint.
func SimpleMotorNew ¶
func SimpleMotorNew(a, b *Body, rate float64) *Constraint
Allocate and initialize a simple motor.
func SlideJointNew ¶
func SlideJointNew(a, b *Body, anchorA, anchorB Vect, min, max float64) *Constraint
Allocate and initialize a slide joint.
func (*Constraint) BodyA ¶
func (c *Constraint) BodyA() *Body
Get the first body the constraint is attached to.
func (*Constraint) BodyB ¶
func (c *Constraint) BodyB() *Body
Get the second body the constraint is attached to.
func (*Constraint) CollideBodies ¶
func (c *Constraint) CollideBodies() bool
Get if the two bodies connected by the constraint are allowed to collide or not.
func (*Constraint) DampedRotarySpringDamping ¶
func (c *Constraint) DampedRotarySpringDamping() float64
Get the damping of the spring.
func (*Constraint) DampedRotarySpringRestAngle ¶
func (c *Constraint) DampedRotarySpringRestAngle() float64
Get the rest length of the spring.
func (*Constraint) DampedRotarySpringSetDamping ¶
func (c *Constraint) DampedRotarySpringSetDamping(damping float64)
Set the damping of the spring.
func (*Constraint) DampedRotarySpringSetStiffness ¶
func (c *Constraint) DampedRotarySpringSetStiffness(stiffness float64)
Set the stiffness of the spring in force/distance.
func (*Constraint) DampedRotarySpringSetTorqueFunc ¶
func (c *Constraint) DampedRotarySpringSetTorqueFunc(f func(spring *Constraint, relativeAngle float64) float64)
Set the damping rotary spring torque callback function.
func (*Constraint) DampedRotarySpringStiffness ¶
func (c *Constraint) DampedRotarySpringStiffness() float64
Get the stiffness of the spring in force/distance.
func (*Constraint) DampedRotarySpringTorqueFunc ¶
func (c *Constraint) DampedRotarySpringTorqueFunc() func(spring *Constraint, relativeAngle float64) float64
Get the damping rotary spring torque callback function.
func (*Constraint) DampedSpringAnchorA ¶
func (c *Constraint) DampedSpringAnchorA() Vect
Get the location of the first anchor relative to the first body.
func (*Constraint) DampedSpringAnchorB ¶
func (c *Constraint) DampedSpringAnchorB() Vect
Get the location of the second anchor relative to the second body.
func (*Constraint) DampedSpringDamping ¶
func (c *Constraint) DampedSpringDamping() float64
Get the damping of the spring.
func (*Constraint) DampedSpringForceFunc ¶
func (c *Constraint) DampedSpringForceFunc() func(spring *Constraint, dist float64) float64
Get the damping rotary spring torque callback function.
func (*Constraint) DampedSpringRestLength ¶
func (c *Constraint) DampedSpringRestLength() float64
Get the rest length of the spring.
func (*Constraint) DampedSpringSetAnchorA ¶
func (c *Constraint) DampedSpringSetAnchorA(anchorA Vect)
Set the location of the first anchor relative to the first body.
func (*Constraint) DampedSpringSetAnchorB ¶
func (c *Constraint) DampedSpringSetAnchorB(anchorA Vect)
Set the location of the second anchor relative to the second body.
func (*Constraint) DampedSpringSetDamping ¶
func (c *Constraint) DampedSpringSetDamping(damping float64)
Set the damping of the spring.
func (*Constraint) DampedSpringSetForceFunc ¶
func (c *Constraint) DampedSpringSetForceFunc(f func(spring *Constraint, dist float64) float64)
Set the damping spring force callback function.
func (*Constraint) DampedSpringSetRestLength ¶
func (c *Constraint) DampedSpringSetRestLength(restLength float64)
Set the rest length of the spring.
func (*Constraint) DampedSpringSetStiffness ¶
func (c *Constraint) DampedSpringSetStiffness(stiffness float64)
Set the stiffness of the spring in force/distance.
func (*Constraint) DampedSpringStiffness ¶
func (c *Constraint) DampedSpringStiffness() float64
Get the stiffness of the spring in force/distance.
func (*Constraint) ErrorBias ¶
func (c *Constraint) ErrorBias() float64
Get rate at which joint error is corrected.
func (*Constraint) Free ¶
func (c *Constraint) Free()
Free is deprecated. Do not use it, it is no-op.
func (*Constraint) GearJointPhase ¶
func (c *Constraint) GearJointPhase() float64
Get the phase offset of the gears.
func (*Constraint) GearJointRatio ¶
func (c *Constraint) GearJointRatio() float64
Get the angular distance of each ratchet.
func (*Constraint) GearJointSetPhase ¶
func (c *Constraint) GearJointSetPhase(phase float64)
Set the phase offset of the gears.
func (*Constraint) GearJointSetRatio ¶
func (c *Constraint) GearJointSetRatio(ratio float64)
Set the ratio of a gear joint.
func (*Constraint) GrooveJointAnchorB ¶
func (c *Constraint) GrooveJointAnchorB() Vect
Get the location of the second anchor relative to the second body.
func (*Constraint) GrooveJointGrooveA ¶
func (c *Constraint) GrooveJointGrooveA() Vect
Get the first endpoint of the groove relative to the first body.
func (*Constraint) GrooveJointGrooveB ¶
func (c *Constraint) GrooveJointGrooveB() Vect
Get the first endpoint of the groove relative to the first body.
func (*Constraint) GrooveJointSetAnchorB ¶
func (c *Constraint) GrooveJointSetAnchorB(grooveB Vect)
Set the location of the second anchor relative to the second body.
func (*Constraint) GrooveJointSetGrooveA ¶
func (c *Constraint) GrooveJointSetGrooveA(grooveA Vect)
Set the first endpoint of the groove relative to the first body.
func (*Constraint) GrooveJointSetGrooveB ¶
func (c *Constraint) GrooveJointSetGrooveB(grooveB Vect)
Set the first endpoint of the groove relative to the first body.
func (*Constraint) Impulse ¶
func (c *Constraint) Impulse() float64
Get the last impulse applied by this constraint.
func (*Constraint) IsDampedRotarySpring ¶
func (c *Constraint) IsDampedRotarySpring() bool
Check if a constraint is a damped rotary spring.
func (*Constraint) IsDampedSpring ¶
func (c *Constraint) IsDampedSpring() bool
Check if a constraint is a damped spring.
func (*Constraint) IsGearJoint ¶
func (c *Constraint) IsGearJoint() bool
Check if a constraint is a ratchet joint.
func (*Constraint) IsGrooveJoint ¶
func (c *Constraint) IsGrooveJoint() bool
Check if a constraint is a groove joint.
func (*Constraint) IsPinJoint ¶
func (c *Constraint) IsPinJoint() bool
Check if a constraint is a pin joint.
func (*Constraint) IsPivotJoint ¶
func (c *Constraint) IsPivotJoint() bool
Check if a constraint is a pivot joint.
func (*Constraint) IsRatchetJoint ¶
func (c *Constraint) IsRatchetJoint() bool
Check if a constraint is a ratchet joint.
func (*Constraint) IsRotaryLimitJoint ¶
func (c *Constraint) IsRotaryLimitJoint() bool
Check if a constraint is a rotary limit joint.
func (*Constraint) IsSimpleMotor ¶
func (c *Constraint) IsSimpleMotor() bool
Check if a constraint is a simple motor.
func (*Constraint) IsSlideJoint ¶
func (c *Constraint) IsSlideJoint() bool
Check if a constraint is a slide joint.
func (*Constraint) MaxBias ¶
func (c *Constraint) MaxBias() float64
Get the maximum rate at which joint error is corrected.
func (*Constraint) MaxForce ¶
func (c *Constraint) MaxForce() float64
Get the maximum force that this constraint is allowed to use.
func (*Constraint) PinJointAnchorA ¶
func (c *Constraint) PinJointAnchorA() Vect
Get the location of the first anchor relative to the first body.
func (*Constraint) PinJointAnchorB ¶
func (c *Constraint) PinJointAnchorB() Vect
Get the location of the second anchor relative to the second body.
func (*Constraint) PinJointDist ¶
func (c *Constraint) PinJointDist() float64
Get the distance the joint will maintain between the two anchors.
func (*Constraint) PinJointSetAnchorA ¶
func (c *Constraint) PinJointSetAnchorA(anchorA Vect)
Set the location of the first anchor relative to the first body.
func (*Constraint) PinJointSetAnchorB ¶
func (c *Constraint) PinJointSetAnchorB(anchorB Vect)
Set the location of the second anchor relative to the second body.
func (*Constraint) PinJointSetDist ¶
func (c *Constraint) PinJointSetDist(dist float64)
Set the distance the joint will maintain between the two anchors.
func (*Constraint) PivotJointAnchorA ¶
func (c *Constraint) PivotJointAnchorA() Vect
Get the location of the first anchor relative to the first body.
func (*Constraint) PivotJointAnchorB ¶
func (c *Constraint) PivotJointAnchorB() Vect
Get the location of the second anchor relative to the second body.
func (*Constraint) PivotJointSetAnchorA ¶
func (c *Constraint) PivotJointSetAnchorA(anchorA Vect)
Set the location of the first anchor relative to the first body.
func (*Constraint) PivotJointSetAnchorB ¶
func (c *Constraint) PivotJointSetAnchorB(anchorB Vect)
Set the location of the second anchor relative to the second body.
func (*Constraint) PostSolveFunc ¶
func (c *Constraint) PostSolveFunc() func(*Constraint, *Space)
Get the post-solve function that is called before the solver runs.
func (*Constraint) PreSolveFunc ¶
func (c *Constraint) PreSolveFunc() func(*Constraint, *Space)
Get the pre-solve function that is called before the solver runs.
func (*Constraint) RatchetJointAngle ¶
func (c *Constraint) RatchetJointAngle() float64
Get the angle of the current ratchet tooth.
func (*Constraint) RatchetJointPhase ¶
func (c *Constraint) RatchetJointPhase() float64
Get the phase offset of the ratchet.
func (*Constraint) RatchetJointRatchet ¶
func (c *Constraint) RatchetJointRatchet() float64
Get the angular distance of each ratchet.
func (*Constraint) RatchetJointSetAngle ¶
func (c *Constraint) RatchetJointSetAngle(angle float64)
Set the angle of the current ratchet tooth.
func (*Constraint) RatchetJointSetPhase ¶
func (c *Constraint) RatchetJointSetPhase(phase float64)
Get the phase offset of the ratchet.
func (*Constraint) RatchetJointSetRatchet ¶
func (c *Constraint) RatchetJointSetRatchet(ratchet float64)
Set the angular distance of each ratchet.
func (*Constraint) RotaryLimitJointMax ¶
func (c *Constraint) RotaryLimitJointMax() float64
Get the maximum distance the joint will maintain between the two anchors.
func (*Constraint) RotaryLimitJointMin ¶
func (c *Constraint) RotaryLimitJointMin() float64
Get the minimum distance the joint will maintain between the two anchors.
func (*Constraint) RotaryLimitJointSetMax ¶
func (c *Constraint) RotaryLimitJointSetMax(max float64)
Set the maximum distance the joint will maintain between the two anchors.
func (*Constraint) RotaryLimitJointSetMin ¶
func (c *Constraint) RotaryLimitJointSetMin(min float64)
Set the minimum distance the joint will maintain between the two anchors.
func (*Constraint) RotarySpringSetRestAngle ¶
func (c *Constraint) RotarySpringSetRestAngle(restAngle float64)
Set the rest length of the spring.
func (*Constraint) SetCollideBodies ¶
func (c *Constraint) SetCollideBodies(collideBodies bool)
Set if the two bodies connected by the constraint are allowed to collide or not. (defaults to cpFalse)
func (*Constraint) SetErrorBias ¶
func (c *Constraint) SetErrorBias(errorBias float64)
Set rate at which joint error is corrected.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
func (*Constraint) SetMaxBias ¶
func (c *Constraint) SetMaxBias(maxBias float64)
Set the maximum rate at which joint error is corrected. (defaults to INFINITY)
func (*Constraint) SetMaxForce ¶
func (c *Constraint) SetMaxForce(maxForce float64)
Set the maximum force that this constraint is allowed to use. (defaults to INFINITY)
func (*Constraint) SetPostSolveFunc ¶
func (c *Constraint) SetPostSolveFunc(f func(*Constraint, *Space))
Set the post-solve function that is called before the solver runs.
func (*Constraint) SetPreSolveFunc ¶
func (c *Constraint) SetPreSolveFunc(f func(*Constraint, *Space))
Set the pre-solve function that is called before the solver runs.
func (*Constraint) SetUserData ¶
func (c *Constraint) SetUserData(i interface{})
Set the user definable data pointer for this constraint
func (*Constraint) SimpleMotorRate ¶
func (c *Constraint) SimpleMotorRate() float64
Get the rate of the motor.
func (*Constraint) SimpleMotorSetRate ¶
func (c *Constraint) SimpleMotorSetRate(rate float64)
Set the rate of the motor.
func (*Constraint) SlideJointAnchorA ¶
func (c *Constraint) SlideJointAnchorA() Vect
Get the location of the first anchor relative to the first body.
func (*Constraint) SlideJointAnchorB ¶
func (c *Constraint) SlideJointAnchorB() Vect
Get the location of the second anchor relative to the second body.
func (*Constraint) SlideJointMax ¶
func (c *Constraint) SlideJointMax() float64
Get the maximum distance the joint will maintain between the two anchors.
func (*Constraint) SlideJointMin ¶
func (c *Constraint) SlideJointMin() float64
Get the minimum distance the joint will maintain between the two anchors.
func (*Constraint) SlideJointSetAnchorA ¶
func (c *Constraint) SlideJointSetAnchorA(anchorA Vect)
Set the location of the first anchor relative to the first body.
func (*Constraint) SlideJointSetAnchorB ¶
func (c *Constraint) SlideJointSetAnchorB(anchorB Vect)
Set the location of the second anchor relative to the second body.
func (*Constraint) SlideJointSetMax ¶
func (c *Constraint) SlideJointSetMax(max float64)
Set the maximum distance the joint will maintain between the two anchors.
func (*Constraint) SlideJointSetMin ¶
func (c *Constraint) SlideJointSetMin(min float64)
Set the minimum distance the joint will maintain between the two anchors.
func (*Constraint) Space ¶
func (c *Constraint) Space() *Space
Get the Space this constraint is added to.
func (*Constraint) UserData ¶
func (c *Constraint) UserData() interface{}
Get the user definable data pointer for this constraint
type ConstraintPostSolveFunc ¶
type ConstraintPostSolveFunc func(c *Constraint, space *Space)
Callback function type that gets called after solving a joint.
type ConstraintPreSolveFunc ¶
type ConstraintPreSolveFunc func(c *Constraint, space *Space)
Callback function type that gets called before solving a joint.
type ContactBufferHeader ¶
type ContactBufferHeader C.cpContactBufferHeader
type ContactPoint ¶
type ContactPoint struct {
// The position of the contact on the surface of each shape.
Point1, Point2 Vect
// Penetration distance of the two shapes. Overlapping means it will be
// negative.
//
// This value is calculated as Vdot(Vsub(point2, point1), normal) and is
// ignored by arbiter.SetContactPointSet().
Distance float64
}
type ContactPointSet ¶
type ContactPointSet struct { // The number of contact points in the set. Count Int // The normal of the collision. Normal Vect // The array of contact points. Points [MAX_CONTACTS_PER_ARBITER]ContactPoint }
A struct that wraps up the important collision data for an arbiter.
type DampedRotarySpring ¶
type DampedRotarySpring C.cpDampedRotarySpring
type DampedSpring ¶
type DampedSpring C.cpDampedSpring
type DataPointer ¶
type GearJoint ¶
type GearJoint C.cpGearJoint
type GrooveJoint ¶
type GrooveJoint C.cpGrooveJoint
type PinJoint ¶
type PinJoint C.cpPinJoint
type PivotJoint ¶
type PivotJoint C.cpPivotJoint
type PointQueryInfo ¶
type PointQueryInfo struct { // The nearest shape, nil if no shape was within range. Shape *Shape // The closest point on the shape's surface. (in world space coordinates) Point Vect // The distance to the point. The distance is negative if the point is // inside the shape. Distance float64 // The gradient of the signed distance function. // // The same as info.p/info.d, but accurate even for very small values of // info.d. Gradient Vect }
Nearest point query info struct.
type PolyShape ¶
type PolyShape C.cpPolyShape
type RatchetJoint ¶
type RatchetJoint C.cpRatchetJoint
type RotaryLimitJoint ¶
type RotaryLimitJoint C.cpRotaryLimitJoint
type SegmentQueryInfo ¶
type SegmentQueryInfo struct { // The shape that was hit, nil if no collision occured. Shape *Shape // The point of impact. Point Vect // The normal of the surface hit. Normal Vect // The normalized distance along the query segment in the range [0, 1]. Alpha float64 }
Segment query info struct.
type SegmentShape ¶
type SegmentShape C.cpSegmentShape
type Shape ¶
type Shape struct {
// contains filtered or unexported fields
}
The Shape struct defines the shape of a rigid body.
func (*Shape) BB ¶
Get the bounding box that contains the shape given it's current position and angle.
func (*Shape) CacheBB ¶
Update, cache and return the bounding box of a shape based on the body it's attached to.
func (*Shape) CenterOfGravity ¶
Get the centroid of this shape.
func (*Shape) CircleRadius ¶
Get the radius of a circle shape.
func (*Shape) CircleShapeSetOffset ¶
Set the offset of a circle shape.
This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.
func (*Shape) CircleShapeSetRadius ¶
Set the radius of a circle shape.
This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.
func (*Shape) CollisionType ¶
func (s *Shape) CollisionType() CollisionType
Get the collision type of this shape.
func (*Shape) Density ¶
Get the density of the shape if you are having Chipmunk calculate mass properties for you.
func (*Shape) Filter ¶
func (s *Shape) Filter() ShapeFilter
Get the collision filtering parameters of this shape.
func (*Shape) Mass ¶
Get the mass of the shape if you are having Chipmunk calculate mass properties for you.
func (*Shape) PointQuery ¶
func (s *Shape) PointQuery(p Vect) (out *PointQueryInfo, d float64)
Perform a nearest point query. It finds the closest point on the surface of shape to a specific point.
The value returned is the distance between the points. A negative distance means the point is inside the shape.
func (*Shape) PolyShapeSetRadius ¶
Set the radius of a poly shape.
This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.
func (*Shape) PolyShapeSetVerts ¶
Set the vertexes of a poly shape.
This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.
func (*Shape) PolyShapeSetVertsRaw ¶
Set the vertexes of a poly shape.
This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.
func (*Shape) SegmentNormal ¶
Get the normal of a segment shape.
func (*Shape) SegmentQuery ¶
func (s *Shape) SegmentQuery(a, b Vect, radius float64) (info *SegmentQueryInfo, ret bool)
Perform a segment query against a shape.
func (*Shape) SegmentRadius ¶
Get the first endpoint of a segment shape.
func (*Shape) SegmentSetNeighbors ¶
Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps.
func (*Shape) SegmentShapeSetEndpoints ¶
Set the endpoints of a segment shape.
This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.
func (*Shape) SegmentShapeSetRadius ¶
Set the radius of a segment shape.
This function is used for mutating collision shapes. Chipmunk does not have any way to get velocity information on changing shapes, so the results will be unrealistic. This function is considered 'unsafe' by Chipmunk.
func (*Shape) SetBody ¶
Set the cpBody this shape is connected to.
Can only be used if the shape is not currently added to a space.
func (*Shape) SetCollisionType ¶
func (s *Shape) SetCollisionType(collisionType CollisionType)
Set the collision type of this shape.
func (*Shape) SetDensity ¶
Set the density of this shape to have Chipmunk calculate mass properties for you.
func (*Shape) SetElasticity ¶
Set the elasticity of this shape.
func (*Shape) SetFilter ¶
func (s *Shape) SetFilter(filter ShapeFilter)
Set the collision filtering parameters of this shape.
func (*Shape) SetFriction ¶
Set the friction of this shape.
func (*Shape) SetMass ¶
Set the mass of this shape to have Chipmunk calculate mass properties for you.
func (*Shape) SetSurfaceVelocity ¶
Set the surface velocity of this shape.
func (*Shape) SetUserData ¶
func (s *Shape) SetUserData(i interface{})
Set the user definable data pointer of this shape.
func (*Shape) ShapesCollide ¶
func (a *Shape) ShapesCollide(b *Shape) ContactPointSet
Return contact information about two shapes.
func (*Shape) SurfaceVelocity ¶
Get the surface velocity of this shape.
type ShapeFilter ¶
func ShapeFilterNew ¶
func ShapeFilterNew(group Group, categories, mask Bitmask) ShapeFilter
type SimpleMotorJoint ¶
type SimpleMotorJoint C.cpSimpleMotorJoint
type SlideJoint ¶
type SlideJoint C.cpSlideJoint
type Space ¶
type Space struct {
// contains filtered or unexported fields
}
func (*Space) AddCollisionHandler ¶
func (s *Space) AddCollisionHandler(a, b CollisionType, handler *CollisionHandler)
func (*Space) AddConstraint ¶
func (s *Space) AddConstraint(constraint *Constraint) *Constraint
Add a constraint to the simulation.
func (*Space) AddDefaultCollisionHandler ¶
func (s *Space) AddDefaultCollisionHandler()
func (*Space) AddPostStepCallback ¶
func (s *Space) AddPostStepCallback(f func())
Schedule a post-step callback to be called when space.Step() finishes.
func (*Space) AddShape ¶
Add a collision shape to the simulation.
If the shape is attached to a static body, it will be added as a static shape.
func (*Space) AddWildcardHandler ¶
func (s *Space) AddWildcardHandler(t CollisionType, handler *CollisionHandler)
func (*Space) BBQuery ¶
func (s *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data interface{})
Perform a fast rectangle query on the space calling func for each shape found.
Only the shape's bounding boxes are checked for overlap, not their full shape.
func (*Space) CollisionBias ¶
Determines how fast overlapping shapes are pushed apart. Expressed as a fraction of the error remaining after each second. Defaults to pow(1.0 - 0.1, 60.0) meaning that Chipmunk fixes 10% of overlap each frame at 60Hz.
func (*Space) CollisionPersistence ¶
Number of frames that contact information should persist.
Defaults to 3. There is probably never a reason to change this value.
func (*Space) CollisionSlop ¶
Amount of encouraged penetration between colliding shapes.
Used to reduce oscillating contacts and keep the collision cache warm.
Defaults to 0.1. If you have poor simulation quality, increase this number as much as possible without allowing visible amounts of overlap.
func (*Space) ContainsBody ¶
Test if a rigid body has been added to the space.
func (*Space) ContainsConstraint ¶
func (s *Space) ContainsConstraint(constraint *Constraint) bool
Test if a constraint has been added to the space.
func (*Space) ContainsShape ¶
Test if a collision shape has been added to the space.
func (*Space) CurrentTimeStep ¶
Returns the current (or most recent) time step used with the given space. Useful from callbacks if your time step is not a compile-time global.
func (*Space) Damping ¶
Damping rate expressed as the fraction of velocity bodies retain each second.
A value of 0.9 would mean that each body's velocity will drop 10% per second.
The default value is 1.0, meaning no damping is applied.
This damping value is different than those of cpDampedSpring and cpDampedRotarySpring.
func (*Space) DebugDraw ¶
func (s *Space) DebugDraw(options *SpaceDebugDrawOptions)
DebugDraw draws the space using the debug draw options (which includes callbacks for performing the actual drawing). All options fields are entirely optional (callbacks may be nil, etc).
options.Data is arbitrary user data fed into the callbacks (this is just for a 1:1 mapping of chipmunks API, in Go you can just use a closure and access the data itself not storing it inside options.Data).
func (*Space) EachConstraint ¶
func (s *Space) EachConstraint(space *Space, f func(c *Constraint))
Call f for each shape in the space.
func (*Space) IdleSpeedThreshold ¶
Speed threshold for a body to be considered idle.
The default value of 0 means to let the space guess a good threshold based on gravity.
func (*Space) Iterations ¶
Number of iterations to use in the impulse solver to solve contacts and other constraints.
func (*Space) PointQuery ¶
func (s *Space) PointQuery(point Vect, maxDistance float64, filter ShapeFilter, f SpacePointQueryFunc, data interface{})
Query the space at a point and call f for each shape found.
func (*Space) PointQueryNearest ¶
func (s *Space) PointQueryNearest(point Vect, maxDistance float64, filter ShapeFilter) (shape *Shape, out *PointQueryInfo)
Query the space at a point and return the nearest shape found. Returns NULL if no shapes were found.
func (*Space) ReindexShape ¶
Update the collision detection data for a specific shape in the space.
func (*Space) ReindexShapesForBody ¶
Update the collision detection data for all shapes attached to a body.
func (*Space) ReindexStatic ¶
func (s *Space) ReindexStatic()
Update the collision detection info for the static shapes in the space.
func (*Space) RemoveBody ¶
Remove a rigid body from the simulation.
func (*Space) RemoveConstraint ¶
func (s *Space) RemoveConstraint(constraint *Constraint)
Remove a constraint from the simulation.
func (*Space) RemoveShape ¶
Remove a collision shape from the simulation.
func (*Space) SegmentQuery ¶
func (s *Space) SegmentQuery(start, end Vect, radius float64, filter ShapeFilter, f SpaceSegmentQueryFunc, data interface{})
Perform a directed line segment query (like a raycast) against the space calling f for each shape intersected.
func (*Space) SegmentQueryFirst ¶
func (s *Space) SegmentQueryFirst(start, end Vect, radius float64, filter ShapeFilter) (shape *Shape, out *SegmentQueryInfo)
Perform a directed line segment query (like a raycast) against the space and return the first shape hit. Returns NULL if no shapes were hit.
func (*Space) SetCollisionBias ¶
func (*Space) SetCollisionPersistence ¶
func (*Space) SetCollisionSlop ¶
func (*Space) SetDamping ¶
func (*Space) SetGravity ¶
func (*Space) SetIdleSpeedThreshold ¶
func (*Space) SetIterations ¶
func (*Space) SetSleepTimeThreshold ¶
func (*Space) SetUserData ¶
func (s *Space) SetUserData(i interface{})
func (*Space) ShapeQuery ¶
func (s *Space) ShapeQuery(shape *Shape, f SpaceShapeQueryFunc, data interface{}) bool
Query a space for any shapes overlapping the given shape and call func for each shape found.
func (*Space) SleepTimeThreshold ¶
Time a group of bodies must remain idle in order to fall asleep.
Enabling sleeping also implicitly enables the the contact graph.
The default value of INFINITY disables the sleeping algorithm.
func (*Space) StaticBody ¶
The Space provided static body for a given cpSpace.
This is merely provided for convenience and you are not required to use it.
func (*Space) UseSpatialHash ¶
Switch the space to use a spatial has as it's spatial index.
type SpaceArbiterApplyImpulseFunc ¶
type SpaceArbiterApplyImpulseFunc func(arb *Arbiter)
type SpaceBBQueryFunc ¶
type SpaceBBQueryFunc func(shape *Shape, data interface{})
Rectangle Query callback function type.
type SpaceDebugDrawCircleImpl ¶
type SpaceDebugDrawCircleImpl func(pos Vect, angle, radius float64, outlineColor, fillColor SpaceDebugColor, data interface{})
type SpaceDebugDrawColorForShapeImpl ¶
type SpaceDebugDrawColorForShapeImpl func(shape *Shape, data interface{}) SpaceDebugColor
type SpaceDebugDrawDotImpl ¶
type SpaceDebugDrawDotImpl func(size float64, pos Vect, color SpaceDebugColor, data interface{})
type SpaceDebugDrawFatSegmentImpl ¶
type SpaceDebugDrawFatSegmentImpl func(a, b Vect, radius float64, outlineColor, fillColor SpaceDebugColor, data interface{})
type SpaceDebugDrawFlags ¶
type SpaceDebugDrawFlags int
const ( SPACE_DEBUG_DRAW_SHAPES SpaceDebugDrawFlags = C.CP_SPACE_DEBUG_DRAW_SHAPES SPACE_DEBUG_DRAW_CONSTRAINTS SpaceDebugDrawFlags = C.CP_SPACE_DEBUG_DRAW_CONSTRAINTS SPACE_DEBUG_DRAW_COLLISION_POINTS SpaceDebugDrawFlags = C.CP_SPACE_DEBUG_DRAW_COLLISION_POINTS )
type SpaceDebugDrawOptions ¶
type SpaceDebugDrawOptions struct { DrawCircle SpaceDebugDrawCircleImpl DrawSegment SpaceDebugDrawSegmentImpl DrawFatSegment SpaceDebugDrawFatSegmentImpl DrawPolygon SpaceDebugDrawPolygonImpl DrawDot SpaceDebugDrawDotImpl ColorForShape SpaceDebugDrawColorForShapeImpl Flags SpaceDebugDrawFlags ShapeOutlineColor SpaceDebugColor ConstraintColor SpaceDebugColor CollisionPointColor SpaceDebugColor Data interface{} }
type SpaceDebugDrawPolygonImpl ¶
type SpaceDebugDrawPolygonImpl func(verts []Vect, radius float64, outlineColor, fillColor SpaceDebugColor, data interface{})
type SpaceDebugDrawSegmentImpl ¶
type SpaceDebugDrawSegmentImpl func(a, b Vect, color SpaceDebugColor, data interface{})
type SpacePointQueryFunc ¶
type SpacePointQueryFunc func(shape *Shape, point Vect, distance float64, gradient Vect, data interface{})
Nearest point query callback function type.
type SpaceSegmentQueryFunc ¶
Nearest point query callback function type.
type SpaceShapeQueryFunc ¶
type SpaceShapeQueryFunc func(shape *Shape, points *ContactPointSet, data interface{})
Shape query callback function type.
type Transform ¶
Column major affine transform.
func TransformAxialScale ¶
func TransformBoneScale ¶
func TransformNew ¶
Construct a new transform matrix.
(a, b) is the x basis vector.
(c, d) is the y basis vector.
(tx, ty) is the translation.
func TransformNewTranspose ¶
Construct a new transform matrix in transposed order.
func TransformOrtho ¶
func TransformRigid ¶
Create a rigid transformation matrix. (translation + rotation)
func TransformTranslate ¶
Create a translation matrix.
func (Transform) RigidInverse ¶
Fast inverse of a rigid transformation matrix.
func (Transform) WrapInverse ¶
type Vect ¶
Chipmunk's 2D vector type.
func CentroidForPoly ¶
Calculate the natural centroid of a polygon.
func ClosetPointOnSegment ¶
Returns the closest point on the line segment ab, to the point p.
func Vlerpconst ¶
Linearly interpolate between v1 towards v2 by distance d.
func Vrotate ¶
Uses complex number multiplication to rotate v1 by v2. Scaling will occur if v1 is not a unit vector.
func Vslerpconst ¶
Spherical linearly interpolate between v1 towards v2 by no more than angle a radians
Source Files ¶
- arbiter.go
- bb.go
- body.go
- chipmunk.go
- constraint.go
- dampedrotaryspring.go
- dampedspring.go
- gearjoint.go
- groovejoint.go
- pinjoint.go
- pivotjoint.go
- polyshape.go
- ratchetjoint.go
- rotarylimitjoint.go
- shape.go
- simplemotor.go
- slicejoint.go
- space.go
- spatialindex.go
- transform.go
- types_amd64.go
- typescompat.go
- unsafe.go
- vect.go