Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
0.8.4:cameras [2022/07/20 14:33] – [Smooth Camera Controller] admin0.8.4:cameras [2022/07/22 12:55] (current) – [Creating a Smooth Controller at Runtime] admin
Line 33: Line 33:
 ===== Target ===== ===== Target =====
  
-A very useful property of Firemonkey's TCamera component is the //Target// property. You can link the camera to another 3D object to always look at. This will compute view direction always towards the linked 3D object.+A very useful property of Firemonkey's TCamera component is the //Target// property. You can link the camera to another 3D object to always look at it. This will generate a view direction always towards the linked 3D object.
  
 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 134: Line 134:
 ===== Smooth Camera Controller ===== ===== Smooth Camera Controller =====
  
-Since version 0.8.4.2341 a TGorillaViewport component provides an embedded //TGorillaSmoothCameraController// component with automatic mouse feedback integration. This means: In case //UsingDesignCamera// is set to TRUE, the viewport will register OnMouseDown, OnMouseUp and OnMouseMove events and forward those events to the embedded TGorillaSmoothCameraController.+Since version 0.8.4.2341 a TGorillaViewport component provides an embedded //TGorillaSmoothCameraController// component with automatic mouse feedback integration. This means: In case //TGorillaViewport.UsingDesignCamera// is set to TRUE, the viewport will register OnMouseDown, OnMouseUp and OnMouseMove events and forward those events to the embedded TGorillaSmoothCameraController.
  
 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.
Line 145: Line 145:
 It is called "Smooth" because it moves smoothly and will not stop abruptly if user stops interacting. This provides a good user experience. It is called "Smooth" because it moves smoothly and will not stop abruptly if user stops interacting. This provides a good user experience.
  
-Nevertheless you're able to control this smoothness by a variety of properties:+Nevertheless you're able to control this smoothness and the controller itself by a variety of properties:
  
 ^Property ^ Description^ ^Property ^ Description^
Line 178: 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 190: Line 190:
  
 In the following code snippet we modify rotation manually in user-specific mouse events. 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>
Line 219: Line 220:
 procedure TForm1.FormCreate(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject);
 begin begin
 +  /// Deactivate design camera controller before registering user-specific events for mouse feedback
 +  GorillaViewport1.UsingDesignCamera := FALSE;
 +  
 +  /// Register user-specific mouse events to control our camera
   GorillaViewport1.OnMouseUp   := DoOnViewportMouseUp;   GorillaViewport1.OnMouseUp   := DoOnViewportMouseUp;
   GorillaViewport1.OnMouseDown := DoOnViewportMouseDown;   GorillaViewport1.OnMouseDown := DoOnViewportMouseDown;
   GorillaViewport1.OnMouseMove := DoOnViewportMouseMove;   GorillaViewport1.OnMouseMove := DoOnViewportMouseMove;
      
 +  /// Create a smooth camera controller
   FCameraCtrl := TGorillaSmoothCameraController.Create(GorillaViewport1);   FCameraCtrl := TGorillaSmoothCameraController.Create(GorillaViewport1);
   FCameraCtrl.Parent := GorillaViewport;   FCameraCtrl.Parent := GorillaViewport;
-  FCameraCtrl.Types := [];+   
 +  /// NOTICE: Enable only rotation. Disable zooming and shifting 
 +  FCameraCtrl.Types := [TGorillaSmoothCameraControlType.scctRotateY, TGorillaSmoothCameraControlType.scctMoveY];
  
 +  /// Create our own camera for this controller
   FMyCamera := TGorillaCamera.Create(FCameraCtrl);   FMyCamera := TGorillaCamera.Create(FCameraCtrl);
   FMyCamera.Parent := FCameraCtrl;   FMyCamera.Parent := FCameraCtrl;
  
 +  /// Link the camera to the controller
   FCameraCtrl.Camera := FMyCamera;   FCameraCtrl.Camera := FMyCamera;
 +  
 +  /// Activate the camera for rendering
 +  GorillaViewport1.Camera := FMyCamera;
      
   [...]   [...]
Line 287: Line 300:
 |ShiftImpulse.Y|Get or set the current impulse for shifting on Y 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.| |ShiftImpulse.Z|Get or set the current impulse for shifting on Z axis.|
 +
 +Next step: [[lights|Lights]]