Expand description
Types and functions for 2D rendering.
The Camera2d type represents a view positioned and oriented in 2D world
space defined as a left-hand^* coordinate system with a default scale of 1
unit == 1 pixel, with the origin at the center of the screen.
^*: “left-hand” in the sense of using the left hand with palm facing down (away) and taking the thumb to be the first coordinate and index finger to be the second coordinate
The camera position and orientation defines the view space transform from world coordinates to camera coordinates. This is represented as a transform where the viewpoint is the x,y position of the camera and the z coordinate is set to 0.0, looking down the negative z axis, and the “up” vector as the y vector of the 2D camera orientation with the z component set to 0.0.
The viewport dimensions and zoom factor defines the view space to clip space orthographic projection. Because world space is defined with the origin in the center of the screen, the frustum planes are +/- half screen widths, scaled by the zoom factor.
TODO: clarify coordinates when rendering into viewports that don’t cover the entire screen
Two functions are provided to map between screen space and world space:
Camera2d::screen_to_world and Camera2d::world_to_screen.
For information on tile-based rendering and tile coordinates, see the tile module.
Structs§
- Camera2d
- Represents a camera (“view”) positioned and oriented in a 2D scene with a 2D transformation and a 2D projection
Functions§
- transform_
mat_ world_ to_ view - Builds a 4x4 transformation matrix that will transform points in world space coordinates to view space coordinates based on the current 2D view position and orientation.