unum

package
v0.0.0-...-76c535a Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MIT Imports: 3 Imported by: 0

README

unum

Go programming helpers for common maths needs; plus vectors, matrices and quaternions.

Usage

const (
	Deg2Rad = math.Pi / 180
	Rad2Deg = 180 / math.Pi
)
var (
	Infinity             = math.Inf(1)
	NegativeInfinity     = math.Inf(-1)
	Epsilon              = math.Nextafter(1, Infinity) - 1
	EpsilonEqFloat       = 1.121039E-44
	EpsilonEqFloatFactor = 1E-06
	EpsilonEqVec         = 9.99999944E-11
)
func Clamp
func Clamp(val, c0, c1 float64) float64

Clamps val between c0 and c1.

func Clamp01
func Clamp01(v float64) float64

Clamps v between 0 and 1.

func ClosestPowerOfTwo
func ClosestPowerOfTwo(v uint32) uint32

Returns v if it is a power-of-two, or else the closest power-of-two.

func DegToRad
func DegToRad(degrees float64) float64

Converts the specified degrees to radians.

func DeltaAngle
func DeltaAngle(cur, target float64) float64

Calculates the shortest difference between two given angles.

func Eq
func Eq(a, b float64) (eq bool)

Compares two floating point values if they are approximately equivalent.

func InvLerp
func InvLerp(from, to, val float64) float64

Calculates the Lerp parameter between of two values.

func IsPowerOfTwo
func IsPowerOfTwo(x uint32) bool

Returns whether x is a power-of-two.

func Lerp
func Lerp(a, b, t float64) float64

Returns a if t is 0, or b if t is 1, or else the linear interpolation from a to b according to t.

func LerpAngle
func LerpAngle(a, b, t float64) float64

Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.

func Mat3Identities
func Mat3Identities(mats ...*Mat3)

Calls the Identity method on all specified mats.

func Mat4Identities
func Mat4Identities(mats ...*Mat4)

Calls the Identity method on all specified mats.

func NextPowerOfTwo
func NextPowerOfTwo(v uint32) uint32

Returns v if it is a power-of-two, or else the next-highest power-of-two.

func Percent
func Percent(p, of float64) float64
func PingPong
func PingPong(t, l float64) float64

Ping-pongs the value t, so that it is never larger than l and never smaller than 0.

func RadToDeg
func RadToDeg(radians float64) float64

Converts the specified radians to degrees.

func Round
func Round(v float64) (fint float64)

Returns the next-higher integer if fraction>0.5; if fraction<0.5 returns the next-lower integer; if fraction==0.5, returns the next even integer.

func Sign
func Sign(v float64) (sign float64)

Returns -1 if v is negative, 1 if v is positive, or 0 if v is zero.

func SmoothStep
func SmoothStep(from, to, t float64) float64

Interpolates between from and to with smoothing at the limits.

func SmootherStep
func SmootherStep(from, to, t float64) float64

Interpolates between from and to with smoother smoothing at the limits.

func SumFrom1To
func SumFrom1To(to int) int

http://betterexplained.com/articles/techniques-for-adding-the-numbers-1-to-100/

func SumFromTo
func SumFromTo(from, to int) int

http://betterexplained.com/articles/techniques-for-adding-the-numbers-1-to-100/

type Mat3
type Mat3 [9]float64

Represents a 3x3 matrix.

var (
	//	The 3x3 identity matrix.
	Mat3Identity Mat3
)
func NewMat3Identity
func NewMat3Identity() (mat *Mat3)

Returns a new 3x3 identity matrix.

func (*Mat3) Identity
func (me *Mat3) Identity()

Sets this 3x3 matrix to Mat3Identity.

func (*Mat3) Transpose
func (me *Mat3) Transpose()

Transposes this 3x3 matrix.

type Mat4
type Mat4 [16]float64

Represents a 4x4 column-major matrix.

var (
	//	The 4x4 identity matrix.
	Mat4Identity Mat4
)
func NewMat4Add
func NewMat4Add(a, b *Mat4) (mat *Mat4)

Returns a new *Mat4 representing the result of adding a to b.

func NewMat4Frustum
func NewMat4Frustum(left, right, bottom, top, near, far float64) (mat *Mat4)

Returns a new *Mat4 representing the specified frustum.

func NewMat4Identity
func NewMat4Identity() (mat *Mat4)

Returns a new *Mat4 representing the identity matrix.

func NewMat4Lookat
func NewMat4Lookat(eyePos, lookTarget, upVec *Vec3) (mat *Mat4)

Returns a new *Mat4 representing the "look-at matrix" computed from the specified vectors.

func NewMat4Mult1
func NewMat4Mult1(m *Mat4, v float64) (mat *Mat4)

Returns a new *Mat4 representing the result of multiplying all values in m with v.

func NewMat4Mult4
func NewMat4Mult4(one, two *Mat4) (mat *Mat4)

Returns a new *Mat4 that represents the result of multiplying one with two.

func NewMat4MultN
func NewMat4MultN(mats ...*Mat4) (mat *Mat4)

Returns a new *Mat4 that represents the result of multiplying all specified mats with one another.

func NewMat4Orient
func NewMat4Orient(lookTarget, worldUp *Vec3) (mat *Mat4)

Returns a new *Mat4 representing the "orientation matrix" computed from the specified vectors.

func NewMat4Perspective
func NewMat4Perspective(fovY, aspect, near, far float64) (mat *Mat4)

Returns a new *Mat4 that represents the specified perspective-projection matrix.

func NewMat4RotationX
func NewMat4RotationX(rad float64) (mat *Mat4)

Returns a new *Mat4 that represents a rotation of rad radians around the X axis.

func NewMat4RotationY
func NewMat4RotationY(rad float64) (mat *Mat4)

Returns a new *Mat4 that represents a rotation of rad radians around the Y axis.

func NewMat4RotationZ
func NewMat4RotationZ(rad float64) (mat *Mat4)

Returns a new *Mat4 that represents a rotation of rad radians around the Z axis.

func NewMat4Scaling
func NewMat4Scaling(vec *Vec3) (mat *Mat4)

Returns a new *Mat4 that represents a transformation of "scale by vec".

func NewMat4Sub
func NewMat4Sub(a, b *Mat4) (mat *Mat4)

Returns a new *Mat4 that represents a minus b.

func NewMat4Translation
func NewMat4Translation(vec *Vec3) (mat *Mat4)

Returns a new *Mat4 that represents a transformation of "translate by vec".

func (*Mat4) Abs
func (me *Mat4) Abs() (abs *Mat4)

Returns a new *Mat4 with each cell representing the math.Abs value of the respective corresponding cell in me.

func (*Mat4) Add
func (me *Mat4) Add(mat *Mat4)

Adds mat to me.

func (*Mat4) Clear
func (me *Mat4) Clear()

Zeroes all cells in me.

func (*Mat4) Clone
func (me *Mat4) Clone() (mat *Mat4)

Returns a new *Mat containing a copy of me.

func (*Mat4) CopyFrom
func (me *Mat4) CopyFrom(mat *Mat4)

Copies all cells from mat to me.

func (*Mat4) CopyTo
func (me *Mat4) CopyTo(mat *Mat4)

Copies all cells from me to mat.

func (*Mat4) Frustum
func (me *Mat4) Frustum(left, right, bottom, top, near, far float64)

Sets me to represent the specified frustum.

func (*Mat4) Identity
func (me *Mat4) Identity()

Copies all cells from Mat4Identity to me.

func (*Mat4) Lookat
func (me *Mat4) Lookat(eyePos, lookTarget, upVec *Vec3)

Sets me to the "look-at matrix" computed from the specified vectors.

func (*Mat4) Mult1
func (me *Mat4) Mult1(v float64)

Multiplies all cells in me with v.

func (*Mat4) Orient
func (me *Mat4) Orient(lookTarget, worldUp *Vec3)

Sets me to the "orientation matrix" computed from the specified vectors.

func (*Mat4) Perspective
func (me *Mat4) Perspective(fovYDeg, a, n, f float64) (fovYRadHalf float64)

Sets me to the specified perspective-projection matrix.

fovYRad -- vertical field-of-view angle in radians. a -- aspect ratio. n -- near-plane. f -- far-plane.

func (*Mat4) RotationX
func (me *Mat4) RotationX(rad float64)

Sets me to a rotation matrix representing "rotate rad radians around the X axis".

func (*Mat4) RotationY
func (me *Mat4) RotationY(rad float64)

Sets me to a rotation matrix representing "rotate rad radians around the Y axis".

func (*Mat4) RotationZ
func (me *Mat4) RotationZ(rad float64)

Sets me to a rotation matrix representing "rotate rad radians around the Z axis".

func (*Mat4) Scaling
func (me *Mat4) Scaling(vec *Vec3)

Sets me to a transformation matrix representing "scale by vec"

func (*Mat4) SetFromMult4
func (me *Mat4) SetFromMult4(one, two *Mat4)

Sets me to the result of multiplying one times two.

func (*Mat4) SetFromMultN
func (me *Mat4) SetFromMultN(mats ...*Mat4)

Sets me to the result of multiplying all the specified mats with one another.

func (*Mat4) SetFromTransposeOf
func (me *Mat4) SetFromTransposeOf(mat *Mat4)

Sets me to the transpose of mat.

func (*Mat4) Sub
func (me *Mat4) Sub(mat *Mat4)

Subtracts mat from me.

func (*Mat4) Translation
func (me *Mat4) Translation(vec *Vec3)

Sets me to a transformation matrix representing "translate by vec"

func (*Mat4) Transposed
func (me *Mat4) Transposed() (mat *Mat4)

Returns the transpose of me.

type Quat
type Quat struct {
	//	X, Y, Z, W
	Vec4
}

Quaternion

func NewQuat
func NewQuat(x, y, z, w float64) *Quat
func Quat_Identity
func Quat_Identity() (q Quat)
func (*Quat) AngleDeg
func (me *Quat) AngleDeg(q *Quat) float64
func (*Quat) AngleRad
func (me *Quat) AngleRad(q *Quat) float64
func (*Quat) Eq
func (me *Quat) Eq(vec *Vec4) bool
func (*Quat) Mul
func (me *Quat) Mul(q *Quat) *Quat
func (*Quat) MulVec3
func (me *Quat) MulVec3(p *Vec3) *Vec3
type Vec2
type Vec2 struct{ X, Y float64 }

A 2-dimensional vector.

func Vec2_Lerp
func Vec2_Lerp(from, to *Vec2, t float64) *Vec2
func Vec2_Max
func Vec2_Max(l, r *Vec2) *Vec2
func Vec2_Min
func Vec2_Min(l, r *Vec2) *Vec2
func Vec2_One
func Vec2_One() Vec2

Vec2{1, 1}

func Vec2_Right
func Vec2_Right() Vec2

Vec2{1, 0}

func Vec2_Up
func Vec2_Up() Vec2

Vec2{0, 1}

func Vec2_Zero
func Vec2_Zero() Vec2

Vec2{0, 0}

func (*Vec2) Add
func (me *Vec2) Add(vec *Vec2)
func (*Vec2) AddedDiv
func (me *Vec2) AddedDiv(a *Vec2, d float64) *Vec2
func (*Vec2) AngleDeg
func (me *Vec2) AngleDeg(to *Vec2) float64
func (*Vec2) AngleRad
func (me *Vec2) AngleRad(to *Vec2) float64
func (*Vec2) ClampMagnitude
func (me *Vec2) ClampMagnitude(maxLength float64) *Vec2
func (*Vec2) Clear
func (me *Vec2) Clear()
func (*Vec2) Distance
func (me *Vec2) Distance(vec *Vec2) float64
func (*Vec2) Div
func (me *Vec2) Div(vec *Vec2) *Vec2

Returns a new *Vec2 that is the result of dividing me by vec without checking for division-by-0.

func (*Vec2) DivSafe
func (me *Vec2) DivSafe(vec *Vec2) *Vec2

Returns a new *Vec2 that is the result of dividing me by vec, safely checking for division-by-0.

func (*Vec2) Divide
func (me *Vec2) Divide(d float64)
func (*Vec2) Divided
func (me *Vec2) Divided(d float64) *Vec2
func (*Vec2) Dot
func (me *Vec2) Dot(vec *Vec2) float64

Returns the dot product of me and vec.

func (*Vec2) Eq
func (me *Vec2) Eq(vec *Vec2) bool
func (*Vec2) Length
func (me *Vec2) Length() float64

Returns the 2D vector length of me.

func (*Vec2) Magnitude
func (me *Vec2) Magnitude() float64

Returns the 2D vector magnitude of me.

func (*Vec2) MoveTowards
func (me *Vec2) MoveTowards(target *Vec2, maxDistanceDelta float64) *Vec2
func (*Vec2) Mult
func (me *Vec2) Mult(vec *Vec2) *Vec2

Returns a new *Vec2 that is the result of multiplying me with vec.

func (*Vec2) Negate
func (me *Vec2) Negate() *Vec2
func (*Vec2) Normalize
func (me *Vec2) Normalize()

Normalizes me in-place without checking for division-by-0.

func (*Vec2) NormalizeSafe
func (me *Vec2) NormalizeSafe()

Normalizes me in-place, safely checking for division-by-0.

func (*Vec2) Normalized
func (me *Vec2) Normalized() *Vec2

Returns a new *Vec2 that is the normalized representation of me without checking for division-by-0.

func (*Vec2) NormalizedSafe
func (me *Vec2) NormalizedSafe() *Vec2

Returns a new *Vec2 that is the normalized representation of me, safely checking for division-by-0.

func (*Vec2) NormalizedScaled
func (me *Vec2) NormalizedScaled(factor float64) *Vec2

Returns a new *Vec2 that is the normalized representation of me scaled by factor without checking for division-by-0.

func (*Vec2) NormalizedScaledSafe
func (me *Vec2) NormalizedScaledSafe(factor float64) *Vec2

Returns a new *Vec2 that is the normalized representation of me scaled by factor, safely checking for division-by-0.

func (*Vec2) Scale
func (me *Vec2) Scale(factor float64)

Multiplies all components in me with factor.

func (*Vec2) Scaled
func (me *Vec2) Scaled(factor float64) *Vec2

Returns a new *Vec2 that represents me scaled by factor.

func (*Vec2) Set
func (me *Vec2) Set(x, y float64)
func (*Vec2) String
func (me *Vec2) String() string

Returns a human-readable (imprecise) string representation of me.

func (*Vec2) Sub
func (me *Vec2) Sub(vec *Vec2) *Vec2

Returns a new *Vec2 that represents me minus vec.

func (*Vec2) Subtract
func (me *Vec2) Subtract(vec *Vec2)

Subtracts vec from me.

type Vec3
type Vec3 struct {
	X, Y, Z float64
}

Represents a 3-dimensional vector.

func Vec3_Back
func Vec3_Back() Vec3
func Vec3_Down
func Vec3_Down() Vec3
func Vec3_Fwd
func Vec3_Fwd() Vec3
func Vec3_Left
func Vec3_Left() Vec3
func Vec3_Lerp
func Vec3_Lerp(from, to *Vec3, t float64) *Vec3
func Vec3_Max
func Vec3_Max(l, r *Vec3) *Vec3
func Vec3_Min
func Vec3_Min(l, r *Vec3) *Vec3
func Vec3_One
func Vec3_One() Vec3
func Vec3_Right
func Vec3_Right() Vec3
func Vec3_Up
func Vec3_Up() Vec3
func Vec3_Zero
func Vec3_Zero() Vec3
func (*Vec3) Add
func (me *Vec3) Add(vec *Vec3)

Adds vec to me in-place.

func (*Vec3) Add1
func (me *Vec3) Add1(val float64)

Adds val to all 3 components of me.

func (*Vec3) Add3
func (me *Vec3) Add3(x, y, z float64)

Adds the specified 3 components to the respective components in me.

func (*Vec3) Added
func (me *Vec3) Added(vec *Vec3) *Vec3

Returns the sum of me and vec.

func (*Vec3) AllEq
func (me *Vec3) AllEq(val float64) bool

Returns whether all 3 components in me are approximately equivalent to their respective counterparts in val.

func (*Vec3) AllGEq
func (me *Vec3) AllGEq(vec *Vec3) bool

Returns whether all 3 components in me are greater than (or approximately equivalent to) their respective component counterparts in vec.

func (*Vec3) AllIn
func (me *Vec3) AllIn(min, max *Vec3) bool

Returns whether all 3 components in me are greater than min, and also less than max.

func (*Vec3) AllLEq
func (me *Vec3) AllLEq(vec *Vec3) bool

Returns whether all 3 components in me are less than (or approximately equivalent to) their respective component counterparts in vec.

func (*Vec3) AngleDeg
func (me *Vec3) AngleDeg(to *Vec3) float64
func (*Vec3) AngleRad
func (me *Vec3) AngleRad(to *Vec3) float64
func (*Vec3) Clamp
func (me *Vec3) Clamp(min, max *Vec3)

Clamps each component in me between the respective corresponding counter-part component in min and max.

func (*Vec3) Clamp01
func (me *Vec3) Clamp01()

Clamps each component in me between 0 and 1.

func (*Vec3) ClampMagnitude
func (me *Vec3) ClampMagnitude(maxLength float64) *Vec3
func (*Vec3) Clear
func (me *Vec3) Clear()

Zeroes all 3 components in me.

func (*Vec3) Cross
func (me *Vec3) Cross(vec *Vec3) *Vec3

Returns a new *Vec3 that represents the cross-product of me and vec.

func (*Vec3) CrossNormalized
func (me *Vec3) CrossNormalized(vec *Vec3) (r *Vec3)

Returns a new *Vec that represents the cross-product of me and vec, normalized.

func (*Vec3) Distance
func (me *Vec3) Distance(vec *Vec3) float64

Returns the distance of me from vec.

func (*Vec3) DistanceManhattan
func (me *Vec3) DistanceManhattan(vec *Vec3) float64

Returns the "manhattan distance" of me from vec.

func (*Vec3) Div
func (me *Vec3) Div(vec *Vec3) *Vec3

Returns a new *Vec3 that represents me divided by vec.

func (*Vec3) Divide
func (me *Vec3) Divide(d float64)
func (*Vec3) Divided
func (me *Vec3) Divided(d float64) *Vec3

Returns a new *Vec3 that represents all 3 components in me, each divided by val.

func (*Vec3) Dot
func (me *Vec3) Dot(vec *Vec3) float64

Returns the dot-product of me and vec.

func (*Vec3) DotSub
func (me *Vec3) DotSub(vec1, vec2 *Vec3) float64

Returns the dot-product of me and (vec1 minus vec2).

func (*Vec3) Eq
func (me *Vec3) Eq(vec *Vec3) bool
func (*Vec3) Length
func (me *Vec3) Length() float64

Returns the 3D vector length of me.

func (*Vec3) Magnitude
func (me *Vec3) Magnitude() float64

Returns the 3D vector magnitude of me.

func (*Vec3) Max
func (me *Vec3) Max() float64

Returns the largest of the 3 components in me.

func (*Vec3) MaxAbs
func (me *Vec3) MaxAbs() float64

Returns the math.Max of the math.Abs values of all 3 components in me.

func (*Vec3) Min
func (me *Vec3) Min() float64

Returns the smallest of the 3 components in me.

func (*Vec3) Mult
func (me *Vec3) Mult(vec *Vec3) *Vec3

Returns a new *Vec3 that represents me multiplied with vec.

func (*Vec3) Mult3
func (me *Vec3) Mult3(x, y, z float64) *Vec3

Returns a new *Vec3 with each component in me multiplied by the respective corresponding specified factor.

func (*Vec3) Negate
func (me *Vec3) Negate()

Reverses the signs of all 3 vector components in me.

func (*Vec3) Negated
func (me *Vec3) Negated() *Vec3

Returns a new *Vec with each component representing the negative (sign inverted) corresponding component in me.

func (*Vec3) Normalize
func (me *Vec3) Normalize()

Normalizes me in-place without checking for division-by-0.

func (*Vec3) NormalizeSafe
func (me *Vec3) NormalizeSafe()

Normalizes me in-place, safely checking for division-by-0.

func (*Vec3) Normalized
func (me *Vec3) Normalized() *Vec3

Returns a new *Vec3 that represents me, normalized.

func (*Vec3) NormalizedScaled
func (me *Vec3) NormalizedScaled(factor float64) (vec *Vec3)

Returns a new *Vec3 that represents me normalized, then scaled by factor.

func (*Vec3) Rcp
func (me *Vec3) Rcp() *Vec3

Returns a new *Vec3 representing 1/me.

func (*Vec3) RotateDeg
func (me *Vec3) RotateDeg(angleDeg float64, axis *Vec3)

Rotates me angleDeg degrees around the specified axis.

func (*Vec3) RotateRad
func (me *Vec3) RotateRad(angleRad float64, axis *Vec3)

Rotates me angleRad radians around the specified axis.

func (*Vec3) Scale
func (me *Vec3) Scale(factor float64)

Scales me by factor.

func (*Vec3) ScaleAdd
func (me *Vec3) ScaleAdd(factor, add *Vec3)

Scales me by factor, then adds add.

func (*Vec3) Scaled
func (me *Vec3) Scaled(factor float64) *Vec3

Returns a new *Vec3 that represents me scaled by factor.

func (*Vec3) ScaledAdded
func (me *Vec3) ScaledAdded(factor float64, add *Vec3) *Vec3

Returns a new *Vec3 that represents me scaled by factor, then add added.

func (*Vec3) Set
func (me *Vec3) Set(x, y, z float64)

Sets all 3 vector components in me to the corresponding respective specified value.

func (*Vec3) SetFromAdd
func (me *Vec3) SetFromAdd(vec1, vec2 *Vec3)

Sets me to the result of adding vec1 and vec2.

func (*Vec3) SetFromAddAdd
func (me *Vec3) SetFromAddAdd(a, b, c *Vec3)

me = a + b + c

func (*Vec3) SetFromAddScaled
func (me *Vec3) SetFromAddScaled(vec1, vec2 *Vec3, mul float64)

me = mul * vec2 + vec1

func (*Vec3) SetFromAddSub
func (me *Vec3) SetFromAddSub(a, b, c *Vec3)

me = a + b - c

func (*Vec3) SetFromCross
func (me *Vec3) SetFromCross(vec *Vec3)

Sets me to the cross-product of me and vec.

func (*Vec3) SetFromCrossOf
func (me *Vec3) SetFromCrossOf(one, two *Vec3)

Sets me to the cross-product of one and two.

func (*Vec3) SetFromDegToRad
func (me *Vec3) SetFromDegToRad(deg *Vec3)

Sets each vector component in me to the radian equivalent of the degree angle stored in the respective corresponding component of vec.

func (*Vec3) SetFromDivided
func (me *Vec3) SetFromDivided(vec *Vec3, d float64)
func (*Vec3) SetFromMad
func (me *Vec3) SetFromMad(mul1, mul2, add *Vec3)

me = mul1 * mul2 + add

func (*Vec3) SetFromMult
func (me *Vec3) SetFromMult(v1, v2 *Vec3)

me = v1 * v2

func (*Vec3) SetFromNegated
func (me *Vec3) SetFromNegated(vec *Vec3)

me = -vec

func (*Vec3) SetFromNormalized
func (me *Vec3) SetFromNormalized(vec *Vec3)

Sets me to vec normalized.

func (*Vec3) SetFromRcp
func (me *Vec3) SetFromRcp(vec *Vec3)

Sets me to the inverse of vec.

func (*Vec3) SetFromRotation
func (me *Vec3) SetFromRotation(pos, rotCos, rotSin *Vec3)

Sets me to pos rotated as expressed in rotCos and rotSin.

func (*Vec3) SetFromScaled
func (me *Vec3) SetFromScaled(vec *Vec3, mul float64)

me = vec * mul

func (*Vec3) SetFromScaledSub
func (me *Vec3) SetFromScaledSub(vec1, vec2 *Vec3, mul float64)

me = (vec1 - vec2) * mul

func (*Vec3) SetFromSub
func (me *Vec3) SetFromSub(vec1, vec2 *Vec3)

me = vec1 - vec2.

func (*Vec3) SetFromSubAdd
func (me *Vec3) SetFromSubAdd(a, b, c *Vec3)

me = a - b + c

func (*Vec3) SetFromSubMult
func (me *Vec3) SetFromSubMult(sub1, sub2, mul *Vec3)

me = (sub1 - sub2) * mul

func (*Vec3) SetFromSubScaled
func (me *Vec3) SetFromSubScaled(v1, v2 *Vec3, v2Scale float64)

me = v1 - v2 * v2Scale

func (*Vec3) SetFromSubSub
func (me *Vec3) SetFromSubSub(a, b, c *Vec3)

me = a - b - c

func (*Vec3) SetToMax
func (me *Vec3) SetToMax()

Sets all 3 vector components in me to math.MaxFloat64.

func (*Vec3) SetToMin
func (me *Vec3) SetToMin()

Sets all 3 vector components in me to -math.MaxFloat64.

func (*Vec3) Sign
func (me *Vec3) Sign() *Vec3

Returns a new *Vec3 with each vector component indicating the sign (-1, 1 or 0) of the respective corresponding component in me.

func (*Vec3) String
func (me *Vec3) String() string

Returns a human-readable (imprecise) string representation of me.

func (*Vec3) Sub
func (me *Vec3) Sub(vec *Vec3) *Vec3

Returns a new *Vec3 that represents me minus vec.

func (*Vec3) SubDivMult
func (me *Vec3) SubDivMult(sub, div, mul *Vec3) *Vec3

Returns a new *Vec3 that represents ((me - sub) / div) * mul.

func (*Vec3) SubFloorDivMult
func (me *Vec3) SubFloorDivMult(div, mul float64) *Vec3

Returns a new *Vec3 that represents mul * math.Floor(me / div).

func (*Vec3) SubFrom
func (me *Vec3) SubFrom(val float64) *Vec3

Returns a new *Vec3 that represents val minus me.

func (*Vec3) SubScaled
func (me *Vec3) SubScaled(vec *Vec3, val float64) *Vec3

Returns a new *Vec3 that represents (me - vec) * val.

func (*Vec3) Subtract
func (me *Vec3) Subtract(vec *Vec3)

Subtracts vec from me.

func (*Vec3) TransformCoord
func (me *Vec3) TransformCoord(mat *Mat4)

Transform coordinate vector me according to the specified *Mat4.

func (*Vec3) TransformNormal
func (me *Vec3) TransformNormal(mat *Mat4, absMat bool)

Transform normal vector me according to the specified *Mat4.

type Vec4
type Vec4 struct {
	X, Y, Z, W float64
}

Represents an arbitrary 4-dimensional vector.

func Vec4_Lerp
func Vec4_Lerp(from, to *Vec4, t float64) *Vec4
func Vec4_Max
func Vec4_Max(l, r *Vec4) *Vec4
func Vec4_Min
func Vec4_Min(l, r *Vec4) *Vec4
func Vec4_One
func Vec4_One() Vec4
func Vec4_Zero
func Vec4_Zero() Vec4
func (*Vec4) AddedDiv
func (me *Vec4) AddedDiv(a *Vec4, d float64) *Vec4
func (*Vec4) Clear
func (me *Vec4) Clear()
func (*Vec4) Clone
func (me *Vec4) Clone() (q *Vec4)

Returns a new *Vec4 containing a copy of me.

func (*Vec4) Conjugate
func (me *Vec4) Conjugate()

Negates the X, Y, Z components in me, but not W.

func (*Vec4) Conjugated
func (me *Vec4) Conjugated() (v *Vec4)

Returns a new *Vec4 that represents me conjugated.

func (*Vec4) Distance
func (me *Vec4) Distance(vec *Vec4) float64
func (*Vec4) Divide
func (me *Vec4) Divide(d float64)
func (*Vec4) Divided
func (me *Vec4) Divided(d float64) *Vec4
func (*Vec4) Dot
func (me *Vec4) Dot(vec *Vec4) float64
func (*Vec4) Eq
func (me *Vec4) Eq(vec *Vec4) bool
func (*Vec4) Length
func (me *Vec4) Length() float64

Returns the 4D vector length of me.

func (*Vec4) Magnitude
func (me *Vec4) Magnitude() float64

Returns the 4D vector magnitude of me.

func (*Vec4) MoveTowards
func (me *Vec4) MoveTowards(target *Vec4, maxDistanceDelta float64) *Vec4
func (*Vec4) MultMat4
func (me *Vec4) MultMat4(mat *Mat4)

Sets me to the result of multiplying the specified *Mat4 with me.

func (*Vec4) MultMat4Vec3
func (me *Vec4) MultMat4Vec3(mat *Mat4, vec *Vec3)

Sets me to the result of multiplying the specified *Mat4 with the specified *Vec3.

func (*Vec4) MultMat4Vec4
func (me *Vec4) MultMat4Vec4(mat *Mat4, vec *Vec4)

Sets me to the result of multiplying the specified *Mat4 with the specified *Vec4.

func (*Vec4) Negate
func (me *Vec4) Negate()
func (*Vec4) Negated
func (me *Vec4) Negated() *Vec4
func (*Vec4) Normalize
func (me *Vec4) Normalize()

Normalizes me according to me.Magnitude.

func (*Vec4) NormalizeFrom
func (me *Vec4) NormalizeFrom(magnitude float64)

Normalizes me according to the specified magnitude.

func (*Vec4) Normalized
func (me *Vec4) Normalized() *Vec4

Returns a new *Vec4 that represents me normalized according to me.Magnitude.

func (*Vec4) Project
func (me *Vec4) Project(vec *Vec4)
func (*Vec4) Projected
func (me *Vec4) Projected(vec *Vec4) *Vec4
func (*Vec4) Scale
func (me *Vec4) Scale(v float64)

Scales all 4 vector components in me by factor v.

func (*Vec4) Scaled
func (me *Vec4) Scaled(v float64) *Vec4
func (*Vec4) SetFromConjugated
func (me *Vec4) SetFromConjugated(c *Vec4)

Sets me to c conjugated.

func (*Vec4) SetFromMult
func (me *Vec4) SetFromMult(l, r *Vec4)

Applies various 4D vector component computations of l and r to me, as needed by the Vec3.RotateRad method.

func (*Vec4) SetFromMult3
func (me *Vec4) SetFromMult3(q *Vec4, v *Vec3)

Applies various 4D vector component computations of q and v to me, as needed by the Vec3.RotateRad method.

func (*Vec4) SetFromVec3
func (me *Vec4) SetFromVec3(vec *Vec3)
func (*Vec4) String
func (me *Vec4) String() string

Returns a human-readable (imprecise) string representation of me.

func (*Vec4) Sub
func (me *Vec4) Sub(vec *Vec4) *Vec4
func (*Vec4) Subtract
func (me *Vec4) Subtract(vec *Vec4)

Documentation

Overview

Go programming helpers for common maths needs; plus vectors, matrices and quaternions.

Index

Constants

View Source
const (
	Deg2Rad = math.Pi / 180
	Rad2Deg = 180 / math.Pi
)

Variables

View Source
var (
	Infinity             = math.Inf(1)
	NegativeInfinity     = math.Inf(-1)
	Epsilon              = math.Nextafter(1, Infinity) - 1
	EpsilonEqFloat       = 1.121039E-44
	EpsilonEqFloatFactor = 1E-06
	EpsilonEqVec         = 9.99999944E-11
)

Functions

func Clamp

func Clamp(val, c0, c1 float64) float64

Clamps `val` between `c0` and `c1`.

func Clamp01

func Clamp01(v float64) float64

Clamps `v` between 0 and 1.

func ClosestPowerOfTwo

func ClosestPowerOfTwo(v uint32) uint32

Returns `v` if it is a power-of-two, or else the closest power-of-two.

func DegToRad

func DegToRad(degrees float64) float64

Converts the specified `degrees` to radians.

func DeltaAngle

func DeltaAngle(cur, target float64) float64

Calculates the shortest difference between two given angles.

func Eq

func Eq(a, b float64) (eq bool)

Compares two floating point values if they are approximately equivalent.

func InvLerp

func InvLerp(from, to, val float64) float64

Calculates the Lerp parameter between of two values.

func IsPowerOfTwo

func IsPowerOfTwo(x uint32) bool

Returns whether `x` is a power-of-two.

func Lerp

func Lerp(a, b, t float64) float64

Returns `a` if `t` is 0, or `b` if `t` is 1, or else the linear interpolation from `a` to `b` according to `t`.

func LerpAngle

func LerpAngle(a, b, t float64) float64

Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.

func Mat3Identities

func Mat3Identities(mats ...*Mat3)

Calls the `Identity` method on all specified `mats`.

func Mat4Identities

func Mat4Identities(mats ...*Mat4)

Calls the `Identity` method on all specified `mats`.

func NextPowerOfTwo

func NextPowerOfTwo(v uint32) uint32

Returns `v` if it is a power-of-two, or else the next-highest power-of-two.

func Percent

func Percent(p, of float64) float64

func PingPong

func PingPong(t, l float64) float64

func RadToDeg

func RadToDeg(radians float64) float64

Converts the specified `radians` to degrees.

func Round

func Round(v float64) (fint float64)

Returns the next-higher integer if fraction>0.5; if fraction<0.5 returns the next-lower integer; if fraction==0.5, returns the next even integer.

func Sign

func Sign(v float64) (sign float64)

Returns -1 if `v` is negative, 1 if `v` is positive, or 0 if `v` is zero.

func SmoothStep

func SmoothStep(from, to, t float64) float64

Interpolates between `from` and `to` with smoothing at the limits.

func SmootherStep

func SmootherStep(from, to, t float64) float64

Interpolates between `from` and `to` with smoother smoothing at the limits.

Types

type Mat3

type Mat3 [9]float64

Represents a 3x3 matrix.

var (
	//	The 3x3 identity matrix.
	Mat3Identity Mat3
)

func NewMat3Identity

func NewMat3Identity() (mat *Mat3)

Returns a new 3x3 identity matrix.

func (*Mat3) Identity

func (me *Mat3) Identity()

Sets this 3x3 matrix to `Mat3Identity`.

func (*Mat3) Transpose

func (me *Mat3) Transpose()

Transposes this 3x3 matrix.

type Mat4

type Mat4 [16]float64

Represents a 4x4 column-major matrix.

var (
	//	The 4x4 identity matrix.
	Mat4Identity Mat4
)

func NewMat4Add

func NewMat4Add(a, b *Mat4) (mat *Mat4)

Returns a new `*Mat4` representing the result of adding `a` to `b`.

func NewMat4Frustum

func NewMat4Frustum(left, right, bottom, top, near, far float64) (mat *Mat4)

Returns a new `*Mat4` representing the specified frustum.

func NewMat4Identity

func NewMat4Identity() (mat *Mat4)

Returns a new `*Mat4` representing the identity matrix.

func NewMat4Lookat

func NewMat4Lookat(eyePos, lookTarget, upVec *Vec3) (mat *Mat4)

Returns a new `*Mat4` representing the "look-at matrix" computed from the specified vectors.

func NewMat4Mult1

func NewMat4Mult1(m *Mat4, v float64) (mat *Mat4)

Returns a new `*Mat4` representing the result of multiplying all values in `m` with `v`.

func NewMat4Mult4

func NewMat4Mult4(one, two *Mat4) (mat *Mat4)

Returns a new `*Mat4` that represents the result of multiplying `one` with `two`.

func NewMat4MultN

func NewMat4MultN(mats ...*Mat4) (mat *Mat4)

Returns a new `*Mat4` that represents the result of multiplying all specified `mats` with one another.

func NewMat4Orient

func NewMat4Orient(lookTarget, worldUp *Vec3) (mat *Mat4)

Returns a new `*Mat4` representing the "orientation matrix" computed from the specified vectors.

func NewMat4Perspective

func NewMat4Perspective(fovY, aspect, near, far float64) (mat *Mat4)

Returns a new `*Mat4` that represents the specified perspective-projection matrix.

func NewMat4RotationX

func NewMat4RotationX(rad float64) (mat *Mat4)

Returns a new `*Mat4` that represents a rotation of `rad` radians around the X axis.

func NewMat4RotationY

func NewMat4RotationY(rad float64) (mat *Mat4)

Returns a new `*Mat4` that represents a rotation of `rad` radians around the Y axis.

func NewMat4RotationZ

func NewMat4RotationZ(rad float64) (mat *Mat4)

Returns a new `*Mat4` that represents a rotation of `rad` radians around the Z axis.

func NewMat4Scaling

func NewMat4Scaling(vec *Vec3) (mat *Mat4)

Returns a new `*Mat4` that represents a transformation of "scale by `vec`".

func NewMat4Sub

func NewMat4Sub(a, b *Mat4) (mat *Mat4)

Returns a new `*Mat4` that represents `a` minus `b`.

func NewMat4Translation

func NewMat4Translation(vec *Vec3) (mat *Mat4)

Returns a new `*Mat4` that represents a transformation of "translate by `vec`".

func (*Mat4) Abs

func (me *Mat4) Abs() (abs *Mat4)

Returns a new `*Mat4` with each cell representing the `math.Abs` value of the respective corresponding cell in `me`.

func (*Mat4) Add

func (me *Mat4) Add(mat *Mat4)

Adds `mat` to `me`.

func (*Mat4) Clear

func (me *Mat4) Clear()

Zeroes all cells in `me`.

func (*Mat4) Clone

func (me *Mat4) Clone() (mat *Mat4)

Returns a new `*Mat` containing a copy of `me`.

func (*Mat4) CopyFrom

func (me *Mat4) CopyFrom(mat *Mat4)

Copies all cells from `mat` to `me`.

func (*Mat4) CopyTo

func (me *Mat4) CopyTo(mat *Mat4)

Copies all cells from `me` to `mat`.

func (*Mat4) Frustum

func (me *Mat4) Frustum(left, right, bottom, top, near, far float64)

Sets `me` to represent the specified frustum.

func (*Mat4) Identity

func (me *Mat4) Identity()

Copies all cells from `Mat4Identity` to `me`.

func (*Mat4) Lookat

func (me *Mat4) Lookat(eyePos, lookTarget, upVec *Vec3)

Sets `me` to the "look-at matrix" computed from the specified vectors.

func (*Mat4) Mult1

func (me *Mat4) Mult1(v float64)

Multiplies all cells in `me` with `v`.

func (*Mat4) Orient

func (me *Mat4) Orient(lookTarget, worldUp *Vec3)

Sets `me` to the "orientation matrix" computed from the specified vectors.

func (*Mat4) Perspective

func (me *Mat4) Perspective(fovYDeg, a, n, f float64) (fovYRadHalf float64)

Sets `me` to the specified perspective-projection matrix.

`fovYRad` -- vertical field-of-view angle in radians. `a` -- aspect ratio. `n` -- near-plane. `f` -- far-plane.

func (*Mat4) RotationX

func (me *Mat4) RotationX(rad float64)

Sets `me` to a rotation matrix representing "rotate `rad` radians around the X axis".

func (*Mat4) RotationY

func (me *Mat4) RotationY(rad float64)

Sets `me` to a rotation matrix representing "rotate `rad` radians around the Y axis".

func (*Mat4) RotationZ

func (me *Mat4) RotationZ(rad float64)

Sets `me` to a rotation matrix representing "rotate `rad` radians around the Z axis".

func (*Mat4) Scaling

func (me *Mat4) Scaling(vec *Vec3)

Sets `me` to a transformation matrix representing "scale by `vec`"

func (*Mat4) SetFromMult4

func (me *Mat4) SetFromMult4(one, two *Mat4)

Sets `me` to the result of multiplying `one` times `two`.

func (*Mat4) SetFromMultN

func (me *Mat4) SetFromMultN(mats ...*Mat4)

Sets `me` to the result of multiplying all the specified `mats` with one another.

func (*Mat4) SetFromTransposeOf

func (me *Mat4) SetFromTransposeOf(mat *Mat4)

Sets `me` to the transpose of `mat`.

func (*Mat4) Sub

func (me *Mat4) Sub(mat *Mat4)

Subtracts `mat` from `me`.

func (*Mat4) Translation

func (me *Mat4) Translation(vec *Vec3)

Sets `me` to a transformation matrix representing "translate by `vec`"

func (*Mat4) Transposed

func (me *Mat4) Transposed() (mat *Mat4)

Returns the transpose of `me`.

type Quat

type Quat struct {
	//	X, Y, Z, W
	Vec4
}

Quaternion

func NewQuat

func NewQuat(x, y, z, w float64) *Quat

func Quat_Identity

func Quat_Identity() (q Quat)

func (*Quat) AngleDeg

func (me *Quat) AngleDeg(q *Quat) float64

func (*Quat) AngleRad

func (me *Quat) AngleRad(q *Quat) float64

func (*Quat) Eq

func (me *Quat) Eq(vec *Vec4) bool

func (*Quat) Mul

func (me *Quat) Mul(q *Quat) *Quat

func (*Quat) MulVec3

func (me *Quat) MulVec3(p *Vec3) *Vec3

type Vec2

type Vec2 struct{ X, Y float64 }

A 2-dimensional vector.

func Vec2_Lerp

func Vec2_Lerp(from, to *Vec2, t float64) *Vec2

func Vec2_Max

func Vec2_Max(l, r *Vec2) *Vec2

func Vec2_Min

func Vec2_Min(l, r *Vec2) *Vec2

func Vec2_One

func Vec2_One() Vec2

Vec2{1, 1}

func Vec2_Right

func Vec2_Right() Vec2

Vec2{1, 0}

func Vec2_Up

func Vec2_Up() Vec2

Vec2{0, 1}

func Vec2_Zero

func Vec2_Zero() Vec2

Vec2{0, 0}

func (*Vec2) Add

func (me *Vec2) Add(vec *Vec2)

func (*Vec2) AddedDiv

func (me *Vec2) AddedDiv(a *Vec2, d float64) *Vec2

func (*Vec2) AngleDeg

func (me *Vec2) AngleDeg(to *Vec2) float64

func (*Vec2) AngleRad

func (me *Vec2) AngleRad(to *Vec2) float64

func (*Vec2) ClampMagnitude

func (me *Vec2) ClampMagnitude(maxLength float64) *Vec2

func (*Vec2) Clear

func (me *Vec2) Clear()

func (*Vec2) Distance

func (me *Vec2) Distance(vec *Vec2) float64

func (*Vec2) Div

func (me *Vec2) Div(vec *Vec2) *Vec2

Returns a new `*Vec2` that is the result of dividing `me` by `vec` without checking for division-by-0.

func (*Vec2) DivSafe

func (me *Vec2) DivSafe(vec *Vec2) *Vec2

Returns a new `*Vec2` that is the result of dividing `me` by `vec`, safely checking for division-by-0.

func (*Vec2) Divide

func (me *Vec2) Divide(d float64)

func (*Vec2) Divided

func (me *Vec2) Divided(d float64) *Vec2

func (*Vec2) Dot

func (me *Vec2) Dot(vec *Vec2) float64

Returns the dot product of `me` and `vec`.

func (*Vec2) Eq

func (me *Vec2) Eq(vec *Vec2) bool

func (*Vec2) Length

func (me *Vec2) Length() float64

Returns the 2D vector length of `me`.

func (*Vec2) Magnitude

func (me *Vec2) Magnitude() float64

Returns the 2D vector magnitude of `me`.

func (*Vec2) MoveTowards

func (me *Vec2) MoveTowards(target *Vec2, maxDistanceDelta float64) *Vec2

func (*Vec2) Mult

func (me *Vec2) Mult(vec *Vec2) *Vec2

Returns a new `*Vec2` that is the result of multiplying `me` with `vec`.

func (*Vec2) Negate

func (me *Vec2) Negate() *Vec2

func (*Vec2) Normalize

func (me *Vec2) Normalize()

Normalizes `me` in-place without checking for division-by-0.

func (*Vec2) NormalizeSafe

func (me *Vec2) NormalizeSafe()

Normalizes `me` in-place, safely checking for division-by-0.

func (*Vec2) Normalized

func (me *Vec2) Normalized() *Vec2

Returns a new `*Vec2` that is the normalized representation of `me` without checking for division-by-0.

func (*Vec2) NormalizedSafe

func (me *Vec2) NormalizedSafe() *Vec2

Returns a new `*Vec2` that is the normalized representation of `me`, safely checking for division-by-0.

func (*Vec2) NormalizedScaled

func (me *Vec2) NormalizedScaled(factor float64) *Vec2

Returns a new `*Vec2` that is the normalized representation of `me` scaled by `factor` without checking for division-by-0.

func (*Vec2) NormalizedScaledSafe

func (me *Vec2) NormalizedScaledSafe(factor float64) *Vec2

Returns a new `*Vec2` that is the normalized representation of `me` scaled by `factor`, safely checking for division-by-0.

func (*Vec2) Scale

func (me *Vec2) Scale(factor float64)

Multiplies all components in `me` with `factor`.

func (*Vec2) Scaled

func (me *Vec2) Scaled(factor float64) *Vec2

Returns a new `*Vec2` that represents `me` scaled by `factor`.

func (*Vec2) Set

func (me *Vec2) Set(x, y float64)

func (*Vec2) String

func (me *Vec2) String() string

Returns a human-readable (imprecise) `string` representation of `me`.

func (*Vec2) Sub

func (me *Vec2) Sub(vec *Vec2) *Vec2

Returns a new `*Vec2` that represents `me` minus `vec`.

func (*Vec2) Subtract

func (me *Vec2) Subtract(vec *Vec2)

Subtracts `vec` from `me`.

type Vec3

type Vec3 struct {
	X, Y, Z float64
}

Represents a 3-dimensional vector.

func Vec3_Back

func Vec3_Back() Vec3

func Vec3_Down

func Vec3_Down() Vec3

func Vec3_Fwd

func Vec3_Fwd() Vec3

func Vec3_Left

func Vec3_Left() Vec3

func Vec3_Lerp

func Vec3_Lerp(from, to *Vec3, t float64) *Vec3

func Vec3_Max

func Vec3_Max(l, r *Vec3) *Vec3

func Vec3_Min

func Vec3_Min(l, r *Vec3) *Vec3

func Vec3_One

func Vec3_One() Vec3

func Vec3_Right

func Vec3_Right() Vec3

func Vec3_Up

func Vec3_Up() Vec3

func Vec3_Zero

func Vec3_Zero() Vec3

func (*Vec3) Add

func (me *Vec3) Add(vec *Vec3)

Adds `vec` to `me` in-place.

func (*Vec3) Add1

func (me *Vec3) Add1(val float64)

Adds `val` to all 3 components of `me`.

func (*Vec3) Add3

func (me *Vec3) Add3(x, y, z float64)

Adds the specified 3 components to the respective components in `me`.

func (*Vec3) Added

func (me *Vec3) Added(vec *Vec3) *Vec3

Returns the sum of `me` and `vec`.

func (*Vec3) AllEq

func (me *Vec3) AllEq(val float64) bool

Returns whether all 3 components in `me` are approximately equivalent to their respective counterparts in `val`.

func (*Vec3) AllGEq

func (me *Vec3) AllGEq(vec *Vec3) bool

Returns whether all 3 components in `me` are greater than (or approximately equivalent to) their respective component counterparts in `vec`.

func (*Vec3) AllIn

func (me *Vec3) AllIn(min, max *Vec3) bool

Returns whether all 3 components in `me` are greater than `min`, and also less than `max`.

func (*Vec3) AllLEq

func (me *Vec3) AllLEq(vec *Vec3) bool

Returns whether all 3 components in `me` are less than (or approximately equivalent to) their respective component counterparts in `vec`.

func (*Vec3) AngleDeg

func (me *Vec3) AngleDeg(to *Vec3) float64

func (*Vec3) AngleRad

func (me *Vec3) AngleRad(to *Vec3) float64

func (*Vec3) Clamp

func (me *Vec3) Clamp(min, max *Vec3)

Clamps each component in `me` between the respective corresponding counter-part component in `min` and `max`.

func (*Vec3) Clamp01

func (me *Vec3) Clamp01()

Clamps each component in `me` between 0 and 1.

func (*Vec3) ClampMagnitude

func (me *Vec3) ClampMagnitude(maxLength float64) *Vec3

func (*Vec3) Clear

func (me *Vec3) Clear()

Zeroes all 3 components in `me`.

func (*Vec3) Cross

func (me *Vec3) Cross(vec *Vec3) *Vec3

Returns a new `*Vec3` that represents the cross-product of `me` and `vec`.

func (*Vec3) CrossNormalized

func (me *Vec3) CrossNormalized(vec *Vec3) (r *Vec3)

Returns a new `*Vec` that represents the cross-product of `me` and `vec`, normalized.

func (*Vec3) Distance

func (me *Vec3) Distance(vec *Vec3) float64

Returns the distance of `me` from `vec`.

func (*Vec3) DistanceManhattan

func (me *Vec3) DistanceManhattan(vec *Vec3) float64

Returns the "manhattan distance" of `me` from `vec`.

func (*Vec3) Div

func (me *Vec3) Div(vec *Vec3) *Vec3

Returns a new `*Vec3` that represents `me` divided by `vec`.

func (*Vec3) Divide

func (me *Vec3) Divide(d float64)

func (*Vec3) Divided

func (me *Vec3) Divided(d float64) *Vec3

Returns a new `*Vec3` that represents all 3 components in `me`, each divided by `val`.

func (*Vec3) Dot

func (me *Vec3) Dot(vec *Vec3) float64

Returns the dot-product of `me` and `vec`.

func (*Vec3) DotSub

func (me *Vec3) DotSub(vec1, vec2 *Vec3) float64

Returns the dot-product of `me` and (`vec1` minus `vec2`).

func (*Vec3) Eq

func (me *Vec3) Eq(vec *Vec3) bool

func (*Vec3) Length

func (me *Vec3) Length() float64

Returns the 3D vector length of `me`.

func (*Vec3) Magnitude

func (me *Vec3) Magnitude() float64

Returns the 3D vector magnitude of `me`.

func (*Vec3) Max

func (me *Vec3) Max() float64

Returns the largest of the 3 components in `me`.

func (*Vec3) MaxAbs

func (me *Vec3) MaxAbs() float64

Returns the `math.Max` of the `math.Abs` values of all 3 components in `me`.

func (*Vec3) Min

func (me *Vec3) Min() float64

Returns the smallest of the 3 components in `me`.

func (*Vec3) Mult

func (me *Vec3) Mult(vec *Vec3) *Vec3

Returns a new `*Vec3` that represents `me` multiplied with `vec`.

func (*Vec3) Mult3

func (me *Vec3) Mult3(x, y, z float64) *Vec3

Returns a new `*Vec3` with each component in `me` multiplied by the respective corresponding specified factor.

func (*Vec3) Negate

func (me *Vec3) Negate()

Reverses the signs of all 3 vector components in `me`.

func (*Vec3) Negated

func (me *Vec3) Negated() *Vec3

Returns a new `*Vec` with each component representing the negative (sign inverted) corresponding component in `me`.

func (*Vec3) Normalize

func (me *Vec3) Normalize()

Normalizes `me` in-place without checking for division-by-0.

func (*Vec3) NormalizeSafe

func (me *Vec3) NormalizeSafe()

Normalizes `me` in-place, safely checking for division-by-0.

func (*Vec3) Normalized

func (me *Vec3) Normalized() *Vec3

Returns a new `*Vec3` that represents `me`, normalized.

func (*Vec3) NormalizedScaled

func (me *Vec3) NormalizedScaled(factor float64) (vec *Vec3)

Returns a new `*Vec3` that represents `me` normalized, then scaled by `factor`.

func (*Vec3) Rcp

func (me *Vec3) Rcp() *Vec3

Returns a new `*Vec3` representing `1/me`.

func (*Vec3) RotateDeg

func (me *Vec3) RotateDeg(angleDeg float64, axis *Vec3)

Rotates `me` `angleDeg` degrees around the specified `axis`.

func (*Vec3) RotateRad

func (me *Vec3) RotateRad(angleRad float64, axis *Vec3)

Rotates `me` `angleRad` radians around the specified `axis`.

func (*Vec3) Scale

func (me *Vec3) Scale(factor float64)

Scales `me` by `factor`.

func (*Vec3) ScaleAdd

func (me *Vec3) ScaleAdd(factor, add *Vec3)

Scales `me` by `factor`, then adds `add`.

func (*Vec3) Scaled

func (me *Vec3) Scaled(factor float64) *Vec3

Returns a new `*Vec3` that represents `me` scaled by `factor`.

func (*Vec3) ScaledAdded

func (me *Vec3) ScaledAdded(factor float64, add *Vec3) *Vec3

Returns a new `*Vec3` that represents `me` scaled by `factor`, then `add` added.

func (*Vec3) Set

func (me *Vec3) Set(x, y, z float64)

Sets all 3 vector components in `me` to the corresponding respective specified value.

func (*Vec3) SetFromAdd

func (me *Vec3) SetFromAdd(vec1, vec2 *Vec3)

Sets `me` to the result of adding `vec1` and `vec2`.

func (*Vec3) SetFromAddAdd

func (me *Vec3) SetFromAddAdd(a, b, c *Vec3)

`me = a + b + c`

func (*Vec3) SetFromAddScaled

func (me *Vec3) SetFromAddScaled(vec1, vec2 *Vec3, mul float64)

`me = mul * vec2 + vec1`

func (*Vec3) SetFromAddSub

func (me *Vec3) SetFromAddSub(a, b, c *Vec3)

`me = a + b - c`

func (*Vec3) SetFromCross

func (me *Vec3) SetFromCross(vec *Vec3)

Sets `me` to the cross-product of `me` and `vec`.

func (*Vec3) SetFromCrossOf

func (me *Vec3) SetFromCrossOf(one, two *Vec3)

Sets `me` to the cross-product of `one` and `two`.

func (*Vec3) SetFromDegToRad

func (me *Vec3) SetFromDegToRad(deg *Vec3)

Sets each vector component in `me` to the radian equivalent of the degree angle stored in the respective corresponding component of `vec`.

func (*Vec3) SetFromDivided

func (me *Vec3) SetFromDivided(vec *Vec3, d float64)

func (*Vec3) SetFromMad

func (me *Vec3) SetFromMad(mul1, mul2, add *Vec3)

`me = mul1 * mul2 + add`

func (*Vec3) SetFromMult

func (me *Vec3) SetFromMult(v1, v2 *Vec3)

`me = v1 * v2`

func (*Vec3) SetFromNegated

func (me *Vec3) SetFromNegated(vec *Vec3)

`me = -vec`

func (*Vec3) SetFromNormalized

func (me *Vec3) SetFromNormalized(vec *Vec3)

Sets `me` to `vec` normalized.

func (*Vec3) SetFromRcp

func (me *Vec3) SetFromRcp(vec *Vec3)

Sets `me` to the inverse of `vec`.

func (*Vec3) SetFromRotation

func (me *Vec3) SetFromRotation(pos, rotCos, rotSin *Vec3)

Sets `me` to `pos` rotated as expressed in `rotCos` and `rotSin`.

func (*Vec3) SetFromScaled

func (me *Vec3) SetFromScaled(vec *Vec3, mul float64)

`me = vec * mul`

func (*Vec3) SetFromScaledSub

func (me *Vec3) SetFromScaledSub(vec1, vec2 *Vec3, mul float64)

`me = (vec1 - vec2) * mul`

func (*Vec3) SetFromSub

func (me *Vec3) SetFromSub(vec1, vec2 *Vec3)

`me = vec1 - vec2`.

func (*Vec3) SetFromSubAdd

func (me *Vec3) SetFromSubAdd(a, b, c *Vec3)

`me = a - b + c`

func (*Vec3) SetFromSubMult

func (me *Vec3) SetFromSubMult(sub1, sub2, mul *Vec3)

`me = (sub1 - sub2) * mul`

func (*Vec3) SetFromSubScaled

func (me *Vec3) SetFromSubScaled(v1, v2 *Vec3, v2Scale float64)

`me = v1 - v2 * v2Scale`

func (*Vec3) SetFromSubSub

func (me *Vec3) SetFromSubSub(a, b, c *Vec3)

`me = a - b - c`

func (*Vec3) SetToMax

func (me *Vec3) SetToMax()

Sets all 3 vector components in `me` to `math.MaxFloat64`.

func (*Vec3) SetToMin

func (me *Vec3) SetToMin()

Sets all 3 vector components in `me` to `-math.MaxFloat64`.

func (*Vec3) Sign

func (me *Vec3) Sign() *Vec3

Returns a new `*Vec3` with each vector component indicating the sign (-1, 1 or 0) of the respective corresponding component in `me`.

func (*Vec3) String

func (me *Vec3) String() string

Returns a human-readable (imprecise) `string` representation of `me`.

func (*Vec3) Sub

func (me *Vec3) Sub(vec *Vec3) *Vec3

Returns a new `*Vec3` that represents `me` minus `vec`.

func (*Vec3) SubDivMult

func (me *Vec3) SubDivMult(sub, div, mul *Vec3) *Vec3

Returns a new `*Vec3` that represents `((me - sub) / div) * mul`.

func (*Vec3) SubFloorDivMult

func (me *Vec3) SubFloorDivMult(div, mul float64) *Vec3

Returns a new `*Vec3` that represents `mul * math.Floor(me / div)`.

func (*Vec3) SubFrom

func (me *Vec3) SubFrom(val float64) *Vec3

Returns a new `*Vec3` that represents `val` minus `me`.

func (*Vec3) SubScaled

func (me *Vec3) SubScaled(vec *Vec3, val float64) *Vec3

Returns a new `*Vec3` that represents `(me - vec) * val`.

func (*Vec3) Subtract

func (me *Vec3) Subtract(vec *Vec3)

Subtracts `vec` from `me`.

func (*Vec3) TransformCoord

func (me *Vec3) TransformCoord(mat *Mat4)

Transform coordinate vector `me` according to the specified `*Mat4`.

func (*Vec3) TransformNormal

func (me *Vec3) TransformNormal(mat *Mat4, absMat bool)

Transform normal vector `me` according to the specified `*Mat4`.

type Vec4

type Vec4 struct {
	X, Y, Z, W float64
}

Represents an arbitrary 4-dimensional vector.

func Vec4_Lerp

func Vec4_Lerp(from, to *Vec4, t float64) *Vec4

func Vec4_Max

func Vec4_Max(l, r *Vec4) *Vec4

func Vec4_Min

func Vec4_Min(l, r *Vec4) *Vec4

func Vec4_One

func Vec4_One() Vec4

func Vec4_Zero

func Vec4_Zero() Vec4

func (*Vec4) AddedDiv

func (me *Vec4) AddedDiv(a *Vec4, d float64) *Vec4

func (*Vec4) Clear

func (me *Vec4) Clear()

func (*Vec4) Clone

func (me *Vec4) Clone() (q *Vec4)

Returns a new `*Vec4` containing a copy of `me`.

func (*Vec4) Conjugate

func (me *Vec4) Conjugate()

Negates the `X`, `Y`, `Z` components in `me`, but not `W`.

func (*Vec4) Conjugated

func (me *Vec4) Conjugated() (v *Vec4)

Returns a new `*Vec4` that represents `me` conjugated.

func (*Vec4) Distance

func (me *Vec4) Distance(vec *Vec4) float64

func (*Vec4) Divide

func (me *Vec4) Divide(d float64)

func (*Vec4) Divided

func (me *Vec4) Divided(d float64) *Vec4

func (*Vec4) Dot

func (me *Vec4) Dot(vec *Vec4) float64

func (*Vec4) Eq

func (me *Vec4) Eq(vec *Vec4) bool

func (*Vec4) Length

func (me *Vec4) Length() float64

Returns the 4D vector length of `me`.

func (*Vec4) Magnitude

func (me *Vec4) Magnitude() float64

Returns the 4D vector magnitude of `me`.

func (*Vec4) MoveTowards

func (me *Vec4) MoveTowards(target *Vec4, maxDistanceDelta float64) *Vec4

func (*Vec4) MultMat4

func (me *Vec4) MultMat4(mat *Mat4)

Sets `me` to the result of multiplying the specified `*Mat4` with `me`.

func (*Vec4) MultMat4Vec3

func (me *Vec4) MultMat4Vec3(mat *Mat4, vec *Vec3)

Sets `me` to the result of multiplying the specified `*Mat4` with the specified `*Vec3`.

func (*Vec4) MultMat4Vec4

func (me *Vec4) MultMat4Vec4(mat *Mat4, vec *Vec4)

Sets `me` to the result of multiplying the specified `*Mat4` with the specified `*Vec4`.

func (*Vec4) Negate

func (me *Vec4) Negate()

func (*Vec4) Negated

func (me *Vec4) Negated() *Vec4

func (*Vec4) Normalize

func (me *Vec4) Normalize()

Normalizes `me` according to `me.Magnitude`.

func (*Vec4) NormalizeFrom

func (me *Vec4) NormalizeFrom(magnitude float64)

Normalizes `me` according to the specified `magnitude`.

func (*Vec4) Normalized

func (me *Vec4) Normalized() *Vec4

Returns a new `*Vec4` that represents `me` normalized according to `me.Magnitude`.

func (*Vec4) Project

func (me *Vec4) Project(vec *Vec4)

func (*Vec4) Projected

func (me *Vec4) Projected(vec *Vec4) *Vec4

func (*Vec4) Scale

func (me *Vec4) Scale(v float64)

Scales all 4 vector components in `me` by factor `v`.

func (*Vec4) Scaled

func (me *Vec4) Scaled(v float64) *Vec4

func (*Vec4) SetFromConjugated

func (me *Vec4) SetFromConjugated(c *Vec4)

Sets `me` to `c` conjugated.

func (*Vec4) SetFromMult

func (me *Vec4) SetFromMult(l, r *Vec4)

Applies various 4D vector component computations of `l` and `r` to `me`, as needed by the `Vec3.RotateRad` method.

func (*Vec4) SetFromMult3

func (me *Vec4) SetFromMult3(q *Vec4, v *Vec3)

Applies various 4D vector component computations of `q` and `v` to `me`, as needed by the `Vec3.RotateRad` method.

func (*Vec4) SetFromVec3

func (me *Vec4) SetFromVec3(vec *Vec3)

func (*Vec4) String

func (me *Vec4) String() string

Returns a human-readable (imprecise) `string` representation of `me`.

func (*Vec4) Sub

func (me *Vec4) Sub(vec *Vec4) *Vec4

func (*Vec4) Subtract

func (me *Vec4) Subtract(vec *Vec4)

Jump to

Keyboard shortcuts

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