-
Notifications
You must be signed in to change notification settings - Fork 64
/
FMain.pas
144 lines (123 loc) · 3.81 KB
/
FMain.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
unit FMain;
interface
uses
System.SysUtils,
System.Math,
System.Types,
System.UITypes,
System.Classes,
System.Variants,
System.Math.Vectors,
System.Diagnostics,
System.RTLConsts,
FMX.Types,
FMX.Controls,
FMX.Forms3D,
FMX.Types3D,
FMX.Forms,
FMX.Graphics,
FMX.Dialogs,
FMX.Controls.Presentation,
FMX.StdCtrls,
FMX.Controls3D,
FMX.Layers3D,
FMX.Objects3D,
FMX.Ani,
Materials, FMX.Objects, FMX.Layouts, FMX.MaterialSources;
type
TFormMain = class(TForm3D)
MeshFireworks: TMesh;
Layer3D: TLayer3D;
LayoutFireworks: TLayout;
TextFireworks: TText;
TrackBarFireworks: TTrackBar;
LayoutSparks: TLayout;
TextSparks: TText;
TrackBarSparks: TTrackBar;
PlaneHappyNewYear: TPlane;
MaterialSourceHappyNewYear: TTextureMaterialSource;
FloatAnimationRotationX: TFloatAnimation;
FloatAnimationRotationY: TFloatAnimation;
DummyHappyNewYear: TDummy;
procedure Form3DCreate(Sender: TObject);
procedure Form3DResize(Sender: TObject);
procedure TrackBarFireworksChange(Sender: TObject);
procedure TrackBarSparksChange(Sender: TObject);
procedure FloatAnimationRotationXProcess(Sender: TObject);
private
{ Private declarations }
FMaterialSourceFireworks: TFireworksMaterialSource;
FStopwatch: TStopwatch;
procedure UpdateTextureCoordinates;
public
{ Public declarations }
end;
var
FormMain: TFormMain;
implementation
{$R *.fmx}
procedure TFormMain.FloatAnimationRotationXProcess(Sender: TObject);
begin
if (FMaterialSourceFireworks <> nil) then
FMaterialSourceFireworks.TimeInSeconds := FStopwatch.Elapsed.TotalSeconds;
end;
procedure TFormMain.Form3DCreate(Sender: TObject);
begin
{ Build vertex buffer for plane }
var VB := MeshFireworks.Data.VertexBuffer;
VB.Length := 4;
VB.Vertices[0] := Point3D(-0.5, -0.5, 0);
VB.Vertices[1] := Point3D( 0.5, -0.5, 0);
VB.Vertices[2] := Point3D(-0.5, 0.5, 0);
VB.Vertices[3] := Point3D( 0.5, 0.5, 0);
UpdateTextureCoordinates;
{ Build index buffer for plane }
var IB := MeshFireworks.Data.IndexBuffer;
IB.Length := 6;
IB[0] := 0;
IB[1] := 1;
IB[2] := 2;
IB[3] := 2;
IB[4] := 1;
IB[5] := 3;
FMaterialSourceFireworks := TFireworksMaterialSource.Create(Self);
MeshFireworks.MaterialSource := FMaterialSourceFireworks;
TrackBarFireworks.Value := FMaterialSourceFireworks.FireworksCount;
TrackBarSparks.Value := FMaterialSourceFireworks.SparkCount;
FStopwatch := TStopwatch.StartNew;
end;
procedure TFormMain.Form3DResize(Sender: TObject);
begin
UpdateTextureCoordinates;
MeshFireworks.Position.Point := Point3D(ClientWidth div 2, ClientHeight div 2, 0);
MeshFireworks.SetSize(ClientWidth, ClientHeight, 0.001);
var W := 0.5 * ClientWidth;
var Texture := MaterialSourceHappyNewYear.Texture;
DummyHappyNewYear.Position.Point := Point3D(ClientWidth div 2, (ClientHeight + Layer3D.Height) * 0.5, -100);
PlaneHappyNewYear.SetSize(W, W * (Texture.Height / Texture.Width), 0.001);
{ Workaround for Thumb not rendering sometimes. }
TrackBarFireworks.RecalcSize;
TrackBarSparks.RecalcSize;
end;
procedure TFormMain.TrackBarFireworksChange(Sender: TObject);
begin
var NewCount := Trunc(TrackBarFireworks.Value);
FMaterialSourceFireworks.FireworksCount := NewCount;
TextFireworks.Text := Format('#Fireworks: %d', [NewCount]);
end;
procedure TFormMain.TrackBarSparksChange(Sender: TObject);
begin
var NewCount := Trunc(TrackBarSparks.Value);
FMaterialSourceFireworks.SparkCount := NewCount;
TextSparks.Text := Format('#Sparks: %d', [NewCount]);
end;
procedure TFormMain.UpdateTextureCoordinates;
begin
var U: Single := ClientWidth / ClientHeight;
var VB := MeshFireworks.Data.VertexBuffer;
VB.TexCoord0[0] := PointF(0, 1);
VB.TexCoord0[1] := PointF(U, 1);
VB.TexCoord0[2] := PointF(0, 0);
VB.TexCoord0[3] := PointF(U, 0);
end;
end.