OrbitCamera requires CNA link

Easy3D / Cameras / OrbitCamera

Easy3D::OrbitCamera computes an eye position orbiting a target — a classic turntable camera. It stores a target and spherical orbit parameters (yaw, pitch, distance). It does not own a Camera3D; call ApplyTo() to push the computed position/target into one.

#include <Easy3D/OrbitCamera.hpp>

namespace Easy3D { class OrbitCamera; }

Type aliases

AliasRefers to
OrbitCamera::Vector3Microsoft::Xna::Framework::Vector3

Defaults

PropertyDefaultNotes
Target(0, 0, 0)Vector3::Zero
Yaw0 radHorizontal angle around the target
Pitch0.3 rad≈ 17° above the horizontal plane
Distance10

API

[[nodiscard]] const Vector3& GetTarget() const noexcept
void SetTarget(const Vector3& value) noexcept
The world-space point being orbited.
[[nodiscard]] float GetYaw() const noexcept
void SetYaw(float radians) noexcept
Horizontal angle around the target, in radians.
[[nodiscard]] float GetPitch() const noexcept
void SetPitch(float radians) noexcept
Vertical angle above the target's horizontal plane, in radians.
[[nodiscard]] float GetDistance() const noexcept
void SetDistance(float value) noexcept
Distance from the target to the computed eye position.
[[nodiscard]] Vector3 ComputePosition() const
The eye position implied by target + yaw/pitch/distance. Requires linking CNA (constructs a CNA Vector3).
void ApplyTo(Camera3D& camera) const
Pushes ComputePosition() and the target into a Camera3D (sets target first, then position). Requires linking CNA.

The math

ComputePosition() places the eye on a sphere of radius distance around the target:

eye.X = target.X + distance * cos(pitch) * sin(yaw)
eye.Y = target.Y + distance * sin(pitch)
eye.Z = target.Z + distance * cos(pitch) * cos(yaw)
Pitch is not clamped. If you drive it from input, clamp it yourself (e.g. to ±1.5 rad) to avoid flipping over the top of the target — see the Recipes page.

Example

#include <Easy3D/Camera3D.hpp>
#include <Easy3D/OrbitCamera.hpp>

Easy3D::Camera3D    camera;
Easy3D::OrbitCamera orbit;

orbit.SetTarget(playerPosition);
orbit.SetDistance(12.0f);
orbit.SetYaw(0.6f);
orbit.SetPitch(0.35f);

orbit.ApplyTo(camera);   // camera now orbits the player

const auto view = camera.GetViewMatrix();
OrbitCamera holds no per-frame state — it is a pure function of its four parameters. You can freely recompute or share it, and drive yaw/pitch directly from accumulated mouse input each frame.