-
Notifications
You must be signed in to change notification settings - Fork 9
/
GBEPlaneExtend.pas
130 lines (114 loc) · 3.53 KB
/
GBEPlaneExtend.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
unit GBEPlaneExtend;
interface
uses
System.SysUtils, System.Classes, FMX.Types, FMX.Controls3D, FMX.Objects3D, System.Math.Vectors, FMX.Types3D, generics.Collections,
System.Threading, FMX.MaterialSources;
type
TWaveRec = record
P, D : TPoint3D;
function Wave(aSum, aX, aY, aT : single):Single;
end;
TGBEPlaneExtend = class(TPlane)
private
fTime, fAmplitude, fLongueur, fVitesse : single;
fOrigine, fCenter : TPoint3D;
fNbMesh : integer;
fActiveWaves, fShowlines, fUseTasks : boolean;
fMaterialLignes: TColorMaterialSource;
{ Déclarations privées }
procedure CalcWaves(D : TPoint3D);
protected
{ Déclarations protégées }
public
{ Déclarations publiques }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Render; override;
published
{ Déclarations publiées }
property ActiveWaves : boolean read fActiveWaves write fActiveWaves;
property Origine : TPoint3D read fOrigine write fOrigine;
property Amplitude : single read fAmplitude write fAmplitude;
property Longueur : single read fLongueur write fLongueur;
property Vitesse : single read fVitesse write fVitesse;
property ShowLines: boolean read fShowlines write fShowLines;
property UseTasks : boolean read fUseTasks write fUseTasks;
property MaterialLines : TColorMaterialSource read fMaterialLignes write fMaterialLignes;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('GBE3D', [TGBEPlaneExtend]);
end;
function TWaveRec.Wave(aSum, aX, aY, aT: single): Single;
var l : single;
begin
l := P.Distance(Point3d(aX,aY,0));
Result:=aSum;
if D.Y > 0 then Result:=Result + D.x * sin (1/D.y*l-D.z*at) * 0.001;
end;
procedure TGBEPlaneExtend.CalcWaves(D : TPoint3D);
var
M:TMeshData;
x,y : integer;
somme: single;
front, back : PPoint3D;
waveRec : TWaveRec;
begin
M:=self.Data;
waveRec.P := Point3d(SubdivisionsWidth, SubdivisionsHeight, 0) * 0.5 + fOrigine * fCenter;
waveRec.D := D;
for y := 0 to SubdivisionsHeight do
for x := 0 to SubdivisionsWidth do
begin
front := M.VertexBuffer.VerticesPtr[X + (Y * (SubdivisionsWidth+1))];
back := M.VertexBuffer.VerticesPtr[fNbMesh + X + (Y * (SubdivisionsWidth+1))];
somme := 0;
somme := waveRec.Wave(somme, x, y, fTime);
somme := somme * 100;
Front^.Z := somme;
Back^.Z := somme;
end;
M.CalcTangentBinormals;
fTime := fTime + 0.01;
end;
constructor TGBEPlaneExtend.Create(AOwner: TComponent);
begin
inherited;
fTime := 0;
fAmplitude := 1;
fLongueur := 1;
fVitesse := 5;
self.SubdivisionsHeight := 30;
self.SubdivisionsWidth := 30;
fOrigine := Point3D(self.SubdivisionsWidth / self.Width, self.SubdivisionsHeight / self.Height, 2);
fNbMesh:=(SubdivisionsWidth + 1) * (SubdivisionsHeight + 1);
fCenter := Point3D(SubdivisionsWidth / self.Width, SubdivisionsHeight / self.Height, 0);
fUseTasks := true;
end;
destructor TGBEPlaneExtend.Destroy;
begin
inherited;
end;
procedure TGBEPlaneExtend.Render;
begin
inherited;
if fActiveWaves then
begin
if fUseTasks then
begin
TTask.Create( procedure
begin
CalcWaves(Point3D(fAmplitude, fLongueur, fVitesse));
end).start;
end
else
begin
CalcWaves(Point3D(fAmplitude, fLongueur, fVitesse));
end;
end;
if ShowLines then
Context.DrawLines(self.Data.VertexBuffer, self.Data.IndexBuffer, TMaterialSource.ValidMaterial(fMaterialLignes),1);
end;
end.