-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewerSH3D.pas
168 lines (132 loc) · 5.08 KB
/
ViewerSH3D.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
unit ViewerSH3D;
interface //#################################################################### ■
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Viewport3D,
LUX,
LUX.D4x4,
LUX.FMX.Graphics.D3,
LUX.Sphere.FMX,
LUX.SH.Diff,
LUX.SH.FMX.Graphics.D3;
type //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【 T Y P E 】
TViewerSH3DFrame = 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;
protected
_World3D :TF3DWorld;
_Camera3D :TCamera3D;
_Light3DX :TLight3D;
_Light3DY :TLight3D;
_Light3DZ :TLight3D;
_SPHarm3D :TSPHarmonics3D;
///// A C C E S S O R
function GetSPHarm :TdSPHarmonics;
procedure SetSPHarm( const SPHarm_:TdSPHarmonics );
function GetN :Integer;
procedure SetN( const N_:Integer );
function GetM :Integer;
procedure SetM( const M_:Integer );
public
constructor Create( Owner_:TComponent ); override;
destructor Destroy; override;
///// P R O P E R T Y
property SPHarm :TdSPHarmonics read GetSPHarm write SetSPHarm;
property N :Integer read GetN write SetN ;
property M :Integer read GetM write SetM ;
end;
implementation //############################################################### ■
{$R *.fmx}
uses System.Math;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TViewerFrame
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
//////////////////////////////////////////////////////////////// A C C E S S O R
function TViewerSH3DFrame.GetSPHarm :TdSPHarmonics;
begin
Result := _SPHarm3D.SPHarm;
end;
procedure TViewerSH3DFrame.SetSPHarm( const SPHarm_:TdSPHarmonics );
begin
_SPHarm3D.SPHarm := SPHarm_;
end;
//------------------------------------------------------------------------------
function TViewerSH3DFrame.GetN :Integer;
begin
Result := _SPHarm3D.N;
end;
procedure TViewerSH3DFrame.SetN( const N_:Integer );
begin
_SPHarm3D.N := N_;
end;
function TViewerSH3DFrame.GetM :Integer;
begin
Result := _SPHarm3D.M;
end;
procedure TViewerSH3DFrame.SetM( const M_:Integer );
begin
_SPHarm3D.M := M_;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TViewerSH3DFrame.Create( Owner_:TComponent );
var
M :TSingleM4;
begin
inherited;
_World3D := TF3DWorld.Create( Viewport3D1 );
_Camera3D := TCamera3D.Create( _World3D );
_Camera3D.AngleX := DegToRad( 10 );
_Camera3D.AngleY := DegToRad( 45 );
Viewport3D1.Camera := _Camera3D.Camera;
_Light3DX := TLight3D.Create( _Camera3D );
_Light3DY := TLight3D.Create( _Camera3D );
_Light3DZ := TLight3D.Create( _Camera3D );
_Light3DX.Color := TAlphaColorF.Create( 1.0, 0.0, 0.0 ).ToAlphaColor;
_Light3DY.Color := TAlphaColorF.Create( 0.0, 1.0, 0.0 ).ToAlphaColor;
_Light3DZ.Color := TAlphaColorF.Create( 0.0, 0.0, 1.0 ).ToAlphaColor;
M := TSingleM4.RotateX( ArcTan( 1/Sqrt(2) ) );
_Light3DX.Pose := M * TSingleM4.RotateX( DegToRad( +90 ) );
_Light3DY.Pose := M * TSingleM4.RotateY( DegToRad( -135 ) );
_Light3DZ.Pose := M * TSingleM4.RotateY( DegToRad( +135 ) );
_SPHarm3D := TSPHarmonics3D.Create( _World3D );
_SPHarm3D.Material.Ambient := TAlphaColors.Black;
_SPHarm3D.Material.Diffuse := TAlphaColors.White;
_SPHarm3D.Material.Specular := TAlphaColors.Null;
_SPHarm3D.Material.Texture.LoadFromFile( '../../_DATA/Sphere 1800x900.png' );
end;
destructor TViewerSH3DFrame.Destroy;
begin
inherited;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
procedure TViewerSH3DFrame.Viewport3D1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
_MouseS := Shift;
_MouseP := TPointF.Create( X, Y );
end;
procedure TViewerSH3DFrame.Viewport3D1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
var
P :TPointF;
begin
if ssLeft in _MouseS then
begin
P := TPointF.Create( X, Y );
with _Camera3D do
begin
AngleX := AngleX - DegToRad( P.X - _MouseP.X );
AngleY := AngleY + DegToRad( P.Y - _MouseP.Y );
end;
_MouseP := P;
end;
end;
procedure TViewerSH3DFrame.Viewport3D1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
Viewport3D1MouseMove( Sender, Shift, X, Y );
_MouseS := [];
end;
end. //######################################################################### ■