-
Notifications
You must be signed in to change notification settings - Fork 1
/
m3drawing.go
361 lines (317 loc) · 8.65 KB
/
m3drawing.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package m3gl
import (
"fmt"
"github.com/freddy33/qsm-go/m3util"
"github.com/freddy33/qsm-go/model/m3point"
"github.com/freddy33/qsm-go/model/m3space"
)
const (
noDimmer = 1.0
defaultGreyDimmer = 0.7
defaultOldEventDimmer = 0.3
)
type ObjectType uint8
const (
AxeX ObjectType = iota
AxeY
AxeZ
NodeEmpty
NodeActive
Connection00
)
type SpaceDrawingElement interface {
// Key of the drawing element to point to the OpenGL buffer to render
Key() ObjectType
// The translation point to apply to the OpenGL model, since all the above are drawn at the origin
Pos() *m3point.Point
// Return the obj_color int for the shader program
Color(blinkValue float64) int32
// Return the obj_dimmer int for the shader program
Dimmer(blinkValue float64) float32
// Display flag
Display(filter SpaceDrawingFilter) bool
}
type SpaceDrawingFilter struct {
// Display grey empty nodes or not
DisplayEmptyNodes bool
// Display grey empty connections or not
DisplayEmptyConnections bool
// The events of certain colors to display. This is a mask.
EventColorMask uint8
// The outgrowth events with how many colors to display.
EventOutgrowthManyColorsThreshold uint8
// The space active Threshold
ActiveThreshold m3space.DistAndTime
}
func (filter *SpaceDrawingFilter) DisplaySettings() {
fmt.Println("========= SpaceTime Settings =========")
fmt.Println("Empty Nodes [N]", filter.DisplayEmptyNodes, ", Empty Connections [C]", filter.DisplayEmptyConnections)
fmt.Println("Event Outgrowth Threshold [UP,DOWN]", filter.ActiveThreshold, ", Event Outgrowth Many Colors Threshold [U,I]", filter.EventOutgrowthManyColorsThreshold)
fmt.Println("Event Colors Mask [1,2,3,4]", filter.EventColorMask)
}
func (filter *SpaceDrawingFilter) EventOutgrowthColorsIncrease() {
filter.EventOutgrowthManyColorsThreshold++
if filter.EventOutgrowthManyColorsThreshold > 4 {
filter.EventOutgrowthManyColorsThreshold = 4
}
}
func (filter *SpaceDrawingFilter) EventOutgrowthColorsDecrease() {
filter.EventOutgrowthManyColorsThreshold--
if filter.EventOutgrowthManyColorsThreshold < 0 {
filter.EventOutgrowthManyColorsThreshold = 0
}
}
func (filter *SpaceDrawingFilter) ColorMaskSwitch(color m3space.EventColor) {
filter.EventColorMask ^= uint8(color)
}
type SpaceDrawingColor struct {
// Bitwise flag of colors. Bits 0->red, 1->green, 2->blue, 3->yellow. If 0 then it means grey
objColors uint8
// The dim yes/no flag ratio to apply to each color set in above bit mask
dimColors uint8
}
type NodeDrawingElement struct {
objectType ObjectType
sdc SpaceDrawingColor
node m3space.SpaceTimeNodeIfc
}
type ConnectionDrawingElement struct {
objectType ObjectType
sdc SpaceDrawingColor
pos *m3point.Point
}
type AxeDrawingElement struct {
objectType ObjectType
max m3point.CInt
neg bool
}
func (ot ObjectType) IsAxe() bool {
return int8(ot) >= 0 && int8(ot) <= int8(AxeZ)
}
func (ot ObjectType) IsNode() bool {
return int8(ot) >= int8(NodeEmpty) && int8(ot) <= int8(NodeActive)
}
func (ot ObjectType) IsConnection() bool {
return int8(ot) >= int8(Connection00)
}
func (sdc *SpaceDrawingColor) hasColor(c m3space.EventColor) bool {
return sdc.objColors&uint8(c) != uint8(0)
}
func (sdc *SpaceDrawingColor) hasDimming(c m3space.EventColor) bool {
return sdc.dimColors&uint8(c) != uint8(0)
}
func (sdc *SpaceDrawingColor) howManyColors() uint8 {
return m3util.CountTheOnes(sdc.objColors)
}
func (sdc *SpaceDrawingColor) singleColor() m3space.EventColor {
if sdc.objColors == 0 {
return 0
}
for _, c := range m3space.AllColors {
if sdc.hasColor(c) {
return c
}
}
return 0
}
func (sdc *SpaceDrawingColor) secondColor() m3space.EventColor {
if sdc.objColors == 0 {
return 0
}
foundOne := false
for _, c := range m3space.AllColors {
if sdc.hasColor(c) {
if foundOne {
return c
}
foundOne = true
}
}
return 0
}
func (sdc *SpaceDrawingColor) color(blinkValue float64) int32 {
colorSwitch := uint8(blinkValue)
color := m3space.EventColor(1 << colorSwitch)
switch sdc.howManyColors() {
case 0:
return 0
case 1:
return int32(sdc.singleColor())
case 2:
if int(colorSwitch)%2 == 0 {
return int32(sdc.singleColor())
} else {
return int32(sdc.secondColor())
}
case 3:
if sdc.hasColor(color) {
return int32(color)
} else {
return 0
}
case 4:
if sdc.hasColor(color) {
return int32(color)
} else {
return 0
}
}
return 0
}
func (sdc *SpaceDrawingColor) dimmer(blinkValue float64) float32 {
colorSwitch := uint8(blinkValue)
color := m3space.EventColor(1 << colorSwitch)
switch sdc.howManyColors() {
case 0:
return defaultGreyDimmer
case 1:
if sdc.hasDimming(sdc.singleColor()) {
return defaultOldEventDimmer
}
return noDimmer
case 2:
if int(colorSwitch)%2 == 0 {
if sdc.hasDimming(sdc.singleColor()) {
return defaultOldEventDimmer
}
return noDimmer
} else {
if sdc.hasDimming(sdc.secondColor()) {
return defaultOldEventDimmer
}
return noDimmer
}
case 3:
if sdc.hasColor(color) {
if sdc.hasDimming(color) {
return defaultOldEventDimmer
}
return noDimmer
} else {
return defaultGreyDimmer
}
case 4:
if sdc.hasColor(color) {
if sdc.hasDimming(color) {
return defaultOldEventDimmer
}
return noDimmer
} else {
return defaultGreyDimmer
}
}
return defaultGreyDimmer
}
func MakeNodeDrawingElement(node m3space.SpaceTimeNodeIfc) *NodeDrawingElement {
// Collect all the colors of event outgrowth of this node. Dim if not latest
sdc := SpaceDrawingColor{}
sdc.objColors = node.GetColorMask()
// TODO: Another threshold for dim?
//if eo.state != EventOutgrowthLatest && !eo.IsRoot() {
// sdc.dimColors |= 1 << uint8(eo.event.color)
//}
if sdc.objColors != uint8(0) {
return &NodeDrawingElement{
NodeActive, sdc, node,
}
} else {
return &NodeDrawingElement{
NodeEmpty, sdc, node,
}
}
}
func MakeConnectionDrawingElement(node m3space.SpaceTimeNodeIfc, point m3point.Point, connId m3point.ConnectionId) *ConnectionDrawingElement {
// Collect all the colors of latest event outgrowth of a node coming from the other node
sdc := SpaceDrawingColor{}
// Take the color of the source. TODO: Not true should be & on src and target
sdc.objColors = node.GetColorMask()
return &ConnectionDrawingElement{getConnectionObjectType(connId), sdc, &point}
}
func getConnectionObjectType(cdId m3point.ConnectionId) ObjectType {
if cdId > 0 {
return ObjectType(m3point.ConnectionId(Connection00) + cdId*2)
} else {
return ObjectType(m3point.ConnectionId(Connection00) + 1 - cdId*2)
}
}
// NodeDrawingElement functions
func (n NodeDrawingElement) Key() ObjectType {
return n.objectType
}
func (n NodeDrawingElement) Display(filter SpaceDrawingFilter) bool {
if n.objectType == NodeActive {
if n.node.HasRoot() {
return true
}
return n.sdc.objColors&filter.EventColorMask != 0 && n.sdc.howManyColors() >= filter.EventOutgrowthManyColorsThreshold
}
return filter.DisplayEmptyNodes
}
func (n NodeDrawingElement) Color(blinkValue float64) int32 {
return n.sdc.color(blinkValue)
}
func (n NodeDrawingElement) Dimmer(blinkValue float64) float32 {
return n.sdc.dimmer(blinkValue)
}
func (n NodeDrawingElement) Pos() *m3point.Point {
p, err := n.node.GetPoint()
if err != nil {
Log.Error(err)
return nil
}
return p
}
// ConnectionDrawingElement functions
func (c ConnectionDrawingElement) Key() ObjectType {
return c.objectType
}
func (c ConnectionDrawingElement) Display(filter SpaceDrawingFilter) bool {
if c.sdc.objColors&filter.EventColorMask != uint8(0) && c.sdc.howManyColors() >= filter.EventOutgrowthManyColorsThreshold {
return true
}
return filter.DisplayEmptyConnections
}
func (c ConnectionDrawingElement) Color(blinkValue float64) int32 {
return c.sdc.color(blinkValue)
}
func (c ConnectionDrawingElement) Dimmer(blinkValue float64) float32 {
dimmer := c.sdc.dimmer(blinkValue)
return dimmer
}
func (c ConnectionDrawingElement) Pos() *m3point.Point {
return c.pos
}
// AxeDrawingElement functions
func (a AxeDrawingElement) Key() ObjectType {
return a.objectType
}
func (a AxeDrawingElement) Display(filter SpaceDrawingFilter) bool {
return true
}
func (a AxeDrawingElement) Color(blinkValue float64) int32 {
switch a.objectType {
case AxeX:
return int32(m3space.RedEvent)
case AxeY:
return int32(m3space.GreenEvent)
case AxeZ:
return int32(m3space.BlueEvent)
}
return 0
}
func (a AxeDrawingElement) Dimmer(blinkValue float64) float32 {
return 1.0
}
func (a AxeDrawingElement) Pos() *m3point.Point {
if a.neg {
switch a.objectType {
case AxeX:
return &m3point.Point{-a.max, 0, 0}
case AxeY:
return &m3point.Point{0, -a.max, 0}
case AxeZ:
return &m3point.Point{0, 0, -a.max}
}
}
return &m3point.Origin
}