Avara3D 0.2.0
C++ API reference
TurntableCameraController.h
1//
2// TurntableCameraController.h
3// avara3d
4//
5// Created by Morgan Davis on 8/9/26.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_EXTENSION_CAMERA_TURNTABLECAMERACONTROLLER_H
10#define AVARA3D_EXTENSION_CAMERA_TURNTABLECAMERACONTROLLER_H
11
12#include <memory>
13#include <optional>
14#include <variant>
15
16#include "a3d/Math.h"
17#include "a3d/input/DesktopInputContext.h"
18
19namespace a3d {
20
21 class Node;
22
23}
24
25namespace a3d::ext {
26
37
38 public:
39 // [Public Types]
40
42 struct NodeTarget {
43
44 std::weak_ptr<Node> node;
46 };
47
49 using Target = std::variant<math::vec3, NodeTarget>;
50
52 struct View {
53
55 float yaw {0.0f};
56 float pitch {0.0f};
57 float distance {10.0f};
58 };
59
61 struct Controls {
62
64 DesktopInputContext::MouseButton::One};
66 DesktopInputContext::MouseButton::Two};
68 DesktopInputContext::Key::LeftShift};
70 DesktopInputContext::Key::LeftControl};
71 };
72
74 struct PointerClick {
75
77 };
78
80 struct Config {
81
82 float minPitch {
83 -math::radians(85.0f)};
84 float maxPitch {math::radians(85.0f)};
85
86 float minDistance {0.01f};
87 float maxDistance {math::F32_MAX};
88
89 float orbitSensitivity {0.004f};
90 float dollySensitivity {0.01f};
91 float scrollDollySensitivity {0.15f};
93 4.0f};
94 bool invertPitch {false};
95
97 };
98
101
102 bool cameraChanged {false};
103 bool pointerDragging {false};
104 std::optional<PointerClick>
106 std::optional<PointerClick>
108 };
109
110 // [Public Lifecycle Functions]
111
114
121
122 // [Public Member Functions]
123
125 const Config& config() const;
126
132 void config(const Config& config);
133
135 const View& view() const;
136
144 void view(const View& view);
145
149 void target(const math::vec3& worldPosition);
150
158 void target(const std::shared_ptr<Node>& node);
159
167 void target(const std::shared_ptr<Node>& node, const math::vec3& localPosition);
168
184 UpdateResult update(DesktopInputContext& input, float vFov, float viewportHeight);
185
192 void apply(Node& pov);
193
194 private:
195 // [Private Types]
196
197 enum class DragMode {
198 Orbit,
199 Pan,
200 Dolly
201 };
202
203 // [Private Member Functions]
204
205 math::vec3 resolveTarget();
206 void translateTarget(const math::vec3& worldTranslation);
207
208 // [Private Member Variables]
209
210 Config _config;
211 View _view;
212 math::vec3 _resolvedTarget;
213 bool _orbitButtonActive;
214 bool _orbitButtonDragging;
215 DragMode _orbitButtonDragMode;
216 math::vec2 _orbitButtonPressPosition;
217 bool _panButtonActive;
218 bool _panButtonDragging;
219 math::vec2 _panButtonPressPosition;
220 };
221
222}
223
224#endif // AVARA3D_EXTENSION_CAMERA_TURNTABLECAMERACONTROLLER_H
Exposes keyboard, pointer-button, pointer-motion, and scroll state.
MouseButton
Identifies one of up to eight pointer buttons.
Key
Identifies keyboard keys reported by desktop-style input contexts.
A transformable object in a Scene hierarchy.
Definition: Node.h:45
Provides orbit, pan, and dolly control around a world-space or Node-relative target.
const Config & config() const
Returns the current controller configuration.
void target(const std::shared_ptr< Node > &node)
Sets the orbit target to the local origin of node.
std::variant< math::vec3, NodeTarget > Target
Orbit target represented by either a fixed world position or a Node-relative point.
const View & view() const
Returns the current orbit View.
void view(const View &view)
Replaces the orbit View, clamping pitch and distance to the configured limits.
TurntableCameraController()
Creates a controller with the default configuration and View.
void target(const std::shared_ptr< Node > &node, const math::vec3 &localPosition)
Sets the orbit target to localPosition in node coordinates.
void target(const math::vec3 &worldPosition)
Sets a fixed world-space orbit target.
void config(const Config &config)
Replaces the controller configuration and clamps the current View to its new limits.
UpdateResult update(DesktopInputContext &input, float vFov, float viewportHeight)
Updates the View from pointer-button, pointer-motion, and scroll input.
void apply(Node &pov)
Applies the current View to pov so it looks at the resolved target.
TurntableCameraController(const Config &config)
Creates a controller with config and the default View.
Limits, sensitivities, and input bindings used by the controller.
float dollySensitivity
Exponential dolly sensitivity for pointer dragging.
float orbitSensitivity
Orbit radians per logical pointer unit.
float dragThreshold
Pointer displacement required to convert a click candidate into a drag.
float maxDistance
Maximum target distance in scene units.
Controls controls
Pointer-button and modifier bindings.
float scrollDollySensitivity
Exponential dolly sensitivity per scroll unit.
float minDistance
Minimum positive target distance in scene units.
float maxPitch
Maximum pitch in radians; must remain below 90 degrees.
bool invertPitch
Reverses vertical orbit direction when true.
float minPitch
Minimum pitch in radians; must remain above -90 degrees.
Pointer buttons and modifier keys used for camera manipulation.
DesktopInputContext::Key dollyModifier
Makes orbit-button dragging dolly.
DesktopInputContext::MouseButton panButton
Dedicated pan/click button.
DesktopInputContext::MouseButton orbitButton
Primary orbit/click button.
DesktopInputContext::Key panModifier
Makes orbit-button dragging pan.
Target point expressed in the local coordinates of a weakly referenced Node.
std::weak_ptr< Node > node
Node whose transform supplies the target coordinate space.
math::vec3 localPosition
Target point in the Node's local coordinates.
Pointer click reported when a configured button is released without becoming a drag.
math::vec2 position
Release position in logical viewport coordinates.
std::optional< PointerClick > panButtonClick
Pan-button click released without crossing the drag threshold.
bool pointerDragging
Whether an orbit or pan button is currently dragging.
bool cameraChanged
Whether update() changed the View.
std::optional< PointerClick > orbitButtonClick
Orbit-button click released without crossing the drag threshold.
float distance
Distance from the target in scene units.
float yaw
Horizontal orbit angle in radians.
float pitch
Vertical orbit angle in radians.
Target target
Point around which the camera orbits.