-
Notifications
You must be signed in to change notification settings - Fork 0
/
Draw.h
972 lines (782 loc) · 34.6 KB
/
Draw.h
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
static void DrawSkeletonBones(RenderGroup *rg, BoneArray bones, m4x4Array boneStates, Quaternion orientation, v3 pos, f32 scale)
{
m4x4 mat = InterpolationDataToMatrix(pos, orientation, scale);
for(u32 i = 0; i < bones.amount; i++)
{
m4x4 bindShapeMat = InvOrId(bones[i].inverseBindShapeMatrix);
v3 p1 = (mat * boneStates[i] * bindShapeMat) * V3(0, 0, 0);
v3 p2 = (mat * boneStates[i] * bindShapeMat) * V3(0, 1, 0);
PushLine(rg, p1, p2);
}
}
static void DrawNumberOnTile(RenderGroup *rg, u32 number, v3i pos, v4 color = V4(1.0f, 0.2f, 0.3f, 0.6f))
{
f32 border = 0.05f;
f32 dim = 1.0f;
f32 dimWoBorder = dim - 2.0f * border;
f32 curZ = - (f32)number * 0.0004f;
PushRectangle(rg, V3(pos) - 0.5f * V3(dim, dim, curZ - 0.0001f), V3(dim, 0, 0), V3(0, dim, 0), V4(1, 1, 1, 1));
PushRectangle(rg, V3(pos) - 0.5f * V3(dimWoBorder, dimWoBorder, curZ - 0.0002f), V3(dimWoBorder, 0, 0), V3(0, dimWoBorder, 0), color);
f32 halfDim = dimWoBorder / 2.0f;
if (number < 10)
{
v3 p1 = V3(pos) - 0.5f * V3(halfDim, halfDim, curZ - 0.0003f);
v3 p2 = p1 + V3(halfDim, 0, 0);
v3 p3 = p1 + V3(0, halfDim, 0);
v3 p4 = p1 + V3(halfDim, halfDim, 0);
CharData data = globalFont.charData['0' + number];
PushTexturedQuad(rg, p1, p2, p3, p4, globalFont.textureId, true, data.minUV, data.maxUV);
}
else if (number < 100)
{
u32 first = number / 10;
u32 second = number - first * 10;
{
v3 p1 = V3(pos) - 0.5f * V3(dimWoBorder, halfDim, curZ - 0.0003f);
v3 p2 = p1 + V3(halfDim, 0, 0);
v3 p3 = p1 + V3(0, halfDim, 0);
v3 p4 = p1 + V3(halfDim, halfDim, 0);
CharData data = globalFont.charData['0' + first];
PushTexturedQuad(rg, p1, p2, p3, p4, globalFont.textureId, true, data.minUV, data.maxUV);
}
{
v3 p1 = V3(pos) - 0.5f * V3(0, halfDim, curZ - 0.0003f);
v3 p2 = p1 + V3(halfDim, 0, 0);
v3 p3 = p1 + V3(0, halfDim, 0);
v3 p4 = p1 + V3(halfDim, halfDim, 0);
CharData data = globalFont.charData['0' + second];
PushTexturedQuad(rg, p1, p2, p3, p4, globalFont.textureId, true, data.minUV, data.maxUV);
}
}
}
static void RenderPathCreator(RenderGroup *rg, EntityManager *entityManager, ExecuteData *exe, PathCreator *pathCreator, AssetHandler *assetHandler, Input input)
{
Camera camera = exe->debug ? exe->debugCamera : exe->camera;
PushProjectiveSetup(rg, camera, exe->lightSource, ShaderFlags_MultiTextured|ShaderFlags_ShadowMapping);
if (pathCreator->hotUnit != 0xFFFFFFFF)
{
UnitData *data = entityManager->unitData + pathCreator->hotUnit;
auto path = data->instructions;
Entity *e = GetEntity(entityManager, data->serial);
u32 pathCounter = 0;
v3i at = e->initialPos;
For(path)
{
DrawNumberOnTile(rg, pathCounter, at);
at += GetAdvanceForOneStep(*it);
pathCounter++;
}
DrawNumberOnTile(rg, pathCounter, at);
pathCounter++;
v3 mouseP = ScreenZeroToOneToZ(camera, input.mouseZeroToOne, e->physicalPos.z);
v3 mouseToPath = mouseP - V3(at);
v4 newTileColor = V4(1.0f, 0.4f, 0.1f, 0.3f);
v3i tilemapDir = ToTilemapDir(mouseToPath);
DrawNumberOnTile(rg, pathCounter, at + tilemapDir, newTileColor);
}
PushProjectiveSetup(rg, camera, exe->lightSource, ShaderFlags_ZBias);
if(exe->debug)
{
For(state, entityManager->animationStates)
{
Entity *e = GetEntity(entityManager, state->serial);
TriangleMesh *mesh = GetMesh(assetHandler, e->meshId);
DrawSkeletonBones(rg, mesh->skeleton.bones, state->boneStates, e->orientation, e->visualPos, e->scale);
}
}
PushProjectiveSetup(rg, camera, exe->lightSource, ShaderFlags_ShadowMapping|ShaderFlags_Textured|ShaderFlags_Phong);
for(u32 i = 0; i < Entity_Count; i++)
{
if(i == Entity_Dude)
{
#if 0
For(state, entityManager->animationStates)
{
Entity *e = GetEntity(entityManager, state->serial);
PushAnimatedMesh(rg, e->meshId, e->orientation, e->visualPos, e->scale, V4(0.75f, 0.0f, 0.0f, 0.0f), state->boneStates);
PushAnimatedMesh(rg, e->meshId, e->orientation, V3(e->initialPos), e->scale, e->color * e->frameColor, state->boneStates);
}
#else
For(entityManager->unitArray)
{
PushTriangleMesh(rg, it->meshId, it->orientation, it->visualPos, it->scale, V4(0.75f, 0.0f, 0.0f, 0.0f));
PushTriangleMesh(rg, it->meshId, it->orientation, it->visualPos, it->scale,
it->color * it->frameColor);
}
#endif
}
else
{
For(entityManager->entityArrays[i])
{
PushTriangleMesh(rg, it->meshId, it->orientation, it->visualPos, it->scale, it->color * it->frameColor);
}
}
}
}
static void RenderPathCreatorUI(RenderGroup *rg, PathCreator *pathCreator, EntityManager *entitiyManager)
{
i32 baseLayer = 4;
{ // render diplay
Rectangle2D displayRect = pathCreator->displayRect;
Tweekable(v4, borderColor);
Tweekable(v4, editorPanelHeaderColor);
v4 headerColor = editorPanelHeaderColor;
Tweekable(v4, editorPanelColor);
v4 backGroundColor = editorPanelColor;
Tweekable(v4, editorPanelValueColor);
v4 valueColor = editorPanelValueColor;
Tweekable(f32, editorPanelFontSize);
f32 fontSize = editorPanelFontSize;
Tweekable(f32, editorBorderWidth);
f32 borderSize = editorBorderWidth;
i32 borderLayer = baseLayer - 0;
i32 backLayer = baseLayer - 1;
i32 entryLayer = baseLayer - 3;
i32 stringLayer = baseLayer - 4;
f32 absoluteBorder = borderSize;
Rectangle2D withBorder;
withBorder.pos = displayRect.pos - V2(absoluteBorder, absoluteBorder);
withBorder.width = displayRect.width + 2.0f * absoluteBorder;
withBorder.height = displayRect.height + 2.0f * absoluteBorder;
PushRectangle(rg, withBorder, borderLayer, borderColor);
PushRectangle(rg, displayRect, backLayer, backGroundColor);
// render variables
Rectangle2D fit;
fit.pos = displayRect.pos + V2(absoluteBorder, absoluteBorder);
fit.width = displayRect.width - 2.0f * absoluteBorder;
fit.height = displayRect.height - 2.0f * absoluteBorder;
if(fit.width <= 0.0f || fit.height <= 0.0f) return;
f32 hBorder = absoluteBorder / fit.height;
// header
f32 headerSize = 0.1f;
PushRelRect(rg, fit, V2(), 1.0f, headerSize, entryLayer, headerColor);
Rectangle2D entryRect = FitRectangle(fit, V2(0, (headerSize + hBorder)), 1.0f, 1.0f - (headerSize + hBorder));
f32 relFontSize = fontSize;
f32 scrollOffset = pathCreator->scrollOffset;
f32 scrollbarWidth = 0.1f;
if(pathCreator->hotUnit != 0xFFFFFFFF)
{ // entries
// todo make get hot unit
UnitData *data = entitiyManager->unitData + pathCreator->hotUnit;
UnitInstructionDynamicArray inst = data->instructions;
v2 p = V2();
For(inst)
{
f32 thisHeight = relFontSize;
f32 yPos = p.y;
p.y += thisHeight + hBorder;
// could do this with relP
if(yPos < scrollOffset) continue;
if((yPos + thisHeight - scrollOffset) >= 1.0f) continue;
v2 relP = V2(p.x, yPos - scrollOffset);
String string = UnitInstructionToString(*it);
PushRelString(rg, entryRect, (char *)string.data, string.length, relP, fontSize, stringLayer);
PushUnscaledRect(rg, entryRect, relP, 1.0f - (scrollbarWidth + hBorder), thisHeight, entryLayer, valueColor);
}
f32 totalHeight = p.y;
{ // scrollbar
Rectangle2D scrollbarRect = FitRectangle(entryRect, V2(1.0f - scrollbarWidth, 0.0f), scrollbarWidth, 1.0f);
RenderScrollbar(rg, scrollbarRect, stringLayer, hBorder, totalHeight, scrollOffset, valueColor, backGroundColor);
}
}
}
switch (pathCreator->state)
{
case PathCreator_CreatingPath:
{
PushRectangle(rg, pathCreator->finishButton.pos, pathCreator->finishButton.width, pathCreator->finishButton.height, 1, V4(1.0f, 0.5, 0.7f, 0.5f));
PushString(rg, pathCreator->finishButton.pos, 0, "Finish", 0.05f);
PushRectangle(rg, pathCreator->resetUnitButton.pos, pathCreator->resetUnitButton.width, pathCreator->resetUnitButton.height, 1, V4(1.0f, 0.7f, 0.3f, 0.5f));
PushString(rg, pathCreator->resetUnitButton.pos, 0, "Reset", 0.05f);
}break;
}
}
static void RenderSimulateUI(RenderGroup *rg, SimData *sim)
{
v2 pos = V2(0.05f, 0.05f);
f32 width = 0.3f;
f32 height = 0.05f;
f32 border = 0.01f;
PushRectangle(rg, pos, width, height, 0, V4(1.0f, 0.2f, 0.3f, 0.6f));
f32 percentage = (f32)sim->blocksCollected / (f32)sim->blocksNeeded;
PushRectangle(rg, pos + V2(border, border), percentage * (width - 2.0f * border), (height - 2.0f * border), -1, V4(1.0f, 0.4f, 0.6f, 0.9f));
String progressString = FormatString("%u32/%u32", sim->blocksCollected, sim->blocksNeeded);
PushString(rg, pos + V2(border, border), -2, progressString, (height - 2.0f * border));
}
static void RenderSimulate(RenderGroup *rg, EntityManager *entityManager, ExecuteData *exe)
{
Camera camera = exe->debug ? exe->debugCamera : exe->camera;
PushProjectiveSetup(rg, camera, exe->lightSource, ShaderFlags_ZBias);
if(exe->debug)
{
For(entityManager->animationStates)
{
Entity *e = GetEntity(entityManager, it->serial);
TriangleMesh *mesh = GetMesh(rg->assetHandler, it->meshId);
DrawSkeletonBones(rg, mesh->skeleton.bones, it->boneStates, e->orientation, e->visualPos, e->scale);
}
}
for(u32 i = 0; i < Entity_Count; i++)
{
if(i == Entity_Dude)
{
PushProjectiveSetup(rg, camera, exe->lightSource, ShaderFlags_ShadowMapping|ShaderFlags_Textured|ShaderFlags_Animated|ShaderFlags_Phong);
For(entityManager->animationStates)
{
Entity *e = GetEntity(entityManager, it->serial);
PushAnimatedMesh(rg, e->meshId, e->orientation, e->visualPos, e->scale, e->color, it->boneStates);
}
}
else
{
PushProjectiveSetup(rg, camera, exe->lightSource, ShaderFlags_ShadowMapping|ShaderFlags_Textured|ShaderFlags_Phong);
For(entityManager->entityArrays[i])
{
PushTriangleMesh(rg, it->meshId, it->orientation, it->visualPos, it->scale, it->color * it->frameColor);
}
}
}
}
static void RenderVictoryUI(RenderGroup *rg)
{
PushString(rg, V2(0.1f, 0.1f), 0, "Victory", 0.2f);
}
static void RenderExecuteUI(RenderGroup *rg, ExecuteData *exe, EntityManager *entityManager)
{
switch (exe->state)
{
case Execute_PlacingUnits:
{
}break;
case Execute_PathCreator:
{
RenderPathCreatorUI(rg, &exe->pathCreator, entityManager);
}break;
case Execute_Simulation:
{
RenderSimulateUI(rg, &exe->simData);
}break;
case Execute_Victory:
{
RenderVictoryUI(rg);
}break;
InvalidDefaultCase;
}
}
static void RenderColorPicker(RenderGroup *rg, ColorPicker *picker)
{
Tweekable(v4, borderColor);
//BackGround
v2 windowUL = picker->pos - V2(picker->border, 2.0f * picker->border + picker->headerSize);
f32 windowWidth = picker->width + 2.0f * picker->border;
f32 windowHeight = picker->height + 2.0f * picker->border + picker->sliderHeight + 2.0f * picker->border + picker->headerSize;
PushRectangle(rg, windowUL, windowWidth, windowHeight, 2, borderColor);
//Header
v2 headerPos = picker->pos - V2(0.0f, picker->headerSize + picker->border);
picker->headerPos = headerPos;
//PushRectangle(rg, headerPos, picker->width, picker->pickerHeaderSize, borderColor);
Tweekable(v4, headerKillColor);
v2 killRectPos = V2(headerPos.x + picker->width - picker->headerSize, headerPos.y);
picker->killRectPos = killRectPos;
PushRectangle(rg, killRectPos, picker->headerSize, picker->headerSize, 1, headerKillColor);
f32 scale = 1.0f / 6.0f;
f32 scaledWidth = scale * picker->width;
u32 colors[7] =
{
0xFFFF0000, // blue
0xFFFFFF00, // cyan
0xFF00FF00, // green
0xFF00FFFF, // yellow
0xFF0000FF, // red
0xFFFF00FF, // purple
0xFFFF0000, // blue
};
// sliderColors
for (u32 i = 0; i < 6; i++)
{
PushRectangle(rg, V2(picker->sliderPos.x + i * scaledWidth, picker->sliderPos.y), scaledWidth, picker->sliderHeight, 0, colors[i], colors[(i + 1)], colors[i], colors[(i + 1)]);
}
// Picker Color
Tweekable(f32, sliderSlider);
f32 ppx = picker->pos.x + picker->pickerPos.x;
f32 ppy = picker->pos.y + picker->pickerPos.y;
PushRectangle(rg, picker->pos, picker->width, picker->height, 1, 0xFFFFFFFF, picker->sliderColor, 0xFF000000, 0xFF000000);
// picker pointer
PushRectangle(rg, V2(ppx - 2.0f * picker->border, ppy - 2.0f * picker->border), 4.0f * picker->border, 1.0f * picker->border, 1, borderColor);
PushRectangle(rg, V2(ppx - 2.0f * picker->border, ppy + 2.0f * picker->border), 4.0f * picker->border, 1.0f * picker->border, 1, borderColor);
PushRectangle(rg, V2(ppx - 2.0f * picker->border, ppy - 2.0f * picker->border), 1.0f * picker->border, 4.0f * picker->border, 1, borderColor);
PushRectangle(rg, V2(ppx + 1.0f * picker->border, ppy - 2.0f * picker->border), 1.0f * picker->border, 4.0f * picker->border, 1, borderColor);
//slider
v2 pickerSliderBoxPos = V2(picker->sliderPos.x + picker->sliderSelectedColorPos - 0.5f * (sliderSlider + picker->border), picker->sliderPos.y - 1.5f * picker->border);
v2 pickerSliderColorPos = V2(picker->sliderPos.x + picker->sliderSelectedColorPos - 0.5f * sliderSlider, picker->sliderPos.y - 0.5f * picker->border);
PushRectangle(rg, pickerSliderBoxPos, sliderSlider + picker->border, picker->sliderHeight + 3.0f * picker->border, 0, borderColor);
PushRectangle(rg, pickerSliderColorPos, sliderSlider, picker->sliderHeight + picker->border, 0, picker->sliderColor);
//a r g b
Tweekable(f32, pickerFontSize);
Tweekable(f32, pickerFontXIncrease);
f32 fontY = picker->pos.y + picker->width - pickerFontSize;
PushString(rg, V2(picker->pos.x + 0.0f * pickerFontXIncrease * pickerFontSize, fontY), -1, FormatString("a:%f32", picker->pickedColor->a), pickerFontSize);
PushString(rg, V2(picker->pos.x + 1.0f * pickerFontXIncrease * pickerFontSize, fontY), -1, FormatString("r:%f32", picker->pickedColor->r), pickerFontSize);
PushString(rg, V2(picker->pos.x + 2.0f * pickerFontXIncrease * pickerFontSize, fontY), -1, FormatString("g:%f32", picker->pickedColor->g), pickerFontSize);
PushString(rg, V2(picker->pos.x + 3.0f * pickerFontXIncrease * pickerFontSize, fontY), -1, FormatString("b:%f32", picker->pickedColor->b), pickerFontSize);
}
static void RenderEditorPanel(RenderGroup *rg, Editor editor)
{
if (editor.state == EditorState_Rotating || editor.state == EditorState_Scaling || editor.state == EditorState_Moving)
{
return;
}
EditorPanel *p = &editor.panel;
if (!p->visible) return;
if (editor.panelIsHidden) return;
Tweekable(v4, editorPanelColor, V4(1, 1, 1, 1));
Tweekable(v4, editorPanelValueColor, V4(1.0f, 0.5f, 0.7f, 1.0f));
Tweekable(v4, editorPanelHeaderColor, V4(1.0f, 0.4f, 0.6f, 0.8f));
Tweekable(f32, editorBorderWidth, 0.01f);
Tweekable(f32, editorHeaderWidth, 0.08f);
Tweekable(f32, editorPanelFontSize, 0.01f);
Tweekable(f32, editorPanelWidth, 0.1f);
Tweekable(f32, editorPanelHeight, 0.6f);
f32 panelWidth = editorPanelWidth;
f32 panelHeight = editorPanelHeight;
//whole thang
PushRectangle(rg, p->pos, panelWidth, panelHeight, 2, editorPanelColor);
//header
f32 widthWithoutBoarder = panelWidth - 2 * editorBorderWidth;
PushRectangle(rg, p->pos + V2(editorBorderWidth, editorBorderWidth), widthWithoutBoarder, editorHeaderWidth, 1, editorPanelHeaderColor);
PushString(rg, p->pos + V2(editorBorderWidth, editorBorderWidth), 0, EditorStateToString(editor.state), 0.5f * editorHeaderWidth);
u32 xyz = editor.panel.hotValueXYZ;
v2 valuePos = p->pos + V2(editorBorderWidth, editorBorderWidth + editorHeaderWidth);
String textInputString = CreateString(p->textInput.inputBuffer, p->textInput.amount);
For(p->values)
{
String name = FormatString("%s:", it->name);
f32 offset = PushString(rg, valuePos, 0, name, editorPanelFontSize);
v2 writePos = valuePos + V2(0, editorPanelFontSize);
v2 continuePos = valuePos + V2(offset + 3 * editorPanelFontSize, 0);
f32 height = HeightForTweekerPanel(it->type, editorBorderWidth, editorPanelFontSize);
// entry outline rect
PushRectangle(rg, valuePos, widthWithoutBoarder, height, 1, editorPanelValueColor);
switch (it->type)
{
case Tweeker_b32:
{
f32 indecatorSquareSize = height - editorBorderWidth;
v2 squarePos = valuePos + V2(widthWithoutBoarder - height, editorBorderWidth);
PushRectangle(rg, squarePos, indecatorSquareSize, indecatorSquareSize, 0, V4(1, 1, 1, 1));
f32 innerSquareSize = indecatorSquareSize - editorBorderWidth;
if (*it->b)
{
PushRectangle(rg, squarePos + 0.5f * V2(editorBorderWidth, editorBorderWidth), innerSquareSize, innerSquareSize, -1, V4(1.0f, 0.3f, 0.8f, 0.3f));
}
else
{
PushRectangle(rg, squarePos + 0.5f * V2(editorBorderWidth, editorBorderWidth), innerSquareSize, innerSquareSize, -1, V4(1.0f, 0.8f, 0.3f, 0.3f));
}
}break;
case Tweeker_u32:
{
if (p->values.data + p->hotValue == it)
{
PushString(rg, continuePos, 0, textInputString, editorPanelFontSize);
break;
}
String str = UtoS(*it->u);
PushString(rg, continuePos, 0, str, editorPanelFontSize);
}break;
case Tweeker_EntityType:
{
writePos.x += 0.3f * widthWithoutBoarder;
switch (*it->u)
{
case Entity_None:
{
PushString(rg, writePos, 0, "None", editorPanelFontSize);
}break;
case Entity_Dude:
{
PushString(rg, writePos, 0, "Dude", editorPanelFontSize);
}break;
case Entity_Wall:
{
PushString(rg, writePos, 0, "Wall", editorPanelFontSize);
}break;
case Entity_Bit:
{
PushString(rg, writePos, 0, "Bit", editorPanelFontSize);
}break;
}
f32 rightArrowPos = widthWithoutBoarder - editorPanelFontSize;
//writePos.y += 0.5f * editorPanelFontSize;
writePos.x -= 0.3f * widthWithoutBoarder;
PushRectangle(rg, writePos + V2(rightArrowPos, 0), editorPanelFontSize, editorPanelFontSize, -1, V4(1.0f, 1.0f, 0.8f, 0.2f));
PushRectangle(rg, writePos, editorPanelFontSize, editorPanelFontSize, -1, V4(1.0f, 1.0f, 0.8f, 0.2f));
}break;
case Tweeker_f32:
{
if (p->values.data + p->hotValue == it)
{
PushString(rg, continuePos, 0, textInputString, editorPanelFontSize);
break;
}
String str = FtoS(*it->f);
PushString(rg, continuePos, 0, str, editorPanelFontSize);
}break;
case Tweeker_v2:
{
if (xyz == 'x' && (p->values.data + p->hotValue == it))
{
String str = FormatString("x: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String strx = FormatString("x: %s", FtoS(it->vec2->x));
PushString(rg, writePos, 0, strx, editorPanelFontSize);
}
writePos.y += editorPanelFontSize;
if (xyz == 'y' && (p->values.data + p->hotValue == it))
{
String str = FormatString("y: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String stry = FormatString("y: %s", FtoS(it->vec2->y));
PushString(rg, writePos, 0, stry, editorPanelFontSize);
}
}break;
case Tweeker_v3:
{
if (xyz == 'x' && (p->values.data + p->hotValue == it))
{
String str = FormatString("x: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String strx = FormatString("x: %s", FtoS(it->vec3->x));
PushString(rg, writePos, 0, strx, editorPanelFontSize);
}
writePos.y += editorPanelFontSize;
if (xyz == 'y' && (p->values.data + p->hotValue == it))
{
String str = FormatString("y: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String stry = FormatString("y: %s", FtoS(it->vec3->y));
PushString(rg, writePos, 0, stry, editorPanelFontSize);
}
writePos.y += editorPanelFontSize;
if (xyz == 'z' && (p->values.data + p->hotValue == it))
{
String str = FormatString("z: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String strz = FormatString("z: %s", FtoS(it->vec3->z));
PushString(rg, writePos, 0, strz, editorPanelFontSize);
}
}break;
case Tweeker_v3i:
{
if (xyz == 'x' && (p->values.data + p->hotValue == it))
{
String str = FormatString("x: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String strx = FormatString("x: %s", ItoS(it->vec3i->x));
PushString(rg, writePos, 0, strx, editorPanelFontSize);
}
writePos.y += editorPanelFontSize;
if (xyz == 'y' && (p->values.data + p->hotValue == it))
{
String str = FormatString("y: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String stry = FormatString("y: %s", ItoS(it->vec3i->y));
PushString(rg, writePos, 0, stry, editorPanelFontSize);
}
writePos.y += editorPanelFontSize;
if (xyz == 'z' && (p->values.data + p->hotValue == it))
{
String str = FormatString("z: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String strz = FormatString("z: %s", ItoS(it->vec3i->z));
PushString(rg, writePos, 0, strz, editorPanelFontSize);
}
}break;
case Tweeker_EulerAngle:
{
Quaternion q = *it->q;
EulerAngle angle = QuaternionToEulerAngle(q);
v3i val;
val.x = Round(angle.XRotation / (2.0f * PI) * 360.0f) + 180;
val.y = Round(angle.YRotation / (2.0f * PI) * 360.0f) + 180;
val.z = Round(angle.ZRotation / (2.0f * PI) * 360.0f) + 180;
if (xyz == 'x' && (p->values.data + p->hotValue == it))
{
String str = FormatString("xRot: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String strx = FormatString("xRot: %s", ItoS(val.x));
PushString(rg, writePos, 0, strx, editorPanelFontSize);
}
writePos.y += editorPanelFontSize;
if (xyz == 'y' && (p->values.data + p->hotValue == it))
{
String str = FormatString("yRot: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String stry = FormatString("yRot: %s", ItoS(val.y));
PushString(rg, writePos, 0, stry, editorPanelFontSize);
}
writePos.y += editorPanelFontSize;
if (xyz == 'z' && (p->values.data + p->hotValue == it))
{
String str = FormatString("zRot: %s", textInputString);
PushString(rg, writePos, 0, str, editorPanelFontSize);
}
else
{
String strz = FormatString("zRot: %s", ItoS(val.z));
PushString(rg, writePos, 0, strz, editorPanelFontSize);
}
}break;
case Tweeker_v4:
{
f32 colorRectSize = 3.0f * editorPanelFontSize;
v4 color = *it->vec4;
PushRectangle(rg, V2(valuePos.x + widthWithoutBoarder - colorRectSize - editorBorderWidth, valuePos.y + editorBorderWidth), colorRectSize, colorRectSize, 0, color);
}break;
default:
{
Die;
}break;
}
valuePos.y += height + editorBorderWidth;
}
}
static void RenderEditor(RenderGroup *rg, AssetHandler *assetHandler, Editor editor, Input input)
{
PushDebugPointCuboid(rg, editor.levelInfo.lightSource.pos, V4(1.0f, 0.8f, 0.7f, 0.1f));
EditorEntities *editorEntities = &editor.editorEntities;
PushProjectiveSetup(rg, editor.camera, editor.levelInfo.lightSource, ShaderFlags_Textured|ShaderFlags_Phong|ShaderFlags_ShadowMapping);
For(editorEntities->entities)
{
PushTriangleMesh(rg, it->meshId, it->orientation, it->visualPos, it->scale, it->color * it->frameColor);
}
switch (editor.state)
{
case EditorState_Moving:
{
if (!editor.editingPhysical) break;
for(u32 i = 0; i < editor.hotEntitySerials.amount; i++)
{
Entity *e = GetEntity(editorEntities, editor.hotEntitySerials[i]);
EntityData *data = editor.hotEntityInitialStates + i;
PushTriangleMesh(rg, e->meshId, e->orientation, V3(e->physicalPos) + data->offset, e->scale, e->color * V4(0.5f, 1.0f, 1.0f, 1.0f));
}
}break;
case EditorState_PlacingNewMesh:
{
v2 mouseP = ScreenZeroToOneToInGame(editor.camera, input.mouseZeroToOne);
v3i clickedTile = SnapToTileMap(i12(mouseP));
v3 clickedOffset = V3(clickedTile) - V3(mouseP, 0.0f);
For(editor.clipBoard)
{
v3i pos = it->physicalPos + clickedTile;
v3 offset = it->offset;
v3 rpos = V3(pos) + offset;
PushTriangleMesh(rg, it->meshId, it->orientation, rpos, it->scale, it->color * V4(0.5f, 1.0f, 1.0f, 1.0f));
}
}break;
}
if (!editor.hotEntitySerials.amount) return;
//v3 averagePos = GetAveragePosForSelection(&editor);
//PushDebugPointCuboid(rg, V3(averagePos.xy, 0.0f));
For(editor.hotEntitySerials)
{
Entity *e = GetEntity(editorEntities, *it);
PushDebugPointCuboid(rg, V3(e->physicalPos), V4(1.0f, 1.0f, 0.3f, 0.2f));
}
PushProjectiveSetup(rg, editor.camera, editor.levelInfo.lightSource, ShaderFlags_None);
For(editor.hotEntitySerials)
{
Entity *e = GetEntity(editorEntities, *it);
AABB transformedAABB = GetMesh(assetHandler, e->meshId)->aabb;
transformedAABB.minDim *= e->scale;
transformedAABB.maxDim *= e->scale;
m4x4 mat = Translate(QuaternionToMatrix4(e->orientation), e->visualPos);
v3 d1 = V3(transformedAABB.maxDim.x - transformedAABB.minDim.x, 0, 0);
v3 d2 = V3(0, transformedAABB.maxDim.y - transformedAABB.minDim.y, 0);
v3 d3 = V3(0, 0, transformedAABB.maxDim.z - transformedAABB.minDim.z);
v3 p[8] =
{
mat * transformedAABB.minDim, //0
mat * (transformedAABB.minDim + d1), //1
mat * (transformedAABB.minDim + d2), //2
mat * (transformedAABB.minDim + d3), //3
mat * (transformedAABB.minDim + d1 + d2), //4
mat * (transformedAABB.minDim + d2 + d3), //5
mat * (transformedAABB.minDim + d3 + d1), //6
mat * transformedAABB.maxDim, //7
};
//_upper_ square
PushLine(rg, p[0], p[1]);
PushLine(rg, p[1], p[4]);
PushLine(rg, p[4], p[2]);
PushLine(rg, p[2], p[0]);
//_lower_ square
PushLine(rg, p[7], p[5]);
PushLine(rg, p[5], p[3]);
PushLine(rg, p[3], p[6]);
PushLine(rg, p[6], p[7]);
//_connecting_ lines
PushLine(rg, p[0], p[3]);
PushLine(rg, p[2], p[5]);
PushLine(rg, p[1], p[6]);
PushLine(rg, p[4], p[7]);
}
}
static void RenderEditorUI(RenderGroup *rg, Editor editor)
{
PushOrthogonalSetup(rg, ShaderFlags_MultiTextured);
if (editor.state == EditorState_DeleteSelection)
{
PushString(rg, V2(0.4f, 0.1f), 0, "Delete?", 0.05f);
}
RenderEditorPanel(rg, editor);
For(editor.colorPickers)
{
RenderColorPicker(rg, it);
}
}
static void RenderEntityAABBOutline(RenderGroup *rg, AssetHandler *assetHandler, Entity *e, f32 t)
{
MeshInfo *info = GetMeshInfo(assetHandler, e->meshId);
if (!info) return;
AABB transformedAABB = info->aabb;
transformedAABB.minDim *= e->scale;
transformedAABB.maxDim *= e->scale;
m4x4 mat = Translate(QuaternionToMatrix4(e->orientation), e->visualPos);
v3 d1 = V3(transformedAABB.maxDim.x - transformedAABB.minDim.x, 0, 0);
v3 d2 = V3(0, transformedAABB.maxDim.y - transformedAABB.minDim.y, 0);
v3 d3 = V3(0, 0, transformedAABB.maxDim.z - transformedAABB.minDim.z);
v3 p[8] =
{
mat * transformedAABB.minDim, //0
mat * (transformedAABB.minDim + d1), //1
mat * (transformedAABB.minDim + d2), //2
mat * (transformedAABB.minDim + d3), //3
mat * (transformedAABB.minDim + d1 + d2), //4
mat * (transformedAABB.minDim + d2 + d3), //5
mat * (transformedAABB.minDim + d3 + d1), //6
mat * transformedAABB.maxDim, //7
};
//_upper_ square
PushLine(rg, p[0], p[1]);
PushLine(rg, p[1], p[4]);
PushLine(rg, p[4], p[2]);
PushLine(rg, p[2], p[0]);
//_lower_ square
PushLine(rg, p[7], p[5]);
PushLine(rg, p[5], p[3]);
PushLine(rg, p[3], p[6]);
PushLine(rg, p[6], p[7]);
//_connecting_ lines
PushLine(rg, p[0], p[3]);
PushLine(rg, p[2], p[5]);
PushLine(rg, p[1], p[6]);
PushLine(rg, p[4], p[7]);
}
static void RenderEntityQuadTree(RenderGroup *rg, TileOctTreeNode *node)
{
if (!node) return;
AABB aabb = { V3(node->bound.minDim) - V3(0.5f, 0.5f, 0.5f), V3(node->bound.maxDim) - V3(0.5f, 0.5f, 0.5f) };
v3 d1 = V3(aabb.maxDim.x - aabb.minDim.x, 0, 0);
v3 d2 = V3(0, aabb.maxDim.y - aabb.minDim.y, 0);
v3 d3 = V3(0, 0, aabb.maxDim.z - aabb.minDim.z);
v3 p[8] =
{
aabb.minDim, //0
(aabb.minDim + d1), //1
(aabb.minDim + d2), //2
(aabb.minDim + d3), //3
(aabb.minDim + d1 + d2), //4
(aabb.minDim + d2 + d3), //5
(aabb.minDim + d3 + d1), //6
aabb.maxDim, //7
};
//_upper_ square
PushLine(rg, p[0], p[1]);
PushLine(rg, p[1], p[4]);
PushLine(rg, p[4], p[2]);
PushLine(rg, p[2], p[0]);
//_lower_ square
PushLine(rg, p[7], p[5]);
PushLine(rg, p[5], p[3]);
PushLine(rg, p[3], p[6]);
PushLine(rg, p[6], p[7]);
//_connecting_ lines
PushLine(rg, p[0], p[3]);
PushLine(rg, p[2], p[5]);
PushLine(rg, p[1], p[6]);
PushLine(rg, p[4], p[7]);
if (!node->isLeaf)
{
for (u32 i = 0; i < 8; i++)
{
RenderEntityQuadTree(rg, node->children[i]);
}
}
}
#if 0
static void AnimationTestStuff(RenderGroup *rg, DAEReturn *stuff, f32 dt)
{
TriangleMesh *mesh = &stuff->mesh;
Skeleton *skeleton = &stuff->mesh.skeleton;
KeyFramedAnimation *animation = &stuff->animation;
v3Array out = PushArray(frameArena, v3, mesh->positions.amount);
static f32 t = 0;
t += dt;
m4x4Array boneTransformes = CalculateBoneTransforms(skeleton, animation, t);
for (u32 i = 0; i < mesh->positions.amount; i++)
{
u32 unflattend = skeleton->vertexMap[i];
WeightDataArray weights = skeleton->vertexToWeightsMap[unflattend];
out[i] = V3();
v3 v = mesh->positions[i];
For(weights)
{
// first inverse then transform it, makes sense!
out[i] += it->weight * (boneTransformes[it->boneIndex] * v);
}
}
for (u32 i = 0; i < mesh->indices.amount; i += 3)
{
u16 i1 = mesh->indices[i + 0];
u16 i2 = mesh->indices[i + 1];
u16 i3 = mesh->indices[i + 2];
v3 p1 = out[i1];
v3 p2 = out[i2];
v3 p3 = out[i3];
PushTriangle(rg, p1, p2, p3, V3(0.8f, 0.8f, 0.8f));
}
}
#endif