Vixen
02b45cc4
csharp
public static class CameraFraming

Where a point lands in the frame, and what a frame is at a given depth.

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

Remarks

The arithmetic FramingBody and ComposerAim share. Both work in normalised device coordinates — (0, 0) the centre, ±1 the edges — because that is the only space in which "keep them in the left third" is one number rather than a number and a field of view and a distance.

A restatement of the projection CameraMath already builds, specialised to a single point and to the stages that need it without a matrix.

⚠ This was internal, and the reason it stopped being internal is the reason it was internal. The note here read "a second public way to project a point is a second place for the reverse-Z convention to be got wrong" — and then a second consumer arrived, in another assembly: Vixen.Animation.Constraints's ScreenFrame, which asks where a camera would have to be for a subject to land at a given place in the frame. Keeping this internal would have meant a copy of the convention over there, which is exactly what the note was against. One implementation, shared, is what it was asking for.

Methods (6)

  • public static Vector2 Extents(in CameraLens lens, float aspectRatio)

    Half the frame's width and height: at unit depth for a perspective lens, in world units for an orthographic one.

  • public static bool Project(Vector3 point, Vector3 position, Quaternion rotation, in CameraLens lens, float aspectRatio, out Vector2 screen, out float depth)

    Where a world-space point lands in the frame.

  • public static Vector3 ToViewSpace(Vector3 direction, Quaternion rotation)

    Takes a world-space direction into the camera's own axes.

  • public static float Overshoot(float value, float centre, float halfExtent)

    How far past a dead zone a coordinate is: zero inside it, and the signed overshoot outside.

  • public static float TurnToEdge(float screen, float centre, float halfExtent, float tangent, out float edge)

    The angle a camera would have to turn through to bring a point from where it is on screen to the nearest edge of the region it belongs in.

  • public static float Correction(float overshoot, float slack, float dampTime, float deltaTime)

    How much of an overshoot to take this frame: the damped share, or more if the damped share would leave the target outside the region it is not allowed to leave.

Used by (4)

  • PlacementTestsVixen.Animation.Tests
  • ScreenFrameVixen.Animation
  • VirtualCameraSystemVixen.Engine
  • VirtualCameraTestsVixen.Engine.Tests