-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdraw.go
More file actions
147 lines (133 loc) · 4.95 KB
/
draw.go
File metadata and controls
147 lines (133 loc) · 4.95 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package b2
import (
"slices"
"unsafe"
)
type DrawPolygon func(vertices []Vec2, color HexColor)
type DrawSolidPolygon func(transform Transform, vertices []Vec2, radius float32, color HexColor)
type DrawCircle func(center Vec2, radius float32, color HexColor)
type DrawSolidCircle func(transform Transform, radius float32, color HexColor)
type DrawSolidCapsule func(p1 Vec2, p2 Vec2, radius float32, color HexColor)
type DrawSegment func(p1 Vec2, p2 Vec2, color HexColor)
type DrawTransform func(transform Transform)
type DrawPoint func(p Vec2, size float32, color HexColor)
type DrawString func(p Vec2, s string, color HexColor)
type DebugDraw struct {
DrawPolygon DrawPolygon
DrawSolidPolygon DrawSolidPolygon
DrawCircle DrawCircle
DrawSolidCircle DrawSolidCircle
DrawSolidCapsule DrawSolidCapsule
DrawSegment DrawSegment
DrawTransform DrawTransform
DrawPoint DrawPoint
DrawString DrawString
DrawingBounds AABB
UseDrawingBounds bool
DrawJoints bool
DrawShapes bool
DrawJointExtras bool
DrawBounds bool
DrawMass bool
DrawBodyNames bool
DrawContacts bool
DrawGraphColors bool
DrawContactNormals bool
DrawContactImpulses bool
DrawContactFeatures bool
DrawFrictionImpulses bool
DrawIslands bool
}
func (b World) Draw(draw DebugDraw) {
// move the DebugDraw object temporarily onto the heap
context := theStack.RegisterObject(&draw)
defer theStack.ForgetObject(context)
var dd b2DebugDraw
dd.DrawPolygonFcn = __ccgo_fp(cbDrawPolygon)
dd.DrawSolidPolygonFcn = __ccgo_fp(cbDrawSolidPolygon)
dd.DrawCircleFcn = __ccgo_fp(cbDrawCircle)
dd.DrawSolidCircleFcn = __ccgo_fp(cbDrawSolidCircle)
dd.DrawSolidCapsuleFcn = __ccgo_fp(cbDrawSolidCapsule)
dd.DrawSegmentFcn = __ccgo_fp(cbDrawSegment)
dd.DrawTransformFcn = __ccgo_fp(cbDrawTransform)
dd.DrawPointFcn = __ccgo_fp(cbDrawPoint)
dd.DrawStringFcn = __ccgo_fp(cbDrawString)
dd.DrawingBounds = draw.DrawingBounds
dd.UseDrawingBounds = boolUint8(draw.UseDrawingBounds)
dd.DrawShapes = boolUint8(draw.DrawShapes)
dd.DrawJoints = boolUint8(draw.DrawJoints)
dd.DrawJointExtras = boolUint8(draw.DrawJointExtras)
dd.DrawBounds = boolUint8(draw.DrawBounds)
dd.DrawMass = boolUint8(draw.DrawMass)
dd.DrawBodyNames = boolUint8(draw.DrawBodyNames)
dd.DrawContacts = boolUint8(draw.DrawContacts)
dd.DrawGraphColors = boolUint8(draw.DrawGraphColors)
dd.DrawContactNormals = boolUint8(draw.DrawContactNormals)
dd.DrawContactImpulses = boolUint8(draw.DrawContactImpulses)
dd.DrawContactFeatures = boolUint8(draw.DrawContactFeatures)
dd.DrawFrictionImpulses = boolUint8(draw.DrawFrictionImpulses)
dd.DrawIslands = boolUint8(draw.DrawIslands)
dd.Context = context
ddStack := copyToStack(theStack, dd)
defer ddStack.Free()
b2World_Draw(theStack, b.Id, ddStack.Addr)
}
func cbDrawPolygon(tls *_Stack, vertices uintptr, vertexCount int32, color HexColor, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawPolygon != nil {
vertices := toSlice[Vec2](vertices, vertexCount)
ctx.DrawPolygon(vertices, color)
}
}
func cbDrawSolidPolygon(tls *_Stack, transform Transform, vertices uintptr, vertexCount int32, radius float32, color HexColor, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawSolidPolygon != nil {
vertices := toSlice[Vec2](vertices, vertexCount)
ctx.DrawSolidPolygon(transform, vertices, radius, color)
}
}
func cbDrawCircle(tls *_Stack, center Vec2, radius float32, color HexColor, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawCircle != nil {
ctx.DrawCircle(center, radius, color)
}
}
func cbDrawSolidCircle(tls *_Stack, transform Transform, radius float32, color HexColor, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawSolidCircle != nil {
ctx.DrawSolidCircle(transform, radius, color)
}
}
func cbDrawSolidCapsule(tls *_Stack, p1 Vec2, p2 Vec2, radius float32, color HexColor, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawSolidCapsule != nil {
ctx.DrawSolidCapsule(p1, p2, radius, color)
}
}
func cbDrawSegment(tls *_Stack, p1 Vec2, p2 Vec2, color HexColor, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawSegment != nil {
ctx.DrawSegment(p1, p2, color)
}
}
func cbDrawTransform(tls *_Stack, transform Transform, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawTransform != nil {
ctx.DrawTransform(transform)
}
}
func cbDrawPoint(tls *_Stack, p Vec2, size float32, color HexColor, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawPoint != nil {
ctx.DrawPoint(p, size, color)
}
}
func cbDrawString(tls *_Stack, p Vec2, s uintptr, color HexColor, context uintptr) {
ctx := tls.GetObject(context).(*DebugDraw)
if ctx.DrawString != nil {
ctx.DrawString(p, toString(s), color)
}
}
func toSlice[T any](ptr uintptr, count int32) []T {
return slices.Clone(unsafe.Slice((*T)(unsafe.Pointer(ptr)), count))
}