// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #if USE_LARGE_WORLDS using Real = System.Double; #else using Real = System.Single; #endif using FlaxEngine; namespace FlaxEditor.Viewport.Cameras { /// /// Base class for view controllers. /// /// [HideInEditor] public abstract class ViewportCamera : IViewportCamera { private EditorViewport _viewport; /// /// Gets the parent viewport. /// public EditorViewport Viewport { get => _viewport; internal set => _viewport = value; } /// /// Gets a value indicating whether the viewport camera uses movement speed. /// public virtual bool UseMovementSpeed => true; /// /// Sets view orientation and position to match the arc ball camera style view for the given target object bounds. /// /// The target object bounds. /// The margin distance scale of the orbit radius. public void SetArcBallView(BoundingBox objectBounds, float marginDistanceScale = 2.0f) { SetArcBallView(BoundingSphere.FromBox(objectBounds), marginDistanceScale); } /// /// Sets view orientation and position to match the arc ball camera style view for the given target object bounds. /// /// The target object bounds. /// The margin distance scale of the orbit radius. public void SetArcBallView(BoundingSphere objectBounds, float marginDistanceScale = 2.0f) { SetArcBallView(new Quaternion(-0.08f, -0.92f, 0.31f, -0.23f), objectBounds.Center, objectBounds.Radius * marginDistanceScale); } /// /// Sets view orientation and position to match the arc ball camera style view for the given orbit radius. /// /// The orbit radius. public void SetArcBallView(float orbitRadius) { SetArcBallView(new Quaternion(-0.08f, -0.92f, 0.31f, -0.23f), Vector3.Zero, orbitRadius); } /// /// Sets view orientation and position to match the arc ball camera style view. /// /// The view rotation. /// The orbit center location. /// The orbit radius. public virtual void SetArcBallView(Quaternion orientation, Vector3 orbitCenter, Real orbitRadius) { // Rotate Viewport.ViewOrientation = orientation; // Move camera to look at orbit center point Vector3 localPosition = Viewport.ViewDirection * (-1 * orbitRadius); Viewport.ViewPosition = orbitCenter + localPosition; } /// public virtual void Update(float deltaTime) { } /// public abstract void UpdateView(float dt, ref Vector3 moveDelta, ref Float2 mouseDelta, out bool centerMouse); } }