-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewer.pas
183 lines (142 loc) · 5.43 KB
/
Viewer.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
unit Viewer;
interface //#################################################################### ■
uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Viewport3D,
LUX.D4x4,
LUX.Complex,
LUX.Complex.Diff,
LUX.Complex.FMX.D3,
LUX.FMX.Graphics.D3;
type //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【 T Y P E 】
TViewerFrame = class( TFrame )
Viewport3D1: TViewport3D;
procedure Viewport3D1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure Viewport3D1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
procedure Viewport3D1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
private
_MouseS :TShiftState;
_MouseP :TPointF;
_Angle :TPointF;
protected
_World3D :TF3DWorld;
_Camera3D :TF3DCamera;
_Light3D :TF3DLight;
_Complex3D :TComplex3D;
///// A C C E S S O R
function GetFunc :TdDoubleCFunc;
procedure SetFunc( const Func_:TdDoubleCFunc );
function GetArea :TDoubleAreaC;
procedure SetArea( const Area_:TDoubleAreaC );
function GetDivX :Integer;
procedure SetDivX( const DivX_:Integer );
function GetDivY :Integer;
procedure SetDivY( const DivY_:Integer );
function GetScale :Double;
procedure SetScale( const Scale_:Double );
public
constructor Create( Owner_:TComponent ); override;
destructor Destroy; override;
///// P R O P E R T Y
property Func :TdDoubleCFunc read GetFunc write SetFunc ;
property Area :TDoubleAreaC read GetArea write SetArea ;
property DivX :Integer read GetDivX write SetDivX ;
property DivY :Integer read GetDivY write SetDivY ;
property Scale :Double read GetScale write SetScale;
end;
implementation //############################################################### ■
{$R *.fmx}
uses System.Math;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TViewerFrame
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
//////////////////////////////////////////////////////////////// A C C E S S O R
function TViewerFrame.GetFunc :TdDoubleCFunc;
begin
Result := _Complex3D.Func;
end;
procedure TViewerFrame.SetFunc( const Func_:TdDoubleCFunc );
begin
_Complex3D.Func := Func_;
end;
//------------------------------------------------------------------------------
function TViewerFrame.GetArea :TDoubleAreaC;
begin
Result := _Complex3D.Area;
end;
procedure TViewerFrame.SetArea( const Area_:TDoubleAreaC );
begin
_Complex3D.Area := Area_;
end;
//------------------------------------------------------------------------------
function TViewerFrame.GetDivX :Integer;
begin
Result := _Complex3D.DivX;
end;
procedure TViewerFrame.SetDivX( const DivX_:Integer );
begin
_Complex3D.DivX := DivX_;
end;
function TViewerFrame.GetDivY :Integer;
begin
Result := _Complex3D.DivY;
end;
procedure TViewerFrame.SetDivY( const DivY_:Integer );
begin
_Complex3D.DivY := DivY_;
end;
//------------------------------------------------------------------------------
function TViewerFrame.GetScale :Double;
begin
Result := _Complex3D.Scale;
end;
procedure TViewerFrame.SetScale( const Scale_:Double );
begin
_Complex3D.Scale := Scale_;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TViewerFrame.Create( Owner_:TComponent );
begin
inherited;
_World3D := TF3DWorld.Create( Viewport3D1 );
_Camera3D := TF3DCamera.Create( _World3D );
_Camera3D.Pose := TSingleM4.Translate( 0, 0, 20 );
Viewport3D1.Camera := _Camera3D.Camera;
_Light3D := TF3DLight.Create( _Camera3D );
_Light3D.Pose := TSingleM4.RotateX( DegToRad( -45 ) );
_Complex3D := TComplex3D.Create( _World3D );
_Complex3D.Material.Ambient := TAlphaColorF.Create( 0.2, 0.2, 0.2 ).ToAlphaColor;
_Complex3D.Material.Diffuse := TAlphaColorF.Create( 0.8, 0.8, 0.8 ).ToAlphaColor;
_Complex3D.Material.Specular := TAlphaColors.Null;
_Complex3D.Material.Texture.LoadFromFile( '../../_DATA/Texture 1024x1024.png' );
_Complex3D.Pose := TSingleM4.Translate( 1/2, -2*Sqrt(Pi), 0 );
end;
destructor TViewerFrame.Destroy;
begin
inherited;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
procedure TViewerFrame.Viewport3D1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
_MouseS := Shift;
_MouseP := TPointF.Create( X, Y );
end;
procedure TViewerFrame.Viewport3D1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
var
P :TPointF;
begin
if ssLeft in _MouseS then
begin
P := TPointF.Create( X, Y );
_Angle := _Angle + ( P - _MouseP );
_Camera3D.Pose := TSingleM4.RotateY( -DegToRad( _Angle.X ) )
* TSingleM4.RotateX( -DegToRad( _Angle.Y ) )
* TSingleM4.Translate( 0, 0, 20 );
_MouseP := P;
end;
end;
procedure TViewerFrame.Viewport3D1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
Viewport3D1MouseMove( Sender, Shift, X, Y );
_MouseS := [];
end;
end. //######################################################################### ■