Skip to main content
Version: 1.0.0-preview.48

Velaptor.ICamera2D

Velaptor​

Velaptor​

ICamera2D Interface​

A simple 2-D camera that applies pan, zoom, and rotation transforms on the CPU for world-to-screen coordinate conversion.

public interface ICamera2D

Derived
↳ Camera2D

Remarks​

Works in screen pixel coordinates: top-left origin, Y increases downward. Position is a pan offset — positive X shifts the view right, which makes scene content appear to move left (standard game-camera convention).

Unlike GPU-uniform cameras, transforms are applied entirely on the CPU before vertex data is submitted. Call TransformPosition(Vector2) and TransformSize(float) when building render data each frame.

Zoom: 1.0 = one world pixel maps to exactly one screen pixel. Values above 1.0 magnify the scene; values below 1.0 shrink it. Zoom is applied relative to the screen center so the center of the window stays fixed while zooming.

Properties​

Position​

Gets or sets the camera pan offset in screen pixel units. Moving the camera right (positive X) shifts all scene content leftward. Default is System.Numerics.Vector2.Zero (no pan).

System.Numerics.Vector2 Position { get; set; }

Property Value​

System.Numerics.Vector2

Rotation​

Gets or sets the camera rotation in degrees. Positive values rotate the view clockwise. Default is 0 (no rotation). Rotation is applied around the screen center after zoom.

float Rotation { get; set; }

Property Value​

System.Single

WindowSize​

Gets the current window size in pixels. Used to locate the screen center for zoom calculations. Updated automatically on window resize.

Velaptor.SizeU WindowSize { get; }

Property Value​

SizeU

WorldBounds​

Gets the axis-aligned bounds of the visible world area in world pixel coordinates. When the camera is rotated, this is the bounding box of the rotated view frustum.

System.Drawing.RectangleF WorldBounds { get; }

Property Value​

System.Drawing.RectangleF

Zoom​

Gets or sets the zoom factor. 1.0 = native pixel size. Values above 1.0 magnify; values below shrink. Default is 1.0.

float Zoom { get; set; }

Property Value​

System.Single

ZoomMax​

Gets or sets the maximum zoom level. Default is 4.0.

float ZoomMax { get; set; }

Property Value​

System.Single

ZoomMin​

Gets or sets the minimum zoom level. Default is 0.1.

float ZoomMin { get; set; }

Property Value​

System.Single

Methods​

IsVisible(Vector2)​

Determines whether a world-space point is visible on the screen.

bool IsVisible(System.Numerics.Vector2 worldPos);

Parameters​

worldPos System.Numerics.Vector2

The position in world pixel coordinates.

Returns​

System.Boolean
true if the point is within the visible screen area; otherwise, false.

IsVisible(Vector2, Vector2)​

Determines whether a world-space rectangle intersects the visible screen area. Use this for culling objects with size (sprites, tiles, etc.).

bool IsVisible(System.Numerics.Vector2 worldPos, System.Numerics.Vector2 worldSize);

Parameters​

worldPos System.Numerics.Vector2

The top-left position of the object in world pixel coordinates.

worldSize System.Numerics.Vector2

The size of the object in world pixels.

Returns​

System.Boolean
true if any part of the rectangle is visible; otherwise, false.

TransformPosition(Vector2)​

Transforms a world-space pixel position into a screen render position, accounting for camera pan and zoom.

System.Numerics.Vector2 TransformPosition(System.Numerics.Vector2 worldPos);

Parameters​

worldPos System.Numerics.Vector2

The position in world pixel coordinates.

Returns​

System.Numerics.Vector2
The position in screen pixel coordinates.

TransformRotation(float)​

Transforms a world-space rotation angle (in degrees) into a screen-space rotation angle, accounting for camera rotation. Rotation is additive: positive camera rotation (clockwise) adds to the object's rotation.

float TransformRotation(float worldRotation);

Parameters​

worldRotation System.Single

The rotation angle in world space, in degrees.

Returns​

System.Single
The rotation angle in screen space, in degrees.

TransformSize(float)​

Scales a size value by the current zoom level. Use this for width, height, radius, and other size-related values.

float TransformSize(float size);

Parameters​

size System.Single

The size in world pixels.

Returns​

System.Single
The scaled size in screen pixels.