-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinjoint.go
70 lines (59 loc) · 1.75 KB
/
pinjoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2014 The Azul3D Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cp
/*
#include "chipmunk/include/chipmunk/chipmunk.h"
*/
import "C"
import (
"runtime"
"unsafe"
)
// Check if a constraint is a pin joint.
func (c *Constraint) IsPinJoint() bool {
return goBool(C.cpConstraintIsPinJoint(c.c))
}
// Allocate and initialize a pin joint.
func PinJointNew(a, b *Body, anchorA, anchorB Vect) *Constraint {
c := &Constraint{
aBodyRef: a,
bBodyRef: b,
c: C.cpPinJointNew(
a.c,
b.c,
anchorA.c(),
anchorB.c(),
),
}
if c.c == nil {
return nil
}
C.cpConstraintSetUserData(c.c, C.cpDataPointer(unsafe.Pointer(c)))
runtime.SetFinalizer(c, finalizeConstraint)
return c
}
// Get the location of the first anchor relative to the first body.
func (c *Constraint) PinJointAnchorA() Vect {
return goVect(C.cpPinJointGetAnchorA(c.c))
}
// Set the location of the first anchor relative to the first body.
func (c *Constraint) PinJointSetAnchorA(anchorA Vect) {
C.cpPinJointSetAnchorA(c.c, anchorA.c())
}
// Get the location of the second anchor relative to the second body.
func (c *Constraint) PinJointAnchorB() Vect {
return goVect(C.cpPinJointGetAnchorB(c.c))
}
// Set the location of the second anchor relative to the second body.
func (c *Constraint) PinJointSetAnchorB(anchorB Vect) {
C.cpPinJointSetAnchorB(c.c, anchorB.c())
}
// Get the distance the joint will maintain between the two anchors.
func (c *Constraint) PinJointDist() float64 {
return float64(C.cpPinJointGetDist(c.c))
}
// Set the distance the joint will maintain between the two anchors.
func (c *Constraint) PinJointSetDist(dist float64) {
C.cpPinJointSetDist(c.c, C.cpFloat(dist))
}