vectors

package
Version: v0.0.0-...-f053a90 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2017 License: MIT Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const MoverDefMass = 1

MoverDefMass keeps the default mass of the Mover

Variables

This section is empty.

Functions

This section is empty.

Types

type Attractor

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

Attractor ...

type GVector

type GVector interface {
	Add()
	Subtract()
	Multiply()
	Mangnitude()
	Normalize()
	Copy()
}

GVector represents a geometric/Eucleadean vector

type Mover

type Mover struct {
	Obj interface{}
	// contains filtered or unexported fields
}

Mover describes a basic moveable object/particle

func NewMover

func NewMover(obj interface{}, location *Vector, container *Vector) *Mover

NewMover creates an object of type Mover (constructor)

func (*Mover) ApplyForce

func (m *Mover) ApplyForce(force *Vector)

ApplyForce adds the force vector the object's acceleration vector

func (*Mover) BounceOff

func (m *Mover) BounceOff()

BounceOff keeps the mover within its container (bounces off) when it reaches an edge

func (*Mover) GetVelocity

func (m *Mover) GetVelocity() *Vector

GetVelocity return the current velocity vector of the Mover

func (*Mover) PixelLoc

func (m *Mover) PixelLoc() (int, int)

PixelLoc returns the rounded values of location's X and Y which are ready for rendering

func (*Mover) Reset

func (m *Mover) Reset()

Reset sets vector state to its initial value

func (*Mover) SetLimit

func (m *Mover) SetLimit(limit float64)

SetLimit puts a velocity limit when accelerating

func (*Mover) SetMass

func (m *Mover) SetMass(mass float64)

SetMass assigns the mass argument to the object's mass

func (*Mover) Update

func (m *Mover) Update()

Update modifies the object's location depending on the applied forces; Should be called on every rendering iteration

func (*Mover) UpdateSdl2

func (m *Mover) UpdateSdl2()

UpdateSdl2 performs Mover.Update() on SDL2-specific objects

type Vector

type Vector struct {
	X float64
	Y float64
}

Vector implements a GVector

func NewVector

func NewVector(x, y float64) *Vector

NewVector creates a new object of type Vector (basically constructor)

func (*Vector) Add

func (v *Vector) Add(u *Vector)

Add performs addition of the current and provided as an argument vectors

func (*Vector) Copy

func (v *Vector) Copy() *Vector

Copy creates a copy of the vector

func (*Vector) Distance

func (v *Vector) Distance(u *Vector) float64

Distance calculates the Eucleadean distance between the two vectors

func (*Vector) Divide

func (v *Vector) Divide(n float64)

Divide performs division of the current vector by N

func (*Vector) Heading

func (v *Vector) Heading() (angle float64)

Heading returns the heading of the vector in degrees

func (*Vector) Limit

func (v *Vector) Limit(mag float64)

Limit vector's magnitude by a provided value

func (*Vector) Magnitude

func (v *Vector) Magnitude() float64

Magnitude returns the magnitude of the vector

func (*Vector) Multiply

func (v *Vector) Multiply(n float64)

Multiply performs multiplication of the current vector by N

func (*Vector) Normalize

func (v *Vector) Normalize()

Normalize sets the magnitude to 1

func (*Vector) Rotate

func (v *Vector) Rotate(deg float64)

Rotate vector by a degree angle

func (*Vector) Subtract

func (v *Vector) Subtract(u *Vector)

Subtract performs subtraction of the current and provided as an argument vectors

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto