spatial

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

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 4 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContinuousCollisionDetector continuousDetector

ContinuousCollisionDetector is the global continuous collision detector instance

View Source
var Detector detector

Detector is the global collision detector instance

View Source
var Resolver resolver

Resolver is the global collision resolver instance (without physics)

Functions

func UpdateSkinAndAAB

func UpdateSkinAndAAB(shape *Shape, scale vector.TwoReader, rot float64)

UpdateSkinAndAAB updates a shape's skin and axis-aligned bounding box based on scale and rotation Uses optimized path for non-rotated shapes

func UpdateWorldVertices

func UpdateWorldVertices(localVerts []vector.Two, pos, scale vector.TwoReader, rot float64) []vector.Two

UpdateWorldVertices transforms local vertices to world space by applying scale, rotation, and translation

func UpdateWorldVerticesSimple

func UpdateWorldVerticesSimple(localVerts []vector.Two, pos vector.Two) []vector.Two

UpdateWorldVerticesSimple transforms local vertices to world space by applying translation only

Types

type AAB

type AAB struct {
	Width  float64
	Height float64
}

AAB represents an axis-aligned bounding box

type Circle

type Circle struct {
	Radius float64
}

Circle represents a circular shape with radius

type Collision

type Collision struct {
	Start, End, Normal vector.Two
	Depth              float64
	CollidingEdgeA     CollisionEdge
	CollidingEdgeB     CollisionEdge
}

Collision represents information about a collision between two objects

func (Collision) IsTop

func (c Collision) IsTop() bool

IsTop determines if the collision occurred from the top of object A relative to object B In a coordinate system where lower Y values are higher up, a top collision normal has Y < 0

func (Collision) IsTopB

func (c Collision) IsTopB() bool

IsTopB determines if the collision occurred from the top of object B relative to object A From B's perspective, the collision normal direction is inverted

type CollisionEdge

type CollisionEdge struct {
	Index    int
	Vertices []vector.Two
}

CollisionEdge represents an edge involved in a collision

type Direction

type Direction struct {
	Value directionValue
}

func NewDirectionLeft

func NewDirectionLeft() Direction

func NewDirectionRight

func NewDirectionRight() Direction

func (*Direction) AsFloat

func (d *Direction) AsFloat() float64

func (*Direction) IsLeft

func (d *Direction) IsLeft() bool

func (*Direction) IsRight

func (d *Direction) IsRight() bool

func (*Direction) SetLeft

func (d *Direction) SetLeft()

func (*Direction) SetRight

func (d *Direction) SetRight()

func (*Direction) Valid

func (d *Direction) Valid() bool

type Polygon

type Polygon struct {
	LocalVertices []vector.Two
	WorldVertices []vector.Two
}

Polygon represents a shape defined by vertices in both local and world space

type Position

type Position struct{ vector.Two }

Position represents a 2D point in space

func NewPosition

func NewPosition(x, y float64) Position

NewPosition creates a new Position at the specified coordinates

type PreviousPosition

type PreviousPosition struct{ vector.Two }

PreviousPosition stores the previous position for continuous collision detection

type Rotation

type Rotation float64

Rotation represents an angle in radians

func (Rotation) AsFloat64

func (r Rotation) AsFloat64() float64

AsFloat64 returns the rotation value as a float64

func (*Rotation) Set

func (r *Rotation) Set(val float64)

type Scale

type Scale struct{ vector.Two }

Scale represents scaling factors for x and y dimensions

func NewScale

func NewScale(x, y float64) Scale

NewScale creates a new Scale with the specified x and y scaling factors

type Shape

type Shape struct {
	LocalAAB AAB
	WorldAAB AAB
	Polygon  Polygon
	Skin     Skin
}

Shape represents a geometric shape with local and world bounds, polygon definition, and skin

func NewDoubleRamp

func NewDoubleRamp(width, height float64, topWidthRatio float64) Shape

NewDoubleRamp creates a two-sided ramp (trapezoid with slopes on both sides) width: total width of the ramp height: height of the ramp topWidthRatio: width of the flat section on top (as a ratio of total width, 0-1) Note: In this engine, lower Y values are higher in the world (y=0 is top of screen)

func NewPolygon

func NewPolygon(localVertices []vector.Two) Shape

NewPolygon creates a new shape from a set of local vertices

func NewRectangle

func NewRectangle(width, height float64) Shape

NewRectangle creates a rectangular shape with specified width and height

func NewRegularPolygon

func NewRegularPolygon(radius float64, numVertices int) Shape

func NewSingleRamp

func NewSingleRamp(width, height float64, leftToRight bool) Shape

NewSingleRamp creates a triangular ramp shape with specified dimensions When leftToRight is true, the ramp ascends from left to right

func NewTrapezoidPlatform

func NewTrapezoidPlatform(width, height float64, slopeRatio float64) Shape

NewTrapezoidPlatform creates a trapezoid shape with a flat top of the specified width, angled sides, and a narrower bottom. The slopeRatio controls how much narrower the bottom is This is useful for creating one-way platforms with more gradual angled sides

func NewTriangularPlatform

func NewTriangularPlatform(width, height float64) Shape

NewTriangularPlatform creates a triangular shape with a flat top of the specified width and angled sides meeting at a point at the specified height below the top This is useful for one-way platforms where you want to prevent side collisions

type Skin

type Skin struct {
	AAB    AAB
	Circle Circle
}

Skin contains collision detection primitives for a shape

func CalcSkin

func CalcSkin(p Polygon, aab AAB, scale vector.TwoReader) Skin

CalcSkin calculates collision primitives for a polygon

Jump to

Keyboard shortcuts

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