我搜索相機旋轉和放大FireMonkey 3D的例子。就像使用鼠標左鍵在場景周圍旋轉相機並使用鼠標滾輪放大和縮小一樣。Embarcadero FireMonkey 3D相機旋轉和變焦
任何人都可以幫助我嗎?
我搜索相機旋轉和放大FireMonkey 3D的例子。就像使用鼠標左鍵在場景周圍旋轉相機並使用鼠標滾輪放大和縮小一樣。Embarcadero FireMonkey 3D相機旋轉和變焦
任何人都可以幫助我嗎?
您可以通過拖動和放大輪來旋轉相機。重要的是,在不同的軸上旋轉應該全部在不同的嵌套對象上處理,這樣旋轉計算應該像我們在現實世界中期望的那樣相互影響。
下面的表單顯示了一個簡單的演示,只需保存.fmx和.pas文件並將表單添加到FMX應用程序。關鍵部分是將相機&嵌套的燈光對象放在Y軸的單獨X &上與作爲相機目標的DummyObject相連。將X & Y作爲單獨的虛擬對象使得旋轉垂直和水平,這在某些情況下是可取的。您還可以將DummyX DummyY對象合併到一個DummyXY對象中,該對象將提供更真實的世界旋轉樣式,但取決於您的需求,哪個更適合。
MainForm.pas:
unit MainForm;
interface
uses
FMX.Forms, FMX.Materials, System.Math.Vectors, FMX.Types3D, FMX.Objects3D, FMX.Controls3D, FMX.Viewport3D,
System.Classes, FMX.Types, FMX.Controls, FMX.Layouts, FMX.MaterialSources, System.Types, System.UITypes;
type
TForm1 = class(TForm)
Viewport3D: TViewport3D;
DummyX: TDummy;
DummyObject: TDummy;
CameraZ: TCamera;
Light1: TLight;
LayoutMain: TLayout;
DummyY: TDummy;
Cone1: TCone;
LightMaterialSource1: TLightMaterialSource;
procedure Viewport3DMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure Viewport3DMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
procedure Viewport3DMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
private
FDown: TPointF;
procedure DoZoom(aIn: Boolean);
public
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
const
CAMERA_MAX_Z = -2;
CAMERA_MIN_Z = -200;
ZOOM_STEP = 2;
procedure TForm1.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 TForm1.Viewport3DMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
FDown := PointF(X, Y);
end;
procedure TForm1.Viewport3DMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
begin
if (ssLeft in Shift) then
begin
DummyX.RotationAngle.X := DummyX.RotationAngle.X - ((Y - FDown.Y) * 0.3);
DummyY.RotationAngle.Y := DummyY.RotationAngle.Y + ((X - FDown.X) * 0.3);
FDown := PointF(X, Y);
end;
end;
procedure TForm1.Viewport3DMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
begin
DoZoom(WheelDelta > 0);
end;
end.
MainForm.fmx:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 592
ClientWidth = 713
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object LayoutMain: TLayout
Align = Client
Size.Width = 713.000000000000000000
Size.Height = 592.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
object Viewport3D: TViewport3D
Align = Client
Camera = CameraZ
Size.Width = 713.000000000000000000
Size.Height = 592.000000000000000000
Size.PlatformDefault = False
UsingDesignCamera = False
OnMouseDown = Viewport3DMouseDown
OnMouseMove = Viewport3DMouseMove
OnMouseWheel = Viewport3DMouseWheel
object DummyX: TDummy
Width = 1.000000000000000000
Height = 1.000000000000000000
Depth = 1.000000000000000000
object DummyY: TDummy
Width = 1.000000000000000000
Height = 1.000000000000000000
Depth = 1.000000000000000000
object CameraZ: TCamera
AngleOfView = 45.000000000000000000
Target = DummyObject
Position.Z = -20.000000000000000000
Width = 1.000000000000000000
Height = 1.000000000000000000
Depth = 1.000000000000000000
object Light1: TLight
Color = claWhite
LightType = Directional
SpotCutOff = 180.000000000000000000
Width = 1.000000000000000000
Height = 1.000000000000000000
Depth = 1.000000000000000000
end
end
end
end
object DummyObject: TDummy
Width = 1.000000000000000000
Height = 1.000000000000000000
Depth = 1.000000000000000000
object Cone1: TCone
Width = 1.000000000000000000
Height = 1.000000000000000000
Depth = 1.000000000000000000
SubdivisionsCap = 3
MaterialSource = LightMaterialSource1
end
end
end
end
object LightMaterialSource1: TLightMaterialSource
Diffuse = claWhite
Ambient = xFF202020
Emissive = claNull
Specular = xFF606060
Shininess = 30
Left = 436
Top = 56
end
end
我把這個從演示的地方,但我需要的偉大工程。應該適用於Delphi XE5以上。
@GlenMorse這裏是最初發布的鏈接:http://delphiscience.wordpress.com/2012/11/14/making-a-pipe-with-bend-feature-using-delphi-firemonkey/ –
哇,一個答案那完全沒有幫助。如何處理一些代碼?每個白癡都知道它應該是拖動鼠標事件。 –