physics

package
v0.0.0-...-2c3a8a6 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HitTestCircle

func HitTestCircle(x, y float64, circle geom.Circle) bool

func HitTestEllipse

func HitTestEllipse(x, y float64, ellipse geom.Ellipse) bool

func HitTestRect

func HitTestRect(x, y float64, rect geom.Rect) bool

func ResolveCollidingCircles

func ResolveCollidingCircles(a, b *geom.Circle) bool

func ResolveCollidingEllipses

func ResolveCollidingEllipses(a, b *geom.Ellipse) bool

func ResolveCollidingPolygons

func ResolveCollidingPolygons(a, b *geom.Polygon) bool

func ResolveCollidingRects

func ResolveCollidingRects(a, b *geom.Rect) bool

Types

type AABB

type AABB struct {
	TopLeft, BottomRight geom.Point
}

AABB is an axis-aligned bounding box with X and Y indicating its top left corner.

func BoundsFromCenterSize

func BoundsFromCenterSize(x, y, w, h float64) AABB

func (AABB) Center

func (b AABB) Center() geom.Point

func (AABB) GetX

func (b AABB) GetX() float64

func (AABB) GetY

func (b AABB) GetY() float64

func (AABB) Height

func (b AABB) Height() float64

func (AABB) HitTest

func (b AABB) HitTest(x, y float64) bool

HitTest returns true when the x and y values are within the AABB.

func (AABB) HitTestXY

func (b AABB) HitTestXY(xy geom.XYGetter) bool

HitTestXY returns true when the position of the XYGetter is inside AABB.

func (AABB) Intersects

func (b AABB) Intersects(target AABB) bool

func (AABB) Rect

func (b AABB) Rect() *sdl.Rect

func (AABB) Union

func (b AABB) Union(target AABB) AABB

func (AABB) Width

func (b AABB) Width() float64

type CircleCollider

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

func (*CircleCollider) Bounds

func (cc *CircleCollider) Bounds() AABB

func (*CircleCollider) HitTest

func (cc *CircleCollider) HitTest(x, y float64) bool

HitTest returns true when position [x y] is inside the Circle. It calculates the squared distance between [x y] and the Circle's center X Y and compares this with the squared Radius.

func (*CircleCollider) HitTestXY

func (cc *CircleCollider) HitTestXY(xy geom.XYGetter) bool

HitTestXY forwards the hit-test call to the geom.Circle HitTest method and returns true when the point [x y] is inside the collider.

func (*CircleCollider) Shape

func (cc *CircleCollider) Shape() geom.Shape

type Collider

type Collider interface {
	HitTester
	Shape() geom.Shape
	Bounds() AABB
}

func NewCollider

func NewCollider(shape geom.Shape) Collider

type EllipseCollider

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

func (*EllipseCollider) Bounds

func (ec *EllipseCollider) Bounds() AABB

func (*EllipseCollider) HitTest

func (ec *EllipseCollider) HitTest(x, y float64) bool

HitTest returns true when position [x y] is inside the EllipseCollider's geom.Ellipse shape. https://math.stackexchange.com/questions/76457/check-if-a-point-is-within-an-ellipse

func (*EllipseCollider) HitTestXY

func (ec *EllipseCollider) HitTestXY(xy geom.XYGetter) bool

HitTestXY returns true when the position of the XYGetter is inside Ellipse.

func (*EllipseCollider) Shape

func (ec *EllipseCollider) Shape() geom.Shape

type HitTester

type HitTester interface {
	// HitTest returns true when the x and y values are within the HitTester.
	HitTest(x, y float64) bool
	HitTestXY(xy geom.XYGetter) bool
}

type PolygonCollider

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

func (*PolygonCollider) Bounds

func (pc *PolygonCollider) Bounds() AABB

func (*PolygonCollider) HitTest

func (pc *PolygonCollider) HitTest(x, y float64) (hit bool)

HitTest tests if the provided point [x y] is inside the PolygonCollider's geom.Polygon shape.

func (*PolygonCollider) HitTestXY

func (pc *PolygonCollider) HitTestXY(xy geom.XYGetter) bool

HitTestXY forwards the hit-test call to the geom.polygon HitTest method and returns true when the point [x y] is inside the collider.

func (*PolygonCollider) Polygon

func (pc *PolygonCollider) Polygon() geom.PolygonShape

func (*PolygonCollider) Shape

func (pc *PolygonCollider) Shape() geom.Shape

type RectCollider

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

func (*RectCollider) Bounds

func (rc *RectCollider) Bounds() AABB

func (*RectCollider) HitTest

func (rc *RectCollider) HitTest(x, y float64) bool

HitTest returns true when the x and y values are within the Rect.

func (*RectCollider) HitTestXY

func (rc *RectCollider) HitTestXY(xy geom.XYGetter) bool

HitTestXY forwards the hit-test call to the geom.Rect HitTest method and returns true when the point [x y] is inside the collider.

func (*RectCollider) Shape

func (rc *RectCollider) Shape() geom.Shape

Jump to

Keyboard shortcuts

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