-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSamplesApp.cpp
More file actions
2579 lines (2237 loc) · 103 KB
/
SamplesApp.cpp
File metadata and controls
2579 lines (2237 loc) · 103 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
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
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#ifdef WIN3D
#include <TestFramework.h>
#include <SamplesApp.h>
#include <Application/EntryPoint.h>
//#include <Jolt/Core/JobSystemThreadPool.h>
#include <Jolt/Core/JobSystemSingleThreaded.h>
#include <Jolt/Core/TempAllocator.h>
#include <Jolt/Core/StreamWrapper.h>
#include <Jolt/Core/StringTools.h>
#include <Jolt/Geometry/OrientedBox.h>
#include <Jolt/Physics/PhysicsSystem.h>
#include <Jolt/Physics/StateRecorderImpl.h>
#include <Jolt/Physics/Body/BodyCreationSettings.h>
#include <Jolt/Physics/SoftBody/SoftBodyMotionProperties.h>
#include <Jolt/Physics/SoftBody/SoftBodyCreationSettings.h>
#include <Jolt/Physics/PhysicsScene.h>
#include <Jolt/Physics/Collision/RayCast.h>
#include <Jolt/Physics/Collision/ShapeCast.h>
#include <Jolt/Physics/Collision/CastResult.h>
#include <Jolt/Physics/Collision/CollidePointResult.h>
#include <Jolt/Physics/Collision/AABoxCast.h>
#include <Jolt/Physics/Collision/CollisionCollectorImpl.h>
#include <Jolt/Physics/Collision/Shape/HeightFieldShape.h>
#include <Jolt/Physics/Collision/Shape/MeshShape.h>
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
#include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
#include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
#include <Jolt/Physics/Collision/Shape/TaperedCapsuleShape.h>
#include <Jolt/Physics/Collision/Shape/CylinderShape.h>
#include <Jolt/Physics/Collision/Shape/TriangleShape.h>
#include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
#include <Jolt/Physics/Collision/Shape/MutableCompoundShape.h>
#include <Jolt/Physics/Collision/Shape/ScaledShape.h>
#include <Jolt/Physics/Collision/NarrowPhaseStats.h>
#include <Jolt/Physics/Constraints/DistanceConstraint.h>
#include <Jolt/Physics/Constraints/PulleyConstraint.h>
#include <Jolt/Physics/Character/CharacterVirtual.h>
#include <Utils/Log.h>
#include <Utils/ShapeCreator.h>
#include <Utils/CustomMemoryHook.h>
#include <Utils/SoftBodyCreator.h>
#include <Renderer/DebugRendererImp.h>
#include "SimSoccer/constants.h"
#include "Common/misc/utils.h"
#include "Common/Time/PrecisionTimer.h"
#include "Common/Game/EntityManager.h"
#include "SimSoccer/SoccerPitch.h"
#include "SimSoccer/SoccerTeam.h"
#include "SimSoccer/PlayerBase.h"
#include "SimSoccer/Goalkeeper.h"
#include "SimSoccer/FieldPlayer.h"
#include "SimSoccer/FieldGoal.h"
#include "SimSoccer/SteeringBehaviors.h"
#include "Common/misc/Snapshot.h"
#include "Common/json/json.hpp"
#include "Common/misc/Cgdi.h"
#include "SimSoccer/ParamLoader.h"
#include "Resource.h"
#include "Common/misc/WindowUtils.h"
#include "Common/Debug/DebugConsole.h"
#include "Common/misc/WinHttpWrapper.h"
//#include "Common/Game/PhysicsManager.h"
#include <Common/Game/PhysicsManager.h>
using namespace WinHttpWrapper;
using namespace std;
using json = nlohmann::json;
//#define PLAYER_STATE_INFO_ON
//#define SERVER_MODE
//#define CLIENT_MODE
#define LIVE_MODE
//#define REMOTE_MODE
//--------------------------------- Globals ------------------------------
//
//------------------------------------------------------------------------
const int MATCH_DURATION = 45;
const int MATCH_RATE = 6;
const int MILLI_IN_SECOND = 20;
const int MILLI_IN_MINUTE = 60 * 20;
const int SECOND_MAX_VALUE = 60;
const bool LOG_MATCH_OUTPUT = true;
const int SNAPSHOT_RATE = 5;
int mTickCount = 0;
bool mMatchFinished = false;
const wstring REMOTE_API_SERVER_URL = L"localhost";
int REMOTE_API_SERVER_PORT = 3010;
bool REMOTE_API_SERVER_HTTPS = false;
const wstring requestHeader = L"Content-Type: application/json";
SoccerPitch* g_SoccerPitch;
Snapshot* g_MatchReplay;
json g_LastSnapshot;
int g_FinalScore1 = 0;
int g_FinalScore2 = 0;
//create a timer
PrecisionTimer timer(Prm.FrameRate);
int updates_count = 0;
void IncrementTime(int rate)
{
mTickCount += MATCH_RATE * rate;
int minutes = mTickCount / MILLI_IN_MINUTE;
if (minutes >= MATCH_DURATION)
{
mMatchFinished = true;
}
}
std::string GetCurrentTimeString()
{
int seconds = (mTickCount / MILLI_IN_SECOND) % SECOND_MAX_VALUE;
int minutes = mTickCount / MILLI_IN_MINUTE;
std::ostringstream stringStream;
stringStream << minutes << " : " << seconds;
std::string time = stringStream.str();
return time;
}
JPH_SUPPRESS_WARNINGS_STD_BEGIN
#include <fstream>
JPH_SUPPRESS_WARNINGS_STD_END
//-----------------------------------------------------------------------------
// RTTI definitions
//-----------------------------------------------------------------------------
struct TestNameAndRTTI
{
const char * mName;
const RTTI * mRTTI;
};
struct TestCategory
{
const char * mName;
TestNameAndRTTI * mTests;
size_t mNumTests;
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SimpleTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, StackTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, WallTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, PyramidTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, IslandTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, FunnelTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, FrictionTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, FrictionPerTriangleTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ConveyorBeltTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, GravityFactorTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, RestitutionTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, DampingTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, KinematicTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ContactManifoldTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ManifoldReductionTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, CenterOfMassTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, HeavyOnLightTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, HighSpeedTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ChangeMotionQualityTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ChangeMotionTypeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ChangeShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ChangeObjectLayerTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, LoadSaveSceneTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, LoadSaveBinaryTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, BigVsSmallTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ActiveEdgesTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, MultithreadedTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ContactListenerTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ModifyMassTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ActivateDuringUpdateTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SensorTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, DynamicMeshTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, TwoDFunnelTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, AllowedDOFsTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ShapeFilterTest)
static TestNameAndRTTI sGeneralTests[] =
{
{ "Simple", JPH_RTTI(SimpleTest) },
{ "Stack", JPH_RTTI(StackTest) },
{ "Wall", JPH_RTTI(WallTest) },
{ "Pyramid", JPH_RTTI(PyramidTest) },
{ "Island", JPH_RTTI(IslandTest) },
{ "Funnel", JPH_RTTI(FunnelTest) },
{ "2D Funnel", JPH_RTTI(TwoDFunnelTest) },
{ "Friction", JPH_RTTI(FrictionTest) },
{ "Friction (Per Triangle)", JPH_RTTI(FrictionPerTriangleTest) },
{ "Conveyor Belt", JPH_RTTI(ConveyorBeltTest) },
{ "Gravity Factor", JPH_RTTI(GravityFactorTest) },
{ "Restitution", JPH_RTTI(RestitutionTest) },
{ "Damping", JPH_RTTI(DampingTest) },
{ "Kinematic", JPH_RTTI(KinematicTest) },
{ "Contact Manifold", JPH_RTTI(ContactManifoldTest) },
{ "Manifold Reduction", JPH_RTTI(ManifoldReductionTest) },
{ "Center Of Mass", JPH_RTTI(CenterOfMassTest) },
{ "Heavy On Light", JPH_RTTI(HeavyOnLightTest) },
{ "High Speed", JPH_RTTI(HighSpeedTest) },
{ "Change Motion Quality", JPH_RTTI(ChangeMotionQualityTest) },
{ "Change Motion Type", JPH_RTTI(ChangeMotionTypeTest) },
{ "Change Shape", JPH_RTTI(ChangeShapeTest) },
{ "Change Object Layer", JPH_RTTI(ChangeObjectLayerTest) },
{ "Load/Save Scene", JPH_RTTI(LoadSaveSceneTest) },
{ "Load/Save Binary", JPH_RTTI(LoadSaveBinaryTest) },
{ "Big vs Small", JPH_RTTI(BigVsSmallTest) },
{ "Active Edges", JPH_RTTI(ActiveEdgesTest) },
{ "Multithreaded", JPH_RTTI(MultithreadedTest) },
{ "Contact Listener", JPH_RTTI(ContactListenerTest) },
{ "Modify Mass", JPH_RTTI(ModifyMassTest) },
{ "Activate During Update", JPH_RTTI(ActivateDuringUpdateTest) },
{ "Sensor", JPH_RTTI(SensorTest) },
{ "Dynamic Mesh", JPH_RTTI(DynamicMeshTest) },
{ "Allowed Degrees of Freedom", JPH_RTTI(AllowedDOFsTest) },
{ "Shape Filter", JPH_RTTI(ShapeFilterTest) },
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, DistanceConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, FixedConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ConeConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SwingTwistConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SixDOFConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, HingeConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, PoweredHingeConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, PointConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SliderConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, PoweredSliderConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SpringTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ConstraintSingularityTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ConstraintPriorityTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, PoweredSwingTwistConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SwingTwistConstraintFrictionTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, PathConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, RackAndPinionConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, GearConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, PulleyConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ConstraintVsCOMChangeTest)
static TestNameAndRTTI sConstraintTests[] =
{
{ "Point Constraint", JPH_RTTI(PointConstraintTest) },
{ "Distance Constraint", JPH_RTTI(DistanceConstraintTest) },
{ "Hinge Constraint", JPH_RTTI(HingeConstraintTest) },
{ "Powered Hinge Constraint", JPH_RTTI(PoweredHingeConstraintTest) },
{ "Slider Constraint", JPH_RTTI(SliderConstraintTest) },
{ "Powered Slider Constraint", JPH_RTTI(PoweredSliderConstraintTest) },
{ "Fixed Constraint", JPH_RTTI(FixedConstraintTest) },
{ "Cone Constraint", JPH_RTTI(ConeConstraintTest) },
{ "Swing Twist Constraint", JPH_RTTI(SwingTwistConstraintTest) },
{ "Powered Swing Twist Constraint", JPH_RTTI(PoweredSwingTwistConstraintTest) },
{ "Swing Twist Constraint Friction", JPH_RTTI(SwingTwistConstraintFrictionTest) },
{ "Six DOF Constraint", JPH_RTTI(SixDOFConstraintTest) },
{ "Path Constraint", JPH_RTTI(PathConstraintTest) },
{ "Rack And Pinion Constraint", JPH_RTTI(RackAndPinionConstraintTest) },
{ "Gear Constraint", JPH_RTTI(GearConstraintTest) },
{ "Pulley Constraint", JPH_RTTI(PulleyConstraintTest) },
{ "Spring", JPH_RTTI(SpringTest) },
{ "Constraint Singularity", JPH_RTTI(ConstraintSingularityTest) },
{ "Constraint vs Center Of Mass Change",JPH_RTTI(ConstraintVsCOMChangeTest) },
{ "Constraint Priority", JPH_RTTI(ConstraintPriorityTest) },
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, BoxShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SphereShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, TaperedCapsuleShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, CapsuleShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, CylinderShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, StaticCompoundShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, MutableCompoundShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, TriangleShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ConvexHullShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, MeshShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, HeightFieldShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, DeformedHeightFieldShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, RotatedTranslatedShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, OffsetCenterOfMassShapeTest)
static TestNameAndRTTI sShapeTests[] =
{
{ "Sphere Shape", JPH_RTTI(SphereShapeTest) },
{ "Box Shape", JPH_RTTI(BoxShapeTest) },
{ "Capsule Shape", JPH_RTTI(CapsuleShapeTest) },
{ "Tapered Capsule Shape", JPH_RTTI(TaperedCapsuleShapeTest) },
{ "Cylinder Shape", JPH_RTTI(CylinderShapeTest) },
{ "Convex Hull Shape", JPH_RTTI(ConvexHullShapeTest) },
{ "Mesh Shape", JPH_RTTI(MeshShapeTest) },
{ "Height Field Shape", JPH_RTTI(HeightFieldShapeTest) },
{ "Deformed Height Field Shape", JPH_RTTI(DeformedHeightFieldShapeTest) },
{ "Static Compound Shape", JPH_RTTI(StaticCompoundShapeTest) },
{ "Mutable Compound Shape", JPH_RTTI(MutableCompoundShapeTest) },
{ "Triangle Shape", JPH_RTTI(TriangleShapeTest) },
{ "Rotated Translated Shape", JPH_RTTI(RotatedTranslatedShapeTest) },
{ "Offset Center Of Mass Shape", JPH_RTTI(OffsetCenterOfMassShapeTest) }
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledSphereShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledBoxShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledCapsuleShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledTaperedCapsuleShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledCylinderShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledConvexHullShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledMeshShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledHeightFieldShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledStaticCompoundShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledMutableCompoundShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledTriangleShapeTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ScaledOffsetCenterOfMassShapeTest)
static TestNameAndRTTI sScaledShapeTests[] =
{
{ "Sphere Shape", JPH_RTTI(ScaledSphereShapeTest) },
{ "Box Shape", JPH_RTTI(ScaledBoxShapeTest) },
{ "Capsule Shape", JPH_RTTI(ScaledCapsuleShapeTest) },
{ "Tapered Capsule Shape", JPH_RTTI(ScaledTaperedCapsuleShapeTest) },
{ "Cylinder Shape", JPH_RTTI(ScaledCylinderShapeTest) },
{ "Convex Hull Shape", JPH_RTTI(ScaledConvexHullShapeTest) },
{ "Mesh Shape", JPH_RTTI(ScaledMeshShapeTest) },
{ "Height Field Shape", JPH_RTTI(ScaledHeightFieldShapeTest) },
{ "Static Compound Shape", JPH_RTTI(ScaledStaticCompoundShapeTest) },
{ "Mutable Compound Shape", JPH_RTTI(ScaledMutableCompoundShapeTest) },
{ "Triangle Shape", JPH_RTTI(ScaledTriangleShapeTest) },
{ "Offset Center Of Mass Shape", JPH_RTTI(ScaledOffsetCenterOfMassShapeTest) }
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, CreateRigTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, LoadRigTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, KinematicRigTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, PoweredRigTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, RigPileTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, LoadSaveRigTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, LoadSaveBinaryRigTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SkeletonMapperTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, BigWorldTest)
static TestNameAndRTTI sRigTests[] =
{
{ "Create Rig", JPH_RTTI(CreateRigTest) },
{ "Load Rig", JPH_RTTI(LoadRigTest) },
{ "Load / Save Rig", JPH_RTTI(LoadSaveRigTest) },
{ "Load / Save Binary Rig", JPH_RTTI(LoadSaveBinaryRigTest) },
{ "Kinematic Rig", JPH_RTTI(KinematicRigTest) },
{ "Powered Rig", JPH_RTTI(PoweredRigTest) },
{ "Skeleton Mapper", JPH_RTTI(SkeletonMapperTest) },
{ "Rig Pile", JPH_RTTI(RigPileTest) },
{ "Big World", JPH_RTTI(BigWorldTest) }
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, CharacterTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, CharacterVirtualTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, CharacterSpaceShipTest)
static TestNameAndRTTI sCharacterTests[] =
{
{ "Character", JPH_RTTI(CharacterTest) },
{ "Character Virtual", JPH_RTTI(CharacterVirtualTest) },
{ "Character Virtual vs Space Ship", JPH_RTTI(CharacterSpaceShipTest) },
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, WaterShapeTest)
static TestNameAndRTTI sWaterTests[] =
{
{ "Shapes", JPH_RTTI(WaterShapeTest) },
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, VehicleSixDOFTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, VehicleConstraintTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, MotorcycleTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, TankTest)
static TestNameAndRTTI sVehicleTests[] =
{
{ "Car (VehicleConstraint)", JPH_RTTI(VehicleConstraintTest) },
{ "Motorcycle (VehicleConstraint)", JPH_RTTI(MotorcycleTest) },
{ "Tank (VehicleConstraint)", JPH_RTTI(TankTest) },
{ "Car (SixDOFConstraint)", JPH_RTTI(VehicleSixDOFTest) },
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SoftBodyShapesTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SoftBodyFrictionTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SoftBodyRestitutionTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SoftBodyPressureTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SoftBodyGravityFactorTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SoftBodyKinematicTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SoftBodyUpdatePositionTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, SoftBodyStressTest)
static TestNameAndRTTI sSoftBodyTests[] =
{
{ "Soft Body vs Shapes", JPH_RTTI(SoftBodyShapesTest) },
{ "Soft Body Friction", JPH_RTTI(SoftBodyFrictionTest) },
{ "Soft Body Restitution", JPH_RTTI(SoftBodyRestitutionTest) },
{ "Soft Body Pressure", JPH_RTTI(SoftBodyPressureTest) },
{ "Soft Body Gravity Factor", JPH_RTTI(SoftBodyGravityFactorTest) },
{ "Soft Body Kinematic", JPH_RTTI(SoftBodyKinematicTest) },
{ "Soft Body Update Position", JPH_RTTI(SoftBodyUpdatePositionTest) },
{ "Soft Body Stress Test", JPH_RTTI(SoftBodyStressTest) },
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, BroadPhaseCastRayTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, BroadPhaseInsertionTest)
static TestNameAndRTTI sBroadPhaseTests[] =
{
{ "Cast Ray", JPH_RTTI(BroadPhaseCastRayTest) },
{ "Insertion", JPH_RTTI(BroadPhaseInsertionTest) }
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, InteractivePairsTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, EPATest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ClosestPointTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ConvexHullTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, ConvexHullShrinkTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, RandomRayTest)
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, CapsuleVsBoxTest)
static TestNameAndRTTI sConvexCollisionTests[] =
{
{ "Interactive Pairs", JPH_RTTI(InteractivePairsTest) },
{ "EPA Test", JPH_RTTI(EPATest) },
{ "Closest Point", JPH_RTTI(ClosestPointTest) },
{ "Convex Hull", JPH_RTTI(ConvexHullTest) },
{ "Convex Hull Shrink", JPH_RTTI(ConvexHullShrinkTest) },
{ "Random Ray", JPH_RTTI(RandomRayTest) },
{ "Capsule Vs Box", JPH_RTTI(CapsuleVsBoxTest) }
};
JPH_DECLARE_RTTI_FOR_FACTORY(JPH_NO_EXPORT, LoadSnapshotTest)
static TestNameAndRTTI sTools[] =
{
{ "Load Snapshot", JPH_RTTI(LoadSnapshotTest) },
};
static TestCategory sAllCategories[] =
{
{ "General", sGeneralTests, size(sGeneralTests) },
{ "Shapes", sShapeTests, size(sShapeTests) },
{ "Scaled Shapes", sScaledShapeTests, size(sScaledShapeTests) },
{ "Constraints", sConstraintTests, size(sConstraintTests) },
{ "Rig", sRigTests, size(sRigTests) },
{ "Character", sCharacterTests, size(sCharacterTests) },
{ "Water", sWaterTests, size(sWaterTests) },
{ "Vehicle", sVehicleTests, size(sVehicleTests) },
{ "Soft Body", sSoftBodyTests, size(sSoftBodyTests) },
{ "Broad Phase", sBroadPhaseTests, size(sBroadPhaseTests) },
{ "Convex Collision", sConvexCollisionTests, size(sConvexCollisionTests) },
{ "Tools", sTools, size(sTools) }
};
//-----------------------------------------------------------------------------
// Configuration
//-----------------------------------------------------------------------------
static constexpr uint cNumBodies = 10240;
static constexpr uint cNumBodyMutexes = 0; // Autodetect
static constexpr uint cMaxBodyPairs = 65536;
static constexpr uint cMaxContactConstraints = 20480;
SamplesApp::SamplesApp()
{
// Allocate temp memory
#ifdef JPH_DISABLE_TEMP_ALLOCATOR
mTempAllocator = new TempAllocatorMalloc();
#else
mTempAllocator = new TempAllocatorImpl(32 * 1024 * 1024);
#endif
// Create job system
mJobSystem = new JobSystemSingleThreaded(cMaxPhysicsJobs);// , cMaxPhysicsBarriers, mMaxConcurrentJobs - 1);
// Create single threaded job system for validating
mJobSystemValidating = new JobSystemSingleThreaded(cMaxPhysicsJobs);
{
// Disable allocation checking
DisableCustomMemoryHook dcmh;
// Create UI
UIElement *main_menu = mDebugUI->CreateMenu();
mDebugUI->CreateTextButton(main_menu, "Select Test", [this]() {
UIElement *tests = mDebugUI->CreateMenu();
for (TestCategory &c : sAllCategories)
{
mDebugUI->CreateTextButton(tests, c.mName, [=]() {
UIElement *category = mDebugUI->CreateMenu();
for (uint j = 0; j < c.mNumTests; ++j)
mDebugUI->CreateTextButton(category, c.mTests[j].mName, [=]() { StartTest(c.mTests[j].mRTTI); });
mDebugUI->ShowMenu(category);
});
}
mDebugUI->ShowMenu(tests);
});
mTestSettingsButton = mDebugUI->CreateTextButton(main_menu, "Test Settings", [this](){
UIElement *test_settings = mDebugUI->CreateMenu();
mTest->CreateSettingsMenu(mDebugUI, test_settings);
mDebugUI->ShowMenu(test_settings);
});
mDebugUI->CreateTextButton(main_menu, "Restart Test (R)", [this]() { StartTest(mTestClass); });
mDebugUI->CreateTextButton(main_menu, "Run All Tests", [this]() { RunAllTests(); });
mNextTestButton = mDebugUI->CreateTextButton(main_menu, "Next Test (N)", [this]() { NextTest(); });
mNextTestButton->SetDisabled(true);
mDebugUI->CreateTextButton(main_menu, "Take Snapshot", [this]() { TakeSnapshot(); });
mDebugUI->CreateTextButton(main_menu, "Take And Reload Snapshot", [this]() { TakeAndReloadSnapshot(); });
mDebugUI->CreateTextButton(main_menu, "Physics Settings", [this]() {
UIElement *phys_settings = mDebugUI->CreateMenu();
mDebugUI->CreateSlider(phys_settings, "Max Concurrent Jobs", float(mMaxConcurrentJobs), 1, float(thread::hardware_concurrency()), 1, [this](float inValue) { mMaxConcurrentJobs = (int)inValue; });
mDebugUI->CreateSlider(phys_settings, "Gravity (m/s^2)", -mPhysicsSystem->GetGravity().GetY(), 0.0f, 20.0f, 1.0f, [this](float inValue) { mPhysicsSystem->SetGravity(Vec3(0, -inValue, 0)); });
mDebugUI->CreateSlider(phys_settings, "Update Frequency (Hz)", mUpdateFrequency, 7.5f, 300.0f, 2.5f, [this](float inValue) { mUpdateFrequency = inValue; });
mDebugUI->CreateSlider(phys_settings, "Num Collision Steps", float(mCollisionSteps), 1.0f, 4.0f, 1.0f, [this](float inValue) { mCollisionSteps = int(inValue); });
mDebugUI->CreateSlider(phys_settings, "Num Velocity Steps", float(mPhysicsSettings.mNumVelocitySteps), 0, 30, 1, [this](float inValue) { mPhysicsSettings.mNumVelocitySteps = int(round(inValue)); mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateSlider(phys_settings, "Num Position Steps", float(mPhysicsSettings.mNumPositionSteps), 0, 30, 1, [this](float inValue) { mPhysicsSettings.mNumPositionSteps = int(round(inValue)); mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateSlider(phys_settings, "Baumgarte Stabilization Factor", mPhysicsSettings.mBaumgarte, 0.01f, 1.0f, 0.05f, [this](float inValue) { mPhysicsSettings.mBaumgarte = inValue; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateSlider(phys_settings, "Speculative Contact Distance (m)", mPhysicsSettings.mSpeculativeContactDistance, 0.0f, 0.1f, 0.005f, [this](float inValue) { mPhysicsSettings.mSpeculativeContactDistance = inValue; });
mDebugUI->CreateSlider(phys_settings, "Penetration Slop (m)", mPhysicsSettings.mPenetrationSlop, 0.0f, 0.1f, 0.005f, [this](float inValue) { mPhysicsSettings.mPenetrationSlop = inValue; });
mDebugUI->CreateSlider(phys_settings, "Linear Cast Threshold", mPhysicsSettings.mLinearCastThreshold, 0.0f, 1.0f, 0.05f, [this](float inValue) { mPhysicsSettings.mLinearCastThreshold = inValue; });
mDebugUI->CreateSlider(phys_settings, "Min Velocity For Restitution (m/s)", mPhysicsSettings.mMinVelocityForRestitution, 0.0f, 10.0f, 0.1f, [this](float inValue) { mPhysicsSettings.mMinVelocityForRestitution = inValue; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateSlider(phys_settings, "Time Before Sleep (s)", mPhysicsSettings.mTimeBeforeSleep, 0.1f, 1.0f, 0.1f, [this](float inValue) { mPhysicsSettings.mTimeBeforeSleep = inValue; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateSlider(phys_settings, "Point Velocity Sleep Threshold (m/s)", mPhysicsSettings.mPointVelocitySleepThreshold, 0.01f, 1.0f, 0.01f, [this](float inValue) { mPhysicsSettings.mPointVelocitySleepThreshold = inValue; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
#if defined(_DEBUG) && !defined(JPH_DISABLE_CUSTOM_ALLOCATOR) && !defined(JPH_COMPILER_MINGW)
mDebugUI->CreateCheckBox(phys_settings, "Enable Checking Memory Hook", IsCustomMemoryHookEnabled(), [](UICheckBox::EState inState) { EnableCustomMemoryHook(inState == UICheckBox::STATE_CHECKED); });
#endif
mDebugUI->CreateCheckBox(phys_settings, "Deterministic Simulation", mPhysicsSettings.mDeterministicSimulation, [this](UICheckBox::EState inState) { mPhysicsSettings.mDeterministicSimulation = inState == UICheckBox::STATE_CHECKED; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateCheckBox(phys_settings, "Constraint Warm Starting", mPhysicsSettings.mConstraintWarmStart, [this](UICheckBox::EState inState) { mPhysicsSettings.mConstraintWarmStart = inState == UICheckBox::STATE_CHECKED; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateCheckBox(phys_settings, "Use Body Pair Contact Cache", mPhysicsSettings.mUseBodyPairContactCache, [this](UICheckBox::EState inState) { mPhysicsSettings.mUseBodyPairContactCache = inState == UICheckBox::STATE_CHECKED; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateCheckBox(phys_settings, "Contact Manifold Reduction", mPhysicsSettings.mUseManifoldReduction, [this](UICheckBox::EState inState) { mPhysicsSettings.mUseManifoldReduction = inState == UICheckBox::STATE_CHECKED; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateCheckBox(phys_settings, "Use Large Island Splitter", mPhysicsSettings.mUseLargeIslandSplitter, [this](UICheckBox::EState inState) { mPhysicsSettings.mUseLargeIslandSplitter = inState == UICheckBox::STATE_CHECKED; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateCheckBox(phys_settings, "Allow Sleeping", mPhysicsSettings.mAllowSleeping, [this](UICheckBox::EState inState) { mPhysicsSettings.mAllowSleeping = inState == UICheckBox::STATE_CHECKED; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateCheckBox(phys_settings, "Check Active Triangle Edges", mPhysicsSettings.mCheckActiveEdges, [this](UICheckBox::EState inState) { mPhysicsSettings.mCheckActiveEdges = inState == UICheckBox::STATE_CHECKED; mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings); });
mDebugUI->CreateCheckBox(phys_settings, "Record State For Playback", mRecordState, [this](UICheckBox::EState inState) { mRecordState = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(phys_settings, "Check Determinism", mCheckDeterminism, [this](UICheckBox::EState inState) { mCheckDeterminism = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(phys_settings, "Install Contact Listener", mInstallContactListener, [this](UICheckBox::EState inState) { mInstallContactListener = inState == UICheckBox::STATE_CHECKED; StartTest(mTestClass); });
mDebugUI->ShowMenu(phys_settings);
});
#ifdef JPH_DEBUG_RENDERER
mDebugUI->CreateTextButton(main_menu, "Drawing Options", [this]() {
UIElement *drawing_options = mDebugUI->CreateMenu();
mDebugUI->CreateCheckBox(drawing_options, "Draw Shapes (H)", mBodyDrawSettings.mDrawShape, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawShape = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Shapes Wireframe (Alt+W)", mBodyDrawSettings.mDrawShapeWireframe, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawShapeWireframe = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateComboBox(drawing_options, "Draw Shape Color", { "Instance", "Shape Type", "Motion Type", "Sleep", "Island", "Material" }, (int)mBodyDrawSettings.mDrawShapeColor, [this](int inItem) { mBodyDrawSettings.mDrawShapeColor = (BodyManager::EShapeColor)inItem; });
mDebugUI->CreateCheckBox(drawing_options, "Draw GetSupport + Cvx Radius (Shift+H)", mBodyDrawSettings.mDrawGetSupportFunction, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawGetSupportFunction = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Shapes Using GetTrianglesStart/Next (Alt+H)", mDrawGetTriangles, [this](UICheckBox::EState inState) { mDrawGetTriangles = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw GetSupport Direction", mBodyDrawSettings.mDrawSupportDirection, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawSupportDirection = inState == UICheckBox::STATE_CHECKED; mBodyDrawSettings.mDrawGetSupportFunction |= mBodyDrawSettings.mDrawSupportDirection; });
mDebugUI->CreateCheckBox(drawing_options, "Draw GetSupportingFace (Shift+F)", mBodyDrawSettings.mDrawGetSupportingFace, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawGetSupportingFace = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Constraints (C)", mDrawConstraints, [this](UICheckBox::EState inState) { mDrawConstraints = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Constraint Limits (L)", mDrawConstraintLimits, [this](UICheckBox::EState inState) { mDrawConstraintLimits = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Constraint Reference Frame", mDrawConstraintReferenceFrame, [this](UICheckBox::EState inState) { mDrawConstraintReferenceFrame = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Contact Point (1)", ContactConstraintManager::sDrawContactPoint, [](UICheckBox::EState inState) { ContactConstraintManager::sDrawContactPoint = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Supporting Faces (2)", ContactConstraintManager::sDrawSupportingFaces, [](UICheckBox::EState inState) { ContactConstraintManager::sDrawSupportingFaces = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Contact Point Reduction (3)", ContactConstraintManager::sDrawContactPointReduction, [](UICheckBox::EState inState) { ContactConstraintManager::sDrawContactPointReduction = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Contact Manifolds (M)", ContactConstraintManager::sDrawContactManifolds, [](UICheckBox::EState inState) { ContactConstraintManager::sDrawContactManifolds = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Motion Quality Linear Cast", PhysicsSystem::sDrawMotionQualityLinearCast, [](UICheckBox::EState inState) { PhysicsSystem::sDrawMotionQualityLinearCast = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Bounding Boxes", mBodyDrawSettings.mDrawBoundingBox, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawBoundingBox = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Center of Mass Transforms", mBodyDrawSettings.mDrawCenterOfMassTransform, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawCenterOfMassTransform = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw World Transforms", mBodyDrawSettings.mDrawWorldTransform, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawWorldTransform = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Velocity", mBodyDrawSettings.mDrawVelocity, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawVelocity = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Sleep Stats", mBodyDrawSettings.mDrawSleepStats, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawSleepStats = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Mass and Inertia (I)", mBodyDrawSettings.mDrawMassAndInertia, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawMassAndInertia = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Joints", mPoseDrawSettings.mDrawJoints, [this](UICheckBox::EState inState) { mPoseDrawSettings.mDrawJoints = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Joint Orientations", mPoseDrawSettings.mDrawJointOrientations, [this](UICheckBox::EState inState) { mPoseDrawSettings.mDrawJointOrientations = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Joint Names", mPoseDrawSettings.mDrawJointNames, [this](UICheckBox::EState inState) { mPoseDrawSettings.mDrawJointNames = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Convex Hull Shape Face Outlines", ConvexHullShape::sDrawFaceOutlines, [](UICheckBox::EState inState) { ConvexHullShape::sDrawFaceOutlines = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Mesh Shape Triangle Groups", MeshShape::sDrawTriangleGroups, [](UICheckBox::EState inState) { MeshShape::sDrawTriangleGroups = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Mesh Shape Triangle Outlines", MeshShape::sDrawTriangleOutlines, [](UICheckBox::EState inState) { MeshShape::sDrawTriangleOutlines = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Height Field Shape Triangle Outlines", HeightFieldShape::sDrawTriangleOutlines, [](UICheckBox::EState inState) { HeightFieldShape::sDrawTriangleOutlines = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Submerged Volumes", Shape::sDrawSubmergedVolumes, [](UICheckBox::EState inState) { Shape::sDrawSubmergedVolumes = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Character Virtual Constraints", CharacterVirtual::sDrawConstraints, [](UICheckBox::EState inState) { CharacterVirtual::sDrawConstraints = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Character Virtual Walk Stairs", CharacterVirtual::sDrawWalkStairs, [](UICheckBox::EState inState) { CharacterVirtual::sDrawWalkStairs = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Character Virtual Stick To Floor", CharacterVirtual::sDrawStickToFloor, [](UICheckBox::EState inState) { CharacterVirtual::sDrawStickToFloor = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Soft Body Vertices", mBodyDrawSettings.mDrawSoftBodyVertices, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawSoftBodyVertices = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Soft Body Edge Constraints", mBodyDrawSettings.mDrawSoftBodyEdgeConstraints, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawSoftBodyEdgeConstraints = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Soft Body Volume Constraints", mBodyDrawSettings.mDrawSoftBodyVolumeConstraints, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawSoftBodyVolumeConstraints = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(drawing_options, "Draw Soft Body Predicted Bounds", mBodyDrawSettings.mDrawSoftBodyPredictedBounds, [this](UICheckBox::EState inState) { mBodyDrawSettings.mDrawSoftBodyPredictedBounds = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->ShowMenu(drawing_options);
});
#endif // JPH_DEBUG_RENDERER
mDebugUI->CreateTextButton(main_menu, "Mouse Probe", [this]() {
UIElement *probe_options = mDebugUI->CreateMenu();
mDebugUI->CreateComboBox(probe_options, "Mode", { "Pick", "Ray", "RayCollector", "CollidePoint", "CollideShape", "CastShape", "CollideSoftBody", "TransfShape", "GetTriangles", "BP Ray", "BP Box", "BP Sphere", "BP Point", "BP OBox", "BP Cast Box" }, (int)mProbeMode, [this](int inItem) { mProbeMode = (EProbeMode)inItem; });
mDebugUI->CreateComboBox(probe_options, "Shape", { "Sphere", "Box", "ConvexHull", "Capsule", "TaperedCapsule", "Cylinder", "Triangle", "StaticCompound", "StaticCompound2", "MutableCompound", "Mesh" }, (int)mProbeShape, [=](int inItem) { mProbeShape = (EProbeShape)inItem; });
mDebugUI->CreateCheckBox(probe_options, "Scale Shape", mScaleShape, [this](UICheckBox::EState inState) { mScaleShape = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateSlider(probe_options, "Scale X", mShapeScale.GetX(), -5.0f, 5.0f, 0.1f, [this](float inValue) { mShapeScale.SetX(inValue); });
mDebugUI->CreateSlider(probe_options, "Scale Y", mShapeScale.GetY(), -5.0f, 5.0f, 0.1f, [this](float inValue) { mShapeScale.SetY(inValue); });
mDebugUI->CreateSlider(probe_options, "Scale Z", mShapeScale.GetZ(), -5.0f, 5.0f, 0.1f, [this](float inValue) { mShapeScale.SetZ(inValue); });
mDebugUI->CreateComboBox(probe_options, "Back Face Cull", { "On", "Off" }, (int)mBackFaceMode, [=](int inItem) { mBackFaceMode = (EBackFaceMode)inItem; });
mDebugUI->CreateComboBox(probe_options, "Active Edge Mode", { "Only Active", "All" }, (int)mActiveEdgeMode, [=](int inItem) { mActiveEdgeMode = (EActiveEdgeMode)inItem; });
mDebugUI->CreateComboBox(probe_options, "Collect Faces Mode", { "Collect Faces", "No Faces" }, (int)mCollectFacesMode, [=](int inItem) { mCollectFacesMode = (ECollectFacesMode)inItem; });
mDebugUI->CreateSlider(probe_options, "Max Separation Distance", mMaxSeparationDistance, 0.0f, 5.0f, 0.1f, [this](float inValue) { mMaxSeparationDistance = inValue; });
mDebugUI->CreateCheckBox(probe_options, "Treat Convex As Solid", mTreatConvexAsSolid, [this](UICheckBox::EState inState) { mTreatConvexAsSolid = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(probe_options, "Return Deepest Point", mReturnDeepestPoint, [this](UICheckBox::EState inState) { mReturnDeepestPoint = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(probe_options, "Shrunken Shape + Convex Radius", mUseShrunkenShapeAndConvexRadius, [this](UICheckBox::EState inState) { mUseShrunkenShapeAndConvexRadius = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateCheckBox(probe_options, "Draw Supporting Face", mDrawSupportingFace, [this](UICheckBox::EState inState) { mDrawSupportingFace = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateSlider(probe_options, "Max Hits", float(mMaxHits), 0, 10, 1, [this](float inValue) { mMaxHits = (int)inValue; });
mDebugUI->ShowMenu(probe_options);
});
mDebugUI->CreateTextButton(main_menu, "Shoot Object", [this]() {
UIElement *shoot_options = mDebugUI->CreateMenu();
mDebugUI->CreateTextButton(shoot_options, "Shoot Object (B)", [=]() { ShootObject(); });
mDebugUI->CreateSlider(shoot_options, "Initial Velocity", mShootObjectVelocity, 0.0f, 500.0f, 10.0f, [this](float inValue) { mShootObjectVelocity = inValue; });
mDebugUI->CreateComboBox(shoot_options, "Shape", { "Sphere", "ConvexHull", "Thin Bar", "Soft Body Cube" }, (int)mShootObjectShape, [=](int inItem) { mShootObjectShape = (EShootObjectShape)inItem; });
mDebugUI->CreateComboBox(shoot_options, "Motion Quality", { "Discrete", "LinearCast" }, (int)mShootObjectMotionQuality, [=](int inItem) { mShootObjectMotionQuality = (EMotionQuality)inItem; });
mDebugUI->CreateSlider(shoot_options, "Friction", mShootObjectFriction, 0.0f, 1.0f, 0.05f, [this](float inValue) { mShootObjectFriction = inValue; });
mDebugUI->CreateSlider(shoot_options, "Restitution", mShootObjectRestitution, 0.0f, 1.0f, 0.05f, [this](float inValue) { mShootObjectRestitution = inValue; });
mDebugUI->CreateCheckBox(shoot_options, "Scale Shape", mShootObjectScaleShape, [this](UICheckBox::EState inState) { mShootObjectScaleShape = inState == UICheckBox::STATE_CHECKED; });
mDebugUI->CreateSlider(shoot_options, "Scale X", mShootObjectShapeScale.GetX(), -5.0f, 5.0f, 0.1f, [this](float inValue) { mShootObjectShapeScale.SetX(inValue); });
mDebugUI->CreateSlider(shoot_options, "Scale Y", mShootObjectShapeScale.GetY(), -5.0f, 5.0f, 0.1f, [this](float inValue) { mShootObjectShapeScale.SetY(inValue); });
mDebugUI->CreateSlider(shoot_options, "Scale Z", mShootObjectShapeScale.GetZ(), -5.0f, 5.0f, 0.1f, [this](float inValue) { mShootObjectShapeScale.SetZ(inValue); });
mDebugUI->ShowMenu(shoot_options);
});
mDebugUI->CreateTextButton(main_menu, "Help", [this](){
UIElement *help = mDebugUI->CreateMenu();
mDebugUI->CreateStaticText(help,
"ESC: Back to previous menu.\n"
"WASD + Mouse: Fly around. Hold Shift to speed up, Ctrl to slow down.\n"
"Space: Hold to pick up and drag a physics object under the crosshair.\n"
"P: Pause / unpause simulation.\n"
"O: Single step the simulation.\n"
",: Step back (only when Physics Settings / Record State for Playback is on).\n"
".: Step forward (only when Physics Settings / Record State for Playback is on).\n"
"Shift + ,: Play reverse (only when Physics Settings / Record State for Playback is on).\n"
"Shift + .: Replay forward (only when Physics Settings / Record State for Playback is on).\n"
"T: Dump frame timing information to profile_*.html (when JPH_PROFILE_ENABLED defined)."
);
mDebugUI->ShowMenu(help);
});
mDebugUI->ShowMenu(main_menu);
}
// Get test name from commandline
String cmd_line = ToLower(GetCommandLineA());
Array<String> args;
StringToVector(cmd_line, args, " ");
if (args.size() == 2)
{
String cmd = args[1];
if (cmd == "alltests")
{
// Run all tests
mCheckDeterminism = true;
mExitAfterRunningTests = true;
RunAllTests();
}
else
{
// Search for the test
const RTTI* test = JPH_RTTI(BoxShapeTest);// LoadRigTest);
for (TestCategory &c : sAllCategories)
for (uint i = 0; i < c.mNumTests; ++i)
{
TestNameAndRTTI &t = c.mTests[i];
String test_name = ToLower(t.mRTTI->GetName());
if (test_name == cmd)
{
test = t.mRTTI;
break;
}
}
// Construct test
StartTest(test);
}
}
else
{
// Otherwise start default test
StartTest(JPH_RTTI(BoxShapeTest));// LoadRigTest));
}
}
SamplesApp::~SamplesApp()
{
// Clean up
delete mTest;
delete mContactListener;
delete mPhysicsSystem;
delete mJobSystemValidating;
delete mJobSystem;
delete mTempAllocator;
}
void SamplesApp::StartTest(const RTTI *inRTTI)
{
// Pop active menus, we might be in the settings menu for the test which will be dangling after restarting the test
mDebugUI->BackToMain();
// Store old gravity
Vec3 old_gravity = mPhysicsSystem != nullptr? mPhysicsSystem->GetGravity() : Vec3(0, -9.81f, 0);
// Discard old test
delete mTest;
delete mContactListener;
delete mPhysicsSystem;
// Create physics system
mPhysicsSystem = new PhysicsSystem();
mPhysicsSystem->Init(cNumBodies, cNumBodyMutexes, cMaxBodyPairs, cMaxContactConstraints, mBroadPhaseLayerInterface, mObjectVsBroadPhaseLayerFilter, mObjectVsObjectLayerFilter);
mPhysicsSystem->SetPhysicsSettings(mPhysicsSettings);
// Restore gravity
mPhysicsSystem->SetGravity(old_gravity);
PhysicsManager::Instance()->SetPhysicsSystem(mPhysicsSystem);
// Reset dragging
mDragAnchor = nullptr;
mDragBody = BodyID();
mDragConstraint = nullptr;
mDragVertexIndex = ~uint(0);
mDragVertexPreviousInvMass = 0.0f;
mDragFraction = 0.0f;
// Reset playback state
mPlaybackFrames.clear();
mPlaybackMode = EPlaybackMode::Play;
mCurrentPlaybackFrame = -1;
// Set new test
mTestClass = inRTTI;
mTest = static_cast<Test *>(inRTTI->CreateObject());
mTest->SetPhysicsSystem(mPhysicsSystem);
mTest->SetJobSystem(mJobSystem);
mTest->SetDebugRenderer(mDebugRenderer);
mTest->SetTempAllocator(mTempAllocator);
if (mInstallContactListener)
{
mContactListener = new ContactListenerImpl;
mContactListener->SetNextListener(mTest->GetContactListener());
mPhysicsSystem->SetContactListener(mContactListener);
}
else
{
mContactListener = nullptr;
mPhysicsSystem->SetContactListener(mTest->GetContactListener());
}
mTest->Initialize();
// Optimize the broadphase to make the first update fast
mPhysicsSystem->OptimizeBroadPhase();
// Make the world render relative to offset specified by test
mRenderer->SetBaseOffset(mTest->GetDrawOffset());
// Reset the camera to the original position
ResetCamera();
// Start paused
Pause(true);
SingleStep();
// Check if test has settings menu
mTestSettingsButton->SetDisabled(!mTest->HasSettingsMenu());
g_SoccerPitch = new SoccerPitch(WindowWidth, WindowHeight);
g_MatchReplay = new Snapshot();
}
void SamplesApp::RunAllTests()
{
mTestsToRun.clear();
for (const TestCategory &c : sAllCategories)
for (uint i = 0; i < c.mNumTests; ++i)
{
TestNameAndRTTI &t = c.mTests[i];
mTestsToRun.push_back(t.mRTTI);
}
NextTest();
}
bool SamplesApp::NextTest()
{
if (mTestsToRun.empty())
{
if (mExitAfterRunningTests)
return false; // Exit the application now
else
MessageBoxA(nullptr, "Test run complete!", "Complete", MB_OK);
}
else
{
// Start the timer for 10 seconds
mTestTimeLeft = 10.0f;
// Take next test
const RTTI *rtti = mTestsToRun.front();
mTestsToRun.erase(mTestsToRun.begin());
// Start it
StartTest(rtti);
// Unpause
Pause(false);
}
mNextTestButton->SetDisabled(mTestsToRun.empty());
return true;
}
bool SamplesApp::CheckNextTest()
{
if (mTestTimeLeft >= 0.0f)
{
// Update status string
if (!mStatusString.empty())
mStatusString += "\n";
mStatusString += StringFormat("%s: Next test in %.1fs", mTestClass->GetName(), (double)mTestTimeLeft);
// Use physics time
mTestTimeLeft -= 1.0f / mUpdateFrequency;
// If time's up then go to the next test
if (mTestTimeLeft < 0.0f)
return NextTest();
}
return true;
}
void SamplesApp::TakeSnapshot()
{
// Convert physics system to scene
Ref<PhysicsScene> scene = new PhysicsScene();
scene->FromPhysicsSystem(mPhysicsSystem);
// Save scene
ofstream stream("snapshot.bin", ofstream::out | ofstream::trunc | ofstream::binary);
StreamOutWrapper wrapper(stream);
if (stream.is_open())
scene->SaveBinaryState(wrapper, true, true);
}
void SamplesApp::TakeAndReloadSnapshot()
{
TakeSnapshot();
StartTest(JPH_RTTI(LoadSnapshotTest));
}
RefConst<Shape> SamplesApp::CreateProbeShape()
{
// Get the scale
Vec3 scale = mScaleShape? mShapeScale : Vec3::sReplicate(1.0f);
// Make it minimally -0.1 or 0.1 depending on the sign
Vec3 clamped_value = Vec3::sSelect(Vec3::sReplicate(-0.1f), Vec3::sReplicate(0.1f), Vec3::sGreaterOrEqual(scale, Vec3::sZero()));
scale = Vec3::sSelect(scale, clamped_value, Vec3::sLess(scale.Abs(), Vec3::sReplicate(0.1f)));
RefConst<Shape> shape;
switch (mProbeShape)
{
case EProbeShape::Sphere:
scale = scale.Swizzle<SWIZZLE_X, SWIZZLE_X, SWIZZLE_X>(); // Only uniform scale supported
shape = new SphereShape(0.2f);
break;
case EProbeShape::Box:
shape = new BoxShape(Vec3(0.1f, 0.2f, 0.3f));
break;
case EProbeShape::ConvexHull:
{
// Create tetrahedron
Array<Vec3> tetrahedron;
tetrahedron.push_back(Vec3::sZero());
tetrahedron.push_back(Vec3(0.2f, 0, 0.4f));
tetrahedron.push_back(Vec3(0.4f, 0, 0));
tetrahedron.push_back(Vec3(0.2f, -0.2f, 1.0f));
shape = ConvexHullShapeSettings(tetrahedron, 0.01f).Create().Get();
}
break;
case EProbeShape::Capsule:
scale = scale.Swizzle<SWIZZLE_X, SWIZZLE_X, SWIZZLE_X>(); // Only uniform scale supported
shape = new CapsuleShape(0.2f, 0.1f);
break;
case EProbeShape::TaperedCapsule:
scale = scale.Swizzle<SWIZZLE_X, SWIZZLE_X, SWIZZLE_X>(); // Only uniform scale supported
shape = TaperedCapsuleShapeSettings(0.2f, 0.1f, 0.2f).Create().Get();
break;
case EProbeShape::Cylinder:
scale = scale.Swizzle<SWIZZLE_X, SWIZZLE_Y, SWIZZLE_X>(); // Scale X must be same as Z
shape = new CylinderShape(0.2f, 0.1f);
break;
case EProbeShape::Triangle:
scale = scale.Swizzle<SWIZZLE_X, SWIZZLE_X, SWIZZLE_X>(); // Only uniform scale supported
shape = new TriangleShape(Vec3(0.1f, 0.9f, 0.3f), Vec3(-0.9f, -0.5f, 0.2f), Vec3(0.7f, -0.3f, -0.1f));
break;
case EProbeShape::StaticCompound:
{
Array<Vec3> tetrahedron;
tetrahedron.push_back(Vec3::sZero());
tetrahedron.push_back(Vec3(-0.2f, 0, 0.4f));
tetrahedron.push_back(Vec3(0, 0.2f, 0));
tetrahedron.push_back(Vec3(0.2f, 0, 0.4f));
RefConst<Shape> convex = ConvexHullShapeSettings(tetrahedron, 0.01f).Create().Get();
StaticCompoundShapeSettings compound_settings;
compound_settings.AddShape(Vec3(-0.5f, 0, 0), Quat::sIdentity(), convex);
compound_settings.AddShape(Vec3(0.5f, 0, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), convex);
shape = compound_settings.Create().Get();
}
break;
case EProbeShape::StaticCompound2:
{
scale = scale.Swizzle<SWIZZLE_X, SWIZZLE_X, SWIZZLE_X>(); // Only uniform scale supported
Ref<StaticCompoundShapeSettings> compound = new StaticCompoundShapeSettings();
compound->AddShape(Vec3(0, 0.5f, 0), Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI), new BoxShape(Vec3(0.5f, 0.15f, 0.1f)));
compound->AddShape(Vec3(0.5f, 0, 0), Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI), new CylinderShape(0.5f, 0.1f));
compound->AddShape(Vec3(0, 0, 0.5f), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), new TaperedCapsuleShapeSettings(0.5f, 0.15f, 0.1f));
StaticCompoundShapeSettings compound2;
compound2.AddShape(Vec3(0, 0, 0), Quat::sRotation(Vec3::sAxisX(), -0.25f * JPH_PI) * Quat::sRotation(Vec3::sAxisZ(), 0.25f * JPH_PI), compound);
compound2.AddShape(Vec3(0, -0.4f, 0), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI) * Quat::sRotation(Vec3::sAxisZ(), -0.75f * JPH_PI), compound);
shape = compound2.Create().Get();
}
break;
case EProbeShape::MutableCompound:
{
Array<Vec3> tetrahedron;
tetrahedron.push_back(Vec3::sZero());
tetrahedron.push_back(Vec3(-0.2f, 0, 0.4f));
tetrahedron.push_back(Vec3(0, 0.2f, 0));
tetrahedron.push_back(Vec3(0.2f, 0, 0.4f));
RefConst<Shape> convex = ConvexHullShapeSettings(tetrahedron, 0.01f).Create().Get();
MutableCompoundShapeSettings compound_settings;
compound_settings.AddShape(Vec3(-0.5f, 0, 0), Quat::sIdentity(), convex);
compound_settings.AddShape(Vec3(0.5f, 0, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), convex);
shape = compound_settings.Create().Get();
}
break;
case EProbeShape::Mesh:
shape = ShapeCreator::CreateTorusMesh(2.0f, 0.25f);
break;
}
JPH_ASSERT(shape != nullptr);
// Scale the shape
if (scale != Vec3::sReplicate(1.0f))
shape = new ScaledShape(shape, scale);
return shape;
}
RefConst<Shape> SamplesApp::CreateShootObjectShape()
{
// Get the scale
Vec3 scale = mShootObjectScaleShape? mShootObjectShapeScale : Vec3::sReplicate(1.0f);
// Make it minimally -0.1 or 0.1 depending on the sign
Vec3 clamped_value = Vec3::sSelect(Vec3::sReplicate(-0.1f), Vec3::sReplicate(0.1f), Vec3::sGreaterOrEqual(scale, Vec3::sZero()));
scale = Vec3::sSelect(scale, clamped_value, Vec3::sLess(scale.Abs(), Vec3::sReplicate(0.1f)));
RefConst<Shape> shape;
switch (mShootObjectShape)
{
case EShootObjectShape::Sphere:
scale = scale.Swizzle<SWIZZLE_X, SWIZZLE_X, SWIZZLE_X>(); // Only uniform scale supported
shape = new SphereShape(GetWorldScale());
break;
case EShootObjectShape::ConvexHull:
{
Array<Vec3> vertices = {
Vec3(-0.044661f, 0.001230f, 0.003877f),
Vec3(-0.024743f, -0.042562f, 0.003877f),
Vec3(-0.012336f, -0.021073f, 0.048484f),
Vec3(0.016066f, 0.028121f, -0.049904f),
Vec3(-0.023734f, 0.043275f, -0.024153f),
Vec3(0.020812f, 0.036341f, -0.019530f),
Vec3(0.012495f, 0.021936f, 0.045288f),
Vec3(0.026750f, 0.001230f, 0.049273f),
Vec3(0.045495f, 0.001230f, -0.022077f),
Vec3(0.022193f, -0.036274f, -0.021126f),
Vec3(0.022781f, -0.037291f, 0.029558f),
Vec3(0.014691f, -0.023280f, 0.052897f),
Vec3(-0.012187f, -0.020815f, -0.040214f),