mat32

package module
v2.0.0-dev0.0.28 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: BSD-3-Clause Imports: 13 Imported by: 67

README

mat32

mat32 is a float32 based vector and matrix package for 2D & 3D graphics, based on the G3N math32 package, but using a value-based design instead of pointer-based, which simplifies chained expressions of multiple operators.

The go-gl/mathgl package is also comparable, which in turn is based on image/math/f32 types, which use arrays instead of structs with named X, Y, Z components. The named components make things easier to read overall. The G3N and this package support a much more complete set of vector and matrix math, covering almost everything you might need, including aggregate types such as triangles, planes, etc.

This package also includes the Matrix class from fogleman/gg (as Mat2) for 2D graphics -- this also includes additional support for SVG-style configuring of a matrix, in the SetString method.

Value-based Vectors

The use of value-based methods means that vectors are passed and returned as values instead of pointers:

So, in this mat32 package, Add looks like this:

// Add adds other vector to this one and returns result in a new vector.
func (v Vec3) Add(other Vec3) Vec3 {
	return V3(v.X + other.X, v.Y + other.Y, v.Z + other.Z)
}

versus G3N:

// Add adds other vector to this one.
// Returns the pointer to this updated vector.
func (v *Vector3) Add(other *Vector3) *Vector3 {
	v.X += other.X
	v.Y += other.Y
	v.Z += other.Z
	return v
}

The value-based design allows you to just string together sequences of expressions naturally, without worrying about allocating intermediate variables:

// Normal returns the triangle's normal.
func Normal(a, b, c Vec3) Vec3 {
	nv := c.Sub(b).Cross(a.Sub(b))
   ...

There may be a small performance cost for the value-based approach (comparative benchmarks have not yet been run), but the overall simplicity advantages are significant.

The matrix types still do use pointer-based logic because they are significantly larger and thus the performance issues are likely to be more important.

Struct vs. Array Performance: Struct is much faster

This is a benchmark from Egon Elbre, showing that small arrays can be significantly slower than a struct: https://github.com/egonelbre/exp/blob/master/bench/vector_fusing/vector_test.go

# array
BenchmarkAddMul-32                      70589480                17.3 ns/op
# struct
BenchmarkStructAddMul-32                1000000000               0.740 ns/op

Discussion: https://github.com/golang/go/issues/15925

Documentation

Overview

mat32 is our version of the G3N math32 32-bit, 3D rendering-based math library.

Initially copied from G3N: github.com/g3n/engine/math32 Copyright 2016 The G3N Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

A major modification from the G3N version is to use value-based logic instead of pointer-based self-modification in the Vector classes, As used in e.g., go-gl/mathgl (which uses slice-based vectors instead of the more intuitive and likely more efficient struct-based ones here).

The pointer-based approach was retained for the Matrix classes, which are larger and that is likely more performant.

Many names were shortened, consistent with more idiomatic Go naming. and again with the go-gl/mathgl library

Index

Constants

View Source
const (
	E   = math.E
	Pi  = math.Pi
	Phi = math.Phi

	Sqrt2   = math.Sqrt2
	SqrtE   = math.SqrtE
	SqrtPi  = math.SqrtPi
	SqrtPhi = math.SqrtPhi

	Ln2    = math.Ln2
	Log2E  = math.Log2E
	Ln10   = math.Ln10
	Log10E = math.Log10E
)

Mathematical constants.

View Source
const (
	MaxFloat32             = math.MaxFloat32
	SmallestNonzeroFloat32 = math.SmallestNonzeroFloat32
)

Floating-point limit values. Max is the largest finite value representable by the type. SmallestNonzero is the smallest positive, non-zero value representable by the type.

View Source
const (
	// DegToRadFactor is the number of radians per degree.
	DegToRadFactor = Pi / 180

	// RadToDegFactor is the number of degrees per radian.
	RadToDegFactor = 180 / Pi
)
View Source
const (
	// Version is the version of this package being used
	Version = "v2.0.0-dev0.0.28"
	// GitCommit is the commit just before the latest version commit
	GitCommit = "1193c79"
	// VersionDate is the date-time of the latest version commit in UTC (in the format 'YYYY-MM-DD HH:MM', which is the Go format '2006-01-02 15:04')
	VersionDate = "2023-12-26 23:27"
)

Variables

View Source
var Infinity = float32(math.Inf(1))

Infinity is positive infinity.

Functions

func Abs

func Abs(x float32) float32

Abs returns the absolute value of x.

Special cases are:

Abs(±Inf) = +Inf
Abs(NaN) = NaN

func Acos

func Acos(x float32) float32

Acos returns the arccosine, in radians, of x.

Special case is:

Acos(x) = NaN if x < -1 or x > 1

func Acosh

func Acosh(x float32) float32

Acosh returns the inverse hyperbolic cosine of x.

Special cases are:

Acosh(+Inf) = +Inf
Acosh(x) = NaN if x < 1
Acosh(NaN) = NaN

func Asin

func Asin(x float32) float32

Asin returns the arcsine, in radians, of x.

Special cases are:

Asin(±0) = ±0
Asin(x) = NaN if x < -1 or x > 1

func Asinh

func Asinh(x float32) float32

Asinh returns the inverse hyperbolic sine of x.

Special cases are:

Asinh(±0) = ±0
Asinh(±Inf) = ±Inf
Asinh(NaN) = NaN

func Atan

func Atan(x float32) float32

Atan returns the arctangent, in radians, of x.

Special cases are:

Atan(±0) = ±0
Atan(±Inf) = ±Pi/2

func Atan2

func Atan2(y, x float32) float32

Atan2 returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value. Special cases are (in order):

Atan2(y, NaN) = NaN
Atan2(NaN, x) = NaN
Atan2(+0, x>=0) = +0
Atan2(-0, x>=0) = -0
Atan2(+0, x<=-0) = +Pi
Atan2(-0, x<=-0) = -Pi
Atan2(y>0, 0) = +Pi/2
Atan2(y<0, 0) = -Pi/2
Atan2(+Inf, +Inf) = +Pi/4
Atan2(-Inf, +Inf) = -Pi/4
Atan2(+Inf, -Inf) = 3Pi/4
Atan2(-Inf, -Inf) = -3Pi/4
Atan2(y, +Inf) = 0
Atan2(y>0, -Inf) = +Pi
Atan2(y<0, -Inf) = -Pi
Atan2(+Inf, x) = +Pi/2
Atan2(-Inf, x) = -Pi/2

func Atanh

func Atanh(x float32) float32

Atanh returns the inverse hyperbolic tangent of x.

Special cases are:

Atanh(1) = +Inf
Atanh(±0) = ±0
Atanh(-1) = -Inf
Atanh(x) = NaN if x < -1 or x > 1
Atanh(NaN) = NaN

func Cbrt

func Cbrt(x float32) float32

Cbrt returns the cube root of x.

Special cases are:

Cbrt(±0) = ±0
Cbrt(±Inf) = ±Inf
Cbrt(NaN) = NaN

func Ceil

func Ceil(x float32) float32

Ceil returns the least integer value greater than or equal to x.

Special cases are:

Ceil(±0) = ±0
Ceil(±Inf) = ±Inf
Ceil(NaN) = NaN

func Clamp

func Clamp(x, a, b float32) float32

Clamp clamps x to the provided closed interval [a, b]

func ClampInt

func ClampInt(x, a, b int) int

ClampInt clamps x to the provided closed interval [a, b]

func ContainsPoint

func ContainsPoint(point, a, b, c Vec3) bool

ContainsPoint returns whether a triangle contains a point.

func CopyFloat32s

func CopyFloat32s(trg *[]float32, src []float32)

CopyFloat32s copies a []float32 slice from src into target

func CopyFloat64s

func CopyFloat64s(trg *[]float64, src []float64)

CopyFloat64s copies a []float64 slice from src into target

func Copysign

func Copysign(f, sign float32) float32

Copysign returns a value with the magnitude of f and the sign of sign.

func Cos

func Cos(x float32) float32

Cos returns the cosine of the radian argument x.

Special cases are:

Cos(±Inf) = NaN
Cos(NaN) = NaN

func Cosh

func Cosh(x float32) float32

Cosh returns the hyperbolic cosine of x.

Special cases are:

Cosh(±0) = 1
Cosh(±Inf) = +Inf
Cosh(NaN) = NaN

func DegToRad

func DegToRad(degrees float32) float32

DegToRad converts a number from degrees to radians

func Dim

func Dim(x, y float32) float32

Dim returns the maximum of x-y or 0.

Special cases are:

Dim(+Inf, +Inf) = NaN
Dim(-Inf, -Inf) = NaN
Dim(x, NaN) = Dim(NaN, x) = NaN

func Erf

func Erf(x float32) float32

Erf returns the error function of x.

Special cases are:

Erf(+Inf) = 1
Erf(-Inf) = -1
Erf(NaN) = NaN

func Erfc

func Erfc(x float32) float32

Erfc returns the complementary error function of x.

Special cases are:

Erfc(+Inf) = 0
Erfc(-Inf) = 2
Erfc(NaN) = NaN

func Erfcinv

func Erfcinv(x float32) float32

Erfcinv returns the inverse of Erfc(x).

Special cases are:

Erfcinv(0) = +Inf
Erfcinv(2) = -Inf
Erfcinv(x) = NaN if x < 0 or x > 2
Erfcinv(NaN) = NaN

func Erfinv

func Erfinv(x float32) float32

Erfinv returns the inverse error function of x.

Special cases are:

Erfinv(1) = +Inf
Erfinv(-1) = -Inf
Erfinv(x) = NaN if x < -1 or x > 1
Erfinv(NaN) = NaN

func Exp

func Exp(x float32) float32

Exp returns e**x, the base-e exponential of x.

Special cases are:

Exp(+Inf) = +Inf
Exp(NaN) = NaN

Very large values overflow to 0 or +Inf. Very small values underflow to 1.

func Exp2

func Exp2(x float32) float32

Exp2 returns 2**x, the base-2 exponential of x.

Special cases are the same as Exp.

func Expm1

func Expm1(x float32) float32

Expm1 returns e**x - 1, the base-e exponential of x minus 1. It is more accurate than Exp(x) - 1 when x is near zero.

Special cases are:

Expm1(+Inf) = +Inf
Expm1(-Inf) = -1
Expm1(NaN) = NaN

Very large values overflow to -1 or +Inf.

func FMA

func FMA(x, y, z float32) float32

FMA returns x * y + z, computed with only one rounding. (That is, FMA returns the fused multiply-add of x, y, and z.)

func FastExp

func FastExp(x float32) float32

FastExp is a quartic spline approximation to the Exp function, by N.N. Schraudolph It does not have any of the sanity checking of a standard method -- returns nonsense when arg is out of range. Runs in 2.23ns vs. 6.3ns for 64bit which is faster than math32.Exp actually.

func FitGeomInWindow

func FitGeomInWindow(stPos, stSz, winPos, winSz int) (pos, sz int)

FitGeomInWindow returns a position and size for a region (sub-window) within a larger window geom (pos and size) that fits entirely within that window to the extent possible, given an initial starting position and size. The position is first adjusted to try to fit the size, and then the size is adjusted to make it fit if it is still too big.

func Floor

func Floor(x float32) float32

Floor returns the greatest integer value less than or equal to x.

Special cases are:

Floor(±0) = ±0
Floor(±Inf) = ±Inf
Floor(NaN) = NaN

func Frexp

func Frexp(f float32) (frac float32, exp int)

Frexp breaks f into a normalized fraction and an integral power of two. It returns frac and exp satisfying f == frac × 2**exp, with the absolute value of frac in the interval [½, 1).

Special cases are:

Frexp(±0) = ±0, 0
Frexp(±Inf) = ±Inf, 0
Frexp(NaN) = NaN, 0

func FromFixed

func FromFixed(x fixed.Int26_6) float32

FromFixed converts a fixed.Int26_6 to a float32

func Gamma

func Gamma(x float32) float32

Gamma returns the Gamma function of x.

Special cases are:

Gamma(+Inf) = +Inf
Gamma(+0) = +Inf
Gamma(-0) = -Inf
Gamma(x) = NaN for integer x < 0
Gamma(-Inf) = NaN
Gamma(NaN) = NaN

func Hypot

func Hypot(p, q float32) float32

Hypot returns Sqrt(p*p + q*q), taking care to avoid unnecessary overflow and underflow.

Special cases are:

Hypot(±Inf, q) = +Inf
Hypot(p, ±Inf) = +Inf
Hypot(NaN, q) = NaN
Hypot(p, NaN) = NaN

func Ilogb

func Ilogb(x float32) float32

Ilogb returns the binary exponent of x as an integer.

Special cases are:

Ilogb(±Inf) = MaxInt32
Ilogb(0) = MinInt32
Ilogb(NaN) = MaxInt32

func Inf

func Inf(sign int) float32

Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.

func IntMultiple

func IntMultiple(val, mod float32) float32

IntMultiple returns the interger multiple of mod closest to given value: Round(val / mod) * mod

func IntMultipleGE

func IntMultipleGE(val, mod float32) float32

IntMultipleGE returns the interger multiple of mod >= given value: Ceil(val / mod) * mod

func IsInf

func IsInf(x float32, sign int) bool

IsInf reports whether f is an infinity, according to sign. If sign > 0, IsInf reports whether f is positive infinity. If sign < 0, IsInf reports whether f is negative infinity. If sign == 0, IsInf reports whether f is either infinity.

func IsNaN

func IsNaN(x float32) bool

IsNaN reports whether f is an IEEE 754 “not-a-number” value.

func J0

func J0(x float32) float32

J0 returns the order-zero Bessel function of the first kind.

Special cases are:

J0(±Inf) = 0
J0(0) = 1
J0(NaN) = NaN

func J1

func J1(x float32) float32

J1 returns the order-one Bessel function of the first kind.

Special cases are:

J1(±Inf) = 0
J1(NaN) = NaN

func Jn

func Jn(n int, x float32) float32

Jn returns the order-n Bessel function of the first kind.

Special cases are:

Jn(n, ±Inf) = 0
Jn(n, NaN) = NaN

func Ldexp

func Ldexp(frac float32, exp int) float32

Ldexp is the inverse of Frexp. It returns frac × 2**exp.

Special cases are:

Ldexp(±0, exp) = ±0
Ldexp(±Inf, exp) = ±Inf
Ldexp(NaN, exp) = NaN

func Lerp

func Lerp(start, stop, amount float32) float32

Lerp returns the linear interpolation between start and stop in proportion to amount

func Lgamma

func Lgamma(x float32) (lgamma float32, sign int)

Lgamma returns the natural logarithm and sign (-1 or +1) of Gamma(x).

Special cases are:

Lgamma(+Inf) = +Inf
Lgamma(0) = +Inf
Lgamma(-integer) = +Inf
Lgamma(-Inf) = -Inf
Lgamma(NaN) = NaN

func Log

func Log(x float32) float32

Log returns the natural logarithm of x.

Special cases are:

Log(+Inf) = +Inf
Log(0) = -Inf
Log(x < 0) = NaN
Log(NaN) = NaN

func Log10

func Log10(x float32) float32

Log10 returns the decimal logarithm of x. The special cases are the same as for Log.

func Log1p

func Log1p(x float32) float32

Log1p returns the natural logarithm of 1 plus its argument x. It is more accurate than Log(1 + x) when x is near zero.

Special cases are:

Log1p(+Inf) = +Inf
Log1p(±0) = ±0
Log1p(-1) = -Inf
Log1p(x < -1) = NaN
Log1p(NaN) = NaN

func Log2

func Log2(x float32) float32

Log2 returns the binary logarithm of x. The special cases are the same as for Log.

func Logb

func Logb(x float32) float32

Logb returns the binary exponent of x.

Special cases are:

Logb(±Inf) = +Inf
Logb(0) = -Inf
Logb(NaN) = NaN

func Max

func Max(x, y float32) float32

Max returns the larger of x or y.

Special cases are:

Max(x, +Inf) = Max(+Inf, x) = +Inf
Max(x, NaN) = Max(NaN, x) = NaN
Max(+0, ±0) = Max(±0, +0) = +0
Max(-0, -0) = -0

Note that this differs from the built-in function max when called with NaN and +Inf.

func Max32i

func Max32i(a, b int32) int32

Max32i returns the max of the two int32 numbers.

func MaxPos

func MaxPos(a, b float32) float32

MaxPos returns the minimum of the two values, excluding any that are <= 0

func Min

func Min(x, y float32) float32

Min returns the smaller of x or y.

Special cases are:

Min(x, -Inf) = Min(-Inf, x) = -Inf
Min(x, NaN) = Min(NaN, x) = NaN
Min(-0, ±0) = Min(±0, -0) = -0

Note that this differs from the built-in function min when called with NaN and -Inf.

func Min32i

func Min32i(a, b int32) int32

Min32i returns the min of the two int32 numbers.

func MinPos

func MinPos(a, b float32) float32

MinPos returns the minimum of the two values, excluding any that are <= 0

func Mod

func Mod(x, y float32) float32

Mod returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x.

Special cases are:

Mod(±Inf, y) = NaN
Mod(NaN, y) = NaN
Mod(x, 0) = NaN
Mod(x, ±Inf) = x
Mod(x, NaN) = NaN

func Modf

func Modf(f float32) (it float32, frac float32)

Modf returns integer and fractional floating-point numbers that sum to f. Both values have the same sign as f.

Special cases are:

Modf(±Inf) = ±Inf, NaN
Modf(NaN) = NaN, NaN

func NaN

func NaN() float32

NaN returns an IEEE 754 “not-a-number” value.

func Nextafter

func Nextafter(x, y float32) float32

Nextafter returns the next representable float32 value after x towards y.

Special cases are:

Nextafter32(x, x)   = x
Nextafter32(NaN, y) = NaN
Nextafter32(x, NaN) = NaN

func ParseAngle32

func ParseAngle32(pstr string) (float32, error)

ParseAngle32 returns radians angle from string that can specify units (deg, grad, rad) -- deg is assumed if not specified

func ParseFloat32

func ParseFloat32(pstr string) (float32, error)

ParseFloat32 logs any strconv.ParseFloat errors

func PointDim

func PointDim(v image.Point, dim Dims) int

Dim returns this vector component from given image.Point

func PointsCheckN

func PointsCheckN(pts []float32, n int, errmsg string) error

PointsCheckN checks the number of points read and emits an error if not equal to n

func Pow

func Pow(x, y float32) float32

Pow returns x**y, the base-x exponential of y.

Special cases are (in order):

Pow(x, ±0) = 1 for any x
Pow(1, y) = 1 for any y
Pow(x, 1) = x for any x
Pow(NaN, y) = NaN
Pow(x, NaN) = NaN
Pow(±0, y) = ±Inf for y an odd integer < 0
Pow(±0, -Inf) = +Inf
Pow(±0, +Inf) = +0
Pow(±0, y) = +Inf for finite y < 0 and not an odd integer
Pow(±0, y) = ±0 for y an odd integer > 0
Pow(±0, y) = +0 for finite y > 0 and not an odd integer
Pow(-1, ±Inf) = 1
Pow(x, +Inf) = +Inf for |x| > 1
Pow(x, -Inf) = +0 for |x| > 1
Pow(x, +Inf) = +0 for |x| < 1
Pow(x, -Inf) = +Inf for |x| < 1
Pow(+Inf, y) = +Inf for y > 0
Pow(+Inf, y) = +0 for y < 0
Pow(-Inf, y) = Pow(-0, -y)
Pow(x, y) = NaN for finite x < 0 and finite non-integer y

func Pow10

func Pow10(n int) float32

Pow10 returns 10**n, the base-10 exponential of n.

Special cases are:

Pow10(n) =    0 for n < -323
Pow10(n) = +Inf for n > 308

func RadToDeg

func RadToDeg(radians float32) float32

RadToDeg converts a number from radians to degrees

func ReadPoints

func ReadPoints(pstr string) []float32

ReadPoints reads a set of floating point values from a SVG format number string -- returns a slice or nil if there was an error

func RectFromPosSizeMax

func RectFromPosSizeMax(pos, sz Vec2) image.Rectangle

RectFromPosSizeMax returns an image.Rectangle from max dims of pos, size (floor on pos, ceil on size)

func RectFromPosSizeMin

func RectFromPosSizeMin(pos, sz Vec2) image.Rectangle

RectFromPosSizeMin returns an image.Rectangle from min dims of pos, size (ceil on pos, floor on size)

func RectInNotEmpty

func RectInNotEmpty(r, b image.Rectangle) bool

RectInNotEmpty returns true if rect r is contained within b box and r is not empty. The existing image.Rectangle.In method returns true if r is empty, but we typically expect that case to be false (out of range box)

func Remainder

func Remainder(x, y float32) float32

Remainder returns the IEEE 754 floating-point remainder of x/y.

Special cases are:

Remainder(±Inf, y) = NaN
Remainder(NaN, y) = NaN
Remainder(x, 0) = NaN
Remainder(x, ±Inf) = x
Remainder(x, NaN) = NaN

func Round

func Round(x float32) float32

Round returns the nearest integer, rounding half away from zero.

Special cases are:

Round(±0) = ±0
Round(±Inf) = ±Inf
Round(NaN) = NaN

func RoundToEven

func RoundToEven(x float32) float32

RoundToEven returns the nearest integer, rounding ties to even.

Special cases are:

RoundToEven(±0) = ±0
RoundToEven(±Inf) = ±Inf
RoundToEven(NaN) = NaN

func SRGBFromLinear

func SRGBFromLinear(lin float32) float32

SRGBFromLinear converts a color with linear gamma correction to SRGB standard 2.4 gamma with offsets.

func SRGBToLinear

func SRGBToLinear(sr float32) float32

SRGBToLinear converts a color with SRGB gamma correction to SRGB standard 2.4 gamma with offsets

func SetPointDim

func SetPointDim(v *image.Point, dim Dims, value int)

SetPointDim is a helper function for image.Point for setting given dimension

func Sign

func Sign(x float32) float32

Sign returns -1 if x < 0 and 1 otherwise.

func Signbit

func Signbit(x float32) bool

Signbit returns true if x is negative or negative zero.

func Sin

func Sin(x float32) float32

Sin returns the sine of the radian argument x.

Special cases are:

Sin(±0) = ±0
Sin(±Inf) = NaN
Sin(NaN) = NaN

func Sincos

func Sincos(x float32) (sin, cos float32)

Sincos returns Sin(x), Cos(x).

Special cases are:

Sincos(±0) = ±0, 1
Sincos(±Inf) = NaN, NaN
Sincos(NaN) = NaN, NaN

func Sinh

func Sinh(x float32) float32

Sinh returns the hyperbolic sine of x.

Special cases are:

Sinh(±0) = ±0
Sinh(±Inf) = ±Inf
Sinh(NaN) = NaN

func Sqrt

func Sqrt(x float32) float32

Sqrt returns the square root of x.

Special cases are:

Sqrt(+Inf) = +Inf
Sqrt(±0) = ±0
Sqrt(x < 0) = NaN
Sqrt(NaN) = NaN

func Tan

func Tan(x float32) float32

Tan returns the tangent of the radian argument x.

Special cases are:

Tan(±0) = ±0
Tan(±Inf) = NaN
Tan(NaN) = NaN

func Tanh

func Tanh(x float32) float32

Tanh returns the hyperbolic tangent of x.

Special cases are:

Tanh(±0) = ±0
Tanh(±Inf) = ±1
Tanh(NaN) = NaN

func ToFixed

func ToFixed(x float32) fixed.Int26_6

ToFixed converts a float32 value to a fixed.Int26_6

func ToFixedPoint

func ToFixedPoint(x, y float32) fixed.Point26_6

ToFixedPoint converts float32 x,y values to a fixed.Point26_6

func Trunc

func Trunc(x float32) float32

Trunc returns the integer value of x.

Special cases are:

Trunc(±0) = ±0
Trunc(±Inf) = ±Inf
Trunc(NaN) = NaN

func Truncate

func Truncate(val float32, prec int) float32

Truncate rounds a float32 number to the given level of precision, which the number of significant digits to include in the result.

func Truncate64

func Truncate64(val float64, prec int) float64

Truncate64 rounds a float64 number to the given level of precision, which the number of significant digits to include in the result.

func Y0

func Y0(x float32) float32

Y0 returns the order-zero Bessel function of the second kind.

Special cases are:

Y0(+Inf) = 0
Y0(0) = -Inf
Y0(x < 0) = NaN
Y0(NaN) = NaN

func Y1

func Y1(x float32) float32

Y1 returns the order-one Bessel function of the second kind.

Special cases are:

Y1(+Inf) = 0
Y1(0) = -Inf
Y1(x < 0) = NaN
Y1(NaN) = NaN

func Yn

func Yn(n int, x float32) float32

Yn returns the order-n Bessel function of the second kind.

Special cases are:

Yn(n, +Inf) = 0
Yn(n ≥ 0, 0) = -Inf
Yn(n < 0, 0) = +Inf if n is odd, -Inf if n is even
Yn(n, x < 0) = NaN
Yn(n, NaN) = NaN

Types

type ArrayF32

type ArrayF32 []float32

ArrayF32 is a slice of float32 with additional convenience methods

func NewArrayF32

func NewArrayF32(size, capacity int) ArrayF32

NewArrayF32 creates a returns a new array of floats with the specified initial size and capacity

func (*ArrayF32) Append

func (a *ArrayF32) Append(v ...float32)

Append appends any number of values to the array

func (*ArrayF32) AppendVec2

func (a *ArrayF32) AppendVec2(v ...Vec2)

AppendVec2 appends any number of Vec2 to the array

func (*ArrayF32) AppendVec3

func (a *ArrayF32) AppendVec3(v ...Vec3)

AppendVec3 appends any number of Vec3 to the array

func (*ArrayF32) AppendVec4

func (a *ArrayF32) AppendVec4(v ...Vec4)

AppendVec4 appends any number of Vec4 to the array

func (*ArrayF32) Bytes

func (a *ArrayF32) Bytes() int

Bytes returns the size of the array in bytes

func (*ArrayF32) CopyFrom

func (a *ArrayF32) CopyFrom(src ArrayF32)

func (*ArrayF32) Extend

func (a *ArrayF32) Extend(addLen int)

Extend appends given number of new float elements to end of existing array

func (ArrayF32) GetMat4

func (a ArrayF32) GetMat4(pos int, m *Mat4)

GetMat4 stores in the specified Mat4 the values from the array starting at the specified pos.

func (ArrayF32) GetVec2

func (a ArrayF32) GetVec2(pos int, v *Vec2)

GetVec2 stores in the specified Vec2 the values from the array starting at the specified pos.

func (ArrayF32) GetVec3

func (a ArrayF32) GetVec3(pos int, v *Vec3)

GetVec3 stores in the specified Vec3 the values from the array starting at the specified pos.

func (ArrayF32) GetVec4

func (a ArrayF32) GetVec4(pos int, v *Vec4)

GetVec4 stores in the specified Vec4 the values from the array starting at the specified pos.

func (*ArrayF32) Len

func (a *ArrayF32) Len() int

Len returns the number of float32 elements in the array It is equivalent to Size()

func (ArrayF32) Set

func (a ArrayF32) Set(pos int, v ...float32)

Set sets the values of the array starting at the specified pos from the specified values

func (ArrayF32) SetVec2

func (a ArrayF32) SetVec2(pos int, v Vec2)

SetVec2 sets the values of the array at the specified pos from the XY values of the specified Vec2

func (ArrayF32) SetVec3

func (a ArrayF32) SetVec3(pos int, v Vec3)

SetVec3 sets the values of the array at the specified pos from the XYZ values of the specified Vec3

func (ArrayF32) SetVec4

func (a ArrayF32) SetVec4(pos int, v Vec4)

SetVec4 sets the values of the array at the specified pos from the XYZ values of the specified Vec4

func (*ArrayF32) Size

func (a *ArrayF32) Size() int

Size returns the number of float32 elements in the array

type ArrayU32

type ArrayU32 []uint32

ArrayU32 is a slice of uint32 with additional convenience methods

func NewArrayU32

func NewArrayU32(size, capacity int) ArrayU32

NewArrayU32 creates a returns a new array of uint32 with the specified initial size and capacity

func (*ArrayU32) Append

func (a *ArrayU32) Append(v ...uint32)

Append appends n elements to the array updating the slice if necessary

func (*ArrayU32) Bytes

func (a *ArrayU32) Bytes() int

Bytes returns the size of the array in bytes

func (*ArrayU32) Extend

func (a *ArrayU32) Extend(addLen int)

Extend appends given number of new elements to end of existing array

func (*ArrayU32) Len

func (a *ArrayU32) Len() int

Len returns the number of float32 elements in the array

func (ArrayU32) Set

func (a ArrayU32) Set(pos int, v ...uint32)

Set sets the values of the array starting at the specified pos from the specified values

func (*ArrayU32) Size

func (a *ArrayU32) Size() int

Size returns the number of float32 elements in the array

type Box2

type Box2 struct {
	Min Vec2
	Max Vec2
}

Box2 represents a 2D bounding box defined by two points: the point with minimum coordinates and the point with maximum coordinates.

func B2

func B2(x0, y0, x1, y1 float32) Box2

B2 returns a new Box2 from the given minimum and maximum x and y coordinates.

func B2Empty

func B2Empty() Box2

B2Empty returns a new Box2 with empty minimum and maximum values

func B2FromRect

func B2FromRect(rect image.Rectangle) Box2

B2FromRect returns a new Box2 from the given image.Rectangle.

func (Box2) Canon

func (b Box2) Canon() Box2

Canon returns the canonical version of the box. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.

func (Box2) Center

func (b Box2) Center() Vec2

Center calculates the center point of this bounding box.

func (Box2) ClampPoint

func (b Box2) ClampPoint(point Vec2) Vec2

ClampPoint calculates a new point which is the specified point clamped inside this box.

func (Box2) ContainsBox

func (b Box2) ContainsBox(box Box2) bool

ContainsBox returns if this bounding box contains other box.

func (Box2) ContainsPoint

func (b Box2) ContainsPoint(point Vec2) bool

ContainsPoint returns if this bounding box contains the specified point.

func (Box2) DistToPoint

func (b Box2) DistToPoint(point Vec2) float32

DistToPoint returns the distance from this box to the specified point.

func (*Box2) ExpandByBox

func (b *Box2) ExpandByBox(box Box2)

ExpandByBox may expand this bounding box to include the specified box

func (*Box2) ExpandByPoint

func (b *Box2) ExpandByPoint(point Vec2)

ExpandByPoint may expand this bounding box to include the specified point.

func (*Box2) ExpandByScalar

func (b *Box2) ExpandByScalar(scalar float32)

ExpandByScalar expands this bounding box by the specified scalar.

func (*Box2) ExpandByVector

func (b *Box2) ExpandByVector(vector Vec2)

ExpandByVector expands this bounding box by the specified vector.

func (Box2) Intersect

func (b Box2) Intersect(other Box2) Box2

Intersect returns the intersection with other box.

func (Box2) IntersectsBox

func (b Box2) IntersectsBox(other Box2) bool

IntersectsBox returns if other box intersects this one.

func (*Box2) IsEmpty

func (b *Box2) IsEmpty() bool

IsEmpty returns if this bounding box is empty (max < min on any coord).

func (Box2) IsEqual

func (b Box2) IsEqual(other Box2) bool

IsEqual returns if this box is equal to other.

func (Box2) MulMat2

func (b Box2) MulMat2(m Mat2) Box2

MulMat2 multiplies the specified matrix to the vertices of this bounding box and computes the resulting spanning Box2 of the transformed points

func (*Box2) Set

func (b *Box2) Set(min, max *Vec2)

Set sets this bounding box minimum and maximum coordinates. If either min or max are nil, then corresponding values are set to +/- Infinity.

func (*Box2) SetEmpty

func (b *Box2) SetEmpty()

SetEmpty set this bounding box to empty (min / max +/- Infinity)

func (*Box2) SetFromCenterAndSize

func (b *Box2) SetFromCenterAndSize(center, size Vec2)

SetFromCenterAndSize set this bounding box from a center point and size. Size is a vector from the minimum point to the maximum point.

func (*Box2) SetFromPoints

func (b *Box2) SetFromPoints(points []Vec2)

SetFromPoints set this bounding box from the specified array of points.

func (*Box2) SetFromRect

func (b *Box2) SetFromRect(rect image.Rectangle)

SetFromRect set this bounding box from an image.Rectangle

func (Box2) Size

func (b Box2) Size() Vec2

Size calculates the size of this bounding box: the vector from its minimum point to its maximum point.

func (Box2) ToRect

func (b Box2) ToRect() image.Rectangle

ToRect returns image.Rectangle version of this bbox, using floor for min and Ceil for max.

func (Box2) Translate

func (b Box2) Translate(offset Vec2) Box2

Translate returns translated position of this box by offset.

func (Box2) Union

func (b Box2) Union(other Box2) Box2

Union returns the union with other box.

type Box3

type Box3 struct {
	Min Vec3
	Max Vec3
}

Box3 represents a 3D bounding box defined by two points: the point with minimum coordinates and the point with maximum coordinates.

func B3

func B3(x0, y0, z0, x1, y1, z1 float32) Box3

B3 returns a new Box3 from the given minimum and maximum x, y, and z coordinates.

func B3Empty

func B3Empty() Box3

B3Empty returns a new Box3 with empty minimum and maximum values.

func (Box3) Center

func (b Box3) Center() Vec3

Center returns the center of the bounding box.

func (Box3) ClampPoint

func (b Box3) ClampPoint(point Vec3) Vec3

ClampPoint returns a new point which is the specified point clamped inside this box.

func (Box3) ContainsBox

func (b Box3) ContainsBox(box Box3) bool

ContainsBox returns if this bounding box contains other box.

func (Box3) ContainsPoint

func (b Box3) ContainsPoint(point Vec3) bool

ContainsPoint returns if this bounding box contains the specified point.

func (Box3) DistToPoint

func (b Box3) DistToPoint(point Vec3) float32

DistToPoint returns the distance from this box to the specified point.

func (*Box3) ExpandByBox

func (b *Box3) ExpandByBox(box Box3)

ExpandByBox may expand this bounding box to include the specified box

func (*Box3) ExpandByPoint

func (b *Box3) ExpandByPoint(point Vec3)

ExpandByPoint may expand this bounding box to include the specified point.

func (*Box3) ExpandByPoints

func (b *Box3) ExpandByPoints(points []Vec3)

ExpandByPoints may expand this bounding box from the specified array of points.

func (*Box3) ExpandByScalar

func (b *Box3) ExpandByScalar(scalar float32)

ExpandByScalar expands this bounding box by the specified scalar subtracting from min and adding to max.

func (*Box3) ExpandByVector

func (b *Box3) ExpandByVector(vector Vec3)

ExpandByVector expands this bounding box by the specified vector subtracting from min and adding to max.

func (Box3) GetBoundingSphere

func (b Box3) GetBoundingSphere() Sphere

GetBoundingSphere returns a bounding sphere to this bounding box.

func (Box3) Intersect

func (b Box3) Intersect(other Box3) Box3

Intersect returns the intersection with other box.

func (Box3) IntersectsBox

func (b Box3) IntersectsBox(other Box3) bool

IntersectsBox returns if other box intersects this one.

func (Box3) IsEmpty

func (b Box3) IsEmpty() bool

IsEmpty returns true if this bounding box is empty (max < min on any coord).

func (Box3) IsEqual

func (b Box3) IsEqual(other Box3) bool

IsEqual returns if this box is equal to other

func (Box3) MVProjToNDC

func (b Box3) MVProjToNDC(m *Mat4) Box3

MVProjToNDC projects bounding box through given MVP model-view-projection Mat4 with perspective divide to return normalized display coordinates (NDC).

func (Box3) MulMat4

func (b Box3) MulMat4(m *Mat4) Box3

MulMat4 multiplies the specified matrix to the vertices of this bounding box and computes the resulting spanning Box3 of the transformed points

func (Box3) MulQuat

func (b Box3) MulQuat(q Quat) Box3

MulQuat multiplies the specified quaternion to the vertices of this bounding box and computes the resulting spanning Box3 of the transformed points

func (*Box3) Set

func (b *Box3) Set(min, max *Vec3)

Set sets this bounding box minimum and maximum coordinates. If either min or max are nil, then corresponding values are set to +/- Infinity.

func (*Box3) SetEmpty

func (b *Box3) SetEmpty()

SetEmpty set this bounding box to empty (min / max +/- Infinity)

func (*Box3) SetFromCenterAndSize

func (b *Box3) SetFromCenterAndSize(center, size Vec3)

SetFromCenterAndSize sets this bounding box from a center point and size. Size is a vector from the minimum point to the maximum point.

func (*Box3) SetFromPoints

func (b *Box3) SetFromPoints(points []Vec3)

SetFromPoints sets this bounding box from the specified array of points.

func (Box3) Size

func (b Box3) Size() Vec3

Size calculates the size of this bounding box: the vector from its minimum point to its maximum point.

func (Box3) Translate

func (b Box3) Translate(offset Vec3) Box3

Translate returns translated position of this box by offset.

func (Box3) Union

func (b Box3) Union(other Box3) Box3

Union returns the union with other box.

type Dims

type Dims int32 //enums:enum

Dims is a list of vector dimension (component) names

const (
	X Dims = iota
	Y
	Z
	W
)
const DimsN Dims = 4

DimsN is the highest valid value for type Dims, plus one.

func DimsValues

func DimsValues() []Dims

DimsValues returns all possible values for the type Dims.

func OtherDim

func OtherDim(d Dims) Dims

OtherDim returns the other dimension for 2D X,Y

func (Dims) Desc

func (i Dims) Desc() string

Desc returns the description of the Dims value.

func (Dims) Int64

func (i Dims) Int64() int64

Int64 returns the Dims value as an int64.

func (Dims) IsValid

func (i Dims) IsValid() bool

IsValid returns whether the value is a valid option for type Dims.

func (Dims) MarshalText

func (i Dims) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Dims) Other

func (d Dims) Other() Dims

func (*Dims) SetInt64

func (i *Dims) SetInt64(in int64)

SetInt64 sets the Dims value from an int64.

func (*Dims) SetString

func (i *Dims) SetString(s string) error

SetString sets the Dims value from its string representation, and returns an error if the string is invalid.

func (Dims) String

func (i Dims) String() string

String returns the string representation of this Dims value.

func (*Dims) UnmarshalText

func (i *Dims) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Dims) Values

func (i Dims) Values() []enums.Enum

Values returns all possible values for the type Dims.

type Frustum

type Frustum struct {
	Planes [6]Plane
}

Frustum represents a frustum

func NewFrustum

func NewFrustum(p0, p1, p2, p3, p4, p5 *Plane) *Frustum

NewFrustum returns a pointer to a new Frustum object made of 6 explicit planes

func NewFrustumFromMatrix

func NewFrustumFromMatrix(m *Mat4) *Frustum

NewFrustumFromMatrix creates and returns a Frustum based on the provided matrix

func (*Frustum) ContainsPoint

func (f *Frustum) ContainsPoint(point Vec3) bool

ContainsPoint determines whether the frustum contains the specified point

func (*Frustum) IntersectsBox

func (f *Frustum) IntersectsBox(box Box3) bool

IntersectsBox determines whether the specified box is intersecting the frustum

func (*Frustum) IntersectsSphere

func (f *Frustum) IntersectsSphere(sphere Sphere) bool

IntersectsSphere determines whether the specified sphere is intersecting the frustum

func (*Frustum) Set

func (f *Frustum) Set(p0, p1, p2, p3, p4, p5 *Plane)

Set sets the frustum's planes

func (*Frustum) SetFromMatrix

func (f *Frustum) SetFromMatrix(m *Mat4)

SetFromMatrix sets the frustum's planes based on the specified Mat4

type Geom2DInt

type Geom2DInt struct {
	Pos  image.Point
	Size image.Point
}

Geom2DInt defines a geometry in 2D dots units (int) -- this is just a more convenient format than image.Rectangle for cases where the size and position are independently updated (e.g., Viewport)

func (*Geom2DInt) Bounds

func (gm *Geom2DInt) Bounds() image.Rectangle

Bounds converts geom to equivalent image.Rectangle

func (*Geom2DInt) FitInWindow

func (gm *Geom2DInt) FitInWindow(win Geom2DInt) Geom2DInt

FitInWindow returns a position and size for a region (sub-window) within a larger window geom that fits entirely within that window to the extent possible, for the initial "ideal" starting position and size. The position is first adjusted to try to fit the size, and then the size is adjusted to make it fit if it is still too big.

func (*Geom2DInt) SetRect

func (gm *Geom2DInt) SetRect(r image.Rectangle)

SetRect sets values from image.Rectangle

func (*Geom2DInt) SizeRect

func (gm *Geom2DInt) SizeRect() image.Rectangle

SizeRect converts geom to rect version of size at 0 pos

type Line3

type Line3 struct {
	Start Vec3
	End   Vec3
}

Line3 represents a 3D line segment defined by a start and an end point.

func NewLine3

func NewLine3(start, end Vec3) Line3

NewLine3 creates and returns a new Line3 with the specified start and end points.

func (*Line3) Center

func (l *Line3) Center() Vec3

Center calculates this line segment center point.

func (*Line3) Delta

func (l *Line3) Delta() Vec3

Delta calculates the vector from the start to end point of this line segment.

func (*Line3) Dist

func (l *Line3) Dist() float32

Dist returns the distance from the start point to the end point.

func (*Line3) DistSq

func (l *Line3) DistSq() float32

DistSq returns the square of the distance from the start point to the end point.

func (*Line3) IsEqual

func (l *Line3) IsEqual(other Line3) bool

IsEqual returns if this line segement is equal to other.

func (*Line3) MulMat4

func (l *Line3) MulMat4(mat *Mat4) Line3

MulMat4 returns specified matrix multiplied to this line segment start and end points.

func (*Line3) Set

func (l *Line3) Set(start, end Vec3)

Set sets this line segment start and end points.

type Mat2

type Mat2 struct {
	XX, YX, XY, YY, X0, Y0 float32
}

func Identity2D

func Identity2D() Mat2

func Rotate2D

func Rotate2D(angle float32) Mat2

func Scale2D

func Scale2D(x, y float32) Mat2

func Shear2D

func Shear2D(x, y float32) Mat2

func Skew2D

func Skew2D(x, y float32) Mat2

func Translate2D

func Translate2D(x, y float32) Mat2

func (Mat2) ExtractRot

func (a Mat2) ExtractRot() float32

ExtractRot extracts the rotation component from a given matrix

func (Mat2) ExtractScale

func (a Mat2) ExtractScale() (scx, scy float32)

ExtractXYScale extracts the X and Y scale factors after undoing any rotation present -- i.e., in the original X, Y coordinates

func (Mat2) Inverse

func (a Mat2) Inverse() Mat2

Inverse returns inverse of matrix, for inverting transforms

func (Mat2) IsIdentity

func (m Mat2) IsIdentity() bool

func (Mat2) Mul

func (a Mat2) Mul(b Mat2) Mat2

Mul returns a*b

func (Mat2) MulCtr

func (a Mat2) MulCtr(b Mat2, ctr Vec2) Mat2

MulCtr multiplies the Mat2, first subtracting given translation center point from the translation components, and then adding it back in.

func (Mat2) MulFixedAsPt

func (a Mat2) MulFixedAsPt(fp fixed.Point26_6) fixed.Point26_6

MulFixedAsPt multiplies the fixed point as a point, including adding translations.

func (Mat2) MulVec2AsPt

func (a Mat2) MulVec2AsPt(v Vec2) Vec2

MulVec2AsPt multiplies the Vec2 as a point, including adding translations.

func (Mat2) MulVec2AsPtCtr

func (a Mat2) MulVec2AsPtCtr(v, ctr Vec2) Vec2

MulVec2AsPtCtr multiplies the Vec2 as a point relative to given center-point including adding translations.

func (Mat2) MulVec2AsVec

func (a Mat2) MulVec2AsVec(v Vec2) Vec2

MulVec2AsVec multiplies the Vec2 as a vector without adding translations. This is for directional vectors and not points.

func (Mat2) Rotate

func (a Mat2) Rotate(angle float32) Mat2

func (Mat2) Scale

func (a Mat2) Scale(x, y float32) Mat2

func (*Mat2) SetMul

func (a *Mat2) SetMul(b Mat2)

SetMul sets a to a*b

func (*Mat2) SetMulCtr

func (a *Mat2) SetMulCtr(b Mat2, ctr Vec2)

SetMulCtr sets the matrix to the result of Mat2.MulCtr.

func (*Mat2) SetString

func (a *Mat2) SetString(str string) error

SetString processes the standard SVG-style transform strings

func (Mat2) Shear

func (a Mat2) Shear(x, y float32) Mat2

func (Mat2) Skew

func (a Mat2) Skew(x, y float32) Mat2

func (*Mat2) String

func (a *Mat2) String() string

String returns the XML-based string representation of the transform

func (Mat2) Translate

func (a Mat2) Translate(x, y float32) Mat2

type Mat3

type Mat3 [9]float32

Mat3 is 3x3 matrix organized internally as column matrix

func NewMat3

func NewMat3() *Mat3

NewMat3 creates and returns a pointer to a new Mat3 initialized as the identity matrix.

func (*Mat3) CopyFrom

func (m *Mat3) CopyFrom(src *Mat3)

CopyFrom copies from source matrix into this matrix (a regular = assign does not copy data, just the pointer!)

func (*Mat3) Determinant

func (m *Mat3) Determinant() float32

Determinant calculates and returns the determinant of this matrix.

func (*Mat3) FromArray

func (m *Mat3) FromArray(array []float32, offset int)

FromArray sets this matrix array starting at offset.

func (*Mat3) Inverse

func (m *Mat3) Inverse() (*Mat3, error)

Inverse returns the inverse of this matrix. If the matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Mat3) Mul

func (m *Mat3) Mul(other *Mat3) *Mat3

Mul returns this matrix times other matrix (this matrix is unchanged)

func (*Mat3) MulMatrices

func (m *Mat3) MulMatrices(a, b *Mat3)

MulMatrices sets ths matrix as matrix multiplication a by b (i.e., b*a).

func (*Mat3) MulScalar

func (m *Mat3) MulScalar(s float32)

MulScalar returns each of this matrix's components multiplied by the specified scalar.

func (*Mat3) MulVec3Array

func (m *Mat3) MulVec3Array(array []float32, start, count int)

MulVec3Array multiplies count vectors (i.e., 3 sequential array values per each increment in count) in the array starting at start index by this matrix.

func (*Mat3) ScaleCols

func (m *Mat3) ScaleCols(v Vec3) *Mat3

ScaleCols returns matrix with columns multiplied by the vector components. This can be used when multiplying this matrix by a diagonal matrix if we store the diagonal components as a vector.

func (*Mat3) Set

func (m *Mat3) Set(n11, n12, n13, n21, n22, n23, n31, n32, n33 float32)

Set sets all the elements of the matrix row by row starting at row1, column1, row1, column2, row1, column3 and so forth.

func (*Mat3) SetFromMat4

func (m *Mat3) SetFromMat4(src *Mat4)

SetFromMat4 sets the matrix elements based on a Mat4.

func (*Mat3) SetIdentity

func (m *Mat3) SetIdentity()

SetIdentity sets this matrix as the identity matrix.

func (*Mat3) SetInverse

func (m *Mat3) SetInverse(src *Mat3) error

SetInverse sets this matrix to the inverse of the src matrix. If the src matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Mat3) SetMul

func (m *Mat3) SetMul(other *Mat3)

SetMul sets this matrix to this matrix * other

func (*Mat3) SetMulScalar

func (m *Mat3) SetMulScalar(s float32)

SetMulScalar multiplies each of this matrix's components by the specified scalar.

func (*Mat3) SetNormalMatrix

func (m *Mat3) SetNormalMatrix(src *Mat4) error

SetNormalMatrix set this matrix to the matrix that can transform the normal vectors from the src matrix which is used transform the vertices (e.g., a ModelView matrix). If the src matrix cannot be inverted returns error.

func (*Mat3) SetRotationFromQuat

func (m *Mat3) SetRotationFromQuat(q Quat)

SetRotationFromQuat sets this matrix as a rotation matrix from the specified quaternion.

func (*Mat3) SetScaleCols

func (m *Mat3) SetScaleCols(v Vec3)

SetScaleCols multiplies the matrix columns by the vector components. This can be used when multiplying this matrix by a diagonal matrix if we store the diagonal components as a vector.

func (*Mat3) SetTranspose

func (m *Mat3) SetTranspose()

SetTranspose transposes this matrix.

func (*Mat3) SetZero

func (m *Mat3) SetZero()

SetZero sets this matrix as the zero matrix.

func (*Mat3) ToArray

func (m *Mat3) ToArray(array []float32, offset int)

ToArray copies this matrix to array starting at offset.

func (*Mat3) Transpose

func (m *Mat3) Transpose() *Mat3

Transpose returns the transpose of this matrix.

type Mat4

type Mat4 [16]float32

Mat4 is 4x4 matrix organized internally as column matrix.

func NewLookAt

func NewLookAt(eye, target, up Vec3) *Mat4

NewLookAt returns Mat4 matrix as view transform matrix with origin at eye, looking at target and using the up vector.

func NewMat4

func NewMat4() *Mat4

NewMat4 creates and returns a pointer to a new Mat4 initialized as the identity matrix.

func (*Mat4) CopyFrom

func (m *Mat4) CopyFrom(src *Mat4)

CopyFrom copies from source matrix into this matrix (a regular = assign does not copy data, just the pointer!)

func (*Mat4) CopyPos

func (m *Mat4) CopyPos(src *Mat4)

CopyPos copies the position elements of the src matrix into this one.

func (*Mat4) Decompose

func (m *Mat4) Decompose() (pos Vec3, quat Quat, scale Vec3)

Decompose updates the position vector, quaternion and scale from this transformation matrix.

func (*Mat4) Determinant

func (m *Mat4) Determinant() float32

Determinant calculates and returns the determinat of this matrix.

func (*Mat4) ExtractBasis

func (m *Mat4) ExtractBasis() (xAxis, yAxis, zAxis Vec3)

ExtractBasis returns the x,y,z basis vectors of this matrix.

func (*Mat4) ExtractRotation

func (m *Mat4) ExtractRotation(src *Mat4)

ExtractRotation sets this matrix as rotation matrix from the src transformation matrix.

func (*Mat4) FromArray

func (m *Mat4) FromArray(array []float32, offset int)

FromArray set this matrix elements from the array starting at offset.

func (*Mat4) GetMaxScaleOnAxis

func (m *Mat4) GetMaxScaleOnAxis() float32

GetMaxScaleOnAxis returns the maximum scale value of the 3 axes.

func (*Mat4) Inverse

func (m *Mat4) Inverse() (*Mat4, error)

Inverse returns the inverse of this matrix. If the matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Mat4) LookAt

func (m *Mat4) LookAt(eye, target, up Vec3)

LookAt sets this matrix as view transform matrix with origin at eye, looking at target and using the up vector.

func (*Mat4) Mul

func (m *Mat4) Mul(other *Mat4) *Mat4

Mul returns this matrix times other matrix (this matrix is unchanged)

func (*Mat4) MulMatrices

func (m *Mat4) MulMatrices(a, b *Mat4)

MulMatrices sets this matrix as matrix multiplication a by b (i.e. b*a).

func (*Mat4) MulScalar

func (m *Mat4) MulScalar(s float32)

SetMulScalar multiplies each element of this matrix by the specified scalar.

func (*Mat4) MulVec3Array

func (m *Mat4) MulVec3Array(array []float32, start, count int)

MulVec3Array multiplies count vectors (i.e., 3 sequential array values per each increment in count) in the array starting at start index by this matrix.

func (*Mat4) Pos

func (m *Mat4) Pos() Vec3

Pos returns the position component of the matrix

func (*Mat4) ScaleCols

func (m *Mat4) ScaleCols(v Vec3) *Mat4

ScaleCols returns matrix with first column of this matrix multiplied by the vector X component, the second column by the vector Y component and the third column by the vector Z component. The matrix fourth column is unchanged.

func (*Mat4) Set

func (m *Mat4) Set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 float32)

Set sets all the elements of this matrix row by row starting at row1, column1, row1, column2, row1, column3 and so forth.

func (*Mat4) SetBasis

func (m *Mat4) SetBasis(xAxis, yAxis, zAxis Vec3)

SetBasis sets this matrix basis vectors from the specified vectors.

func (*Mat4) SetFromMat3

func (m *Mat4) SetFromMat3(src *Mat3)

SetFromMat3 sets the matrix elements based on a Mat3, filling in 0's for missing off-diagonal elements, and 1 on the diagonal.

func (*Mat4) SetFrustum

func (m *Mat4) SetFrustum(left, right, bottom, top, near, far float32)

SetFrustum sets this matrix to a projection frustum matrix bounded by the specified planes.

func (*Mat4) SetIdentity

func (m *Mat4) SetIdentity()

SetIdentity sets this matrix as the identity matrix.

func (*Mat4) SetInverse

func (m *Mat4) SetInverse(src *Mat4) error

SetInverse sets this matrix to the inverse of the src matrix. If the src matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Mat4) SetMul

func (m *Mat4) SetMul(other *Mat4)

SetMul sets this matrix to this matrix times other

func (*Mat4) SetOrthographic

func (m *Mat4) SetOrthographic(width, height, near, far float32)

SetOrthographic sets this matrix to an orthographic projection matrix.

func (*Mat4) SetPerspective

func (m *Mat4) SetPerspective(fov, aspect, near, far float32)

SetPerspective sets this matrix to a perspective projection matrix with the specified field of view in degrees, aspect ratio (width/height) and near and far planes.

func (*Mat4) SetPos

func (m *Mat4) SetPos(v Vec3)

SetPos sets this transformation matrix position fields from the specified vector v.

func (*Mat4) SetRotationAxis

func (m *Mat4) SetRotationAxis(axis *Vec3, angle float32)

SetRotationAxis sets this matrix to a rotation matrix of the specified angle around the specified axis.

func (*Mat4) SetRotationFromEuler

func (m *Mat4) SetRotationFromEuler(euler Vec3)

SetRotationFromEuler set this a matrix as a rotation matrix from the specified euler angles.

func (*Mat4) SetRotationFromQuat

func (m *Mat4) SetRotationFromQuat(q Quat)

SetRotationFromQuat sets this matrix as a rotation matrix from the specified quaternion.

func (*Mat4) SetRotationX

func (m *Mat4) SetRotationX(theta float32)

SetRotationX sets this matrix to a rotation matrix of angle theta around the X axis.

func (*Mat4) SetRotationY

func (m *Mat4) SetRotationY(theta float32)

SetRotationY sets this matrix to a rotation matrix of angle theta around the Y axis.

func (*Mat4) SetRotationZ

func (m *Mat4) SetRotationZ(theta float32)

SetRotationZ sets this matrix to a rotation matrix of angle theta around the Z axis.

func (*Mat4) SetScale

func (m *Mat4) SetScale(x, y, z float32)

SetScale sets this matrix to a scale transformation matrix using the specified x, y and z values.

func (*Mat4) SetScaleCols

func (m *Mat4) SetScaleCols(v Vec3)

SetScaleCols multiplies the first column of this matrix by the vector X component, the second column by the vector Y component and the third column by the vector Z component. The matrix fourth column is unchanged.

func (*Mat4) SetTransform

func (m *Mat4) SetTransform(pos Vec3, quat Quat, scale Vec3)

SetTransform sets this matrix to a transformation matrix for the specified position, rotation specified by the quaternion and scale.

func (*Mat4) SetTranslation

func (m *Mat4) SetTranslation(x, y, z float32)

SetTranslation sets this matrix to a translation matrix from the specified x, y and z values.

func (*Mat4) SetTranspose

func (m *Mat4) SetTranspose()

SetTranspose transposes this matrix.

func (*Mat4) SetVkFrustum

func (m *Mat4) SetVkFrustum(left, right, bottom, top, near, far float32)

SetVkFrustum sets this matrix to a projection frustum matrix bounded by the specified planes. This version is for use with Vulkan, and does the equivalent of GLM_DEPTH_ZERO_ONE in glm and also multiplies the Y axis by -1, preserving the original OpenGL Y-up system. OpenGL provides a "natural" coordinate system for the physical world so it is useful to retain that for the world system and just convert on the way out to the render using this projection matrix.

func (*Mat4) SetVkPerspective

func (m *Mat4) SetVkPerspective(fov, aspect, near, far float32)

SetVkPerspective sets this matrix to a vulkan appropriate perspective projection matrix, assuming the use of the OpenGL Y-up coordinate system for the geometry points. OpenGL provides a "natural" coordinate system for the physical world so it is useful to retain that for the world system and just convert on the way out to the render using this projection matrix. The specified field of view is in degrees, aspect ratio (width/height) and near and far planes.

func (*Mat4) SetZero

func (m *Mat4) SetZero()

SetZero sets this matrix as the zero matrix.

func (*Mat4) ToArray

func (m *Mat4) ToArray(array []float32, offset int)

ToArray copies this matrix elements to array starting at offset.

func (*Mat4) Transpose

func (m *Mat4) Transpose() *Mat4

Transpose returns the transpose of this matrix.

type Plane

type Plane struct {
	Norm Vec3
	Off  float32
}

Plane represents a plane in 3D space by its normal vector and a constant offset. When the the normal vector is the unit vector the offset is the distance from the origin.

func NewPlane

func NewPlane(normal Vec3, offset float32) *Plane

NewPlane creates and returns a new plane from a normal vector and a offset.

func (*Plane) CoplanarPoint

func (p *Plane) CoplanarPoint() Vec3

CoplanarPoint returns a point in the plane that is the closest point from the origin.

func (*Plane) DistToPoint

func (p *Plane) DistToPoint(point Vec3) float32

DistToPoint returns the distance of this plane from point.

func (*Plane) DistToSphere

func (p *Plane) DistToSphere(sphere Sphere) float32

DistToSphere returns the distance of this place from the sphere.

func (*Plane) IntersectLine

func (p *Plane) IntersectLine(line Line3) (Vec3, bool)

IntersectLine calculates the point in the plane which intersets the specified line. Returns false if the line does not intersects the plane.

func (*Plane) IsEqual

func (p *Plane) IsEqual(other *Plane) bool

IsEqual returns if this plane is equal to other

func (*Plane) IsIntersectionLine

func (p *Plane) IsIntersectionLine(line Line3) bool

IsIntersectionLine returns the line intersects this plane.

func (*Plane) Negate

func (p *Plane) Negate()

Negate negates this plane normal.

func (*Plane) Normalize

func (p *Plane) Normalize()

Normalize normalizes this plane normal vector and adjusts the offset. Note: will lead to a divide by zero if the plane is invalid.

func (*Plane) Set

func (p *Plane) Set(normal Vec3, offset float32)

Set sets this plane normal vector and offset.

func (*Plane) SetDims

func (p *Plane) SetDims(x, y, z, w float32)

SetDims sets this plane normal vector dimensions and offset.

func (*Plane) SetFromCoplanarPoints

func (p *Plane) SetFromCoplanarPoints(a, b, c Vec3)

SetFromCoplanarPoints sets this plane from three coplanar points.

func (*Plane) SetFromNormalAndCoplanarPoint

func (p *Plane) SetFromNormalAndCoplanarPoint(normal Vec3, point Vec3)

SetFromNormalAndCoplanarPoint sets this plane from a normal vector and a point on the plane.

func (*Plane) SetTranslate

func (p *Plane) SetTranslate(offset Vec3)

SetTranslate translates this plane in the direction of its normal by offset.

type Quat

type Quat struct {
	X float32
	Y float32
	Z float32
	W float32
}

Quat is quaternion with X,Y,Z and W components.

func NewQuat

func NewQuat(x, y, z, w float32) Quat

NewQuat returns a new quaternion from the specified components.

func NewQuatAxisAngle

func NewQuatAxisAngle(axis Vec3, angle float32) Quat

NewQuatAxisAngle returns a new quaternion from given axis and angle rotation (radians).

func NewQuatEuler

func NewQuatEuler(euler Vec3) Quat

NewQuatEuler returns a new quaternion from given Euler angles.

func (*Quat) Conjugate

func (q *Quat) Conjugate() Quat

Conjugate returns the conjugate of this quaternion.

func (*Quat) Dot

func (q *Quat) Dot(other Quat) float32

Dot returns the dot products of this quaternion with other.

func (*Quat) FromArray

func (q *Quat) FromArray(array []float32, offset int)

FromArray sets this quaternion's components from array starting at offset.

func (*Quat) GenGoNew

func (q *Quat) GenGoNew() string

GenGoNew returns code to create new

func (*Quat) GenGoSet

func (q *Quat) GenGoSet(path string) string

GenGoSet returns code to set values in object at given path (var.member etc)

func (*Quat) Inverse

func (q *Quat) Inverse() Quat

Inverse returns the inverse of this quaternion.

func (*Quat) IsEqual

func (q *Quat) IsEqual(other Quat) bool

IsEqual returns if this quaternion is equal to other.

func (*Quat) IsIdentity

func (q *Quat) IsIdentity() bool

IsIdentity returns if this is an identity quaternion.

func (*Quat) IsNil

func (q *Quat) IsNil() bool

IsNil returns true if all values are 0 (uninitialized).

func (Quat) Length

func (q Quat) Length() float32

Length returns the length of this quaternion

func (Quat) LengthSq

func (q Quat) LengthSq() float32

LengthSq returns this quanternion's length squared

func (*Quat) Mul

func (q *Quat) Mul(other Quat) Quat

Mul returns returns multiplication of this quaternion with other

func (*Quat) MulQuats

func (q *Quat) MulQuats(a, b Quat)

MulQuats set this quaternion to the multiplication of a by b.

func (*Quat) Normalize

func (q *Quat) Normalize()

Normalize normalizes this quaternion.

func (*Quat) NormalizeFast

func (q *Quat) NormalizeFast()

NormalizeFast approximates normalizing this quaternion. Works best when the quaternion is already almost-normalized.

func (*Quat) Set

func (q *Quat) Set(x, y, z, w float32)

Set sets this quaternion's components.

func (*Quat) SetConjugate

func (q *Quat) SetConjugate()

SetConjugate sets this quaternion to its conjugate.

func (*Quat) SetFromAxisAngle

func (q *Quat) SetFromAxisAngle(axis Vec3, angle float32)

SetFromAxisAngle sets this quaternion with the rotation specified by the given axis and angle.

func (*Quat) SetFromEuler

func (q *Quat) SetFromEuler(euler Vec3)

SetFromEuler sets this quaternion from the specified vector with Euler angles for each axis. It is assumed that the Euler angles are in XYZ order.

func (*Quat) SetFromRotationMatrix

func (q *Quat) SetFromRotationMatrix(m *Mat4)

SetFromRotationMatrix sets this quaternion from the specified rotation matrix.

func (*Quat) SetFromUnitVectors

func (q *Quat) SetFromUnitVectors(vFrom, vTo Vec3)

SetFromUnitVectors sets this quaternion to the rotation from vector vFrom to vTo. The vectors must be normalized.

func (*Quat) SetIdentity

func (q *Quat) SetIdentity()

SetIdentity sets this quanternion to the identity quaternion.

func (*Quat) SetInverse

func (q *Quat) SetInverse()

SetInverse sets this quaternion to its inverse.

func (*Quat) SetMul

func (q *Quat) SetMul(other Quat)

SetMul sets this quaternion to the multiplication of itself by other.

func (*Quat) Slerp

func (q *Quat) Slerp(other Quat, t float32)

Slerp sets this quaternion to another quaternion which is the spherically linear interpolation from this quaternion to other using t.

func (Quat) String

func (q Quat) String() string

func (*Quat) ToArray

func (q *Quat) ToArray(array []float32, offset int)

ToArray copies this quaternions's components to array starting at offset.

func (*Quat) ToAxisAngle

func (q *Quat) ToAxisAngle() Vec4

ToAxisAngle returns the Vec4 holding axis and angle of this Quaternion

func (*Quat) ToEuler

func (q *Quat) ToEuler() Vec3

ToEuler returns a Vec3 with components as the Euler angles from the given quaternion.

type Ray

type Ray struct {
	Origin Vec3
	Dir    Vec3
}

Ray represents an oriented 3D line segment defined by an origin point and a direction vector.

func NewRay

func NewRay(origin, dir Vec3) *Ray

NewRay creates and returns a pointer to a Ray object with the specified origin and direction vectors. If a nil pointer is supplied for any of the parameters, the zero vector will be used.

func (*Ray) ApplyMat4

func (ray *Ray) ApplyMat4(mat4 *Mat4)

MulMat4 multiplies this ray origin and direction by the specified matrix4, basically transforming this ray coordinates.

func (*Ray) At

func (ray *Ray) At(t float32) Vec3

At calculates the point in the ray which is at the specified t distance from the origin along its direction.

func (*Ray) ClosestPointToPoint

func (ray *Ray) ClosestPointToPoint(point Vec3) Vec3

ClosestPointToPoint calculates the point in the ray which is closest to the specified point.

func (*Ray) DistSqToPoint

func (ray *Ray) DistSqToPoint(point Vec3) float32

DistSqToPoint returns the smallest squared distance from the ray direction vector to the specified point. If the ray was pointed directly at the point this distance would be 0.

func (*Ray) DistSqToSegment

func (ray *Ray) DistSqToSegment(v0, v1 Vec3, optPointOnRay, optPointOnSegment *Vec3) float32

DistSqToSegment returns the smallest squared distance from this ray to the line segment from v0 to v1. If optPointOnRay Vec3 is not nil, it is set with the coordinates of the point on the ray. if optPointOnSegment Vec3 is not nil, it is set with the coordinates of the point on the segment.

func (*Ray) DistToPlane

func (ray *Ray) DistToPlane(plane Plane) float32

DistToPlane returns the distance of this ray origin to its intersection point in the plane. If the ray does not intersects the plane, returns NaN.

func (*Ray) DistToPoint

func (ray *Ray) DistToPoint(point Vec3) float32

DistToPoint returns the smallest distance from the ray direction vector to the specified point.

func (*Ray) IntersectBox

func (ray *Ray) IntersectBox(box Box3) (Vec3, bool)

IntersectBox calculates the point which is the intersection of this ray with the specified box. If no intersection is found false is returned.

func (*Ray) IntersectPlane

func (ray *Ray) IntersectPlane(plane Plane) (Vec3, bool)

IntersectPlane calculates the point which is the intersection of this ray with the specified plane. If no intersection is found false is returned.

func (*Ray) IntersectSphere

func (ray *Ray) IntersectSphere(sphere Sphere) (Vec3, bool)

IntersectSphere calculates the point which is the intersection of this ray with the specified sphere. If no intersection is found false is returne.

func (*Ray) IntersectTriangle

func (ray *Ray) IntersectTriangle(a, b, c Vec3, backfaceCulling bool) (Vec3, bool)

IntersectTriangle returns if this ray intersects the triangle with the face defined by points a, b, c. Returns true if it intersects and the point parameter with the intersected point coordinates. If backfaceCulling is false it ignores the intersection if the face is not oriented in the ray direction.

func (*Ray) IntersectsBox

func (ray *Ray) IntersectsBox(box Box3) bool

IntersectsBox returns if this ray intersects the specified box.

func (*Ray) IsEqual

func (ray *Ray) IsEqual(other Ray) bool

IsEqual returns if this ray is equal to other

func (*Ray) IsIntersectPlane

func (ray *Ray) IsIntersectPlane(plane Plane) bool

IsIntersectPlane returns if this ray intersects the specified plane.

func (*Ray) IsIntersectionSphere

func (ray *Ray) IsIntersectionSphere(sphere Sphere) bool

IsIntersectionSphere returns if this ray intersects with the specified sphere.

func (*Ray) Recast

func (ray *Ray) Recast(t float32)

Recast sets the new origin of the ray at the specified distance t from its origin along its direction.

func (*Ray) Set

func (ray *Ray) Set(origin, dir Vec3)

Set sets the origin and direction vectors of this Ray.

type Sphere

type Sphere struct {
	Center Vec3    // center of the sphere
	Radius float32 // radius of the sphere
}

Sphere represents a 3D sphere defined by its center point and a radius

func NewSphere

func NewSphere(center Vec3, radius float32) *Sphere

NewSphere creates and returns a pointer to a new sphere with the specified center and radius.

func (*Sphere) ClampPoint

func (s *Sphere) ClampPoint(point Vec3) Vec3

ClampPoint clamps the specified point inside the sphere. If the specified point is inside the sphere, it is the clamped point. Otherwise the clamped point is the the point in the sphere surface in the nearest of the specified point.

func (*Sphere) ContainsPoint

func (s *Sphere) ContainsPoint(point Vec3) bool

ContainsPoint returns if this sphere contains the specified point.

func (*Sphere) DistToPoint

func (s *Sphere) DistToPoint(point Vec3) float32

DistToPoint returns the distance from the sphere surface to the specified point.

func (*Sphere) GetBoundingBox

func (s *Sphere) GetBoundingBox() Box3

GetBoundingBox calculates a Box3 which bounds this sphere.

func (*Sphere) IntersectSphere

func (s *Sphere) IntersectSphere(other Sphere) bool

IntersectSphere returns if other sphere intersects this one.

func (*Sphere) IsEmpty

func (s *Sphere) IsEmpty(sphere *Sphere) bool

IsEmpty checks if this sphere is empty (radius <= 0)

func (*Sphere) MulMat4

func (s *Sphere) MulMat4(mat *Mat4)

MulMat4 applies the specified matrix transform to this sphere.

func (*Sphere) Set

func (s *Sphere) Set(center Vec3, radius float32)

Set sets the center and radius of this sphere.

func (*Sphere) SetFromBox

func (s *Sphere) SetFromBox(box Box3)

SetFromBox sets the center and radius of this sphere to surround given box

func (*Sphere) SetFromPoints

func (s *Sphere) SetFromPoints(points []Vec3, optCenter *Vec3)

SetFromPoints sets this sphere from the specified points array and optional center.

func (*Sphere) Translate

func (s *Sphere) Translate(offset Vec3)

Translate translates this sphere by the specified offset.

type Spline

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

func NewSpline

func NewSpline(points []Vec3) Spline

func (*Spline) InitFromArray

func (sp *Spline) InitFromArray(a []float32)

type Triangle

type Triangle struct {
	A Vec3
	B Vec3
	C Vec3
}

Triangle represents a triangle made of three vertices.

func NewTriangle

func NewTriangle(a, b, c Vec3) Triangle

NewTriangle returns a new Triangle object.

func (*Triangle) Area

func (t *Triangle) Area() float32

Area returns the triangle's area.

func (*Triangle) BarycoordFromPoint

func (t *Triangle) BarycoordFromPoint(point Vec3) Vec3

BarycoordFromPoint returns the barycentric coordinates for the specified point.

func (*Triangle) ContainsPoint

func (t *Triangle) ContainsPoint(point Vec3) bool

ContainsPoint returns whether the triangle contains a point.

func (*Triangle) IsEqual

func (t *Triangle) IsEqual(tri Triangle) bool

IsEqual returns whether the triangles are equal in all their vertices.

func (*Triangle) Midpoint

func (t *Triangle) Midpoint() Vec3

Midpoint returns the triangle's midpoint.

func (*Triangle) Normal

func (t *Triangle) Normal() Vec3

Normal returns the triangle's normal.

func (*Triangle) Plane

func (t *Triangle) Plane() Plane

Plane returns a Plane object aligned with the triangle.

func (*Triangle) Set

func (t *Triangle) Set(a, b, c Vec3)

Set sets the triangle's three vertices.

func (*Triangle) SetFromPointsAndIndices

func (t *Triangle) SetFromPointsAndIndices(points []Vec3, i0, i1, i2 int)

SetFromPointsAndIndices sets the triangle's vertices based on the specified points and indices.

type Vec2

type Vec2 struct {
	X float32
	Y float32
}

Vec2 is a 2D vector/point with X and Y components.

func V2

func V2(x, y float32) Vec2

V2 returns a new Vec2 with the given x and y components.

func V2FromFixed

func V2FromFixed(pt fixed.Point26_6) Vec2

V2FromFixed returns a new Vec2 from the given fixed.Point26_6.

func V2FromPoint

func V2FromPoint(pt image.Point) Vec2

V2FromPoint returns a new Vec2 from the given image.Point.

func V2Scalar

func V2Scalar(s float32) Vec2

V2Scalar returns a new Vec2 with all components set to the given scalar value.

func (Vec2) Abs

func (v Vec2) Abs() Vec2

Abs returns the absolute value for each dimension

func (Vec2) Add

func (v Vec2) Add(other Vec2) Vec2

Add adds other vector to this one and returns result in a new vector.

func (Vec2) AddScalar

func (v Vec2) AddScalar(s float32) Vec2

AddScalar adds scalar s to each component of this vector and returns new vector.

func (Vec2) AlmostEqual

func (v Vec2) AlmostEqual(other Vec2, tol float32) bool

AlmostEqual returns whether the vector is almost equal to another vector within the specified tolerance.

func (Vec2) AngleTo

func (v Vec2) AngleTo(other Vec2) float32

AngleTo returns the angle between this vector and other. Returns angles in range of -PI to PI (not 0 to 2 PI).

func (Vec2) Ceil

func (v Vec2) Ceil() Vec2

Ceil returns vector with mat32.Ceil() applied to each of this vector's components.

func (*Vec2) Clamp

func (v *Vec2) Clamp(min, max Vec2)

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly.

func (*Vec2) ClampScalar

func (v *Vec2) ClampScalar(minVal, maxVal float32)

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal.

func (Vec2) CosTo

func (v Vec2) CosTo(other Vec2) float32

CosTo returns the cosine (normalized dot product) between this vector and other.

func (Vec2) Cross

func (v Vec2) Cross(other Vec2) float32

Cross returns the cross product of this vector with other which is a scalar, equivalent to the Z coord in 3D: X1 * Y2 - X2 Y1

func (Vec2) Dim

func (v Vec2) Dim(dim Dims) float32

Dim returns this vector component.

func (Vec2) DistTo

func (v Vec2) DistTo(other Vec2) float32

DistTo returns the distance of this point to other.

func (Vec2) DistToSquared

func (v Vec2) DistToSquared(other Vec2) float32

DistToSquared returns the distance squared of this point to other.

func (Vec2) Div

func (v Vec2) Div(other Vec2) Vec2

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vec2) DivScalar

func (v Vec2) DivScalar(scalar float32) Vec2

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (Vec2) Dot

func (v Vec2) Dot(other Vec2) float32

Dot returns the dot product of this vector with other.

func (Vec2) Fixed

func (a Vec2) Fixed() fixed.Point26_6

func (Vec2) Floor

func (v Vec2) Floor() Vec2

Floor returns vector with mat32.Floor() applied to each of this vector's components.

func (*Vec2) FromArray

func (v *Vec2) FromArray(array []float32, offset int)

FromArray sets this vector's components from the specified array and offset.

func (Vec2) InTriangle

func (v Vec2) InTriangle(p0, p1, p2 Vec2) bool

InTriangle returns whether the vector is inside the specified triangle.

func (Vec2) IsEqual

func (v Vec2) IsEqual(other Vec2) bool

IsEqual returns if this vector is equal to other.

func (Vec2) Length

func (v Vec2) Length() float32

Length returns the length of this vector.

func (Vec2) LengthSq

func (v Vec2) LengthSq() float32

LengthSq returns the length squared of this vector. LengthSq can be used to compare vectors' lengths without the need to perform a square root.

func (Vec2) Lerp

func (v Vec2) Lerp(other Vec2, alpha float32) Vec2

Lerp returns vector with each components as the linear interpolated value of alpha between itself and the corresponding other component.

func (Vec2) Max

func (v Vec2) Max(other Vec2) Vec2

Max returns max of this vector components vs. other vector.

func (Vec2) Min

func (v Vec2) Min(other Vec2) Vec2

Min returns min of this vector components vs. other vector.

func (Vec2) MinPos

func (a Vec2) MinPos(b Vec2) Vec2

MinPos returns minimum of all positive (> 0) numbers

func (Vec2) Mul

func (v Vec2) Mul(other Vec2) Vec2

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vec2) MulScalar

func (v Vec2) MulScalar(s float32) Vec2

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vec2) Negate

func (v Vec2) Negate() Vec2

Negate returns vector with each component negated.

func (Vec2) Normal

func (v Vec2) Normal() Vec2

Normal returns this vector divided by its length

func (*Vec2) Normalize

func (v *Vec2) Normalize()

Normalize normalizes this vector so its length will be 1.

func (Vec2) Round

func (v Vec2) Round() Vec2

Round returns vector with mat32.Round() applied to each of this vector's components.

func (*Vec2) Set

func (v *Vec2) Set(x, y float32)

Set sets this vector's X and Y components.

func (*Vec2) SetAdd

func (v *Vec2) SetAdd(other Vec2)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vec2) SetAddDim

func (a *Vec2) SetAddDim(d Dims, val float32)

func (*Vec2) SetAddScalar

func (v *Vec2) SetAddScalar(s float32)

SetAddScalar sets this to addition with scalar.

func (*Vec2) SetByName

func (v *Vec2) SetByName(name string, value float32)

SetByName sets this vector component value by its case insensitive name: "x" or "y".

func (*Vec2) SetCeil

func (v *Vec2) SetCeil()

SetCeil applies mat32.Ceil() to each of this vector's components.

func (*Vec2) SetDim

func (v *Vec2) SetDim(dim Dims, value float32)

SetDim sets this vector component value by its dimension index.

func (*Vec2) SetDiv

func (v *Vec2) SetDiv(other Vec2)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vec2) SetDivDim

func (a *Vec2) SetDivDim(d Dims, val float32)

func (*Vec2) SetDivScalar

func (v *Vec2) SetDivScalar(s float32)

SetDivScalar sets this to division by scalar.

func (*Vec2) SetFixed

func (a *Vec2) SetFixed(pt fixed.Point26_6)

func (*Vec2) SetFloor

func (v *Vec2) SetFloor()

SetFloor applies mat32.Floor() to each of this vector's components.

func (*Vec2) SetFromVec2i

func (v *Vec2) SetFromVec2i(vi Vec2i)

SetFromVec2i sets from a Vec2i (int32) vector.

func (*Vec2) SetLength

func (v *Vec2) SetLength(l float32)

SetLength sets this vector to have the specified length.

func (*Vec2) SetLerp

func (v *Vec2) SetLerp(other Vec2, alpha float32)

Lerp sets each of this vector's components to the linear interpolated value of alpha between ifself and the corresponding other component.

func (*Vec2) SetMax

func (v *Vec2) SetMax(other Vec2)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vec2) SetMaxDim

func (a *Vec2) SetMaxDim(d Dims, val float32)

set the value along a given dimension to max of current val and new val

func (*Vec2) SetMaxPos

func (a *Vec2) SetMaxPos(o Vec2)

set the value along a given dimension to min of current val and new val

func (*Vec2) SetMaxScalar

func (v *Vec2) SetMaxScalar(val float32)

SetMaxScalar sets to max of current value and scalar val

func (*Vec2) SetMin

func (v *Vec2) SetMin(other Vec2)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vec2) SetMinDim

func (a *Vec2) SetMinDim(d Dims, val float32)

set the value along a given dimension to min of current val and new val

func (*Vec2) SetMinPos

func (v *Vec2) SetMinPos(b Vec2)

SetMinPos set to minpos of current vs. other

func (*Vec2) SetMinPosDim

func (a *Vec2) SetMinPosDim(d Dims, val float32)

set the value along a given dimension to min of current val and new val

func (*Vec2) SetMinPosScalar

func (v *Vec2) SetMinPosScalar(val float32)

SetMinPosScalar sets to minpos of current value and scalar val

func (*Vec2) SetMinScalar

func (v *Vec2) SetMinScalar(val float32)

SetMinScalar sets to min of current value and scalar val

func (*Vec2) SetMul

func (v *Vec2) SetMul(other Vec2)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vec2) SetMulDim

func (a *Vec2) SetMulDim(d Dims, val float32)

func (*Vec2) SetMulScalar

func (v *Vec2) SetMulScalar(s float32)

SetMulScalar sets this to multiplication by scalar.

func (*Vec2) SetNegate

func (v *Vec2) SetNegate()

SetNegate negates each of this vector's components.

func (*Vec2) SetNormal

func (v *Vec2) SetNormal()

SetNormal normalizes this vector so its length will be 1.

func (*Vec2) SetPoint

func (a *Vec2) SetPoint(pt image.Point)

func (*Vec2) SetRound

func (v *Vec2) SetRound()

SetRound rounds each of this vector's components.

func (*Vec2) SetScalar

func (v *Vec2) SetScalar(s float32)

SetScalar sets all vector components to same scalar value.

func (*Vec2) SetSub

func (v *Vec2) SetSub(other Vec2)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vec2) SetSubDim

func (a *Vec2) SetSubDim(d Dims, val float32)

func (*Vec2) SetSubScalar

func (v *Vec2) SetSubScalar(s float32)

SetSubScalar sets this to subtraction of scalar.

func (*Vec2) SetZero

func (v *Vec2) SetZero()

SetZero sets this vector X and Y components to be zero.

func (Vec2) String

func (a Vec2) String() string

func (Vec2) Sub

func (v Vec2) Sub(other Vec2) Vec2

Sub subtracts other vector from this one and returns result in new vector.

func (Vec2) SubScalar

func (v Vec2) SubScalar(s float32) Vec2

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vec2) ToArray

func (v Vec2) ToArray(array []float32, offset int)

ToArray copies this vector's components to array starting at offset.

func (Vec2) ToCeil

func (a Vec2) ToCeil() Vec2

func (Vec2) ToFloor

func (a Vec2) ToFloor() Vec2

func (Vec2) ToPoint

func (a Vec2) ToPoint() image.Point

func (Vec2) ToPointCeil

func (a Vec2) ToPointCeil() image.Point

func (Vec2) ToPointFloor

func (a Vec2) ToPointFloor() image.Point

func (Vec2) ToPointRound

func (a Vec2) ToPointRound() image.Point

func (Vec2) ToRound

func (a Vec2) ToRound() Vec2

func (Vec2) WindowToNDC

func (v Vec2) WindowToNDC(size, off Vec2, flipY bool) Vec3

WindowToNDC converts window (pixel) coordinates to normalized display coordinates (NDC), using given window size parameters. The Z depth coordinate (0-1) must be set manually or by reading from framebuffer flipY if true means flip the Y axis (top = 0 for windows vs. bottom = 0 for 3D coords)

type Vec2i

type Vec2i struct {
	X int32
	Y int32
}

Vec2i is a 2D vector/point with X and Y integer32 components.

func V2i

func V2i(x, y int32) Vec2i

V2i returns a new Vec2i with the given x and y components.

func V2iScalar

func V2iScalar(s int32) Vec2i

V2iScalar returns a new Vec2i with all components set to the given scalar value.

func (Vec2i) Add

func (v Vec2i) Add(other Vec2i) Vec2i

Add adds other vector to this one and returns result in a new vector.

func (Vec2i) AddScalar

func (v Vec2i) AddScalar(s int32) Vec2i

AddScalar adds scalar s to each component of this vector and returns new vector.

func (*Vec2i) Clamp

func (v *Vec2i) Clamp(min, max Vec2i)

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly.

func (*Vec2i) ClampScalar

func (v *Vec2i) ClampScalar(minVal, maxVal int32)

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal.

func (Vec2i) Dim

func (v Vec2i) Dim(dim Dims) int32

Dim returns this vector component

func (Vec2i) Div

func (v Vec2i) Div(other Vec2i) Vec2i

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vec2i) DivScalar

func (v Vec2i) DivScalar(scalar int32) Vec2i

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (*Vec2i) FromArray

func (v *Vec2i) FromArray(array []int32, offset int)

FromArray sets this vector's components from the specified array and offset.

func (Vec2i) IsEqual

func (v Vec2i) IsEqual(other Vec2i) bool

IsEqual returns if this vector is equal to other.

func (Vec2i) Max

func (v Vec2i) Max(other Vec2i) Vec2i

Max returns max of this vector components vs. other vector.

func (Vec2i) Min

func (v Vec2i) Min(other Vec2i) Vec2i

Min returns min of this vector components vs. other vector.

func (Vec2i) Mul

func (v Vec2i) Mul(other Vec2i) Vec2i

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vec2i) MulScalar

func (v Vec2i) MulScalar(s int32) Vec2i

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vec2i) Negate

func (v Vec2i) Negate() Vec2i

Negate returns vector with each component negated.

func (*Vec2i) Set

func (v *Vec2i) Set(x, y int32)

Set sets this vector X and Y components.

func (*Vec2i) SetAdd

func (v *Vec2i) SetAdd(other Vec2i)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vec2i) SetAddScalar

func (v *Vec2i) SetAddScalar(s int32)

SetAddScalar sets this to addition with scalar.

func (*Vec2i) SetByName

func (v *Vec2i) SetByName(name string, value int32)

SetByName sets this vector component value by its case insensitive name: "x" or "y".

func (*Vec2i) SetDim

func (v *Vec2i) SetDim(dim Dims, value int32)

SetDim sets this vector component value by its dimension index

func (*Vec2i) SetDiv

func (v *Vec2i) SetDiv(other Vec2i)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vec2i) SetDivScalar

func (v *Vec2i) SetDivScalar(s int32)

SetDivScalar sets this to division by scalar.

func (*Vec2i) SetFromVec2

func (v *Vec2i) SetFromVec2(vf Vec2)

SetFromVec2 sets from a Vec2 (float32) vector.

func (*Vec2i) SetMax

func (v *Vec2i) SetMax(other Vec2i)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vec2i) SetMin

func (v *Vec2i) SetMin(other Vec2i)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vec2i) SetMul

func (v *Vec2i) SetMul(other Vec2i)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vec2i) SetMulScalar

func (v *Vec2i) SetMulScalar(s int32)

SetMulScalar sets this to multiplication by scalar.

func (*Vec2i) SetNegate

func (v *Vec2i) SetNegate()

SetNegate negates each of this vector's components.

func (*Vec2i) SetScalar

func (v *Vec2i) SetScalar(s int32)

SetScalar sets all vector components to same scalar value.

func (*Vec2i) SetSub

func (v *Vec2i) SetSub(other Vec2i)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vec2i) SetSubScalar

func (v *Vec2i) SetSubScalar(s int32)

SetSubScalar sets this to subtraction of scalar.

func (*Vec2i) SetZero

func (v *Vec2i) SetZero()

SetZero sets this vector X and Y components to be zero.

func (Vec2i) Sub

func (v Vec2i) Sub(other Vec2i) Vec2i

Sub subtracts other vector from this one and returns result in new vector.

func (Vec2i) SubScalar

func (v Vec2i) SubScalar(s int32) Vec2i

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vec2i) ToArray

func (v Vec2i) ToArray(array []int32, offset int)

ToArray copies this vector's components to array starting at offset.

type Vec3

type Vec3 struct {
	X float32
	Y float32
	Z float32
}

Vec3 is a 3D vector/point with X, Y and Z components.

func BarycoordFromPoint

func BarycoordFromPoint(point, a, b, c Vec3) Vec3

BarycoordFromPoint returns the barycentric coordinates for the specified point.

func NewEulerAnglesFromMatrix

func NewEulerAnglesFromMatrix(m *Mat4) Vec3

NewEulerAnglesFromMatrix returns a Vec3 with components as the Euler angles from the specified pure rotation matrix.

func NewVec3Color

func NewVec3Color(clr color.Color) Vec3

NewVec3Color returns a Vec3 from Go standard color.Color (R,G,B components only)

func Normal

func Normal(a, b, c Vec3) Vec3

Normal returns the triangle's normal.

func V3

func V3(x, y, z float32) Vec3

V3 returns a new Vec3 with the given x, y and z components.

func V3FromV4

func V3FromV4(v Vec4) Vec3

V3FromV4 returns a new Vec3 from the given Vec4.

func V3Scalar

func V3Scalar(s float32) Vec3

V3Scalar returns a new Vec3 with all components set to the given scalar value.

func (Vec3) Abs

func (v Vec3) Abs() Vec3

Abs returns vector with Abs of each component.

func (Vec3) Add

func (v Vec3) Add(other Vec3) Vec3

Add adds other vector to this one and returns result in a new vector.

func (Vec3) AddScalar

func (v Vec3) AddScalar(s float32) Vec3

AddScalar adds scalar s to each component of this vector and returns new vector.

func (*Vec3) AlmostEqual

func (v *Vec3) AlmostEqual(other Vec3, tol float32) bool

AlmostEqual returns whether the vector is almost equal to another vector within the specified tolerance.

func (Vec3) AngleTo

func (v Vec3) AngleTo(other Vec3) float32

AngleTo returns the angle between this vector and other. Returns angles in range of -PI to PI (not 0 to 2 PI).

func (Vec3) Ceil

func (v Vec3) Ceil() Vec3

Ceil returns vector with mat32.Ceil() applied to each of this vector's components.

func (*Vec3) Clamp

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

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly.

func (*Vec3) ClampScalar

func (v *Vec3) ClampScalar(minVal, maxVal float32)

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal.

func (Vec3) CosTo

func (v Vec3) CosTo(other Vec3) float32

CosTo returns the cosine (normalized dot product) between this vector and other.

func (Vec3) Cross

func (v Vec3) Cross(other Vec3) Vec3

Cross returns the cross product of this vector with other.

func (Vec3) Dim

func (v Vec3) Dim(dim Dims) float32

Dim returns this vector component

func (Vec3) DistTo

func (v Vec3) DistTo(other Vec3) float32

DistTo returns the distance of this point to other.

func (Vec3) DistToSquared

func (v Vec3) DistToSquared(other Vec3) float32

DistToSquared returns the distance squared of this point to other.

func (Vec3) Div

func (v Vec3) Div(other Vec3) Vec3

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vec3) DivScalar

func (v Vec3) DivScalar(scalar float32) Vec3

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (Vec3) Dot

func (v Vec3) Dot(other Vec3) float32

Dot returns the dot product of this vector with other.

func (Vec3) Floor

func (v Vec3) Floor() Vec3

Floor returns vector with mat32.Floor() applied to each of this vector's components.

func (*Vec3) FromArray

func (v *Vec3) FromArray(array []float32, offset int)

FromArray sets this vector's components from the specified array and offset.

func (*Vec3) GenGoNew

func (v *Vec3) GenGoNew() string

GenGoNew returns code to create new

func (*Vec3) GenGoSet

func (v *Vec3) GenGoSet(path string) string

GenGoSet returns code to set values in object at given path (var.member etc)

func (Vec3) IsEqual

func (v Vec3) IsEqual(other Vec3) bool

IsEqual returns if this vector is equal to other.

func (Vec3) Length

func (v Vec3) Length() float32

Length returns the length of this vector.

func (Vec3) LengthSq

func (v Vec3) LengthSq() float32

LengthSq returns the length squared of this vector. LengthSq can be used to compare vectors' lengths without the need to perform a square root.

func (Vec3) Lerp

func (v Vec3) Lerp(other Vec3, alpha float32) Vec3

Lerp returns vector with each components as the linear interpolated value of alpha between itself and the corresponding other component.

func (Vec3) MVProjToNDC

func (v Vec3) MVProjToNDC(m *Mat4, w float32) Vec3

MVProjToNDC project given vector through given MVP model-view-projection Mat4 and do perspective divide to return normalized display coordinates (NDC). w is value for 4th coordinate -- use 1 for positions, 0 for normals.

func (Vec3) Max

func (v Vec3) Max(other Vec3) Vec3

Max returns max of this vector components vs. other vector.

func (Vec3) Min

func (v Vec3) Min(other Vec3) Vec3

Min returns min of this vector components vs. other vector.

func (Vec3) Mul

func (v Vec3) Mul(other Vec3) Vec3

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vec3) MulMat3

func (v Vec3) MulMat3(m *Mat3) Vec3

MulMat3 returns vector multiplied by specified 3x3 matrix.

func (Vec3) MulMat4

func (v Vec3) MulMat4(m *Mat4) Vec3

MulMat4 returns vector multiplied by specified 4x4 matrix.

func (Vec3) MulMat4AsVec4

func (v Vec3) MulMat4AsVec4(m *Mat4, w float32) Vec3

MulMat4AsVec4 returns 3-dim vector multiplied by specified 4x4 matrix using a 4-dim vector with given 4th dimensional value, then reduced back to a 3-dimensional vector. This is somehow different from just straight MulMat4 on the 3-dim vector. Use 0 for normals and 1 for positions as the 4th dim to set.

func (Vec3) MulProjection

func (v Vec3) MulProjection(m *Mat4) Vec3

MulProjection returns vector multiplied by the projection matrix m

func (Vec3) MulQuat

func (v Vec3) MulQuat(q Quat) Vec3

MulQuat returns vector multiplied by specified quaternion and then by the quaternion inverse. It basically applies the rotation encoded in the quaternion to this vector.

func (Vec3) MulScalar

func (v Vec3) MulScalar(s float32) Vec3

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vec3) NDCToWindow

func (v Vec3) NDCToWindow(size, off Vec2, near, far float32, flipY bool) Vec3

NDCToWindow converts normalized display coordinates (NDC) to window (pixel) coordinates, using given window size parameters. near, far are 0, 1 by default (glDepthRange defaults). flipY if true means flip the Y axis (top = 0 for windows vs. bottom = 0 for 3D coords)

func (Vec3) Negate

func (v Vec3) Negate() Vec3

Negate returns vector with each component negated.

func (Vec3) Normal

func (v Vec3) Normal() Vec3

Normal returns this vector divided by its length

func (*Vec3) Normalize

func (v *Vec3) Normalize()

Normalize normalizes this vector so its length will be 1.

func (*Vec3) ProjectOnPlane

func (v *Vec3) ProjectOnPlane(planeNormal Vec3) Vec3

ProjectOnPlane returns vector projected on the plane specified by normal vector.

func (*Vec3) ProjectOnVector

func (v *Vec3) ProjectOnVector(other Vec3) Vec3

ProjectOnVector returns vector projected on other vector.

func (*Vec3) RandomTangents

func (v *Vec3) RandomTangents() (Vec3, Vec3)

RandomTangents computes and returns two arbitrary tangents to the vector.

func (*Vec3) Reflect

func (v *Vec3) Reflect(normal Vec3) Vec3

Reflect returns vector reflected relative to the normal vector (assumed to be already normalized).

func (Vec3) RotateAxisAngle

func (v Vec3) RotateAxisAngle(axis Vec3, angle float32) Vec3

RotateAxisAngle returns vector rotated around axis by angle.

func (Vec3) Round

func (v Vec3) Round() Vec3

Round returns vector with mat32.Round() applied to each of this vector's components.

func (Vec3) SRGBFromLinear

func (v Vec3) SRGBFromLinear() Vec3

SRGBFromLinear returns an SRGB color space value from a linear source

func (Vec3) SRGBToLinear

func (v Vec3) SRGBToLinear() Vec3

SRGBToLinear returns a linear color space value from a SRGB source

func (*Vec3) Set

func (v *Vec3) Set(x, y, z float32)

Set sets this vector X, Y and Z components.

func (*Vec3) SetAdd

func (v *Vec3) SetAdd(other Vec3)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vec3) SetAddScalar

func (v *Vec3) SetAddScalar(s float32)

SetAddScalar sets this to addition with scalar.

func (*Vec3) SetByName

func (v *Vec3) SetByName(name string, value float32)

SetByName sets this vector component value by its case insensitive name: "x", "y", or "z".

func (*Vec3) SetCeil

func (v *Vec3) SetCeil()

SetCeil applies mat32.Ceil() to each of this vector's components.

func (*Vec3) SetColor

func (v *Vec3) SetColor(clr color.Color)

SetColor sets from Go standard color.Color (R,G,B components only)

func (*Vec3) SetDim

func (v *Vec3) SetDim(dim Dims, value float32)

SetDim sets this vector component value by dimension index.

func (*Vec3) SetDiv

func (v *Vec3) SetDiv(other Vec3)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vec3) SetDivScalar

func (v *Vec3) SetDivScalar(s float32)

SetDivScalar sets this to division by scalar.

func (*Vec3) SetEulerAnglesFromMatrix

func (v *Vec3) SetEulerAnglesFromMatrix(m *Mat4)

SetEulerAnglesFromMatrix sets this vector components to the Euler angles from the specified pure rotation matrix.

func (*Vec3) SetEulerAnglesFromQuat

func (v *Vec3) SetEulerAnglesFromQuat(q Quat)

SetEulerAnglesFromQuat sets this vector components to the Euler angles from the specified quaternion.

func (*Vec3) SetFloor

func (v *Vec3) SetFloor()

SetFloor applies mat32.Floor() to each of this vector's components.

func (*Vec3) SetFromMatrixCol

func (v *Vec3) SetFromMatrixCol(index int, m *Mat4)

SetFromMatrixCol set this vector with the column at index of the m matrix.

func (*Vec3) SetFromMatrixPos

func (v *Vec3) SetFromMatrixPos(m *Mat4)

SetFromMatrixPos set this vector from the translation coordinates in the specified transformation matrix.

func (*Vec3) SetFromVec3i

func (v *Vec3) SetFromVec3i(vi Vec3i)

SetFromVec3i sets from a Vec3i (int32) vector.

func (*Vec3) SetFromVec4

func (v *Vec3) SetFromVec4(other Vec4)

SetFromVec4 sets this vector from a Vec4

func (*Vec3) SetLength

func (v *Vec3) SetLength(l float32)

SetLength sets this vector to have the specified length. If the current length is zero, does nothing.

func (*Vec3) SetLerp

func (v *Vec3) SetLerp(other Vec3, alpha float32)

SetLerp sets each of this vector's components to the linear interpolated value of alpha between itself and the corresponding other component.

func (*Vec3) SetMax

func (v *Vec3) SetMax(other Vec3)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vec3) SetMin

func (v *Vec3) SetMin(other Vec3)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vec3) SetMul

func (v *Vec3) SetMul(other Vec3)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vec3) SetMulMat3

func (v *Vec3) SetMulMat3(m *Mat3)

SetMulMat3 sets vector multiplied by specified 3x3 matrix.

func (*Vec3) SetMulMat4

func (v *Vec3) SetMulMat4(m *Mat4)

SetMulMat4 sets vector multiplied by specified 4x4 matrix.

func (*Vec3) SetMulQuat

func (v *Vec3) SetMulQuat(q Quat)

SetMulQuat multiplies vector by specified quaternion and then by the quaternion inverse. It basically applies the rotation encoded in the quaternion to this vector.

func (*Vec3) SetMulScalar

func (v *Vec3) SetMulScalar(s float32)

SetMulScalar sets this to multiplication by scalar.

func (*Vec3) SetNegate

func (v *Vec3) SetNegate()

SetNegate negates each of this vector's components.

func (*Vec3) SetNormal

func (v *Vec3) SetNormal()

SetNormal normalizes this vector so its length will be 1.

func (*Vec3) SetRotateAxisAngle

func (v *Vec3) SetRotateAxisAngle(axis Vec3, angle float32)

SetRotateAxisAngle sets vector rotated around axis by angle.

func (*Vec3) SetRound

func (v *Vec3) SetRound()

SetRound rounds each of this vector's components.

func (*Vec3) SetScalar

func (v *Vec3) SetScalar(s float32)

SetScalar sets all vector X, Y and Z components to same scalar value.

func (*Vec3) SetSub

func (v *Vec3) SetSub(other Vec3)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vec3) SetSubScalar

func (v *Vec3) SetSubScalar(s float32)

SetSubScalar sets this to subtraction of scalar.

func (*Vec3) SetZero

func (v *Vec3) SetZero()

SetZero sets this vector X, Y and Z components to be zero.

func (Vec3) String

func (a Vec3) String() string

func (Vec3) Sub

func (v Vec3) Sub(other Vec3) Vec3

Sub subtracts other vector from this one and returns result in new vector.

func (Vec3) SubScalar

func (v Vec3) SubScalar(s float32) Vec3

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vec3) ToArray

func (v Vec3) ToArray(array []float32, offset int)

ToArray copies this vector's components to array starting at offset.

type Vec3i

type Vec3i struct {
	X int32
	Y int32
	Z int32
}

Vec3i is a 3D vector/point with X, Y and Z int32 components.

func V3i

func V3i(x, y, z int32) Vec3i

V3i returns a new Vec3i with the given x, y and y components.

func V3iScalar

func V3iScalar(s int32) Vec3i

V3iScalar returns a new Vec3i with all components set to the given scalar value.

func (Vec3i) Add

func (v Vec3i) Add(other Vec3i) Vec3i

Add adds other vector to this one and returns result in a new vector.

func (Vec3i) AddScalar

func (v Vec3i) AddScalar(s int32) Vec3i

AddScalar adds scalar s to each component of this vector and returns new vector.

func (*Vec3i) Clamp

func (v *Vec3i) Clamp(min, max Vec3i)

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly.

func (*Vec3i) ClampScalar

func (v *Vec3i) ClampScalar(minVal, maxVal int32)

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal.

func (Vec3i) Dim

func (v Vec3i) Dim(dim Dims) int32

Dim returns this vector component

func (Vec3i) Div

func (v Vec3i) Div(other Vec3i) Vec3i

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vec3i) DivScalar

func (v Vec3i) DivScalar(scalar int32) Vec3i

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (*Vec3i) FromArray

func (v *Vec3i) FromArray(array []int32, offset int)

FromArray sets this vector's components from the specified array and offset

func (Vec3i) IsEqual

func (v Vec3i) IsEqual(other Vec3i) bool

IsEqual returns if this vector is equal to other.

func (Vec3i) Max

func (v Vec3i) Max(other Vec3i) Vec3i

Max returns max of this vector components vs. other vector.

func (Vec3i) Min

func (v Vec3i) Min(other Vec3i) Vec3i

Min returns min of this vector components vs. other vector.

func (Vec3i) Mul

func (v Vec3i) Mul(other Vec3i) Vec3i

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vec3i) MulScalar

func (v Vec3i) MulScalar(s int32) Vec3i

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vec3i) Negate

func (v Vec3i) Negate() Vec3i

Negate returns vector with each component negated.

func (*Vec3i) Set

func (v *Vec3i) Set(x, y, z int32)

Set sets this vector X, Y and Z components.

func (*Vec3i) SetAdd

func (v *Vec3i) SetAdd(other Vec3i)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vec3i) SetAddScalar

func (v *Vec3i) SetAddScalar(s int32)

SetAddScalar sets this to addition with scalar.

func (*Vec3i) SetByName

func (v *Vec3i) SetByName(name string, value int32)

SetByName sets this vector component value by its case insensitive name: "x", "y", or "z".

func (*Vec3i) SetDim

func (v *Vec3i) SetDim(dim Dims, value int32)

SetDim sets this vector component value by dimension index.

func (*Vec3i) SetDiv

func (v *Vec3i) SetDiv(other Vec3i)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vec3i) SetDivScalar

func (v *Vec3i) SetDivScalar(s int32)

SetDivScalar sets this to division by scalar.

func (*Vec3i) SetFromVec3

func (v *Vec3i) SetFromVec3(vf Vec3)

SetFromVec3 sets from a Vec3 (float32) vector.

func (*Vec3i) SetMax

func (v *Vec3i) SetMax(other Vec3i)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vec3i) SetMin

func (v *Vec3i) SetMin(other Vec3i)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vec3i) SetMul

func (v *Vec3i) SetMul(other Vec3i)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vec3i) SetMulScalar

func (v *Vec3i) SetMulScalar(s int32)

SetMulScalar sets this to multiplication by scalar.

func (*Vec3i) SetNegate

func (v *Vec3i) SetNegate()

SetNegate negates each of this vector's components.

func (*Vec3i) SetScalar

func (v *Vec3i) SetScalar(s int32)

SetScalar sets all vector X, Y and Z components to same scalar value.

func (*Vec3i) SetSub

func (v *Vec3i) SetSub(other Vec3i)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vec3i) SetSubScalar

func (v *Vec3i) SetSubScalar(s int32)

SetSubScalar sets this to subtraction of scalar.

func (*Vec3i) SetZero

func (v *Vec3i) SetZero()

SetZero sets this vector X, Y and Z components to be zero.

func (Vec3i) Sub

func (v Vec3i) Sub(other Vec3i) Vec3i

Sub subtracts other vector from this one and returns result in new vector.

func (Vec3i) SubScalar

func (v Vec3i) SubScalar(s int32) Vec3i

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vec3i) ToArray

func (v Vec3i) ToArray(array []int32, offset int)

ToArray copies this vector's components to array starting at offset.

type Vec4

type Vec4 struct {
	X float32
	Y float32
	Z float32
	W float32
}

Vec4 is a vector/point in homogeneous coordinates with X, Y, Z and W components.

func NewVec4Color

func NewVec4Color(clr color.Color) Vec4

NewVec4Color returns a Vec4 from Go standard color.Color (full R,G,B,A components)

func V4

func V4(x, y, z, w float32) Vec4

V4 returns a new Vec4 with the given x, y, z, and w components.

func V4FromV3

func V4FromV3(v Vec3, w float32) Vec4

V4FromV3 returns a new Vec4 from the given Vec3 and w component.

func V4Scalar

func V4Scalar(s float32) Vec4

V4Scalar returns a new Vec4 with all components set to the given scalar value.

func (Vec4) Add

func (v Vec4) Add(other Vec4) Vec4

Add adds other vector to this one and returns result in a new vector.

func (Vec4) AddScalar

func (v Vec4) AddScalar(s float32) Vec4

AddScalar adds scalar s to each component of this vector and returns new vector.

func (*Vec4) AlmostEqual

func (v *Vec4) AlmostEqual(other Vec4, tol float32) bool

AlmostEqual returns whether the vector is almost equal to another vector within the specified tolerance.

func (Vec4) Ceil

func (v Vec4) Ceil() Vec4

Ceil returns vector with mat32.Ceil() applied to each of this vector's components.

func (*Vec4) Clamp

func (v *Vec4) Clamp(min, max Vec4)

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly.

func (*Vec4) ClampScalar

func (v *Vec4) ClampScalar(minVal, maxVal float32)

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal.

func (Vec4) Dim

func (v Vec4) Dim(dim Dims) float32

Dim returns this vector component.

func (Vec4) Div

func (v Vec4) Div(other Vec4) Vec4

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vec4) DivScalar

func (v Vec4) DivScalar(scalar float32) Vec4

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (Vec4) Dot

func (v Vec4) Dot(other Vec4) float32

Dot returns the dot product of this vector with other.

func (Vec4) Floor

func (v Vec4) Floor() Vec4

Floor returns vector with mat32.Floor() applied to each of this vector's components.

func (*Vec4) FromArray

func (v *Vec4) FromArray(array []float32, offset int)

FromArray sets this vector's components from the specified array and offset

func (*Vec4) IsEqual

func (v *Vec4) IsEqual(other Vec4) bool

IsEqual returns if this vector is equal to other.

func (Vec4) Length

func (v Vec4) Length() float32

Length returns the length of this vector.

func (Vec4) LengthSq

func (v Vec4) LengthSq() float32

LengthSq returns the length squared of this vector. LengthSq can be used to compare vectors' lengths without the need to perform a square root.

func (Vec4) Lerp

func (v Vec4) Lerp(other Vec4, alpha float32) Vec4

Lerp returns vector with each components as the linear interpolated value of alpha between itself and the corresponding other component.

func (Vec4) Max

func (v Vec4) Max(other Vec4) Vec4

Max returns max of this vector components vs. other vector.

func (Vec4) Min

func (v Vec4) Min(other Vec4) Vec4

Min returns min of this vector components vs. other vector.

func (Vec4) Mul

func (v Vec4) Mul(other Vec4) Vec4

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vec4) MulMat4

func (v Vec4) MulMat4(m *Mat4) Vec4

MulMat4 returns vector multiplied by specified 4x4 matrix.

func (Vec4) MulScalar

func (v Vec4) MulScalar(s float32) Vec4

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vec4) Negate

func (v Vec4) Negate() Vec4

Negate returns vector with each component negated.

func (Vec4) Normal

func (v Vec4) Normal() Vec4

Normal returns this vector divided by its length

func (*Vec4) Normalize

func (v *Vec4) Normalize()

Normalize normalizes this vector so its length will be 1.

func (Vec4) PerspDiv

func (v Vec4) PerspDiv() Vec3

PerspDiv returns the 3-vector of normalized display coordinates (NDC) from given 4-vector By dividing by the 4th W component

func (Vec4) Round

func (v Vec4) Round() Vec4

Round returns vector with mat32.Round() applied to each of this vector's components.

func (Vec4) SRGBFromLinear

func (v Vec4) SRGBFromLinear() Vec4

SRGBFromLinear returns an SRGB color space value from a linear source

func (Vec4) SRGBToLinear

func (v Vec4) SRGBToLinear() Vec4

SRGBToLinear returns a linear color space value from a SRGB source

func (*Vec4) Set

func (v *Vec4) Set(x, y, z, w float32)

Set sets this vector X, Y, Z and W components.

func (*Vec4) SetAdd

func (v *Vec4) SetAdd(other Vec4)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vec4) SetAddScalar

func (v *Vec4) SetAddScalar(s float32)

SetAddScalar sets this to addition with scalar.

func (*Vec4) SetAxisAngleFromQuat

func (v *Vec4) SetAxisAngleFromQuat(q Quat)

SetAxisAngleFromQuat set this vector to be the axis (x, y, z) and angle (w) of a rotation specified the quaternion q. Assumes q is normalized.

func (*Vec4) SetAxisFromRotationMatrix

func (v *Vec4) SetAxisFromRotationMatrix(m *Mat4)

SetAxisFromRotationMatrix sets this vector to be the axis (x, y, z) and angle (w) of a rotation specified the matrix m. Assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled).

func (*Vec4) SetByName

func (v *Vec4) SetByName(name string, value float32)

SetByName sets this vector component value by its case insensitive name: "x", "y", "z" or "w".

func (*Vec4) SetCeil

func (v *Vec4) SetCeil()

SetCeil applies mat32.Ceil() to each of this vector's components.

func (*Vec4) SetColor

func (v *Vec4) SetColor(clr color.Color)

SetColor sets a Vec4 from Go standard color.Color

func (*Vec4) SetDim

func (v *Vec4) SetDim(dim Dims, value float32)

SetDim sets this vector component value by dimension index.

func (*Vec4) SetDiv

func (v *Vec4) SetDiv(other Vec4)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vec4) SetDivScalar

func (v *Vec4) SetDivScalar(s float32)

SetDivScalar sets this to division by scalar.

func (*Vec4) SetFloor

func (v *Vec4) SetFloor()

SetFloor applies mat32.Floor() to each of this vector's components.

func (*Vec4) SetFromVec2

func (v *Vec4) SetFromVec2(other Vec2)

SetFromVec2 sets this vector from a Vec2 with 0,1 for Z,W

func (*Vec4) SetFromVec3

func (v *Vec4) SetFromVec3(other Vec3, w float32)

SetFromVec3 sets this vector from a Vec3 and W

func (*Vec4) SetLength

func (v *Vec4) SetLength(l float32)

SetLength sets this vector to have the specified length. If the current length is zero, does nothing.

func (*Vec4) SetLerp

func (v *Vec4) SetLerp(other *Vec4, alpha float32)

SetLerp sets each of this vector's components to the linear interpolated value of alpha between ifself and the corresponding other component.

func (*Vec4) SetMax

func (v *Vec4) SetMax(other Vec4)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vec4) SetMin

func (v *Vec4) SetMin(other Vec4)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vec4) SetMul

func (v *Vec4) SetMul(other Vec4)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vec4) SetMulScalar

func (v *Vec4) SetMulScalar(s float32)

SetMulScalar sets this to multiplication by scalar.

func (*Vec4) SetNegate

func (v *Vec4) SetNegate()

SetNegate negates each of this vector's components.

func (*Vec4) SetNormal

func (v *Vec4) SetNormal()

SetNormal normalizes this vector so its length will be 1.

func (*Vec4) SetRound

func (v *Vec4) SetRound()

SetRound rounds each of this vector's components.

func (*Vec4) SetSub

func (v *Vec4) SetSub(other Vec4)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vec4) SetSubScalar

func (v *Vec4) SetSubScalar(s float32)

SetSubScalar sets this to subtraction of scalar.

func (*Vec4) SetZero

func (v *Vec4) SetZero()

SetZero sets this vector X, Y and Z components to be zero and W to be one.

func (Vec4) String

func (v Vec4) String() string

func (Vec4) Sub

func (v Vec4) Sub(other Vec4) Vec4

Sub subtracts other vector from this one and returns result in new vector.

func (Vec4) SubScalar

func (v Vec4) SubScalar(s float32) Vec4

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vec4) ToArray

func (v Vec4) ToArray(array []float32, offset int)

ToArray copies this vector's components to array starting at offset.

Jump to

Keyboard shortcuts

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