FPixelPerfectCamera
Pixel-perfect orthographic framing for 2D games: the view always shows a whole number of screen pixels per texel, so a 16 px sprite never lands on a fractional pixel and never shimmers while the camera pans.
- Module
- Camera
- Header
#include "Camera/PixelPerfect.h"- Namespace
Mowo
Public functions
| Returns | Name | Description |
|---|---|---|
uint32_t | IntegerScale | The largest whole-number multiple of the reference height that fits the viewport, never below 1 (a window smaller than the reference crops instead of shrinking the art). |
float | OrthoHalfHeight | Half the viewport height in world units for scale screen pixels per texel and pixelsPerUnit texels per world unit. |
float | PixelWorldSize | World length of one screen pixel. |
float | SnapToPixel | Rounds value to a whole screen pixel. |
void | Resolve | Resolves the component's scale and ortho size for a viewport of this height. |
void | SnapPosition | Snaps a camera position along its own right and up axes so the pan moves in whole pixels. |
Function details
IntegerScale
static uint32_t IntegerScale(uint32_t viewportHeightPx, uint32_t referenceHeightPx)The largest whole-number multiple of the reference height that fits the viewport, never below 1 (a window smaller than the reference crops instead of shrinking the art).
OrthoHalfHeight
static float OrthoHalfHeight(uint32_t viewportHeightPx, uint32_t scale, float pixelsPerUnit)Half the viewport height in world units for scale screen pixels per texel and pixelsPerUnit texels per world unit.
PixelWorldSize
static float PixelWorldSize(uint32_t scale, float pixelsPerUnit)World length of one screen pixel.
SnapToPixel
static float SnapToPixel(float value, float pixelWorldSize)Rounds value to a whole screen pixel.
Resolve
static void Resolve(CameraComponent& camera, uint32_t viewportHeightPx)Resolves the component's scale and ortho size for a viewport of this height. A component that is not pixel-perfect is left alone.
SnapPosition
static void SnapPosition(const CameraComponent& camera, const Vec3& right, const Vec3& up, Vec3& position)Snaps a camera position along its own right and up axes so the pan moves in whole pixels. No-op until Resolve has run for the component.