v0.3.0 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
21class Node;
22
23} // namespace a3d
24
25namespace a3d::ext {
26
37
38public:
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 {-math::radians(85.0f)};
83 float maxPitch {math::radians(85.0f)};
84
85 float minDistance {0.01f};
86 float maxDistance {math::F32_MAX};
87
88 float orbitSensitivity {0.002f};
89 float dollySensitivity {0.002f};
90 float scrollDollySensitivity {0.05f};
91 float dragThreshold {5.0f};
92 bool invertPitch {false};
93
95 };
96
98 struct UpdateResult {
99
100 bool cameraChanged {false};
101 bool pointerDragging {false};
102 std::optional<PointerClick>
104 std::optional<PointerClick>
106 };
107
108 // [Public Lifecycle Functions]
109
112
119
120 // [Public Member Functions]
121
123 const Config& config() const;
124
130 void config(const Config& config);
131
133 const View& view() const;
134
142 void view(const View& view);
143
147 void target(const math::vec3& worldPosition);
148
156 void target(const std::shared_ptr<Node>& node);
157
165 void target(const std::shared_ptr<Node>& node, const math::vec3& localPosition);
166
182 UpdateResult update(DesktopInputContext& input, float vFov, float viewportHeight);
183
190 void apply(Node& pov);
191
192private:
193 // [Private Types]
194
195 enum class DragMode {
196 Orbit,
197 Pan,
198 Dolly
199 };
200
201 // [Private Member Functions]
202
203 math::vec3 resolveTarget();
204 void translateTarget(const math::vec3& worldTranslation);
205
206 // [Private Member Variables]
207
208 Config _config;
209 View _view;
210 math::vec3 _resolvedTarget;
211 bool _orbitButtonActive;
212 bool _orbitButtonDragging;
213 DragMode _orbitButtonDragMode;
214 math::vec2 _orbitButtonPressPosition;
215 bool _panButtonActive;
216 bool _panButtonDragging;
217 math::vec2 _panButtonPressPosition;
218};
219
220} // namespace a3d::ext
221
222#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.