view

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package view is a display-free 2D pan/zoom camera: it maps between world and screen space around a centred focus, with follow and fit-to-bounds framing, and imports no rendering backend — so headless sims and web front-ends share the same camera math the Ebiten front-ends use. When a draw transform is needed on top of this, the front-end layers github.com/danielriddell21/crucible/camera over it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	// X and Y are the world point at the centre of the view.
	X, Y float64
	// Zoom is the magnification factor.
	Zoom float64
	// ViewW and ViewH are the screen size in pixels.
	ViewW, ViewH float64
}

Camera frames a 2D world onto a ViewW×ViewH screen, centred on (X, Y) and magnified by Zoom.

func New

func New(viewW, viewH float64) *Camera

New returns a camera at unit zoom filling a viewW×viewH screen.

func (*Camera) FitBounds

func (c *Camera) FitBounds(minX, minY, maxX, maxY, margin float64)

FitBounds centres and zooms the camera so the world rectangle, grown by margin (a fraction of its size), fits the screen. A degenerate rectangle resets the zoom to 1.

func (*Camera) Follow

func (c *Camera) Follow(wx, wy float64)

Follow centres the camera on a world point.

func (*Camera) ScreenToWorld

func (c *Camera) ScreenToWorld(sx, sy float64) (wx, wy float64)

ScreenToWorld maps a screen point back to world coordinates.

func (*Camera) WorldToScreen

func (c *Camera) WorldToScreen(wx, wy float64) (sx, sy float64)

WorldToScreen maps a world point to screen coordinates.

Jump to

Keyboard shortcuts

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