phy2

package
v0.0.0-...-ef5f187 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 3 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Angle

func Angle(a, b Vec) float64

Finds the angle between two vectors

Types

type Circle

type Circle struct {
	Center Vec2
	Radius float64
}

-------------------------------------------------------------------------------- - Circle --------------------------------------------------------------------------------

func NewCircle

func NewCircle(center Vec2, radius float64) Circle

type CircleCollider

type CircleCollider struct {
	CenterX, CenterY float64 // TODO - right now this holds the entire position of the circle (relative to world space). You might consider stripping that out though
	Radius           float64
	HitLayer         CollisionLayer
	Layer            CollisionLayer
}

func NewCircleCollider

func NewCircleCollider(radius float64) CircleCollider

func (*CircleCollider) Bounds

func (c *CircleCollider) Bounds() Rect

func (*CircleCollider) Contains

func (c *CircleCollider) Contains(yProjection float64, pos Vec) bool

func (*CircleCollider) LayerMask

func (c *CircleCollider) LayerMask(layer CollisionLayer) bool

func (*CircleCollider) Overlaps

func (c *CircleCollider) Overlaps(yProjection float64, c2 *CircleCollider) bool

type ColliderCache

type ColliderCache struct {
	Current       []ecs.Id
	Last          []ecs.Id
	NewCollisions []ecs.Id // This list contains all new collisions
}

This tracks the list of current collisions

func NewColliderCache

func NewColliderCache() ColliderCache

func (*ColliderCache) Add

func (c *ColliderCache) Add(id ecs.Id)

func (*ColliderCache) Clear

func (c *ColliderCache) Clear()

type CollisionLayer

type CollisionLayer uint8

func (CollisionLayer) Mask

func (c CollisionLayer) Mask(layer CollisionLayer) bool

type HashPosition

type HashPosition struct {
	X, Y int32
}

type Rect

type Rect struct {
	Min, Max Vec
}

-------------------------------------------------------------------------------- - Rect --------------------------------------------------------------------------------

func CR

func CR(center Vec2, radius Vec2) Rect

Returns a centered Rect

func R

func R(minX, minY, maxX, maxY float64) Rect

Returns a rect with specified dimensions

func (Rect) Center

func (r Rect) Center() Vec2

func (Rect) Contains

func (r Rect) Contains(pos Vec) bool

func (Rect) H

func (r Rect) H() float64

func (Rect) Intersects

func (r Rect) Intersects(r2 Rect) bool

func (Rect) Moved

func (r Rect) Moved(v Vec2) Rect

func (Rect) Pad

func (r Rect) Pad(pad Rect) Rect

func (Rect) Unpad

func (r Rect) Unpad(pad Rect) Rect

func (Rect) W

func (r Rect) W() float64

func (Rect) WithCenter

func (r Rect) WithCenter(v Vec2) Rect

type Rigidbody

type Rigidbody struct {
	Mass     float64
	Velocity Vec2
}

func (*Rigidbody) DecodeCod

func (t *Rigidbody) DecodeCod(bs []byte) (int, error)

func (Rigidbody) EncodeCod

func (t Rigidbody) EncodeCod(bs []byte) []byte

type Rotation

type Rotation float64

func (*Rotation) DecodeCod

func (t *Rotation) DecodeCod(bs []byte) (int, error)

func (Rotation) EncodeCod

func (t Rotation) EncodeCod(bs []byte) []byte

type Scale

type Scale Vec2

func (*Scale) DecodeCod

func (t *Scale) DecodeCod(bs []byte) (int, error)

func (Scale) EncodeCod

func (t Scale) EncodeCod(bs []byte) []byte

type SpatialBucket

type SpatialBucket struct {
	// contains filtered or unexported fields
}

func NewSpatialBucket

func NewSpatialBucket(hashPos HashPosition) *SpatialBucket

type SpatialHash

type SpatialHash struct {
	// contains filtered or unexported fields
}

This holds a spatial hash of objects placed inside

func NewSpatialHash

func NewSpatialHash(bucketSize float64) *SpatialHash

TODO - pass in world dimensions? TODO - 2d bucket sizes?

func (*SpatialHash) AddCircle

func (s *SpatialHash) AddCircle(id ecs.Id, circle *CircleCollider)

func (*SpatialHash) ToHashPosition

func (s *SpatialHash) ToHashPosition(x, y float64) HashPosition

type Vec

type Vec = Vec2

func (Vec) Angle

func (v Vec) Angle() float64

type Vec2

type Vec2 struct {
	X, Y float64
}

func V2

func V2(x, y float64) Vec2

func (Vec2) Add

func (v Vec2) Add(v2 Vec2) Vec2

func (*Vec2) DecodeCod

func (t *Vec2) DecodeCod(bs []byte) (int, error)

func (Vec2) Dist

func (v Vec2) Dist(u Vec2) float64

func (Vec2) DistSq

func (v Vec2) DistSq(u Vec2) float64

func (Vec2) Dot

func (v Vec2) Dot(u Vec2) float64

func (Vec2) EncodeCod

func (t Vec2) EncodeCod(bs []byte) []byte

func (Vec2) Len

func (v Vec2) Len() float64

Returns the length of the vector

func (Vec2) LenSq

func (v Vec2) LenSq() float64

Returns the length of the vector squared. Note this is slightly faster b/c it doesn't take the square root

func (Vec2) Norm

func (v Vec2) Norm() Vec2

func (Vec2) Rotated

func (v Vec2) Rotated(radians float64) Vec2

func (Vec2) Scaled

func (v Vec2) Scaled(s float64) Vec2

func (Vec2) Sub

func (v Vec2) Sub(v2 Vec2) Vec2

type Vel

type Vel Vec2

func (Vel) Add

func (v Vel) Add(v2 Vel) Vel

func (Vel) Angle

func (v Vel) Angle() float64

func (*Vel) DecodeCod

func (t *Vel) DecodeCod(bs []byte) (int, error)

func (Vel) Dot

func (v Vel) Dot(u Vel) float64

func (Vel) EncodeCod

func (t Vel) EncodeCod(bs []byte) []byte

func (Vel) Len

func (v Vel) Len() float64

func (Vel) Norm

func (v Vel) Norm() Vel

func (Vel) Rotated

func (v Vel) Rotated(radians float64) Vel

func (Vel) Scaled

func (v Vel) Scaled(s float64) Vel

func (Vel) Sub

func (v Vel) Sub(v2 Vel) Vel

Jump to

Keyboard shortcuts

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