Camera
Cameras in Gorilla3D control the viewpoint and projection of your 3D scene. The framework provides TGorillaCamera for basic camera functionality and TGorillaSmoothCameraController for interactive, smooth camera navigation.
TGorillaCamera
TGorillaCamera extends FireMonkey's TCamera with additional Gorilla3D-specific features and better integration with the rendering pipeline.
Creating a Camera
Design-Time
- Drop a
TGorillaCameraonto your viewport from the tool palette - Set it as the active camera in the viewport's
Cameraproperty - Deactivate the design time camera by
Viewport.UsingDesignCamera := False; - Configure position and field of view as needed
Runtime
var
Camera: TGorillaCamera;
begin
Camera := TGorillaCamera.Create(Viewport);
Camera.Parent := Viewport;
Camera.Position.Z := -10;
Camera.FOV := 45;
Viewport.Camera := Camera;
Viewport.UsingDesignCamera := False;
end;
Field of View
The field of view (FOV) controls how wide the camera's perspective is:
// Narrow FOV (zoomed in)
Camera.FOV := 30;
// Standard FOV
Camera.FOV := 45;
// Wide angle FOV
Camera.FOV := 75;
Guidelines:
- 30-40°: Telephoto lens effect, good for portraits
- 45-60°: Standard perspective, most natural
- 70-90°: Wide angle, good for interiors or expansive scenes
- >90°: Fish-eye effect
Do not use a tiny FOV to fake an orthographic view. A common trick is to set a very small FOV and push the camera far back so the perspective flattens out. Use
ProjectionModeinstead. The trick forces a camera distance of roughly 57× the size of your subject, and at that distance depth precision collapses: for a 2 unit model with the defaultNearPlane/FarPlaneyou drop from about 5700 distinguishable depth steps at FOV 45 to about 2 at FOV 1, which means z-fighting on anything nearly coplanar.
Projection Modes
ProjectionMode switches the camera between a perspective, an orthographic and
an isometric view.
// Perspective (default) - distant objects get smaller
Camera.ProjectionMode := TGorillaCameraProjection.cpPerspective;
// Orthographic - objects keep their size regardless of distance
Camera.ProjectionMode := TGorillaCameraProjection.cpOrthographic;
Camera.OrthoHeight := 10;
// Isometric - orthographic plus a fixed camera axis
Camera.ProjectionMode := TGorillaCameraProjection.cpIsometric;
Camera.IsometricPreset := TGorillaIsometricPreset.ipTrueIsometric;
| Mode | Projection | Typical use |
|---|---|---|
cpPerspective |
View pyramid, built from FOV |
Everything with a sense of depth |
cpOrthographic |
View box, built from OrthoHeight |
CAD-like views, 2D-in-3D, map overlays |
cpIsometric |
View box plus a fixed camera axis | Tile-based games, strategy maps, diagrams |
Isometry is not a projection of its own. It is what you get when you look at an
orthographic scene down one particular axis, which is why cpIsometric is
cpOrthographic with an orientation attached.
IsOrthographic() is True for both cpOrthographic and cpIsometric.
Important:
TGorillaViewport.UsingDesignCameradefaults toTrue, and while it is on the viewport renders through its own design camera — the camera assigned toCamerais ignored entirely, projection included. SwitchingProjectionModethen has no visible effect. See Creating a Camera.
Orthographic Size
OrthoHeight is the orthographic counterpart of FOV: it is the height of the
visible area in world units, and smaller values zoom in.
Camera.OrthoHeight := 10; // 10 world units fit on screen vertically
Camera.OrthoHeight := 4; // zoomed in
OrthoWidth defaults to 0, which means derive the width from OrthoHeight
and the viewport aspect ratio. That is almost always what you want, because it
keeps the image undistorted while the window is resized. Set it only to
reproduce an imported camera that pins both extents:
Camera.OrthoWidth := 0; // automatic (recommended)
Camera.OrthoWidth := 17.8; // fixed width, independent of the viewport
Unlike a perspective camera, moving an orthographic camera along its view axis
does not change the image at all — it only shifts the scene inside the
near/far range. Zoom by changing OrthoHeight. TGorillaSmoothCameraController
does this for you: under an orthographic camera the mouse wheel scales
OrthoHeight instead of moving the camera.
Isometric Presets
While ProjectionMode is cpIsometric, the camera orients itself from
IsometricPreset:
Camera.IsometricPreset := TGorillaIsometricPreset.ipTrueIsometric;
| Preset | Azimuth | Elevation | Notes |
|---|---|---|---|
ipTrueIsometric |
45° | 35.264° | View direction (1, 1, 1) — all three world axes foreshortened equally |
ipDimetric2To1 |
45° | 26.565° | The classic 2:1 pixel-art angle; a unit cube lands on whole pixel counts |
ipMilitary |
45° | 45° | Military / cavalier style top-down view |
ipCustom |
IsometricYaw |
IsometricPitch |
Your own angles |
The elevation of a true isometric view is ArcTan(1 / Sqrt(2)). Strictly
speaking ipDimetric2To1 is dimetric rather than isometric, but it is what most
tile engines mean by "isometric".
IsometricYaw and IsometricPitch are only read while the preset is
ipCustom. Selecting any other preset mirrors its angles into those two
properties, so switching to ipCustom afterwards continues from what is on
screen instead of jumping:
Camera.IsometricPreset := TGorillaIsometricPreset.ipCustom;
Camera.IsometricYaw := 30; // azimuth around the world Y axis
Camera.IsometricPitch := 40; // elevation above the horizon, positive looks down
The framework exposes the preset angles as constants, should you need them elsewhere:
GORILLA_ISOMETRIC_YAW // 45.0
GORILLA_ISOMETRIC_PITCH // 35.264389682...
GORILLA_DIMETRIC_PITCH // 26.565051177...
GORILLA_MILITARY_PITCH // 45.0
How the Orientation is Applied
This depends on whether the camera has a Target:
- No target — the camera writes its own
RotationAngle. - With a target —
TCamerabuilds its view matrix towards the target and ignoresAbsoluteDirection, so a rotation would have no effect. The camera is therefore placed on the isometric axis through its target instead, keeping the distance it already had.
Set AutoIsometricOrientation := False to keep the projection but orient the
camera yourself:
Camera.AutoIsometricOrientation := False;
Camera.RotationAngle.Point := Point3D(-30, 60, 0);
You can also trigger the orientation manually, which is what you need after changing angles while the automatic mode is off:
Camera.ApplyIsometricOrientation();
What Else Changes
Switching projection is not limited to the main image — the rest of the pipeline follows automatically:
- Frustum culling builds a box instead of a pyramid, so objects are culled by the orthographic extents at every depth rather than by a widening cone.
- Picking stays accurate. An orthographic pick ray starts spread across the
camera plane instead of at the eye, and
RayCastIntersect,ObjectAtPointandTGorillaMesh.PickTriangleall account for that. - Render passes that render the scene through a context of their own — custom depth, SSAO, screen-space shadows — receive the same projection, so depth and colour stay in agreement.
- Sky boxes keep rendering through a perspective frustum built from
FOV. A sky sits at infinity and has no orthographic interpretation: parallel rays would sample a single direction across the whole screen. This is whyFOVstill matters under an orthographic camera.
Imported Cameras
Model formats that carry orthographic cameras — glTF and COLLADA among them —
are applied on import. TGorillaCamera.LoadFromDefinition reads the camera type
from the definition layer and sets ProjectionMode, deriving OrthoWidth and
OrthoHeight from the stored magnification and aspect ratio.
Camera Positioning
// Set position directly
Camera.Position.Point := Point3D(0, 5, -10);
// Or use individual components
Camera.Position.X := 0;
Camera.Position.Y := 5;
Camera.Position.Z := -10;
// Set rotation
Camera.RotationAngle.Point := Point3D(15, 0, 0);
Target Focus
In case you want to always focus a specific 3D element, you can set the Target property of your TCamera/TGorillaCamera component.
It will automatically adjust the camera's rotation to it.
TGorillaSmoothCameraController
The smooth camera controller provides interactive camera navigation with physics-based movement, perfect for viewers, object inspectors, and interactive 3D applications.
Basic Setup
Design-Time Setup
Every TGorillaViewport component has a built-in smooth camera controller, which you can access by GorillaViewport1.GetDesignCameraController()
This is also the default setup and default navigation available if you do not overwrite with your own camera settings.
You can modify the design camera controller at runtime, f.e. to increase movement speed.
with GorillaViewport1.GetDesignCameraController() do
begin
// Change the kind of mouse and keyboard inputs to control the camera
NavigationProfile := TGorillaCameraNavigationProfile.cnpOrbit;
// Timer interval for updating camera position
Interval := 10;
// Intensity values to control navigation speed
ShiftIntensity := 5;
IntensityZoom := 15;
IntensityRotate := 20;
IntensityUpAndDown := 5;
end;
Runtime Setup
var
Controller: TGorillaSmoothCameraController;
Camera: TGorillaCamera;
begin
// Create controller
Controller := TGorillaSmoothCameraController.Create(Viewport);
Controller.Parent := Viewport;
Controller.Position.Point := Point3D(0, 0, 0);
// Create camera as child
Camera := TGorillaCamera.Create(Controller);
Camera.Parent := Controller;
Camera.Position.Z := -10; // Distance from target
// Link them
Controller.Camera := Camera;
Controller.Viewport := Viewport;
Controller.Enabled := True;
end;
Navigation Profiles
Choose a preset profile for familiar navigation:
// Default profile (no orbiting)
Controller.NavigationProfile := cnpDefault;
// - Rotate: Left mouse button
// - Shift XZ: Right mouse button
// - Shift XY: Shift + Right mouse button
// - Zoom: Mouse wheel
// Orbit profile
Controller.NavigationProfile := cnpOrbit;
// - Rotate: Right mouse button (orbits around target)
// - Shift XY: Left mouse button
// - Shift XZ: Shift + Left mouse button
// - Zoom: Mouse wheel
// Blender-like profile
Controller.NavigationProfile := cnpBlender;
// - Rotate: Ctrl + Right mouse button (orbits)
// - Shift XY: Ctrl + Left mouse button
// - Shift XZ: Shift + Left mouse button
// - Zoom: Mouse wheel
// Sketchfab-like profile
Controller.NavigationProfile := cnpSketchfab;
// - Rotate: Left mouse button (orbits)
// - Shift XY: Right mouse button
// - Shift XZ: Shift + Right mouse button
// - Move forward: Mouse wheel
// - Zoom: Ctrl + Mouse wheel
Orbiting vs. Non-Orbiting
Non-Orbiting (Default)
Controller.Orbiting := False;
- Controller rotates in place
- Camera stays at fixed distance from controller
- Good for first-person style navigation
Orbiting Mode
Controller.Orbiting := True;
- Camera rotates around the controller position
- Controller acts as the focus point
- Perfect for object inspection and turntables
Customizing Movement
Intensity (Sensitivity)
// Faster rotation
Controller.IntensityRotate := 2.0; // Default: 1.0
// Slower up/down movement
Controller.IntensityUpAndDown := 0.5;
// More sensitive zoom
Controller.IntensityZoom := 1.5;
// Faster shifting
Controller.ShiftIntensity := 2.0;
Damping (Smoothness)
Higher damping = slower impulse decay = smoother, more "floaty" movement:
// Very smooth rotation
Controller.DampingRotate := 0.95; // Default: 0.85
// Quick stop for zoom
Controller.DampingZoom := 0.7;
// Smooth shifting
Controller.ShiftDamping := 0.9;
Movement Limits
Constrain camera movement to specific bounds:
// Limit rotation angle (in degrees)
Controller.LimitRotationMin := -180;
Controller.LimitRotationMax := 180;
// Limit vertical movement
Controller.LimitUpAndDownMin := -10;
Controller.LimitUpAndDownMax := 20;
// Limit zoom distance
Controller.LimitZoomMin := 5;
Controller.LimitZoomMax := 50;
In orbit mode (Orbiting = True) the camera does not move up and down, it tilts. There
LimitUpAndDownMin / LimitUpAndDownMax limit the pitch of the camera (rotation
around X) in degrees. A range of less than 360 degrees is not wrapped round, so f.e.
-85..-5 keeps the orbiting camera above the ground:
Controller.Orbiting := True;
// never look from below the ground, never straight down
Controller.LimitUpAndDownMin := -85;
Controller.LimitUpAndDownMax := -5;
Shifting on the Ground
By default shifting forward/backward and left/right follows the view direction - a camera
looking down shifts its focus into the ground when shifted forward. With ShiftOnGround
the controller moves level on the ground plane (XZ), whatever the camera's pitch.
Shifting up and down is unaffected.
Controller.ShiftOnGround := True; // Default: False
Programmatic Control
Adding Impulses
// Rotate left (negative) or right (positive)
Controller.AddXImpulse(-0.5);
// Move up (positive) or down (negative)
Controller.AddYImpulse(0.3);
// Combined rotation and vertical movement
Controller.AddImpulse(PointF(0.5, -0.2));
Zooming
// Zoom in
Controller.Zoom(1.0);
// Zoom out
Controller.Zoom(-1.0);
// Stronger zoom
Controller.Zoom(2.0);
Note: Under an orthographic or isometric camera these calls scale the
camera's OrthoHeight instead of moving it along the view axis — moving an
orthographic camera would not change the image. See
Orthographic Size.
Shifting
// Shift on all axes
Controller.Shift(Point3D(1, 0, 0.5));
Direct Positioning
// Set exact position and angle
Controller.SetPositionAndAngle(
Point3D(0, 5, 0), // Position
Point3D(0, 45, 0) // Rotation angles
);
Custom Input Controls
Define your own mouse/keyboard combinations:
// Use middle mouse button for rotation
Controller.Rotation := [cssMiddle];
// Use Ctrl + Left button for shifting
Controller.Shifting := [cssCtrl, cssLeft];
// Use Shift + Right mouse button to move the camera up or down
Controller.ShiftUp := [cssRight + cssShift];
// Use Alt + Mouse wheel for zoom
Controller.Zooming := [cssAlt, cssMouseWheel];
Enabling/Disabling Controls
Selectively enable or disable control types:
// Enable all controls
Controller.Types := [scctRotateX, scctRotateY, scctMoveY, scctZoom,
scctShiftX, scctShiftY, scctShiftZ];
// Only allow rotation and zoom
Controller.Types := [scctRotateY, scctZoom];
// Lock camera (disable all controls)
Controller.Types := [];
Events
React to camera movements:
procedure TForm1.CameraControllerBeforeModify(ASender: TObject;
AType: TGorillaSmoothCameraControlType; var AValue: Single);
begin
// Modify the value before it's applied
case AType of
scctZoom:
begin
// Limit zoom speed
if Abs(AValue) > 5 then
AValue := Sign(AValue) * 5;
end;
end;
end;
procedure TForm1.CameraControllerAfterModify(ASender: TObject;
AType: TGorillaSmoothCameraControlType; var AValue: Single);
begin
// React to camera changes
case AType of
scctZoom:
StatusBar1.Text := Format('Zoom: %.2f', [AValue]);
end;
end;
// Assign events
Controller.OnBeforeModify := CameraControllerBeforeModify;
Controller.OnAfterModify := CameraControllerAfterModify;
Advanced Techniques
Object Inspector Pattern
Perfect for viewing 3D models:
procedure SetupObjectInspector(AController: TGorillaSmoothCameraController);
begin
// Use orbiting mode
AController.Orbiting := True;
AController.NavigationProfile := cnpOrbit;
// Center on object
AController.Position.Point := Point3D(0, 0, 0);
// Set comfortable distance
AController.Camera.Position.Z := -20;
// Limit zoom range
AController.LimitZoomMin := 10;
AController.LimitZoomMax := 100;
// Smooth movement
AController.DampingRotate := 0.92;
AController.DampingZoom := 0.88;
end;
First-Person Camera
Navigation style for games and walkthroughs:
procedure SetupFirstPersonCamera(AController: TGorillaSmoothCameraController);
begin
// No orbiting
AController.Orbiting := False;
AController.NavigationProfile := cnpDefault;
// Quick response
AController.DampingRotate := 0.75;
AController.DampingZoom := 0.7;
// Higher sensitivity
AController.IntensityRotate := 1.5;
AController.IntensityZoom := 2.0;
// Limit vertical look angle
AController.LimitUpAndDownMin := -30;
AController.LimitUpAndDownMax := 30;
end;
Animated Camera Movement
Smoothly move camera to a target position:
procedure AnimateCameraToPosition(AController: TGorillaSmoothCameraController;
ATarget: TPoint3D);
var
Delta: TPoint3D;
begin
Delta := ATarget - AController.Position.Point;
// Add impulses to move toward target
AController.Shift(Delta * 0.1); // Adjust multiplier for speed
end;
// Call repeatedly in a timer or render loop until close enough
Camera Shake Effect
procedure AddCameraShake(AController: TGorillaSmoothCameraController;
AIntensity: Single);
begin
AController.AddImpulse(PointF(
Random * AIntensity * 2 - AIntensity, // Random X
Random * AIntensity * 2 - AIntensity // Random Y
));
end;
Best Practices
-
Always Link Viewport: Set the
Viewportproperty for automatic mouse event handling -
Choose Appropriate Profile: Use preset profiles when possible instead of custom configurations
-
Set Reasonable Limits: Always define min/max limits to prevent users from getting lost
-
Adjust Damping for Feel: Lower damping (0.7-0.8) for responsive controls, higher damping (0.9-0.95) for smooth, cinematic movement
-
Test on Target Platform: Camera feel can differ between desktop (mouse) and mobile (touch) platforms
-
Consider Scene Scale: Adjust intensity and zoom limits based on your scene size
-
Provide Visual Feedback: Show controller position with
ShowController := Trueduring development
Troubleshooting
Camera Settings Have No Effect
Most often the design camera is still active. It renders instead of the camera
you assigned, so nothing you set on your own camera — position, rotation, FOV
or ProjectionMode — reaches the image.
Viewport.Camera := MyCamera;
Viewport.UsingDesignCamera := False; // easy to forget, defaults to True
// Verify which camera actually renders
if Viewport.CurrentCamera <> MyCamera then
ShowMessage('The design camera is still active!');
Camera Not Responding
// Check all required properties are set
if not Assigned(Controller.Camera) then
ShowMessage('Camera not linked!');
if not Assigned(Controller.Viewport) then
ShowMessage('Viewport not linked!');
if not Controller.Enabled then
ShowMessage('Controller is disabled!');
Movement Too Fast/Slow
// Adjust intensity
Controller.IntensityRotate := 0.5; // Slower
Controller.IntensityZoom := 2.0; // Faster
Camera Drifts Continuously
// Increase damping to stop movement faster
Controller.DampingRotate := 0.95;
Controller.DampingZoom := 0.92;
// Or reset impulses manually
Controller.Impulse := Point3D(0, 0, 0);
Controller.ShiftImpulse := Point3D(0, 0, 0);