Beispiel #1
0
// c converts BB to C.cpBB.
func (b BB) c() C.cpBB {
	return C.cpBB{
		l: C.cpFloat(b.l),
		b: C.cpFloat(b.b),
		r: C.cpFloat(b.r),
		t: C.cpFloat(b.t)}
}
Beispiel #2
0
// DampedSpringNew creates a new damped spring.
func DampedSpringNew(a, b Body, anchr1, anchr2 Vect,
	restLength, stiffness, damping float64) DampedSpring {

	c := C.cpDampedSpringNew(a.c(), b.c(), anchr1.c(), anchr2.c(), C.cpFloat(restLength),
		C.cpFloat(stiffness), C.cpFloat(damping))

	return DampedSpring{cpConstraintBaseNew(c)}
}
// DampedRotarySpringNew creates a new damped rotary spring.
func DampedRotarySpringNew(a, b Body, restAngle, stiffness, damping float64) DampedRotarySpring {
	c := C.cpDampedRotarySpringNew(
		a.c(),
		b.c(),
		C.cpFloat(restAngle),
		C.cpFloat(stiffness),
		C.cpFloat(damping))

	return DampedRotarySpring{cpconstraint_new(c)}
}
Beispiel #4
0
func MomentForPoly(mass float64, verts []Vect, offset Vect) float64 {
	cpverts := make([]C.cpVect, 0)
	for _, vert := range verts {
		cpverts = append(cpverts, vert.CPVect)
	}
	return float64(C.cpMomentForPoly(C.cpFloat(mass), C.int(len(verts)), &cpverts[0], offset.CPVect))
}
Beispiel #5
0
// ConvexHull calculates the convex hull of a given set of points.
// Returns the points and index of the first vertex in the hull came from the input.
// Tolerance is the allowed amount to shrink the hull when simplifying it.
// A tolerance of 0.0 creates an exact hull.
func ConvexHull(verts []Vect, tolerance float64) ([]Vect, int) {
	result := make([]Vect, len(verts))
	var first C.int
	v := (*C.cpVect)(unsafe.Pointer(&verts[0]))
	r := (*C.cpVect)(unsafe.Pointer(&result[0]))
	num := int(C.cpConvexHull(C.int(len(verts)), v, r, &first, C.cpFloat(tolerance)))
	final := make([]Vect, num, num)
	copy(final, result[:num])
	return final, int(first)
}
Beispiel #6
0
func (v *Vect) WrapToBounds(ax float64, ay float64, bx float64, by float64) {
	x, y := float64(v.CPVect.x), float64(v.CPVect.y)
	w, h := bx-ax, by-ay

	if x < ax {
		x += w
	} else if x >= bx {
		x -= w
	}

	if y < ay {
		y += h
	} else if y >= by {
		y -= h
	}

	v.CPVect.x = C.cpFloat(x)
	v.CPVect.y = C.cpFloat(y)
}
Beispiel #7
0
// SetContactPoints replaces the contact point set for an arbiter.
// This can be a very powerful feature, but use it with caution!
func (a Arbiter) SetContactPoints(cp []ContactPoint) {
	if len(cp) > C.CP_MAX_CONTACTS_PER_ARBITER {
		cp = cp[:C.CP_MAX_CONTACTS_PER_ARBITER]
	}
	set := &C.cpContactPointSet{count: C.int(len(cp))}
	for i := range cp {
		set.points[i].point = cp[i].Point.c()
		set.points[i].normal = cp[i].Normal.c()
		set.points[i].dist = C.cpFloat(cp[i].Dist)
	}
	C.cpArbiterSetContactPointSet(a.c(), set)
}
Beispiel #8
0
// NearestPointQuery queries the space at a point and calls a callback function for each shape found.
func (s *Space) NearestPointQuery(
	point Vect,
	maxDistance float64,
	layers Layers,
	group Group,
	f NearestPointQuery) {
	C.space_nearest_point_query(
		s.c(),
		point.c(),
		C.cpFloat(maxDistance),
		layers.c(),
		group.c(),
		Pointer(&f))
}
Beispiel #9
0
func (b *Body) SetVelocityLimit(limit float64) {
	b.CPBody.v_limit = C.cpFloat(limit)
}
Beispiel #10
0
func NewBody(mass float64, moment float64) *Body {
	var cpbody *C.cpBody = C.cpBodyNew(C.cpFloat(mass), C.cpFloat(moment))
	body := Body{cpbody}
	bodyLookup[cpbody] = &body
	return &body
}
Beispiel #11
0
func (b *Body) SetAngle(angle float64) {
	C.cpBodySetAngle(b.CPBody, C.cpFloat(angle))
}
Beispiel #12
0
// Step makes the space step forward in time by dt seconds.
func (s *Space) Step(dt float64) {
	C.cpSpaceStep(s.c(), C.cpFloat(dt))
}
Beispiel #13
0
// UseSpatialHash switches the space to use a spatial has as it's spatial index.
func (s *Space) UseSpatialHash(dim float64, count int) {
	C.cpSpaceUseSpatialHash(s.c(), C.cpFloat(dim), C.int(count))
}
Beispiel #14
0
func (s *Shape) SetFriction(friction float64) {
	s.CPShape.u = C.cpFloat(friction)
}
Beispiel #15
0
// SetSleepTimeThreshold sets the 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 math.Inf(1) disables the sleeping algorithm.
func (s *Space) SetSleepTimeThreshold(t float64) {
	C.cpSpaceSetSleepTimeThreshold(s.c(), C.cpFloat(t))
}
Beispiel #16
0
func NewBoundingBox(l float64, b float64, r float64, t float64) *BoundingBox {
	cpbb := C.cpBBNew(C.cpFloat(l), C.cpFloat(b), C.cpFloat(r), C.cpFloat(t))
	boundingbox := BoundingBox{cpbb}
	return &boundingbox
}
Beispiel #17
0
// SetRestLength sets the length the spring wants to contract or expand to.
func (c DampedSpring) SetRestLength(restLength float64) {
	C.cpDampedSpringSetRestLength(c.c(), C.cpFloat(restLength))
}
Beispiel #18
0
// SetMaxBias sets the maximum rate (speed) that a joint can be corrected at (defaults to infinity).
func (c constraintBase) SetMaxBias(b float64) {
	C.cpConstraintSetMaxBias(c.c(), C.cpFloat(b))
}
Beispiel #19
0
func (b *Body) SetAngularRotation(omega float64) {
	b.CPBody.w = C.cpFloat(omega)
}
// SetRestAngle sets the angular offset in radians the spring attempts to keep between the two bodies.
func (c DampedRotarySpring) SetRestAngle(restAngle float64) {
	C.cpDampedRotarySpringSetRestAngle(c.c(), C.cpFloat(restAngle))
}
Beispiel #21
0
// SetFriction sets coefficient of friction.
func (s shapeBase) SetFriction(f float64) {
	C.cpShapeSetFriction(s.c(), C.cpFloat(f))
}
Beispiel #22
0
// SetElasticity sets coefficient of restitution.
func (s shapeBase) SetElasticity(e float64) {
	C.cpShapeSetElasticity(s.c(), C.cpFloat(e))
}
Beispiel #23
0
func (b *Body) MultiplyAngularRotation(mult float64) {
	b.CPBody.w *= C.cpFloat(mult)
}
Beispiel #24
0
// SetCollisionBias sets the speed of 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 (s *Space) SetCollisionBias(b float64) {
	C.cpSpaceSetCollisionBias(s.c(), C.cpFloat(b))
}
Beispiel #25
0
// SetMaxForce sets the maximum force this constraint is allowed to use (defalts to infinity).
// This allows joints to be pulled apart if too much force is applied to them.
// It also allows you to use constraints as force or friction generators for controlling bodies.
func (c constraintBase) SetMaxForce(f float64) {
	C.cpConstraintSetMaxForce(c.c(), C.cpFloat(f))
}
Beispiel #26
0
// SetCollisionSlop sets 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 (s *Space) SetCollisionSlop(sl float64) {
	C.cpSpaceSetCollisionSlop(s.c(), C.cpFloat(sl))
}
Beispiel #27
0
// SetDamping sets the amount of viscous damping to apply.
func (c DampedSpring) SetDamping(damping float64) {
	C.cpDampedSpringSetDamping(c.c(), C.cpFloat(damping))
}
Beispiel #28
0
// SetDamping sets the 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.
func (s *Space) SetDamping(d float64) {
	C.cpSpaceSetDamping(s.c(), C.cpFloat(d))
}
Beispiel #29
0
// SetStiffness sets the young's modulus of the spring.
func (c DampedSpring) SetStiffness(stiffness float64) {
	C.cpDampedSpringSetStiffness(c.c(), C.cpFloat(stiffness))
}
Beispiel #30
0
// SetIdleSpeedThreshold sets the speed threshold for a body to be considered idle.
// The default value of 0.0 means to let the space guess a good threshold based on gravity.
func (s *Space) SetIdleSpeedThreshold(t float64) {
	C.cpSpaceSetIdleSpeedThreshold(s.c(), C.cpFloat(t))
}