-
Notifications
You must be signed in to change notification settings - Fork 33
/
constraint.go
68 lines (55 loc) · 1.46 KB
/
constraint.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
package chipmunk
import "github.com/vova616/chipmunk/vect"
const (
errorBias = 0.00179701029991443 //cpfpow(1.0f - 0.1f, 60.0f)
)
type ConstraintCallback interface {
CollisionPreSolve(constraint Constraint)
CollisionPostSolve(constraint Constraint)
}
type Constraint interface {
Constraint() *BasicConstraint
PreSolve()
PostSolve()
PreStep(dt vect.Float)
ApplyCachedImpulse(dt_coef vect.Float)
ApplyImpulse()
Impulse() vect.Float
}
type BasicConstraint struct {
BodyA, BodyB *Body
space *Space
MaxForce vect.Float
ErrorBias vect.Float
MaxBias vect.Float
CallbackHandler ConstraintCallback
UserData Data
}
func NewConstraint(a, b *Body) BasicConstraint {
return BasicConstraint{BodyA: a, BodyB: b, MaxForce: Inf, MaxBias: Inf, ErrorBias: errorBias}
}
func (this *BasicConstraint) Constraint() *BasicConstraint {
return this
}
func (this *BasicConstraint) PreStep(dt vect.Float) {
panic("empty constraint")
}
func (this *BasicConstraint) ApplyCachedImpulse(dt_coef vect.Float) {
panic("empty constraint")
}
func (this *BasicConstraint) ApplyImpulse() {
panic("empty constraint")
}
func (this *BasicConstraint) Impulse() vect.Float {
panic("empty constraint")
}
func (this *BasicConstraint) PreSolve() {
if this.CallbackHandler != nil {
this.CallbackHandler.CollisionPreSolve(this)
}
}
func (this *BasicConstraint) PostSolve() {
if this.CallbackHandler != nil {
this.CallbackHandler.CollisionPostSolve(this)
}
}