-
Notifications
You must be signed in to change notification settings - Fork 33
/
shape.go
94 lines (73 loc) · 1.94 KB
/
shape.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package chipmunk
import (
"github.com/vova616/chipmunk/transform"
"github.com/vova616/chipmunk/vect"
"math"
//"fmt"
)
const (
RadianConst = math.Pi / 180
DegreeConst = 180 / math.Pi
)
type Group int
type Layer int
type Shape struct {
DefaultHash
ShapeClass
/// The rigid body this collision shape is attached to.
Body *Body
/// The current bounding box of the shape.
BB AABB
/// Sensor flag.
/// Sensor shapes call collision callbacks but don't produce collisions.
IsSensor bool
/// Coefficient of restitution. (elasticity)
e vect.Float
/// Coefficient of friction.
u vect.Float
/// Surface velocity used when solving for friction.
Surface_v vect.Vect
/// User definable data pointer.
/// Generally this points to your the game object class so you can access it
/// when given a cpShape reference in a callback.
UserData interface{}
/// Collision type of this shape used when picking collision handlers.
//collision_type CollisionType
/// Group of this shape. Shapes in the same group don't collide.
Group Group
// Layer bitmask for this shape. Shapes only collide if the bitwise and of their layers is non-zero.
Layer Layer
space *Space
velocityIndexed bool
}
func newShape() *Shape {
return &Shape{velocityIndexed: true, e: 0.5, u: 0.5, Layer: -1}
}
func (shape *Shape) Velocity() (vect.Vect, bool) {
return shape.Body.v, shape.velocityIndexed
}
func (shape *Shape) SetFriction(friction vect.Float) {
shape.u = friction
}
func (shape *Shape) SetElasticity(e vect.Float) {
shape.e = e
}
func (shape *Shape) Shape() *Shape {
return shape
}
func (shape *Shape) AABB() AABB {
return shape.BB
}
func (shape *Shape) Clone() *Shape {
clone := *shape
cc := &clone
cc.space = nil
cc.DefaultHash.Reset()
cc.Body = nil
cc.ShapeClass = cc.ShapeClass.Clone(cc)
return cc
}
func (shape *Shape) Update() {
//fmt.Println("Rot", shape.Body.rot)
shape.BB = shape.ShapeClass.update(transform.NewTransform(shape.Body.p, shape.Body.a))
}