-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFormSimpleCameraUnit.pas
More file actions
107 lines (93 loc) · 3.02 KB
/
FormSimpleCameraUnit.pas
File metadata and controls
107 lines (93 loc) · 3.02 KB
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
unit FormSimpleCameraUnit;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Viewport3D,
System.Math.Vectors, FMX.Types3D, FMX.Controls3D, FMX.Objects3D,
FMX.MaterialSources, FMX.Gestures;
type
TFormSimpleCamera = class(TForm)
Viewport3DMain: TViewport3D;
DummyScene: TDummy;
DummyXY: TDummy;
CameraZ: TCamera;
LightCamera: TLight;
GestureManager1: TGestureManager;
MaterialSourceY: TLightMaterialSource;
MaterialSourceZ: TLightMaterialSource;
MaterialSourceX: TLightMaterialSource;
CylX: TCylinder;
ConeX: TCone;
CylY: TCylinder;
ConeY: TCone;
CylZ: TCylinder;
ConeZ: TCone;
procedure Viewport3DMainMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure Viewport3DMainMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
procedure Viewport3DMainMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; var Handled: Boolean);
procedure FormGesture(Sender: TObject;
const [Ref] EventInfo: TGestureEventInfo; var Handled: Boolean);
private
FDown: TPointF;
FLastDistance: integer;
procedure DoZoom(aIn: boolean);
public
{ Public declarations }
end;
var
FormSimpleCamera: TFormSimpleCamera;
implementation
{$R *.fmx}
const
ROTATION_STEP = 0.3;
ZOOM_STEP = 2;
CAMERA_MAX_Z = -2;
CAMERA_MIN_Z = -102;
procedure TFormSimpleCamera.DoZoom(aIn: boolean);
var newZ: single;
begin
if aIn then
newZ := CameraZ.Position.Z + ZOOM_STEP
else
newZ := CameraZ.Position.Z - ZOOM_STEP;
if (newZ < CAMERA_MAX_Z) and (newZ > CAMERA_MIN_Z) then
CameraZ.Position.Z := newZ;
end;
procedure TFormSimpleCamera.FormGesture(Sender: TObject;
const [Ref] EventInfo: TGestureEventInfo; var Handled: Boolean);
var delta: integer;
begin
if EventInfo.GestureID = igiZoom then
begin
if (not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags)) and (not(TInteractiveGestureFlag.gfEnd in EventInfo.Flags)) then
begin
delta := EventInfo.Distance - FLastDistance;
DoZoom(delta > 0);
end;
FLastDistance := EventInfo.Distance;
end;
end;
procedure TFormSimpleCamera.Viewport3DMainMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
FDown := PointF(X, Y);
end;
procedure TFormSimpleCamera.Viewport3DMainMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Single);
begin
if (ssLeft in Shift) then
begin
DummyXY.RotationAngle.X := DummyXY.RotationAngle.X - ((Y - FDown.Y) * ROTATION_STEP);
DummyXY.RotationAngle.Y := DummyXY.RotationAngle.Y + ((X - FDown.X) * ROTATION_STEP);
FDown := PointF(X, Y);
end;
end;
procedure TFormSimpleCamera.Viewport3DMainMouseWheel(Sender: TObject;
Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
begin
DoZoom(WheelDelta > 0);
end;
end.