forked from gbegreg/GBE3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGBE_Om_OceanWaves.pas
642 lines (519 loc) · 22.7 KB
/
GBE_Om_OceanWaves.pas
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
unit GBE_Om_OceanWaves; // Om: TTwoWavesOceanSurface
// TGBEPlaneExtend has one wave. Added a second to TTwoWavesOceanSurface
// actually 3 waves... and counting
// set21: increased the wave system from 3 to 5 waves
// jun22: fixed boat pitch calculation
interface
uses
System.SysUtils, System.Classes, System.Math, System.Types,
FMX.Types, FMX.Controls3D, FMX.Objects3D, System.Math.Vectors, FMX.Types3D, generics.Collections,
System.Threading, FMX.MaterialSources,
GBEPlaneExtend; // TGBEPlaneExtend and WaveRec
type
TWaveSystem = class( TComponent ) // collection of sea surface sinoid waves (3 for now)
private
fTime:Single; //Om: movd stuff to protected
// wave params
fAmplitude,fLongueur,fVitesse:single; //wave 1
fOrigine: TPoint3D;
fAmplitude2, fLongueur2, fVitesse2 : single;
fOrigine2:TPoint3d;
fAmplitude3, fLongueur3, fVitesse3 : single;
fOrigine3:TPoint3d;
fAmplitude4, fLongueur4, fVitesse4 : single;
fOrigine4:TPoint3d;
fAmplitude5, fLongueur5, fVitesse5 : single;
fOrigine5:TPoint3d;
protected
function getWaveParams1:TPoint3d;
function getWaveParams2:TPoint3d;
function getWaveParams3:TPoint3d;
function getWaveParams4:TPoint3d;
function getWaveParams5:TPoint3d;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure IncTime;
Property WaveTime:Single read fTime write fTime;
published
property Origine : TPoint3D read fOrigine write fOrigine; // wave 1
property Amplitude : single read fAmplitude write fAmplitude;
property Longueur : single read fLongueur write fLongueur;
property Vitesse : single read fVitesse write fVitesse;
property Origine2 : TPoint3D read fOrigine2 write fOrigine2; // wave 2
property Amplitude2: single read fAmplitude2 write fAmplitude2;
property Longueur2 : single read fLongueur2 write fLongueur2;
property Vitesse2 : single read fVitesse2 write fVitesse2;
property Origine3 : TPoint3D read fOrigine3 write fOrigine3; // wave 3
property Amplitude3: single read fAmplitude3 write fAmplitude3;
property Longueur3 : single read fLongueur3 write fLongueur3;
property Vitesse3 : single read fVitesse3 write fVitesse3;
property Origine4 : TPoint3D read fOrigine4 write fOrigine4; // wave 4
property Amplitude4: single read fAmplitude4 write fAmplitude4;
property Longueur4 : single read fLongueur4 write fLongueur4;
property Vitesse4 : single read fVitesse4 write fVitesse4;
property Origine5 : TPoint3D read fOrigine5 write fOrigine5; // wave 5
property Amplitude5: single read fAmplitude5 write fAmplitude5;
property Longueur5 : single read fLongueur5 write fLongueur5;
property Vitesse5 : single read fVitesse5 write fVitesse5;
end;
TOceanSurface = class( TPlane )
private
fWaveSystem:TWaveSystem;
procedure CalcWaves;
protected
fNbMesh : integer; // number of tiles in the mesh
fActiveWaves, fShowlines, fUseTasks : boolean;
fDivPerM : TPoint3D;
fMaterialLignes: TColorMaterialSource;
public
fVirtualSeaOrigin:TPoint3D; // position of the origin of the virtual sea
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// Property Data; //om: publica
function calcWaveAmplitudeAndPitch(P:TPoint3d; const aCap:Single; var aAmplitude,aPitch:Single ):boolean; //Om:
procedure Render; override;
procedure MoveTextureBy(var dx,dy:Single);
procedure GetPointsTexCoordinates(var P, TC: String); // W1,W2 = Point3D(Amplitude, Longueur, Vitesse)
published
property ActiveWaves : boolean read fActiveWaves write fActiveWaves;
property ShowLines: boolean read fShowlines write fShowLines;
property WaveSystem:TWaveSystem read fWaveSystem write fWaveSystem;
property MaterialLines : TColorMaterialSource read fMaterialLignes write fMaterialLignes;
property DivPerM:TPoint3D read fDivPerM;
end;
TWindArrowSurface = class( TPlane ) // Ondulating wind arrow. Less CPU intensive then OceanSurface
private
fVersion: integer;
fWaveSystem:TWaveSystem; // using only wave 1 here
procedure CalcArrowMesh;
procedure setVersion(const Value: integer);
protected
fNbMesh : integer; // number of tiles in the mesh
fActiveWaves, fShowlines, fUseTasks : boolean;
fDivPerM : TPoint3D;
fMaterialLignes: TColorMaterialSource;
procedure SetDepth(const Value: Single); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// Property Data; //om: publica
procedure Render; override;
published
property ActiveWaves : boolean read fActiveWaves write fActiveWaves;
property ShowLines: boolean read fShowlines write fShowLines;
property MaterialLines : TColorMaterialSource read fMaterialLignes write fMaterialLignes;
property DivPerM:TPoint3D read fDivPerM;
Property version:integer read fVersion write setVersion;
end;
TTwoWavesOceanSurface = class(TOceanSurface); // compatibility w/ old forms
procedure Register;
implementation //---------------------------------------------------
procedure Register;
begin
RegisterComponents('GBE3D', [TWaveSystem, TOceanSurface, TTwoWavesOceanSurface, TWindArrowSurface]);
end;
{ TWaveSystem }
constructor TWaveSystem.Create(AOwner: TComponent);
begin
inherited;
fTime := 0;
fAmplitude := 2.5; // wave params
fLongueur := 5; // Om: only 1 ?
fVitesse := 5; //
fOrigine := Point3D(1,1 , 2);
fAmplitude2 := 1.1; //2.5; //wave 2 params
fLongueur2 := 2.1;
fVitesse2 := 3;
fOrigine2 := Point3D(3, 10, 2); // (SubdivisionsWidth/Width, SubdivisionsHeight/Height, 2)
fAmplitude3 := 1.5; //wave 3 params
fLongueur3 := 4.2;
fVitesse3 := 3.2;
fOrigine3 := Point3D(7, -8, 1);
fAmplitude4 := 0.5; //wave 4 params
fLongueur4 := 2.2;
fVitesse4 := 2.2;
fOrigine4 := Point3D(7, -8, 1);
fAmplitude5 := 0.7; //wave 5 params
fLongueur5 := 4.2;
fVitesse5 := 2.2;
fOrigine5 := Point3D(7, -8, 1);
end;
destructor TWaveSystem.Destroy;
begin
inherited;
end;
function TWaveSystem.getWaveParams1: TPoint3d;
begin
Result := Point3D(Amplitude, Longueur, Vitesse); // pack wave params
end;
function TWaveSystem.getWaveParams2: TPoint3d;
begin
Result := Point3D(fAmplitude2, fLongueur2, fVitesse2);
end;
function TWaveSystem.getWaveParams3: TPoint3d;
begin
Result := Point3D(fAmplitude3, fLongueur3, fVitesse3);
end;
function TWaveSystem.getWaveParams4: TPoint3d;
begin
Result := Point3D(fAmplitude4, fLongueur4, fVitesse4);
end;
function TWaveSystem.getWaveParams5: TPoint3d;
begin
Result := Point3D(fAmplitude5, fLongueur5, fVitesse5 );
end;
procedure TWaveSystem.IncTime;
begin
fTime := fTime + 0.010; // advance wave time.. slow advance
end;
{ TOceanSurface }
constructor TOceanSurface.Create(AOwner: TComponent);
begin
inherited;
fWaveSystem := nil;
self.SubdivisionsHeight := 30; // plane subdivisions
self.SubdivisionsWidth := 30;
fNbMesh := (SubdivisionsWidth + 1) * (SubdivisionsHeight + 1);
// fDivPerM = SubD / width --> units div/m
fDivPerM := Point3D( SubdivisionsWidth / self.Width, SubdivisionsHeight / self.Height, 0);
fUseTasks := true; // default= using tasks instead of inline mesh builds
fVirtualSeaOrigin := Point3D( 0,0,0);
end;
destructor TOceanSurface.Destroy;
begin
inherited;
end;
Function MyFrac(const n:single):Single;
begin
Result := Frac(n);
if (Result<0) then Result:=Result+1.0;
end;
// MoveTextureBy uses existent mesh, by just displacing the tex pts
procedure TOceanSurface.MoveTextureBy(var dx,dy:Single); // dx,dy in 3d units (m)
var
M:TMeshData;
S:String;
x,y : integer;
front, back : TPointF;
ixf,ixb:integer;
du,dv:Single;
begin
M := self.Data; //get mesh
fVirtualSeaOrigin := fVirtualSeaOrigin - Point3D(dx, dy, 0); // move by virtual sea coordinate system
du := dx/Width; // in 0..1 range
dv := dy/Height;
fNbMesh := (SubdivisionsWidth + 1) * (SubdivisionsHeight + 1);
for y := 0 to SubdivisionsHeight do
for x := 0 to SubdivisionsWidth do
begin
ixf := X + (Y * (SubdivisionsWidth+1)); //calc front and back point indexes
ixb := fNbMesh + X + (Y * (SubdivisionsWidth+1));
front := M.VertexBuffer.TexCoord0[ixf]; // TexCoord0 must be in 0.0 .. 1.0 range ( UV coordinates )
back := M.VertexBuffer.TexCoord0[ixb];
front.x := MyFrac( front.x + du ); // Frac() wraps around the texture coordinates
front.y := MyFrac( front.y + dv ); // TODO: this leaves the last row,column w/ inverted texture ..
back.x := MyFrac( back.x + du );
back.y := MyFrac( back.y + dv );
M.VertexBuffer.TexCoord0[ixf] := front;
M.VertexBuffer.TexCoord0[ixb] := back;
end;
// format TexCoordinates as a str
// '0.0 0.0, 1 0, 0.0 1, 1 1';
// S := FloatToStr(u) +' '+FloatToStr(v) +','+
// FloatToStr(u+1)+' '+FloatToStr(v) +','+
// FloatToStr(u) +' '+FloatToStr(v+1) +','+
// FloatToStr(u+1)+' '+FloatToStr(v+1);
// M.Points :=
// M.TexCoordinates :=
end;
procedure TOceanSurface.GetPointsTexCoordinates(var P,TC:String);
var
M:TMeshData;
begin
M := self.Data; //get mesh
P := M.Points;
TC := M.TexCoordinates;
end;
procedure TOceanSurface.CalcWaves; // Wx = Point3D(Amplitude, Longueur, Vitesse)
var
M:TMeshData;
x,y : integer;
ax,ay:Single;
somme: single;
PCenter:TPoint3D;
front, back : PPoint3D;
waveRec1,waveRec2,waveRec3,waveRec4,waveRec5 : TWaveRec;
begin
if not Assigned(fWaveSystem) then exit;
M := self.Data; //get mesh
// init waveRecs
PCenter := Point3d( SubdivisionsWidth, SubdivisionsHeight, 0)*0.5;
fDivPerM := Point3D( SubdivisionsWidth / self.Width, SubdivisionsHeight / self.Height, 0);
fNbMesh := (SubdivisionsWidth + 1) * (SubdivisionsHeight + 1);
// Waves 1 and 2 move with OceanSurface, like the floating stuff
waveRec1.P := fWaveSystem.Origine+fVirtualSeaOrigin*fDivPerM; // calc sin wave origin position
waveRec1.D := fWaveSystem.getWaveParams1; // D = Point3D( Amplitude, Longueur, Vitesse)
waveRec2.P := fWaveSystem.fOrigine2+fVirtualSeaOrigin*fDivPerM;
waveRec2.D := fWaveSystem.getWaveParams2;
// waves 3,4,5 move with the boat
waveRec3.P := fWaveSystem.fOrigine3;
waveRec3.D := fWaveSystem.getWaveParams3;
waveRec4.P := fWaveSystem.fOrigine4;
waveRec4.D := fWaveSystem.getWaveParams4;
waveRec5.P := fWaveSystem.fOrigine5;
waveRec5.D := fWaveSystem.getWaveParams5;
for y := 0 to SubdivisionsHeight do
begin
ay := y-PCenter.y; // + PCenter.y;
for x := 0 to SubdivisionsWidth do
begin
ax := x-PCenter.x; // + PCenter.x; //ax,ay in div
// preserve original TPlane vertice's x,y. Apply wave amplitude to z coordinate
front := M.VertexBuffer.VerticesPtr[X + (Y * (SubdivisionsWidth+1))];
back := M.VertexBuffer.VerticesPtr[fNbMesh + X + (Y * (SubdivisionsWidth+1))];
// calc sum of wave amplitudes. Here x,y is in division units ! ( not m )
somme := 0; // sum, effect of waves
somme := waveRec1.Wave(somme, ax, ay, fWaveSystem.fTime); // 1 st
somme := waveRec2.Wave(somme, ax, ay, fWaveSystem.fTime); // 2 nd
somme := waveRec3.Wave(somme, ax, ay, fWaveSystem.fTime); // 3 rd
somme := waveRec4.Wave(somme, ax, ay, fWaveSystem.fTime); // 4 nd
somme := waveRec5.Wave(somme, ax, ay, fWaveSystem.fTime); // 5 nd
somme := somme * 100; // scale amplitude to div x 100 ?!
Front^.Z := somme;
Back^.Z := somme;
end;
end;
M.CalcTangentBinormals;
fWaveSystem.IncTime; //adv time by 0.01 sec
end;
// P in m
function TOceanSurface.calcWaveAmplitudeAndPitch( P:TPoint3d; const aCap:Single; var aAmplitude,aPitch:Single ):boolean; //Om:
var waveRec1,waveRec2,waveRec3,waveRec4,waveRec5:TWaveRec;
aSumAmpl,aSumDeriv,D,AbsD,ax,ay:Single;
// PCenter:TPoint3d;
begin
Result := false;
if not Assigned(fWaveSystem) then exit;
// init waveRecs
// PCenter := Point3d( SubdivisionsWidth, SubdivisionsHeight, 0)*0.5;
fDivPerM := Point3D( SubdivisionsWidth / self.Width, SubdivisionsHeight / self.Height, 0);
// waves 1 n 2 Oringines move with the sea surface
waveRec1.P := fWaveSystem.Origine + fVirtualSeaOrigin * fDivPerM; // calc sin wave origin position
waveRec1.D := fWaveSystem.getWaveParams1; // D = Point3D( Amplitude, Longueur, Vitesse)
waveRec2.P := fWaveSystem.fOrigine2 + fVirtualSeaOrigin * fDivPerM; // + fVirtualSeaOrigin * fDivPerM;
waveRec2.D := fWaveSystem.getWaveParams2;
// waves 3,4,5 move with the boat ( stationary )
waveRec3.P := fWaveSystem.fOrigine3; // ugly array :(
waveRec3.D := fWaveSystem.getWaveParams3;
waveRec4.P := fWaveSystem.fOrigine4;
waveRec4.D := fWaveSystem.getWaveParams4;
waveRec5.P := fWaveSystem.fOrigine5;
waveRec5.D := fWaveSystem.getWaveParams5;
// Sum amplitudes. Note that the derivative of a sum is the sum of the derivatives
// f(x)=g(x)+h(x) ---> f'(x)=g'(x)+h'(x)
ax := ( P.x - Position.x )*fDivPerM.x; // ax,ay in div
ay := ( P.z + Position.z )*fDivPerM.y;
aSumAmpl := 0;
aSumDeriv := 0;
if waveRec1.calcWaveAmplitudeAndPitch(aCap, ax, ay, fWaveSystem.fTime,{out:} aSumAmpl, aSumDeriv) and // x,y in divs
waveRec2.calcWaveAmplitudeAndPitch(aCap, ax, ay, fWaveSystem.fTime,{out:} aSumAmpl, aSumDeriv) and
waveRec3.calcWaveAmplitudeAndPitch(aCap, ax, ay, fWaveSystem.fTime,{out:} aSumAmpl, aSumDeriv) and
waveRec4.calcWaveAmplitudeAndPitch(aCap, ax, ay, fWaveSystem.fTime,{out:} aSumAmpl, aSumDeriv) and
waveRec5.calcWaveAmplitudeAndPitch(aCap, ax, ay, fWaveSystem.fTime,{out:} aSumAmpl, aSumDeriv) then
begin
Result := true;
aAmplitude := aSumAmpl*100; // scale amplitude x 100, as was done creating the mesh
// calc pitch in degrees
D := aSumDeriv*100*3; // scale deriv by 1000 ( cause amplitudes )
AbsD := Abs(D);
if (AbsD>1) then D:=D/AbsD;
if (D>=-1.0) and (D<=1.0) then aPitch := ArcSin( D )*180/Pi; // ad hoc formula
if aPitch<-25 then aPitch:=-25 // limit pitch to 25 deg
else if aPitch>25 then aPitch:=25;
end;
end;
// function TOceanSurface.calcWaveAmplitudeAndPitch(P:TPoint3d; const aCap:Single; var aAmplitude,aPitch:Single ):boolean; //Om:
// var
// M:TMeshData;
// x,y,z,x1,y1,z1 : integer;
// front, back, next : PPoint3D;
// P1:TPoint3d;
// aAng,D,AbsD:Single;
//
// begin
// M := Data;
//
// x := Round( P.x - Position.x + SubdivisionsHeight/2 );
// y := Round( P.z - Position.z + SubdivisionsWidth/2 );
//
// aAng := -aCap*Pi/180; // cap to radians
//
// P1 := Point3D(x,y,0) + 1.0 * Point3d( sin(aAng), cos(aAng), 0); // P1 = pto futuro, for pitch calculation
// x1 := Round( P1.x );
// y1 := Round( P1.y );
//
// if (x>=0) and (x<SubdivisionsWidth) and (y>0) and (y<SubdivisionsHeight) then
// begin
// front := M.VertexBuffer.VerticesPtr[x + (y * (SubdivisionsWidth+1))];
// // back := M.VertexBuffer.VerticesPtr[fNbMesh + X + (Y * (SubdivisionsWidth+1))];
// aAmplitude := front^.Z; // +back^.Z)/2; //??
// Result := true;
//
// if (x1>=0) and (x1<SubdivisionsWidth) and (y1>0) and (y1<SubdivisionsHeight) then
// begin
// next := M.VertexBuffer.VerticesPtr[x1 + (y1 * (SubdivisionsWidth+1))];
// D := (next^.Z-aAmplitude)/1.5;
// // AbsD := Abs(D);
// // if (AbsD>1) then D:=D/AbsD;
// // 0.8 is dynamic dampening
// if (D>=-1.0) and (D<=1.0) then aPitch := ArcSin( D )*180/Pi * 1.0; // ad hoc formula
// if aPitch<-25 then aPitch:=-25 // limit pitch to 25 deg
// else if aPitch>25 then aPitch:=25;
// end
// else aPitch:=0; //no pitch
// end
// else Result := false;
// end;
procedure TOceanSurface.Render;
begin
inherited;
if Assigned(fWaveSystem) and fActiveWaves then
begin
if fUseTasks then
begin
TTask.Create( procedure
begin
CalcWaves; // recalc mesh
end).start;
end
else begin
CalcWaves;
end;
end;
if ShowLines then
Context.DrawLines(self.Data.VertexBuffer, self.Data.IndexBuffer, TMaterialSource.ValidMaterial(fMaterialLignes),1);
end;
{ TWindArrowSurface }
constructor TWindArrowSurface.Create(AOwner: TComponent);
begin
inherited; // TPlane.Create
// create an own wave system
fWaveSystem := TWaveSystem.Create(nil);
fWaveSystem.Amplitude := 0.8; // set wave 1
fWaveSystem.Vitesse := 20.0;
fWaveSystem.Longueur := 1.1;
fWaveSystem.Origine := Point3D( 0, -10, 0); // to have ondulation on y axis
fWaveSystem.Amplitude2 := 0; // don't need those
fWaveSystem.Amplitude3 := 0;
fWaveSystem.Amplitude4 := 0;
fWaveSystem.Amplitude5 := 0;
SubdivisionsHeight := 25; // default plane subdivisions
SubdivisionsWidth := 2;
fNbMesh := (SubdivisionsWidth + 1) * (SubdivisionsHeight + 1);
// fDivPerM = SubD / width --> units div/m
fDivPerM := Point3D( SubdivisionsWidth / self.Width, SubdivisionsHeight / self.Height, 0);
fUseTasks := true; // default= using tasks instead of inline mesh builds
fVersion := 0;
end;
destructor TWindArrowSurface.Destroy;
begin
fWaveSystem.Free;
inherited;
end;
// transforms a plane into an arrow, by squeezing the x coordinate
procedure TWindArrowSurface.CalcArrowMesh; //
var // 0.0
M:TMeshData; // Y /\ 0.5
x,y : integer; // / \
front,back:PPoint3D; // / \
somme,h,Dh,z,ah,al,ax,ay:Single; // +-- --+ 0.3
waveRec1:TWaveRec; // | |
PCenter:TPoint3D; // | |
// | | 0
function _xArrowFunction(const aAx,aAy:Single ):Single; // takes a plane mesh // | |
begin // and turns it into // | |
if (aAy>=0.3) then Result := aAx*(0.5-aAy)/0.1 // an arrow // + + +--+ -0.5 X >
else Result := aAx/1.6; // for y in -0.5..0.4, slim the mesh // -0.5 0 0.5
end;
begin
// sail params sanity test
if (SubdivisionsHeight<=0) or (SubdivisionsWidth<=0) then exit; // invalid subdiv values
M := self.Data; // use default TPlane mesh
fNbMesh := (SubdivisionsWidth + 1) * (SubdivisionsHeight + 1); //recalc mesh number of vertices
// mesh is calculated to fit into [-0.5,-0.5..0.5,0.5] interval.
h := -0.5;
Dh := 1.0/SubdivisionsHeight;
// this will create an arrow mesh in h range -0.5 .. 0.5
PCenter := Point3D( SubdivisionsWidth / self.Width, SubdivisionsHeight / self.Height, 0);
// Wave 1
waveRec1.P := fWaveSystem.Origine; // calc sin wave origin position
waveRec1.D := fWaveSystem.getWaveParams1; // D = Point3D( Amplitude, Longueur, Vitesse)
for y := 0 to SubdivisionsHeight do
begin
somme := 0; // arrow ondulation
somme := waveRec1.Wave(somme, 0, y, fWaveSystem.fTime) * 1000;
for x := 0 to SubdivisionsWidth do // L
begin //
front := M.VertexBuffer.VerticesPtr[X + (Y * (SubdivisionsWidth+1))];
back := M.VertexBuffer.VerticesPtr[fNbMesh + X + (Y * (SubdivisionsWidth+1))];
ax := -0.5+x/SubdivisionsWidth;
ax := _xArrowFunction( ax, h ); // L,h in -0.5..0.5 range
ay := h;
Front^.X := ax;
Front^.Y := ay;
Back^.X := ax;
Back^.Y := ay;
// add some sail side movement ( camber ) //
Front^.Z := somme;
Back^.Z := somme;
end;
h := h+Dh; //inc h
end;
M.CalcTangentBinormals;
// fTime := fTime + 0.01; //??
fWaveSystem.IncTime; //adv time by 0.01 sec
end;
procedure TWindArrowSurface.Render;
begin
inherited;
if Assigned(fWaveSystem) and fActiveWaves then
begin
if fUseTasks then
begin
TTask.Create( procedure
begin
CalcArrowMesh; // recalc mesh
end).start;
end
else begin
CalcArrowMesh;
end;
end;
if ShowLines then
Context.DrawLines(self.Data.VertexBuffer, self.Data.IndexBuffer, TMaterialSource.ValidMaterial(fMaterialLignes),1);
end;
procedure TWindArrowSurface.setVersion(const Value: integer);
begin
if (fVersion<>Value) then
begin
CalcArrowMesh; // recalc mesh
fVersion := Value;
end;
end;
procedure TWindArrowSurface.SetDepth(const Value: Single); // override TPlane tendency to set Depth to 0.01
begin
if (Self.fDepth<>Value) then // this copies what TPlane removed
begin
Self.fDepth := Value;
Resize3D;
if (FDepth < 0) and (csDesigning in ComponentState) then
begin
FDepth := abs(FDepth);
FScale.Z := -FScale.Z;
end;
if not (csLoading in ComponentState) then
Repaint;
end;
end;
end.