Documentation ¶
Overview ¶
Package physics provides vector types and operations to perform math and simple physics on those types. It also provides rules for attaching entities to vectors.
Index ¶
- Constants
- func Push(a Pushes, b Pushable) error
- type Attachable
- type ForceVector
- type Mass
- type Pushable
- type Pushes
- type Vector
- func (v Vector) Add(vs ...Vector) Vector
- func (v Vector) Angle() float64
- func (v Vector) Attach(a Attachable, offsets ...float64) Vector
- func (v Vector) AttachX(a Attachable, offX float64) Vector
- func (v Vector) AttachY(a Attachable, offY float64) Vector
- func (v Vector) Copy() Vector
- func (v Vector) Detach() Vector
- func (v Vector) Distance(v2 Vector) float64
- func (v Vector) Dot(v2 Vector) float64
- func (v Vector) GetForce() ForceVector
- func (v Vector) GetPos() (float64, float64)
- func (v Vector) Magnitude() float64
- func (v Vector) Normalize() Vector
- func (v Vector) Rotate(fs ...float64) Vector
- func (v Vector) Scale(fs ...float64) Vector
- func (v Vector) SetPos(x, y float64) Vector
- func (v Vector) SetX(x float64) Vector
- func (v Vector) SetY(y float64) Vector
- func (v Vector) ShiftX(x float64) Vector
- func (v Vector) ShiftY(y float64) Vector
- func (v Vector) Sub(vs ...Vector) Vector
- func (v Vector) Vec() Vector
- func (v Vector) X() float64
- func (v Vector) Xp() *float64
- func (v Vector) Y() float64
- func (v Vector) Yp() *float64
- func (v Vector) Zero() Vector
Constants ¶
const ( // CUTOFF is used for rounding after floating point operations to // zero out vector values that are sufficiently close to zero CUTOFF = 0.001 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attachable ¶
type Attachable interface { Detach() Vector Attach(Attachable, ...float64) Vector AttachX(Attachable, float64) Vector AttachY(Attachable, float64) Vector Vec() Vector }
Attachable represents things that can be attached to Vectors
type ForceVector ¶
ForceVector is a vector that has some force and can operate on entites with mass
func DefaultForceVector ¶
func DefaultForceVector(delta Vector, mass float64) ForceVector
DefaultForceVector returns a force vector that converts the mass given into a force float
func NewForceVector ¶
func NewForceVector(direction Vector, force float64) ForceVector
NewForceVector returns a force vector
func (ForceVector) GetForce ¶
func (f ForceVector) GetForce() ForceVector
GetForce is a self-returning call
type Mass ¶
type Mass struct {
// contains filtered or unexported fields
}
A Mass can have forces applied against it
type Pushable ¶
Pushable is implemented by anything that has mass and directional movement, and therefore can be pushed.
type Pushes ¶
type Pushes interface {
GetForce() ForceVector
}
A Pushes can push Pushable things through its associated ForceVector, or how hard the Pushable should move in a given direction
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
A Vector is a two-dimensional point or vector used throughout oak to maintain functionality between packages.
func AngleVector ¶
AngleVector creates a unit vector by the cosine and sine of the given angle in degrees
func NewVector32 ¶
NewVector32 accepts float32s (and will cast them to float64s), to create a vector
func PtrVector ¶
PtrVector takes in pointers as opposed to float values-- these same pointers will be used in the returned vector and by attachments to that vector.
func (Vector) Attach ¶
func (v Vector) Attach(a Attachable, offsets ...float64) Vector
Attach takes in something for this vector to attach to and a set of offsets. The resulting combined vector with the offsets is then returned, and needs to be assigned to the calling vector.
func (Vector) AttachX ¶
func (v Vector) AttachX(a Attachable, offX float64) Vector
AttachX performs an attachment that only attaches on the X axis.
func (Vector) AttachY ¶
func (v Vector) AttachY(a Attachable, offY float64) Vector
AttachY performs an attachment that only attaches on the Y axis.
func (Vector) Detach ¶
Detach returns a vector no longer attached to anything. The returned vector needs to be assigned to the caller for the caller to be replaced (vectors do not use pointer receivers)
func (Vector) GetForce ¶
func (v Vector) GetForce() ForceVector
GetForce on a non-force vector returns a zero-value for force
func (Vector) Rotate ¶
Rotate takes in a set of angles and rotates v by their sum the input angles are assumed to be in degrees.
func (Vector) Scale ¶
Scale scales a vector by a set of floating points Scale(f1,f2,f3) is equivalent to Scale(f1*f2*f3)