Vixen
02b45cc4
csharp
public sealed class EditorCamera

The camera a scene viewport looks through.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Stored as a pivot, a distance and two angles, not as a matrix or a transform. Every navigation a scene view has is an operation on those four: orbit turns the angles, pan moves the pivot, zoom changes the distance, and focus-on-selection sets the pivot and solves the distance. Storing a position and a rotation instead would make orbit the only hard one, and it is the one people use most.

⚠ Pitch is clamped just short of straight up and straight down. At exactly ninety degrees the forward vector is parallel to the world up and the basis is undefined; the camera flips over and the horizon spins. Every scene view has this bug once, and clamping is what every one of them ends up doing.

Flying is orbiting from where you are. WASD moves the pivot along the camera's own basis rather than switching to a different camera model, so leaving fly mode does not teleport the view and the orbit afterwards is about something in front of you. The alternative — a free camera with its own state — is two cameras that disagree about where the view is.

Fields and properties (21)

  • public const float MinimumDistance

    How near the near plane gets, whatever anyone asks for.

  • public const float PitchLimit

    How far off vertical the pitch is held, in radians.

  • public Vector3 Pivot

    What the camera orbits and what focus moves.

  • public float Distance

    How far the camera is from the pivot.

  • public float Yaw

    Rotation about the world's up, in radians.

  • public float Pitch

    Rotation above the horizon, in radians. Clamped short of vertical.

  • public float FieldOfView

    Vertical field of view, in radians.

  • public float NearPlane

    Distance to the near plane.

  • public float FarPlane

    Distance to the far plane.

  • public bool IsOrthographic

    Whether the projection is orthographic.

  • public float OrbitSpeed

    How fast an orbit turns, in radians per render pixel.

  • public bool InvertOrbitY

    Whether a vertical orbit drag goes the other way.

  • public float ZoomSpeed

    How much one wheel notch changes the distance, as a fraction.

  • public float FlySpeed

    How fast WASD moves, in world units per second at a distance of one.

  • public Vector3 Position

    Where the camera is.

  • public Vector3 Forward

    Which way it looks.

  • public Vector3 Right

    Its own +X, in world space.

  • public Vector3 Up

    Its own +Y, in world space.

  • public Matrix4x4 Rotation

    The camera's orientation, which is what the corner gizmo shows.

  • public Matrix4x4 View

    The world-to-view matrix.

  • public float OrthographicHeight

    How tall the orthographic view is, derived from the distance so that switching projection does not change how big anything looks.

Methods (20)

  • public Matrix4x4 Projection(float aspectRatio)

    The view-to-clip matrix.

  • public Matrix4x4 ViewProjection(float aspectRatio)

    The world-to-clip matrix.

  • public BoundingFrustum Frustum(float aspectRatio)

    What the camera can see, for culling.

  • public void Orbit(float deltaX, float deltaY)

    Turns the camera about its pivot.

  • public void Turn(float yaw, float pitch)

    Turns the camera about its pivot by an angle rather than by a drag.

  • public void OrbitAround(Vector3 anchor, float deltaX, float deltaY)

    Turns the camera about a point that is not its pivot.

  • public void Pan(float deltaX, float deltaY, float viewportHeight)

    Slides the view sideways and up, keeping the direction.

  • public void Zoom(float notches)

    Moves the camera towards or away from its pivot.

  • public void ZoomTowards(Vector3 target, float notches)

    Moves the camera towards or away from a point, keeping that point still on screen.

  • public float WorldPerPixel(Vector3 at, int height)

    How many world units one render pixel covers, at a point.

  • public float PixelScale(int height)

    The part of WorldPerPixel that does not depend on the point.

  • public Vector3 OnPivotPlane(Ray ray)

    Where a ray crosses the plane through the pivot that faces the camera.

  • public void Fly(float right, float up, float forward, float seconds, bool fast = false)

    Moves the view along its own basis, for WASDQE flight.

  • public void Focus(BoundingBox bounds, float margin = 1.4)

    Points the camera at something, from where it already is.

  • public void LookFrom(ViewDirection direction)

    Looks along an axis, keeping the pivot.

  • public ViewBookmark Bookmark(string name)

    Records where the camera is.

  • public void Restore(ViewBookmark bookmark)

    Goes back to a bookmark.

  • public Ray PickingRay(Vector2 point, int width, int height)

    The ray under a point in the viewport.

  • public Vector3 Project(Vector3 world, int width, int height)

    Where a world point lands in the viewport.

  • public bool TryProject(Vector3 world, int width, int height, out Vector2 point)

    Where a world point lands in the viewport, if it lands in it at all.

Used by (37)

  • BlockoutCreateTestsVixen.Editor.Blockout.Tests
  • CameraTestsVixen.Editor.SceneView.Tests
  • EditorApplicationVixen.Editor.App
  • EditorModeTestsVixen.Editor.App.Tests
  • FlightTestsVixen.Editor.SceneView.Tests
  • GizmoGeometryVixen.Editor.SceneView
  • GizmoGeometryTestsVixen.Editor.SceneView.Tests
  • GizmoTestsVixen.Editor.SceneView.Tests
  • GridTestsVixen.Editor.SceneView.Tests
  • IScenePickerVixen.Editor.SceneView
  • ISceneProbeVixen.Editor.SceneView
  • ISubObjectPickerVixen.Editor.SceneView
  • MarqueeTestsVixen.Editor.SceneView.Tests
  • NavigationTestsVixen.Editor.SceneView.Tests
  • NothingPickerVixen.Editor.SceneView.Tests
  • OutOfTreePluginTestsVixen.Editor.App.Tests
  • OutlinerColumnTestsVixen.Editor.App.Tests
  • PaneVixen.Editor.SceneView.Tests
  • PickingTestsVixen.Editor.SceneView.Tests
  • PrecisionTestsVixen.Editor.SceneView.Tests
  • SceneGridVixen.Editor.SceneView
  • SceneLinesVixen.Editor.SceneView
  • ScenePickerVixen.Editor.SceneView
  • ScenePresenterVixen.Editor.App
  • SceneProbeVixen.Editor.SceneView
  • SceneTestsVixen.Editor.SceneView.Tests
  • SceneViewportVixen.Editor.SceneView
  • SnapContextTestsVixen.Editor.SceneView.Tests
  • SnapTestsVixen.Editor.SceneView.Tests
  • SubObjectPickerVixen.Editor.SceneView
  • SubObjectTestsVixen.Editor.SceneView.Tests
  • TerrainViewportTestsVixen.Editor.App.Tests
  • TransformGizmoVixen.Editor.SceneView
  • ViewportLayoutVixen.Editor.SceneView
  • ViewportStateTestsVixen.Editor.SceneView.Tests
  • ViewportTestsVixen.Editor.App.Tests
  • WorkPlaneTestsVixen.Editor.SceneView.Tests