-
Notifications
You must be signed in to change notification settings - Fork 3
/
fMain.frm
1225 lines (915 loc) · 35.8 KB
/
fMain.frm
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
VERSION 5.00
Begin VB.Form fMain
Caption = "3D smoothed particles hydrodynamics"
ClientHeight = 10230
ClientLeft = 120
ClientTop = 420
ClientWidth = 15120
BeginProperty Font
Name = "Tahoma"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 682
ScaleMode = 3 'Pixel
ScaleWidth = 1008
StartUpPosition = 1 'CenterOwner
Begin VB.CommandButton Command2
Caption = "R"
Height = 615
Left = 13200
TabIndex = 19
Top = 6240
Width = 615
End
Begin VB.CheckBox chkRot
Caption = "Rotate CAM"
Height = 495
Left = 12360
TabIndex = 18
Top = 9720
Width = 1695
End
Begin VB.CommandButton cmdErase
Caption = "Clean 2"
Height = 375
Index = 1
Left = 13680
TabIndex = 17
Top = 8520
Width = 1335
End
Begin VB.CommandButton cmdErase
Caption = "Clean 1"
Height = 375
Index = 0
Left = 12360
TabIndex = 16
Top = 8520
Width = 1215
End
Begin VB.CheckBox chkCOMG
Caption = "COM Gravity"
Height = 495
Left = 12360
TabIndex = 15
ToolTipText = "Center of Mass gravity"
Top = 7440
Width = 1695
End
Begin VB.CheckBox chkFaucet
Caption = "Faucet 2"
Height = 495
Index = 1
Left = 13680
TabIndex = 14
Top = 8040
Width = 1695
End
Begin VB.PictureBox picGravity
Appearance = 0 'Flat
BackColor = &H80000005&
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 1350
Left = 12360
ScaleHeight = 88
ScaleMode = 3 'Pixel
ScaleWidth = 88
TabIndex = 12
ToolTipText = "Right click for 0,0,0"
Top = 5520
Width = 1350
Begin VB.Line Line1
X1 = 72
X2 = 96
Y1 = 72
Y2 = 112
End
End
Begin VB.CheckBox chkFaucet
Caption = "Faucet 1"
Height = 495
Index = 0
Left = 12360
TabIndex = 11
Top = 8040
Width = 1335
End
Begin VB.CheckBox chkRG
Caption = "Rnd Gravity"
Height = 495
Left = 12360
TabIndex = 10
Top = 6960
Width = 1695
End
Begin VB.CheckBox chkJPG
Caption = "Save PNG Frames"
Height = 495
Left = 12360
TabIndex = 9
Top = 9240
Width = 1695
End
Begin VB.TextBox txtMaxD
Alignment = 2 'Center
Height = 390
Left = 12360
TabIndex = 8
Text = "Text1"
Top = 4320
Width = 1815
End
Begin VB.TextBox txtNP
Alignment = 2 'Center
Height = 390
Left = 12360
TabIndex = 7
Text = "Text1"
Top = 3600
Width = 1815
End
Begin VB.HScrollBar ScrollDRAW
Height = 255
Left = 12480
Max = 10
TabIndex = 3
Top = 2160
Value = 2
Width = 1815
End
Begin VB.Timer Timer1
Interval = 1000
Left = 11640
Top = 240
End
Begin VB.CheckBox chkDRAWP
Caption = "Draw Pairs"
Height = 495
Left = 12480
TabIndex = 2
Top = 2640
Visible = 0 'False
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "(re)Start"
Height = 1335
Left = 12480
TabIndex = 1
Top = 120
Width = 1455
End
Begin VB.PictureBox PIC
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 0 'None
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 5175
Left = 120
ScaleHeight = 345
ScaleMode = 3 'Pixel
ScaleWidth = 529
TabIndex = 0
ToolTipText = "Clcik and Move to Rotate Camera (Right click to Reset)"
Top = 120
Width = 7935
End
Begin VB.Label Label3
Caption = "Gravity: Click Pic."
Height = 375
Left = 12360
TabIndex = 13
Top = 5160
Width = 1695
End
Begin VB.Label Label2
Caption = "Max Dist:"
Height = 375
Left = 12360
TabIndex = 6
Top = 4080
Width = 1695
End
Begin VB.Label Label1
Caption = "N Points:"
Height = 375
Left = 12360
TabIndex = 5
Top = 3240
Width = 1695
End
Begin VB.Label lSkip
Alignment = 2 'Center
Caption = " "
BeginProperty Font
Name = "Tahoma"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 14040
TabIndex = 4
Top = 1560
Width = 1935
End
End
Attribute VB_Name = "fMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private SRF As cCairoSurface
Private CC As cCairoContext
Private RecomputeBOX As Boolean
Private InvGravScale As Single
Private Sub chkCOMG_Click()
COMGravity = chkCOMG.Value = vbChecked
End Sub
Private Sub chkDRAWP_Click()
DrawPairs = chkDRAWP.Value = vbChecked
End Sub
Private Sub chkFaucet_Click(Index As Integer)
If Index = 0 Then DoFaucet1 = chkFaucet(Index).Value = vbChecked
If Index = 1 Then DoFaucet2 = chkFaucet(Index).Value = vbChecked
End Sub
Private Sub chkJPG_Click()
DoSaveFrames = chkJPG = vbChecked
End Sub
Private Sub chkRG_Click()
rndGravity = chkRG.Value = vbChecked
End Sub
Private Sub chkRot_Click()
CamRot = chkRot.Value = vbChecked
End Sub
Private Sub cmdErase_Click(Index As Integer)
Dim I&, J&
Dim tpx() As Single
Dim tpy() As Single
Dim tpz() As Single
Dim tVx() As Single
Dim tVy() As Single
Dim tVz() As Single
Dim tPhase() As Long
ReDim tpx(NP)
ReDim tpy(NP)
ReDim tpz(NP)
ReDim tVx(NP)
ReDim tVy(NP)
ReDim tVz(NP)
ReDim tPhase(NP)
Index = Index + 1
For I = 1 To NP
If Phase(I) <> Index Then
J = J + 1
tpx(J) = px(I)
tpy(J) = py(I)
tpz(J) = pz(I)
tVx(J) = vX(I)
tVy(J) = vY(I)
tVz(J) = vZ(I)
tPhase(J) = Phase(I)
End If
Next
px() = tpx()
py() = tpy()
pz() = tpz()
vX() = tVx()
vY() = tVy()
vZ() = tVz()
Phase() = tPhase()
NP = J
ReDim Preserve px(NP)
ReDim Preserve py(NP)
ReDim Preserve pz(NP)
ReDim Preserve vX(NP)
ReDim Preserve vY(NP)
ReDim Preserve vZ(NP)
ReDim Preserve pvX(NP)
ReDim Preserve pvY(NP)
ReDim Preserve pvZ(NP)
ReDim Preserve Phase(NP)
End Sub
Private Sub Command2_Click()
gTOX = (Rnd * 2 - 1) * GravScale
gTOY = (Rnd * 2 - 1) * GravScale
gTOZ = (Rnd * 2 - 1) * GravScale * 1.1
If Rnd > 0.2 Then '0.1
If Abs(gTOX) > Abs(gTOY) And Abs(gTOX) > Abs(gTOZ) Then gTOY = 0: gTOZ = 0
If Abs(gTOY) > Abs(gTOX) And Abs(gTOY) > Abs(gTOX) Then gTOX = 0: gTOZ = 0
If Abs(gTOZ) > Abs(gTOY) And Abs(gTOZ) > Abs(gTOX) Then gTOY = 0: gTOX = 0
If Rnd < 0.1 Then gTOX = 0: gTOY = 0: gTOZ = 0
End If
Line1.X1 = picGravity.Width * 0.5
Line1.Y1 = picGravity.Height * 0.5
Line1.X2 = Line1.X1 + gTOX * picGravity.Width * 0.5 * InvGravScale
Line1.Y2 = Line1.Y1 + gTOY * picGravity.Height * 0.5 * InvGravScale
End Sub
Private Sub Form_Load()
On Error Resume Next
Randomize Timer
PIC.Cls
Me.Caption = Me.Caption & " V." & App.Major
If Dir(App.Path & "\Frames", vbDirectory) = vbNullString Then MkDir App.Path & "\Frames"
If Dir(App.Path & "\Frames\*.*", vbArchive) <> vbNullString Then Kill App.Path & "\Frames\*.*"
HH = 520
WW = 4 / 3 * HH
' WW = 16 / 9 * HH
If WW < HH Then ZZ = WW Else: ZZ = HH
ZZ = ZZ * 0.5
invZZ = 1 / ZZ
WW = WW - (WW Mod 4)
PIC.Height = HH
PIC.Width = WW
PIChDC = PIC.hDC
ScrollDRAW.Value = 2
txtNP.Text = 5000 '2000 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
txtMaxD.Text = 14 '25
Dim ctr As Control
For Each ctr In Me
If ctr.Name <> "PIC" And ctr.Name <> "Line1" And ctr.Name <> "Timer1" _
And ctr.Name <> "Command2" Then
ctr.Left = PIC.Width + 50
End If
Next
chkFaucet(1).Left = chkFaucet(0).Left + chkFaucet(0).Width + 1
cmdErase(1).Left = cmdErase(0).Left + cmdErase(0).Width + 10
chkRG.Value = vbChecked
rndGravity = True
'-------------------------------------------------- CAMERA V3
' Scree.Size = Vec3(WW * 1, HH * 1, ZZ * 1)
' Scree.InvSize.X = 1 / Scree.Size.X
' Scree.InvSize.Y = 1 / Scree.Size.Y
' Scree.InvSize.Z = 1 / Scree.Size.Z
' Scree.Center = Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5)
' InitCamera Vec3(WW * 0.5, HH * 0.5, HH * 1.252), Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5)
' Camera V4
' CameraInit Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5 + WW * 0.7), _
Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5), _
Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5), Vec3(0, 1, 0)
'V6
Set CAMERA = New c3DEasyCam
CAMERA.Init Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5 - WW * 0.7), _
Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5), _
Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5), Vec3(0, -1, 0)
End Sub
Private Sub Command1_Click()
RecomputeBOX = True
Set SRF = Cairo.CreateSurface(WW + 1, HH + 1, ImageSurface)
Set CC = SRF.CreateContext
CC.AntiAlias = CAIRO_ANTIALIAS_FAST
' Set SpatialGRID = New cSpatialGrid3D
' ' Set HASH3D = New cSpatialHash3D
Set OCTTREE = New cOctTree
H = Val(txtMaxD.Text)
invH = 1 / H
InvH2 = 1 / (H * H)
MainLoop
End Sub
Public Sub MainLoop()
Dim I As Long
Dim J As Long
Dim V As Single
Dim OnP As String
Dim X As Single
Dim Y As Single
Dim Z As Single
Dim InvZ As Single
Dim DrawOrderIDX() As Long
Dim DistFromCamera() As Single
ReDim DrawOrderIDX(1)
ReDim DistFromCamera(1)
Dim L As Long
Dim tV As tVec3
' V5 BOX
Dim LP1(1 To 12) As tVec3
Dim LP2(1 To 12) As tVec3
Dim Vis(1 To 12) As Boolean
Dim DrawR As Single
Dim yyy As Single
Dim ppp As Single
Dim C As cHashD
Dim CamPosX As Single
Dim CamPosY As Single
Dim CamPosZ As Single
Dim DX As Single, DY As Single, DZ As Single
Dim MAXNPairs As Long
DrawR = H * 0.12
'''OLDPointToScreen If DrawR < 1.5 Then DrawR = 1.5
DoLOOP = True
NP = Val(txtNP.Text)
SPH_InitConst
'SpatialGRID.Init WW, HH, ZZ, h * 1
OCTTREE.Setup -H, -H, -H, WW + H, HH + H, ZZ + H, 65 ', H '60 ' 50 ' 50 '60 '10
' HASH3D.constructor h * 1, NP
' Set C = New_c.HashD(NP)
'GravScale = (h / 60) * invDT
GravScale = (H / 70) * invDT '2022
InvGravScale = 1 / GravScale
ReDim px(NP)
ReDim py(NP)
ReDim pz(NP)
ReDim vX(NP)
ReDim vY(NP)
ReDim vZ(NP)
ReDim pvX(NP)
ReDim pvY(NP)
ReDim pvZ(NP)
gX = 0
gY = 1
gZ = 0
For I = 1 To NP
px(I) = Rnd * WW * 1
py(I) = Rnd * HH * 1
pz(I) = Rnd * ZZ * 1
vX(I) = (Rnd * 2 - 1) * 1
vY(I) = (Rnd * 2 - 1) * 1
vZ(I) = (Rnd * 2 - 1) * 1
' X = PX(I) - WW * 0.5
' Z = PZ(I) - ZZ * 0.5
' A = Atan2(X, Z)
' D = Sqr(X * X + Z * Z)
'
' vX(I) = Cos(A) * 0.05 * invDT * D
' vY(I) = 0
' vZ(I) = Sin(A) * 0.05 * invDT * D
Phase(I) = 1
Next
Do
' CAMERA.Follow Vec3(pX(1), pY(1), pZ(1)), 0.03, 0.0125, 30000, 18000: RecomputeBOX = True
' CAMERA.Follow Vec3(COMx, COMy, COMz), 0.025, 0.0125, 80600, 40000: RecomputeBOX = True
SPH_MOVE
'------------------------
'------------------------
'------------------------MODO grid
'SpatialGRID.ResetPoints
''------------------------
' SpatialGRID.InsertALLpoints px, py, pz
''------------------------
OCTTREE.InsertALLpoints px, py, pz
Dim tdt As Single
tdt = DT * 0.5
'''' '' '-------using pvX '? Dampig?
'' For I = 1 To NP
'' pvX(I) = pX(I) + vX(I) * tdt
'' pvY(I) = pY(I) + vY(I) * tdt
'' pvZ(I) = pZ(I) + vZ(I) * tdt
'' Next
'' SpatialGRID.InsertALLpoints pvX, pvY, pvZ
'' '------------------------
'------------------------
'SpatialGRID.GetPairsWDist4 P1, P2, arrDX, arrDY, arrDZ, arrD, RetNofPairs
'' SpatialGRID.GetPairsWDist2 P1, P2, arrDX, arrDY, arrDZ, arrD, RetNofPairs
OCTTREE.GetPairsWDist H, P1, P2, arrDX, arrDY, arrDZ, arrD, RetNofPairs, MAXNPairs
'------------------------
'------------------------
'------------------------MODO HASH
''' Dim nr&
'''
''' Dim DX as single, DY as single, DZ as single, D as single
'''
''' HASH3D.InsertPoints2 pX, pY, pZ
''' RetNofPairs = 0
''' C.ReInit MaxNofPairs
'''
''' For I = 1 To NP
'''
''' HASH3D.Query Vec3(pX(I), pY(I), pZ(I)), h
''' For nr = 1 To HASH3D.querySize
'''
''' J = HASH3D.QueryIds(nr)
'''
''' If Not (C.Exists(J & I)) Then
'''
'''
''' DX = pX(J) - pX(I)
''' DY = pY(J) - pY(I)
''' DZ = pZ(J) - pZ(I)
''' D = DX * DX + DY * DY + DZ * DZ
''' If D > 0 And D < (h * h) Then
'''
''' If Not (C.Exists(I & J)) Then
''' C.Add I & J, ""
'''
''' RetNofPairs = RetNofPairs + 1
'''
''' If RetNofPairs > MaxNofPairs Then
''' MaxNofPairs = RetNofPairs * 1.7
''' ReDim Preserve P1(MaxNofPairs): ReDim Preserve P2(MaxNofPairs)
''' ReDim Preserve arrDX(MaxNofPairs): ReDim Preserve arrDY(MaxNofPairs): ReDim Preserve arrDZ(MaxNofPairs)
''' ReDim Preserve arrD(MaxNofPairs)
''' End If
'''
''' P1(RetNofPairs) = I
''' P2(RetNofPairs) = J
''' arrDX(RetNofPairs) = DX
''' arrDY(RetNofPairs) = DY
''' arrDZ(RetNofPairs) = DZ
''' arrD(RetNofPairs) = D
''' If I = 0 And J = 0 Then Stop
''' End If
''' End If
'''
''' End If
'''
'''
''' Next
'''
''' Next
'------------------------
'------------------------
'------------------------
SPH_ComputePAIRS
'----------------------
If (CNT And RenderEvery) = 0& Then
With CC
.SetSourceColor 0
.Paint
' DRAW BOX------------------------------ V5
If RecomputeBOX Then
CAMERA.LineToScreen Vec3(0, 0, 0), Vec3(WW * 1, 0, 0), LP1(1), LP2(1), Vis(1)
CAMERA.LineToScreen Vec3(WW * 1, 0, 0), Vec3(WW * 1, HH * 1, 0), LP1(2), LP2(2), Vis(2)
CAMERA.LineToScreen Vec3(WW * 1, HH * 1, 0), Vec3(0, HH * 1, 0), LP1(3), LP2(3), Vis(3)
CAMERA.LineToScreen Vec3(0, HH * 1, 0), Vec3(0, 0, 0), LP1(4), LP2(4), Vis(4)
CAMERA.LineToScreen Vec3(0, 0, ZZ * 1), Vec3(WW * 1, 0, ZZ * 1), LP1(5), LP2(5), Vis(5)
CAMERA.LineToScreen Vec3(WW * 1, 0, ZZ * 1), Vec3(WW * 1, HH * 1, ZZ * 1), LP1(6), LP2(6), Vis(6)
CAMERA.LineToScreen Vec3(WW * 1, HH * 1, ZZ * 1), Vec3(0, HH * 1, ZZ * 1), LP1(7), LP2(7), Vis(7)
CAMERA.LineToScreen Vec3(0, HH * 1, ZZ * 1), Vec3(0, 0, ZZ * 1), LP1(8), LP2(8), Vis(8)
CAMERA.LineToScreen Vec3(0, 0, 0), Vec3(0, 0, ZZ * 1), LP1(9), LP2(9), Vis(9)
CAMERA.LineToScreen Vec3(WW * 1, 0, 0), Vec3(WW * 1, 0, ZZ * 1), LP1(10), LP2(10), Vis(10)
CAMERA.LineToScreen Vec3(WW * 1, HH * 1, 0), Vec3(WW * 1, HH * 1, ZZ * 1), LP1(11), LP2(11), Vis(11)
CAMERA.LineToScreen Vec3(0, HH * 1, 0), Vec3(0, HH * 1, ZZ * 1), LP1(12), LP2(12), Vis(12)
RecomputeBOX = False
End If
.SetSourceRGBA 0.5, 0.85, 0.5, 0.5 ' 0.35
For L = 1 To 12
' If LP1(L).Z > 0 And LP2(L).Z > 0 Then .MoveTo LP1(L).X, LP1(L).Y: .LineTo LP2(L).X, LP2(L).Y: .Stroke
If Vis(L) Then .MoveTo LP1(L).X, LP1(L).Y: .LineTo LP2(L).X, LP2(L).Y: .Stroke
Next
' END DRAW BOX--------------------------------------------
'--------------------------------------------------------
'--------- DRAW Points ----------------------------------
'--------------------------------------------------------
' DRAW ORDER -------
If NP <> UBound(DrawOrderIDX) Then
ReDim DrawOrderIDX(NP)
For I = 1 To NP
DrawOrderIDX(I) = I
Next
End If
If NP > UBound(DistFromCamera) Then ReDim DistFromCamera(NP)
With CAMERA.Position
CamPosX = .X
CamPosY = .Y
CamPosZ = .Z
End With
For I = 1 To NP
' ' DrawOrderIDX(I) = I
' ' 'OK ! Project camera to point vector to CamNormFrontDIR (Front camera Vector)
' ' 'DistFromCamera(I) = dot3(DIFF3(Camera.position, Vec3(pX(I), pY(I), pZ(I))), CamNormFrontDIR) 'Camera V3
' ' 'Camera V4
' ' 'DistFromCamera(I) = DOT3(DIFF3(CAMERA.Position, Vec3(pX(I), pY(I), pZ(I))), CAMERA.Direction)
' 'With DIFF3(CAMERA.Position, Vec3(pX(I), pY(I), pZ(I)))
' ' DistFromCamera(I) = -(.x * .x + .y * .y + .z * .z)
' 'End With
'
' DX = pX(I) - CamPosX
' DY = pY(I) - CamPosY
' DZ = pZ(I) - CamPosZ
' DistFromCamera(I) = -(DX * DX + DY * DY + DZ * DZ)
'---- Speed up Sort:
J = DrawOrderIDX(I)
DX = px(J) - CamPosX
DY = py(J) - CamPosY
DZ = pz(J) - CamPosZ
DistFromCamera(I) = -(DX * DX + DY * DY + DZ * DZ)
Next
SORTSWAPS = 0
'QuickSortSingle2 DistFromCamera(), DrawOrderIDX(), 1, NP
QuickSortSingle3 DistFromCamera(), DrawOrderIDX(), 1, NP
' END DRAW ORDER -------
For I = NP To 1 Step -1
J = DrawOrderIDX(I)
'
' 'V = Pressure(J) * 0.075
' 'V = Pressure(J) * 0.15 'V5
V = Pressure(J) * 0.12 '2022
'V = (vX(J) * vX(J) + vY(J) * vY(J) + vZ(J) * vZ(J)) * 0.0015
CAMERA.PointToScreenCoords px(J), py(J), pz(J), X, Y, Z, InvZ
'If Z > 0 Then
'If CAMERA.IsPointVisibleGap(Vec3(X, y, Z), 20) Then
If CAMERA.IsPointVisibleGap2(X, Y, Z, 20) Then
V = 0.4 + V - 0.0009 * Z 'Darker distance
' V = V + Z * 50 - 0.2
If Phase(J) = 1& Then
'cyan
'.SetSourceRGBA 0.1 + V, 0.65 + V, 0.75 + V, 0.7 (V 1 , 2 )
' .SetSourceRGBA 0.02 + V, 0.5 + V, 0.6 + V, 0.85 '(V 3 )
'.SetSourceRGBA 0.01 + V, 0.45 + V, 0.55 + V, 0.8 '0.7 '(V 4)
'.SetSourceRGBA 0.015 + V, 0.5 + V, 0.6 + V, 0.8 '0.7 '(V 5)
.SetSourceRGBA 0.015 + V, 0.5 + V, 0.6 + V, 0.7 '0.55
' .SetSourceRGB 0.015 + V, 0.5 + V, 0.6 + V
Else
'.SetSourceRGBA 0.2 + V, 0.7 + V, 0.2 + V, 0.7
' .SetSourceRGBA 0.15 + V, 0.6 + V, 0.15 + V, 0.8
.SetSourceRGBA 0.1 + V, 0.5 + V, 0.1 + V, 0.7 ' 0.55
' .SetSourceRGB 0.1 + V, 0.5 + V, 0.1 + V
End If
'.Arc X, Y, 0.7 + DrawR * Z * 340 '(V3)
'.Arc X, Y, 0.7 + DrawR * InvZ * 450 'V4
.Arc X, Y, 1 + DrawR * InvZ * 400
.Fill
End If
Next
'--------------------------------------------------------
'--------------------------------------------------------
'--------------------------------------------------------
''' If DrawPairs Then
''' .SetSourceRGBA 1, 1, 0, 0.5
''' For I = 1 To RetNofPairs
''' .MoveTo pX(P1(I)), pY(P1(I))
''' .LineTo pX(P2(I)), pY(P2(I))
''' .Stroke
''' Next
''' End If
'--------- DRAW Gravity
.SetSourceColor vbGreen
.Arc 30, 30, 25
.Stroke
.MoveTo 30, 30
.LineTo 30 + gX * 25 * InvGravScale, 30 + gY * 25 * InvGravScale
.Stroke
.Arc 30 + gX * 25 * InvGravScale, 30 + gY * 25 * InvGravScale, 15 * Abs(gZ) * InvGravScale
If gZ > 0 Then .Fill Else: .Stroke
If COMGravity Then
.DrawRegularPolygon 30, 80, 20, 8, splNormal, 5
.Stroke
End If
'---------
.SelectFont "Courier New", 10, vbGreen, True
.TextOut 80, 4, "Pts: " & Format$(NP, "###,###,###") & " " & "h = " & H & " Pairs: " & OnP & " "
.TextOut WW - 185, 4, "Simple SPH by miorsoft"
' .TextOut 80, 35, " camera Pos X " & CAMERA.Position.X
' .TextOut 80, 55, " Y " & CAMERA.Position.Y
' .TextOut 80, 75, " Z " & CAMERA.Position.Z
' CAMERA.GetRotation yyy, ppp
' .TextOut 80, 95, " Yaw " & yyy
' .TextOut 80, 115, " Pitch " & ppp
End With
SRF.DrawToDC PIChDC
If DoSaveFrames Then SRF.WriteContentToPngFile App.Path & "\Frames\" & Format$(Frame, "0000") & ".png": Frame = Frame + 1
End If
CNT = CNT + 1&
If rndGravity Then
' If (CNT And 511) = 0& Then
If (CNT Mod 900) = 0& Then
gTOX = (Rnd * 2 - 1) * GravScale
gTOY = (Rnd * 2 - 1) * GravScale
gTOZ = (Rnd * 2 - 1) * GravScale * 1.1
If Rnd > 0.2 Then '0.1
If Abs(gTOX) > Abs(gTOY) And Abs(gTOX) > Abs(gTOZ) Then gTOY = 0: gTOZ = 0
If Abs(gTOY) > Abs(gTOX) And Abs(gTOY) > Abs(gTOX) Then gTOX = 0: gTOZ = 0
If Abs(gTOZ) > Abs(gTOY) And Abs(gTOZ) > Abs(gTOX) Then gTOY = 0: gTOX = 0
If Rnd < 0.1 Then gTOX = 0: gTOY = 0: gTOZ = 0
End If
End If
Line1.X1 = picGravity.Width * 0.5
Line1.Y1 = picGravity.Height * 0.5
Line1.X2 = Line1.X1 + gTOX * picGravity.Width * 0.5 * InvGravScale
Line1.Y2 = Line1.Y1 + gTOY * picGravity.Height * 0.5 * InvGravScale
End If
gX = gX * 0.98 + gTOX * 0.02
gY = gY * 0.98 + gTOY * 0.02
gZ = gZ * 0.98 + gTOZ * 0.02
''''CameraMoveWithGravity
'''CAMERA.Position = SUM3(CAMERA.lookat, MUL3(Normalize3(Vec3(gZ, -Abs(gX), gY)), 680))
''tV = SUM3(MUL3(DIFF3(CAMERA.Position, CAMERA.lookat), 0.95), MUL3(Normalize3(Vec3(gZ, -Abs(gX), gY)), 0.05 * 610))
''CAMERA.Position = SUM3(CAMERA.lookat, tV)
'''CAMERA.VectorUP = SUM3(MUL3(CAMERA.VectorUP, 0.5), MUL3(Vec3(-gX, -gY, -gZ), 0.5)): RecomputeBOX = True
''CAMERA.VectorUP = Vec3(-gX, -gY, -gZ): RecomputeBOX = True
If DoFaucet1 Then FaucetSource (1)
If DoFaucet2 Then FaucetSource (2)
'If DoFaucet1 Then FaucetSourceB (1)
'If DoFaucet2 Then FaucetSourceB (2)
If (CNT And 31&) = 0& Then
fMain.Caption = "NP: " & NP & " Pairs: " & RetNofPairs & " computed FPS: " & FPS & " SortSwaps: " & SORTSWAPS & " MaxDensity: " & TestMaxDens
OnP = Format$(RetNofPairs, "###,###,###")
End If
If CamRot Then
RecomputeBOX = True
CAMERA.SetPositionAndLookAt Vec3(WW * 0.5 + Cos(CNT * 0.0007) * 520, HH * 0.5, ZZ * 0.5 + Sin(CNT * 0.0007) * 520), Vec3(WW * 0.5, HH * 0.5, ZZ * 0.5)
End If
FauxDoEvents
Loop While DoLOOP
' Set SpatialGRID = Nothing
Set OCTTREE = Nothing
End Sub
Private Sub PIC_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
CAMERA.SetRotation 0, 0
CAMERA.Position = SUM3(MUL3(Normalize3(DIFF3(CAMERA.Position, CAMERA.lookat)), -WW * 0.7), CAMERA.lookat)
RecomputeBOX = True
End If
End Sub
Private Sub PIC_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim D As Single
Dim Pitch As Single
Dim Yaw As Single
Static X0!, Y0!, DX!, DY!
DX = X - X0: DY = Y - Y0
Select Case Button
Case 0
X0 = X: Y0 = Y
Case 1
CAMERA.GetRotation Yaw, Pitch
'Left hand
Pitch = Pitch - 0.25 * DY
Yaw = (Yaw + 0.25 * DX)
' Right Hand