camera

package
v0.0.0-...-5e2a49b Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodeDimensions

func NodeDimensions(n *node.Node) (w, h float64)

NodeDimensions returns the width and height used for AABB culling.

func ShouldCull

func ShouldCull(n *node.Node, viewWorld [6]float64, cullBounds types.Rect) bool

ShouldCull returns true if the node should be skipped during rendering. viewWorld is the coordinate-space transform used for AABB computation (typically view * worldTransform for screen-space culling). Containers are never culled. Text nodes are culled when measured dimensions are available.

func WorldAABB

func WorldAABB(transform [6]float64, w, h float64) types.Rect

WorldAABB computes the axis-aligned bounding box for a rectangle of size (w, h) transformed by the given affine matrix. Zero allocations.

Types

type Camera

type Camera struct {
	// X and Y are the world-space position the camera centers on.
	X, Y float64
	// Zoom is the scale factor (1.0 = no zoom, >1 = zoom in, <1 = zoom out).
	Zoom float64
	// Rotation is the camera rotation in radians (clockwise).
	Rotation float64
	// Viewport is the screen-space rectangle this camera renders into.
	Viewport types.Rect

	// CullEnabled skips nodes whose world AABB doesn't intersect the
	// camera's visible bounds.
	CullEnabled bool

	// BoundsEnabled clamps the camera position so the visible area stays
	// within Bounds.
	BoundsEnabled bool
	// Bounds is the world-space rectangle the camera is clamped to when
	// BoundsEnabled is true.
	Bounds types.Rect
	// contains filtered or unexported fields
}

Camera controls the view into the scene: position, zoom, rotation, and viewport.

func NewCamera

func NewCamera(viewport types.Rect) *Camera

NewCamera creates a Camera with default values and the given viewport.

func (*Camera) ClampToBounds

func (c *Camera) ClampToBounds()

ClampToBounds immediately clamps the camera position so the visible area stays within Bounds. Call this after modifying X/Y directly (e.g. in a drag callback) to prevent a single frame where the camera sees outside the bounds. No-op if BoundsEnabled is false.

func (*Camera) ClearBounds

func (c *Camera) ClearBounds()

ClearBounds disables camera bounds clamping.

func (*Camera) ComputeViewMatrix

func (c *Camera) ComputeViewMatrix() [6]float64

ComputeViewMatrix recomputes the cached view matrix if dirty.

viewMatrix = Translate(cx, cy) * Scale(zoom) * Rotate(-rotation) * Translate(-X, -Y) where cx, cy = viewport center.

func (*Camera) Follow

func (c *Camera) Follow(n *node.Node, offsetX, offsetY, lerp float64)

Follow makes the camera track a target node with the given offset and lerp factor. A lerp of 1.0 snaps immediately; lower values give smoother following.

func (*Camera) Invalidate

func (c *Camera) Invalidate()

Invalidate forces a recomputation of the view matrix.

func (*Camera) IsDirty

func (c *Camera) IsDirty() bool

IsDirty reports whether the view matrix needs recomputation.

func (*Camera) ScreenToWorld

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

ScreenToWorld converts screen coordinates to world coordinates.

func (*Camera) ScrollTo

func (c *Camera) ScrollTo(x, y float64, cfg types.TweenConfig)

ScrollTo animates the camera to the given world position using the provided TweenConfig for duration and easing.

func (*Camera) ScrollToTile

func (c *Camera) ScrollToTile(tileX, tileY int, tileW, tileH float64, cfg types.TweenConfig)

ScrollToTile scrolls to the center of the given tile in a tile-based layout.

func (*Camera) ScrollTweenActive

func (c *Camera) ScrollTweenActive() bool

ScrollTweenActive reports whether a scroll animation is in progress.

func (*Camera) SetBounds

func (c *Camera) SetBounds(bounds types.Rect)

SetBounds enables camera bounds clamping.

func (*Camera) Unfollow

func (c *Camera) Unfollow()

Unfollow stops tracking the current target node.

func (*Camera) Update

func (c *Camera) Update(dt float32)

Update advances follow, scroll, and bounds clamping. Called from Scene.Update().

func (*Camera) VisibleBounds

func (c *Camera) VisibleBounds() types.Rect

VisibleBounds returns the axis-aligned bounding rect of the camera's visible area in world space.

func (*Camera) WorldToScreen

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

WorldToScreen converts world coordinates to screen coordinates.

Jump to

Keyboard shortcuts

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