Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
0.8.4:cameras [2022/07/20 14:13] – [Creating a Smooth Controller at Runtime] admin | 0.8.4:cameras [2022/07/20 16:01] – [Target] admin | ||
---|---|---|---|
Line 33: | Line 33: | ||
===== Target ===== | ===== Target ===== | ||
- | A very useful property of Firemonkey' | + | A very useful property of Firemonkey' |
You can use this property for easy camera navigation in 3D space. Combine a camera component with a non-visual TDummy instance to navigate. | You can use this property for easy camera navigation in 3D space. Combine a camera component with a non-visual TDummy instance to navigate. | ||
Line 137: | Line 137: | ||
This enables an easy-to-use mouse navigation for your 3D scene without any effort. | This enables an easy-to-use mouse navigation for your 3D scene without any effort. | ||
- | The component | + | The smooth camera controller supports the following control: |
+ | * Rotation around Y-axis | ||
+ | * Rotation around X-axis (moving up / down) | ||
+ | * Zooming in / out | ||
+ | * Shifting / Translating on X-, Y- and Z-axis | ||
+ | |||
+ | It is called " | ||
+ | |||
+ | Nevertheless you're able to control this smoothness and the controller | ||
^Property ^ Description^ | ^Property ^ Description^ | ||
Line 170: | Line 178: | ||
^Function^ | ^Function^ | ||
- | |function GetDesignCamera() : TCamera; virtual;| | + | |function GetDesignCamera() : TCamera;| |
- | |function GetDesignCameraController() : TGorillaSmoothCameraController; virtual;| | + | |function GetDesignCameraController() : TGorillaSmoothCameraController; |
==== Creating a Smooth Controller at Runtime ==== | ==== Creating a Smooth Controller at Runtime ==== | ||
Line 178: | Line 186: | ||
If you link the controller to a viewport component, it will automatically setup the necessary mouse events for you. | If you link the controller to a viewport component, it will automatically setup the necessary mouse events for you. | ||
- | But you are also allow to control it yourself, f.e. by Gamepad or Keyboard events. For manual controlling please leave the viewport property empty. | + | But you are also allowed |
+ | |||
+ | |||
+ | In the following code snippet we modify rotation manually in user-specific mouse events. | ||
+ | We're also blocking shifting, because we only want to rotate the camera. | ||
<file pascal> | <file pascal> | ||
uses | uses | ||
Gorilla.Camera; | Gorilla.Camera; | ||
+ | |||
+ | [...] | ||
+ | |||
+ | type | ||
+ | TForm1 = class(TForm) | ||
+ | GorillaViewport1: | ||
+ | FCameraCtrl : TGorillaSmoothCameraController; | ||
+ | FMyCamera : TGorillaCamera; | ||
+ | |||
+ | private | ||
+ | FIsMoving : Boolean; | ||
+ | FLastPoint : TPointF; | ||
+ | |||
+ | procedure DoOnViewportMouseUp(ASender : TObject; AButton : TMouseButton; | ||
+ | AShift : TShiftState; | ||
+ | procedure DoOnViewportMouseDown(ASender : TObject; AButton : TMouseButton; | ||
+ | AShift : TShiftState; | ||
+ | procedure DoOnViewportMouseMove(ASender : TObject; AShiftState : TShiftState; | ||
+ | X, Y : Single); | ||
+ | end; | ||
| | ||
- | var FCameraCtrl : TGorillaSmoothCameraController; | + | [...] |
- | var FMyCamera | + | |
+ | procedure TForm1.FormCreate(Sender: | ||
+ | begin | ||
+ | GorillaViewport1.OnMouseUp | ||
+ | GorillaViewport1.OnMouseDown := DoOnViewportMouseDown; | ||
+ | GorillaViewport1.OnMouseMove := DoOnViewportMouseMove; | ||
+ | |||
+ | /// Create a smooth camera controller | ||
+ | | ||
+ | | ||
+ | |||
+ | /// NOTICE: Enable only rotation. Disable zooming and shifting | ||
+ | FCameraCtrl.Types | ||
- | FCameraCtrl | + | /// Create our own camera for this controller |
- | FCameraCtrl.Parent := GorillaViewport; | + | FMyCamera |
- | FCameraCtrl.Types := []; | + | |
- | FMyCamera | + | /// Link the camera to the controller |
- | FMyCamera.Parent | + | FCameraCtrl.Camera |
+ | |||
+ | /// Activate the camera for rendering | ||
+ | GorillaViewport1.Camera := FMyCamera; | ||
+ | GorillaViewport1.UsingDesignCamera | ||
+ | |||
+ | [...] | ||
+ | end; | ||
- | FCameraCtrl.Camera | + | procedure TForm1.DoOnViewportMouseUp(ASender : TObject; AButton : TMouseButton; |
+ | AShift : TShiftState; | ||
+ | begin | ||
+ | FIsMoving := false; | ||
+ | end; | ||
+ | |||
+ | procedure TForm1.DoOnViewportMouseDown(ASender : TObject; AButton : TMouseButton; | ||
+ | AShift : TShiftState; | ||
+ | begin | ||
+ | FIsMoving | ||
+ | FLastPoint := PointF(X, Y); | ||
+ | end; | ||
+ | |||
+ | procedure TForm1.DoOnViewportMouseMove(ASender : TObject; AShiftState : TShiftState; | ||
+ | X, Y : Single); | ||
+ | var LDiff : TPointF; | ||
+ | begin | ||
+ | if FIsMoving then | ||
+ | begin | ||
+ | if (ssLeft in AShiftState) then | ||
+ | begin | ||
+ | LDiff := PointF(X, Y) - FLastPoint; | ||
+ | |||
+ | /// Rotate around y-axis + Move up and down | ||
+ | | ||
+ | end; | ||
+ | |||
+ | /// finally store the last mouse position | ||
+ | FLastPoint | ||
+ | end; | ||
+ | end; | ||
</ | </ | ||
+ | The smooth camera controller provides a number of helpful functions to modify it from external. | ||
+ | |||
+ | ^Function^Description^ | ||
+ | |procedure AddImpulse(AOfs : TPointF); | ||
+ | |procedure AddXImpulse(AAngle : Single); | ||
+ | |procedure AddYImpulse(AAngle : Single); |Call this procedure to move camera up and down.| | ||
+ | |procedure Zoom(AStrength : Single = 1);|Call this procedure if you want to zoom in or out. The strength parameter defines the intensity of zooming.| | ||
+ | |procedure Shift(AOfs : TPoint3D); | ||
+ | |||
+ | |||
+ | You can manipulate impulse values for rotation, zooming and shifting directly by the following properties. | ||
+ | |||
+ | ^Property^Description^ | ||
+ | |Impulse.X|Get or set the current impulse for rotation around Y-axis (X value).| | ||
+ | |Impulse.Y|Get or set the current impulse for moving up and down (Y value)| | ||
+ | |Impulse.Z|Get or set the current impulse for zooming in/out (Z value)| | ||
+ | |ShiftImpulse.X|Get or set the current impulse for shifting on X axis.| | ||
+ | |ShiftImpulse.Y|Get or set the current impulse for shifting on Y axis.| | ||
+ | |ShiftImpulse.Z|Get or set the current impulse for shifting on Z axis.| |