camera

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClampZoom

func ClampZoom(c *Camera)

ClampZoom clamps c.Zoom to [MinZoom, MaxZoom].

func MustRegisterECS

func MustRegisterECS(w *ecs.World) ecs.Comp[Camera]

MustRegisterECS is RegisterECS, panicking on error.

func RegisterECS

func RegisterECS(w *ecs.World) (ecs.Comp[Camera], error)

RegisterECS registers the Camera component type and returns the handle used to reach it. The handle is the only way to read or write a Camera, so a caller keeps what this returns.

func ViewProj

func ViewProj(c Camera, vpW, vpH float32) [16]float32

ViewProj builds a column-major 4x4 orthographic view-projection matrix from a Camera component and viewport size.

Types

type Camera

type Camera struct {
	X, Y    float32
	Zoom    float32
	MinZoom float32
	MaxZoom float32
	Active  uint8 // 1 = primary camera
}

Camera is an ECS 2D camera component and the single source of truth for all view state (position, zoom, limits).

func (*Camera) ClampToBounds

func (c *Camera) ClampToBounds(worldW, worldH, vpW, vpH float32)

ClampToBounds keeps the visible region from drifting off the world.

func (*Camera) Fit

func (c *Camera) Fit(worldW, worldH, vpW, vpH float32)

Fit centres the camera on the world and picks a zoom that shows the whole world inside the viewport, clamped to [MinZoom, MaxZoom].

func (*Camera) LocalToWorld

func (c *Camera) LocalToWorld(lx, ly, vpW, vpH float32) (float32, float32)

LocalToWorld converts a local viewport pixel to world coordinates.

func (*Camera) Pan

func (c *Camera) Pan(dx, dy float32)

Pan moves the view by (dx, dy) in local viewport pixels. Dragging right (positive dx) shifts the world left. Dragging down (positive dy) shifts the world down (camera Y decreases).

func (*Camera) WorldToLocal

func (c *Camera) WorldToLocal(wx, wy, vpW, vpH float32) (float32, float32)

WorldToLocal converts a world point to local viewport pixels.

func (*Camera) ZoomAt

func (c *Camera) ZoomAt(factor, cursorX, cursorY, vpW, vpH float32)

ZoomAt multiplies Zoom by factor while keeping the world point under the cursor fixed on screen. cursorX/cursorY are in viewport pixels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL