Skip to content

OrbitControls

Interactive camera controller for orbit-style navigation.

OrbitControls lets the user rotate, pan, and zoom a camera around a target point using mouse input. It is added to the scene like any other node and updates the attached camera each frame. The controller maintains a spherical orbit radius and angular orientation pitch and yaw and applies smoothing when a non-zero damping factor is set.

The control scheme includes:

  • Left mouse drag: orbit around the target
  • Right mouse drag or Shift + left mouse drag: pan in view space
  • Scroll wheel: zoom in and out
cpp
struct MyScene : public vglx::Scene {
  MyScene(vglx::Camera* camera) {
    Add(vglx::OrbitControls::Create(camera, {
      .radius = 5.0f
    }));
  }
};

INFO

Derives from Node and inherits all public properties and methods.

Construction

Constructors


OrbitControls()

Constructs orbit controls.

cpp
OrbitControls::OrbitControls(Camera* camera, const Parameters& params);
ParameterDescription
cameraCamera the controller manipulates.
paramsConfiguration parameters.

Factories preferred


OrbitControls::Create() std::unique_ptr<OrbitControls>

Creates an instance of OrbitControls.

cpp
static std::unique_ptr<OrbitControls> OrbitControls::Create(Camera* camera, const Parameters& params);
ParameterDescription
cameraCamera the controller manipulates.
paramsConfiguration parameters.

Types

OrbitControls::Parameters struct

Parameters for constructing an OrbitControls object.

ParameterDescription
radius floatInitial distance of the camera from its target.
pitch floatInitial pitch angle in radians.
yaw floatInitial yaw angle in radians.
target Vector3Initial point the camera orbits around.
orbit_speed floatOrbit sensitivity in radians per viewport-height drag.
pan_speed floatPan sensitivity. At 1 the target tracks the cursor exactly.
zoom_speed floatScroll wheel zoom sensitivity multiplier.
damping_factor floatSet to 1 for instant response.
min_distance floatMinimum orbit distance from the target.
max_distance floatMaximum orbit distance from the target.
min_pitch floatMinimum pitch angle in radians.
max_pitch floatMaximum pitch angle in radians.

Properties

enabled bool

When false, all mouse input is ignored.

cpp
bool enabled {true};

Functions

OnMouseEvent() void virtual

Responds to mouse input for orbiting, panning, and zooming.

cpp
void OrbitControls::OnMouseEvent(MouseEvent* event) override;
ParameterDescription
eventMouse event pointer.

OnUpdate() void virtual

Updates camera position each frame, applying damping if enabled.

cpp
void OrbitControls::OnUpdate(float delta) override;
ParameterDescription
deltaTime step in seconds.

SetTarget() void

Sets the point the camera orbits around.

The camera keeps its current position and re-derives its orbit distance and orientation toward the new target. Any in-flight damped motion is cancelled.

cpp
void OrbitControls::SetTarget(const Vector3& target);
ParameterDescription
targetWorld space position to orbit around.

Released under the MIT License.