mathf

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AnchorTopLeft      = Vec2{X: 0, Y: 0}
	AnchorTopCenter    = Vec2{X: 0.5, Y: 0}
	AnchorTopRight     = Vec2{X: 1, Y: 0}
	AnchorMiddleLeft   = Vec2{X: 0, Y: 0.5}
	AnchorMiddleCenter = Vec2{X: 0.5, Y: 0.5}
	AnchorMiddleRight  = Vec2{X: 1, Y: 0.5}
	AnchorBottomLeft   = Vec2{X: 0, Y: 1}
	AnchorBottomCenter = Vec2{X: 0.5, Y: 1}
	AnchorBottomRight  = Vec2{X: 1, Y: 1}
)

9 standard anchors

View Source
var (
	// Vec2Zero is a Vec2 of (0, 0)
	Vec2Zero = Vec2{0, 0}
	// Vec2One is a Vec2 of (1, 1)
	Vec2One = Vec2{1, 1}
)

Functions

func BindAngle

func BindAngle(angle float64) float64

func Clamp

func Clamp(value, min, max float64) float64

func DeltaAngle

func DeltaAngle(current, target float64) float64

func EaseInBack

func EaseInBack(t float64) float64

func EaseInBounce

func EaseInBounce(t float64) float64

func EaseInCirc

func EaseInCirc(t float64) float64

func EaseInCubic

func EaseInCubic(t float64) float64

func EaseInElastic

func EaseInElastic(t float64) float64

func EaseInExpo

func EaseInExpo(t float64) float64

func EaseInOutBack

func EaseInOutBack(t float64) float64

func EaseInOutBounce

func EaseInOutBounce(t float64) float64

func EaseInOutCirc

func EaseInOutCirc(t float64) float64

func EaseInOutCubic

func EaseInOutCubic(t float64) float64

func EaseInOutElastic

func EaseInOutElastic(t float64) float64

func EaseInOutExpo

func EaseInOutExpo(t float64) float64

func EaseInOutQuad

func EaseInOutQuad(t float64) float64

func EaseInOutQuart

func EaseInOutQuart(t float64) float64

func EaseInOutQuint

func EaseInOutQuint(t float64) float64

func EaseInOutSine

func EaseInOutSine(t float64) float64

func EaseInQuad

func EaseInQuad(t float64) float64

func EaseInQuart

func EaseInQuart(t float64) float64

func EaseInQuint

func EaseInQuint(t float64) float64

func EaseInSine

func EaseInSine(t float64) float64

func EaseLinear

func EaseLinear(t float64) float64

func EaseOutBack

func EaseOutBack(t float64) float64

func EaseOutBounce

func EaseOutBounce(t float64) float64

func EaseOutCirc

func EaseOutCirc(t float64) float64

func EaseOutCubic

func EaseOutCubic(t float64) float64

func EaseOutElastic

func EaseOutElastic(t float64) float64

func EaseOutExpo

func EaseOutExpo(t float64) float64

func EaseOutQuad

func EaseOutQuad(t float64) float64

func EaseOutQuart

func EaseOutQuart(t float64) float64

func EaseOutQuint

func EaseOutQuint(t float64) float64

func EaseOutSine

func EaseOutSine(t float64) float64

func Lerp

func Lerp(start, end, percent float64) float64

func MoveTowards

func MoveTowards(current, target, maxDelta float64) float64

func Repeat

func Repeat(value, length float64) float64

func RotateTowards

func RotateTowards(current, target, maxDelta float64) float64

RotateTowards calculates the angle going from current to target not exceeding max delta and respecting the jump from +pi to -pi. All angles are in radians.

func Sign

func Sign(value float64) float64

Types

type Bounds

type Bounds struct {
	X      float64
	Y      float64
	Width  float64
	Height float64
}

func NewBoundsWidthHeight

func NewBoundsWidthHeight(x, y, width, height float64) Bounds

func (Bounds) Bottom

func (b Bounds) Bottom() float64

func (Bounds) Contains

func (b Bounds) Contains(p Vec2) bool

Contains returns true if the point is inside our bounds

func (Bounds) Inside added in v0.3.0

func (b Bounds) Inside(o Bounds) bool

Inside returns true if our bounds is entirely inside the other bounds

func (Bounds) Overlaps

func (b Bounds) Overlaps(o Bounds) bool

Overlaps returns true if we are even partially overlapping with the other bounds

func (Bounds) Right

func (b Bounds) Right() float64

func (Bounds) Surrounds added in v0.3.0

func (b Bounds) Surrounds(o Bounds) bool

Surrounds returns true if our bounds entirely surrounds the other bounds

type EaseFunc

type EaseFunc func(float64) float64

func EaseInElasticFunc

func EaseInElasticFunc(period float64) EaseFunc

func EaseInOutElasticFunc

func EaseInOutElasticFunc(period float64) EaseFunc

func EaseOutElasticFunc

func EaseOutElasticFunc(period float64) EaseFunc

type GameTime

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

func NewGameTime

func NewGameTime() *GameTime

func (*GameTime) DeltaTime

func (gt *GameTime) DeltaTime() float64

func (*GameTime) TotalDuration

func (gt *GameTime) TotalDuration() time.Duration

func (*GameTime) TotalSeconds

func (gt *GameTime) TotalSeconds() float64

type Ticker

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

func NewTicker

func NewTicker() *Ticker

func (*Ticker) Add

func (t *Ticker) Add(imp TickerImp)

func (*Ticker) Tick

func (t *Ticker) Tick(gameTime *GameTime)

type TickerImp

type TickerImp interface {
	Start()                  // first run, should reset to starting state
	Pause()                  // stops ticking but keeps state
	Resume()                 // resumes ticking
	IsPaused() bool          // if we are paused
	IsComplete() bool        // if we are complete
	Tick(gameTime *GameTime) // update our listeners
}

type Timer

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

func NewTimer

func NewTimer(duration float64, options ...TimerOption) *Timer

func (*Timer) IsComplete

func (t *Timer) IsComplete() bool

func (*Timer) IsPaused

func (t *Timer) IsPaused() bool

func (*Timer) Pause

func (t *Timer) Pause()

func (*Timer) Resume

func (t *Timer) Resume()

func (*Timer) Start

func (t *Timer) Start()

func (*Timer) Tick

func (t *Timer) Tick(gameTime *GameTime)

type TimerCompleteFunc

type TimerCompleteFunc func()

type TimerOption

type TimerOption func(timer *Timer)

func TimerOnComplete

func TimerOnComplete(fn TimerCompleteFunc) TimerOption

func TimerPlay added in v0.3.0

func TimerPlay() TimerOption

func TimerWithRepeat

func TimerWithRepeat(mode TimerRepeatMode) TimerOption

type TimerRepeatMode

type TimerRepeatMode string
const (
	TimerNoRepeat TimerRepeatMode = "NoRepeat"
	TimerRepeats  TimerRepeatMode = "Repeats"
)

type Transform

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

Transform holds all data associated to a location

func NewTransform

func NewTransform(options ...TransformOption) *Transform

NewTransform will create a new transform with: * position at 0,0, * rotation of 0 degress * anchor at top left * width, height, natural width and natural height are all 0 * you will have to set these before the first build Note that transforms start dirty.

func (*Transform) Anchor added in v0.3.0

func (t *Transform) Anchor() Vec2

func (*Transform) Bounds added in v0.3.0

func (t *Transform) Bounds() Bounds

Bounds of our transform NOTE: does not take into account rotation yet...

func (*Transform) Clean

func (t *Transform) Clean()

Clean will clean up the dirty status back to false

func (*Transform) GeoM added in v0.3.0

func (t *Transform) GeoM() ebiten.GeoM

func (*Transform) Height added in v0.3.0

func (t *Transform) Height() float64

func (*Transform) IsDirty

func (t *Transform) IsDirty() bool

IsDirty returns whether or not we have changed since the last update

func (*Transform) NaturalHeight added in v0.3.0

func (t *Transform) NaturalHeight() float64

func (*Transform) NaturalSize added in v0.3.0

func (t *Transform) NaturalSize() (float64, float64)

func (*Transform) NaturalWidth added in v0.3.0

func (t *Transform) NaturalWidth() float64

func (*Transform) Position

func (t *Transform) Position() Vec2

Position will return our position vector

func (*Transform) ResetScale added in v0.3.0

func (t *Transform) ResetScale()

ResetScale will set the width and height values to match the natural width and height values.

func (*Transform) Rotation

func (t *Transform) Rotation() float64

Rotation will return the rotation value

func (*Transform) SetAnchor added in v0.3.0

func (t *Transform) SetAnchor(anchor Vec2)

func (*Transform) SetHeight added in v0.3.0

func (t *Transform) SetHeight(height float64)

func (*Transform) SetNaturalHeight added in v0.3.0

func (t *Transform) SetNaturalHeight(naturalHeight float64)

SetNaturalHeight will set the natural height

func (*Transform) SetNaturalWidth added in v0.3.0

func (t *Transform) SetNaturalWidth(naturalWidth float64)

SetNaturalWidth will set the natural width

func (*Transform) SetPosition

func (t *Transform) SetPosition(pos Vec2)

SetPosition will set our position to a different one

func (*Transform) SetRotation

func (t *Transform) SetRotation(rotation float64)

SetRotation will change the rotation value and mark us as dirty.

func (*Transform) SetSize added in v0.3.0

func (t *Transform) SetSize(width, height float64)

func (*Transform) SetWidth added in v0.3.0

func (t *Transform) SetWidth(width float64)

func (*Transform) SetX

func (t *Transform) SetX(x float64)

SetX will change the x value and mark us as dirty.

func (*Transform) SetY

func (t *Transform) SetY(y float64)

SetY will change the y value and mark us as dirty.

func (*Transform) Size added in v0.3.0

func (t *Transform) Size() (float64, float64)

Size of our transform

func (*Transform) Translate

func (t *Transform) Translate(delta Vec2)

Translate will move x and y by our vec2

func (*Transform) TranslateX

func (t *Transform) TranslateX(x float64)

TranslateX moves us in the X axis

func (*Transform) TranslateY

func (t *Transform) TranslateY(y float64)

TranslateY moves us in the Y axis

func (*Transform) Width added in v0.3.0

func (t *Transform) Width() float64

func (*Transform) X

func (t *Transform) X() float64

X will return the x value

func (*Transform) Y

func (t *Transform) Y() float64

Y will return the y value

type TransformOption added in v0.3.0

type TransformOption func(t *Transform)

func TransformAtPosition added in v0.3.0

func TransformAtPosition(position Vec2) TransformOption

func TransformAtXY added in v0.3.0

func TransformAtXY(x, y float64) TransformOption

func TransformWithAnchor added in v0.3.0

func TransformWithAnchor(anchor Vec2) TransformOption

func TransformWithFixedOffset added in v0.3.0

func TransformWithFixedOffset(offset float64) TransformOption

func TransformWithHeight added in v0.3.0

func TransformWithHeight(height float64) TransformOption

func TransformWithNaturalHeight added in v0.3.0

func TransformWithNaturalHeight(naturalHeight float64) TransformOption

TransformWithNaturalHeight will set the transform natural height value this will also override the current height to match

func TransformWithNaturalSize added in v0.3.0

func TransformWithNaturalSize(naturalWidth, naturalHeight float64) TransformOption

func TransformWithNaturalWidth added in v0.3.0

func TransformWithNaturalWidth(naturalWidth float64) TransformOption

TransformWithNaturalWidth will set the transform natural width value this will also override the current height to match

func TransformWithRotation added in v0.3.0

func TransformWithRotation(rotation float64) TransformOption

func TransformWithSize added in v0.3.0

func TransformWithSize(width, height float64) TransformOption

func TransformWithWidth added in v0.3.0

func TransformWithWidth(width float64) TransformOption

type Tween

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

func NewPositionTween added in v0.3.0

func NewPositionTween(
	target *Transform,
	start, end Vec2,
	duration float64,
	useRelative bool,
	options ...TweenOption,
) *Tween

func NewRotationTween added in v0.3.0

func NewRotationTween(
	target *Transform,
	start, end, duration float64,
	useRelative bool,
	options ...TweenOption,
) *Tween

func NewTween

func NewTween(duration float64, options ...TweenOption) *Tween

func NewWidthTween added in v0.3.0

func NewWidthTween(
	target *Transform,
	start, end float64,
	duration float64,
	options ...TweenOption,
) *Tween

func (*Tween) Bounce added in v0.3.0

func (t *Tween) Bounce()

Bounce will start the tween bouncing back if the tween was not yet complete

func (*Tween) IsComplete

func (t *Tween) IsComplete() bool

func (*Tween) IsPaused

func (t *Tween) IsPaused() bool

func (*Tween) Pause

func (t *Tween) Pause()

func (*Tween) Reset added in v0.3.0

func (t *Tween) Reset()

func (*Tween) Resume

func (t *Tween) Resume()

func (*Tween) Start

func (t *Tween) Start()

func (*Tween) Tick

func (t *Tween) Tick(gameTime *GameTime)

type TweenOption

type TweenOption func(t *Tween)

func TweenOnComplete

func TweenOnComplete(fn TweenStatusChangedFunc) TweenOption

func TweenOnStart

func TweenOnStart(fn TweenStatusChangedFunc) TweenOption

func TweenPlay added in v0.3.0

func TweenPlay() TweenOption

func TweenUpdateFunc

func TweenUpdateFunc(fn TweenValueFunc) TweenOption

func TweenUpdatePointer

func TweenUpdatePointer(value *float64) TweenOption

func TweenWithEase

func TweenWithEase(easeFunc EaseFunc) TweenOption

func TweenWithRepeat

func TweenWithRepeat(mode TweenRepeatMode) TweenOption

type TweenRepeatMode

type TweenRepeatMode string
const (
	// Does not repeat, will trigger complete and be removed from ticker
	TweenNoRepeat TweenRepeatMode = "NoRepeat"
	// Repeats the tween from the start over and over again
	TweenRepeatLoop TweenRepeatMode = "Loop"
	// Bounces the tween going from 0>1>0 in a loop, reversing the ease to get a good bounce
	TweenRepeatBounceLoop TweenRepeatMode = "RepeatBounce"
	// Bounces the tween going from 0>1>0, reversing the ease to get a good bounce
	TweenRepeatBounce TweenRepeatMode = "Bounce"
	// Pauses the tween at the end ready to start again
	TweenRepeatPause TweenRepeatMode = "Pause"
)

type TweenStatusChangedFunc

type TweenStatusChangedFunc func(tween *Tween)

type TweenValueFunc

type TweenValueFunc func(value float64)

func TweenVec2Func

func TweenVec2Func(start, end Vec2, fn func(Vec2)) TweenValueFunc

func TweenVec2Pointer

func TweenVec2Pointer(start, end Vec2, ptr *Vec2) TweenValueFunc

type Vec2

type Vec2 struct {
	X, Y float64
}

Vec2 describes a 2D vector or point in floats

func Vec2FromAngle

func Vec2FromAngle(angle float64) Vec2

Vec2FromAngle returns a Vec2 from an angle in radians

func Vec2FromInts added in v0.3.0

func Vec2FromInts(x, y int) Vec2

Vec2FromInts returns a Vec2 from an image point

func Vec2FromPoint

func Vec2FromPoint(pt image.Point) Vec2

Vec2FromPoint returns a Vec2 from an image point

func Vec2Lerp

func Vec2Lerp(start, end Vec2, percent float64) Vec2

Vec2Lerp returns a Vec2 as a linear interpolation between two vectors

func (Vec2) Add

func (v Vec2) Add(other Vec2) Vec2

Add other to us

func (Vec2) AddScalar

func (v Vec2) AddScalar(scalar float64) Vec2

AddScalar adds scalar to both elements

func (Vec2) Angle

func (v Vec2) Angle() float64

Angle returns the angle in radians of our vector

func (Vec2) Cross

func (v Vec2) Cross(other Vec2) float64

Cross returns the cross product of vectors v and other

func (Vec2) Dist

func (v Vec2) Dist(other Vec2) float64

Dist returns the distance between two vectors

func (Vec2) Div

func (v Vec2) Div(other Vec2) Vec2

Div other from us

func (Vec2) DivScalar

func (v Vec2) DivScalar(scalar float64) Vec2

SubScalar subtracts both elements by a scalar

func (Vec2) Dot

func (v Vec2) Dot(other Vec2) float64

Dot returns the dot product of vectors v and other

func (Vec2) Mag

func (v Vec2) Mag() float64

Mag returns the magnitude of our vector

func (Vec2) Map

func (v Vec2) Map(fun func(float64) float64) Vec2

Map applies a function to both X and Y components and returns a new Vec2 of the result

func (Vec2) Mul

func (v Vec2) Mul(other Vec2) Vec2

Mul multiplies other to us

func (Vec2) MulScalar

func (v Vec2) MulScalar(scalar float64) Vec2

MulScalar multiplies both elements by a scalar

func (Vec2) Normal

func (v Vec2) Normal() Vec2

Normal returns a vectors normal, same as rotating 90 degress

func (Vec2) SqrDist

func (v Vec2) SqrDist(other Vec2) float64

SqrDist returns the square distance between us and another vector

func (Vec2) SqrMag

func (v Vec2) SqrMag() float64

SqrMag returns the Square Magnitude of our vector

func (*Vec2) String

func (v *Vec2) String() string

String returns vec2 as a string

func (Vec2) Sub

func (v Vec2) Sub(other Vec2) Vec2

Sub other from us

func (Vec2) SubScalar

func (v Vec2) SubScalar(scalar float64) Vec2

SubScalar subtracts both elements by a scalar

func (Vec2) ToPoint

func (v Vec2) ToPoint() image.Point

func (Vec2) Unit

func (v Vec2) Unit() Vec2

Unit is a 1 unit vector in the same direction as v. Unless v is (0,0) in which case it returns (0,0).

func (Vec2) XY

func (v Vec2) XY() (float64, float64)

XY returns the X and Y components separately

Jump to

Keyboard shortcuts

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