Documentation ¶
Overview ¶
Package gm math and gl math for floats32 Contains code from github.com/go-gl/mathgl/mgl32 BSD-3 Copyright ©2013 The go-gl Authors. All rights reserved.
Index ¶
- Constants
- Variables
- func FloatEqual(a, b Float) bool
- func FloatEqualThreshold(a, b, epsilon Float) bool
- func Sincos(x Float) (Float, Float)
- type Float
- func Abs(x Float) Float
- func Acos(x Float) Float
- func Asin(x Float) Float
- func Atan2(y, x Float) Float
- func Cbrt(x Float) Float
- func Ceil(x Float) Float
- func Clamp(v, min, max Float) Float
- func Copysign(x, y Float) Float
- func Cos(x Float) Float
- func Hypot(x, y Float) Float
- func Lerp(v0, v1, t Float) Float
- func Max(a, b Float) Float
- func Min(a, b Float) Float
- func Mod(x, y Float) Float
- func Sin(x Float) Float
- func Sqrt(x Float) Float
- func Tan(x Float) Float
- type Mat3
- func (m Mat3) Abs() Mat3
- func (m Mat3) Add(m2 Mat3) Mat3
- func (m Mat3) ApproxEqual(m2 Mat3) bool
- func (m Mat3) ApproxEqualThreshold(m2 Mat3, threshold Float) bool
- func (m Mat3) ApproxFuncEqual(m2 Mat3, eq func(Float, Float) bool) bool
- func (m Mat3) At(row, col int) Float
- func (m Mat3) Col(col int) Vec3
- func (m Mat3) Cols() (col0, col1, col2 Vec3)
- func (m Mat3) Det() Float
- func (m Mat3) Diag() Vec3
- func (m Mat3) Index(row, col int) int
- func (m Mat3) Inv() Mat3
- func (m Mat3) Mat4() Mat4
- func (m Mat3) Mul(m2 Mat3) Mat3
- func (m Mat3) MulS(c Float) Mat3
- func (m Mat3) MulV3(v Vec3) Vec3
- func (m Mat3) Row(row int) Vec3
- func (m Mat3) Rows() (row0, row1, row2 Vec3)
- func (m *Mat3) Set(row, col int, value Float)
- func (m Mat3) String() string
- func (m Mat3) Sub(m2 Mat3) Mat3
- func (m Mat3) Trace() Float
- func (m Mat3) Transpose() Mat3
- type Mat4
- func (m Mat4) Abs() Mat4
- func (m Mat4) Add(m2 Mat4) Mat4
- func (m Mat4) ApproxEqual(m2 Mat4) bool
- func (m Mat4) ApproxEqualThreshold(m2 Mat4, threshold Float) bool
- func (m Mat4) ApproxFuncEqual(m2 Mat4, eq func(Float, Float) bool) bool
- func (m Mat4) Col(n int) Vec4
- func (m Mat4) Det() Float
- func (m Mat4) Diag() Vec4
- func (m Mat4) Inv() Mat4
- func (m Mat4) Mat3() Mat3
- func (m Mat4) Mul(m2 Mat4) Mat4
- func (m Mat4) MulS(v Float) Mat4
- func (m Mat4) MulV4(m2 Vec4) Vec4
- func (m Mat4) Quat() Quat
- func (m Mat4) Row(row int) Vec4
- func (m Mat4) String() string
- func (m Mat4) Sub(m2 Mat4) Mat4
- func (m Mat4) Trace() Float
- func (m Mat4) Transpose() Mat4
- type Quat
- type Rand
- type RotationOrder
- type Vec2
- func (v Vec2) Abs() Vec2
- func (v Vec2) Add(v2 Vec2) Vec2
- func (v Vec2) Clamp(min, max Vec2) Vec2
- func (v Vec2) Len() Float
- func (v Vec2) Lerp(b Vec2, t Float) Vec2
- func (v Vec2) Mul(c Float) Vec2
- func (v Vec2) MulVec2(v2 Vec2) Vec2
- func (v Vec2) Sub(v2 Vec2) Vec2
- func (v Vec2) Vec3(z Float) Vec3
- func (v Vec2) Vec4(z, w Float) Vec4
- func (v Vec2) X() Float
- func (v Vec2) Y() Float
- type Vec3
- func (v Vec3) Add(v2 Vec3) Vec3
- func (v Vec3) Clamp(min, max Vec3) Vec3
- func (v Vec3) Cross(v2 Vec3) Vec3
- func (v Vec3) Dot(v2 Vec3) Float
- func (v Vec3) Len() Float
- func (v Vec3) Lerp(b Vec3, t Float) Vec3
- func (v Vec3) Mul(c Float) Vec3
- func (v Vec3) MulVec3(v2 Vec3) Vec3
- func (v Vec3) Normalize() Vec3
- func (v Vec3) Reflect(n Vec3) Vec3
- func (v Vec3) Sub(v2 Vec3) Vec3
- func (v Vec3) Vec2() Vec2
- func (v Vec3) Vec4(w Float) Vec4
- func (v Vec3) X() Float
- func (v Vec3) XY() Vec2
- func (v Vec3) Y() Float
- func (v Vec3) YZ() Vec2
- func (v Vec3) Z() Float
- type Vec4
- func (v Vec4) Add(v2 Vec4) Vec4
- func (v Vec4) Dot(v2 Vec4) Float
- func (v Vec4) Equal(v2 Vec4) bool
- func (v Vec4) Len() Float
- func (v Vec4) Lerp(b Vec4, t Float) Vec4
- func (v Vec4) Mul(c Float) Vec4
- func (v Vec4) MulVec4(v2 Vec4) Vec4
- func (v Vec4) Normalize() Vec4
- func (v Vec4) Sub(v2 Vec4) Vec4
- func (v Vec4) Vec2() Vec2
- func (v Vec4) Vec3() Vec3
- func (v Vec4) W() Float
- func (v Vec4) X() Float
- func (v Vec4) XY() Vec2
- func (v Vec4) XYZ() Vec3
- func (v Vec4) XZ() Vec2
- func (v Vec4) Y() Float
- func (v Vec4) YW() Vec2
- func (v Vec4) YZ() Vec2
- func (v Vec4) Z() Float
- func (v Vec4) ZW() Vec2
Constants ¶
const ( Epsilon = 0.000001 MinNormal = 1.1754943508222875e-38 // 1 / 2**(127 - 1) MinValue = math.SmallestNonzeroFloat32 MaxValue = math.MaxFloat32 Pi = math.Pi )
Epsilon float error stuff.
Variables ¶
var ( InfPos = Float(math.Inf(1)) InfNeg = Float(math.Inf(-1)) NaN = Float(math.NaN()) )
values from math
Functions ¶
func FloatEqual ¶
FloatEqual is a safe utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/
It is slightly altered to not call Abs when not needed.
func FloatEqualThreshold ¶
FloatEqualThreshold is a utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/
It is slightly altered to not call Abs when not needed.
This differs from FloatEqual in that it lets you pass in your comparison threshold, so that you can adjust the comparison value to your specific needs
Types ¶
type Float ¶
type Float = float32
func Acos ¶
Acos returns the arccosine, in radians, of x.
Special case is:
Acos(x) = NaN if x < -1 or x > 1
func Asin ¶
Asin returns the arcsine, in radians, of x.
Special cases are:
Asin(±0) = ±0 Asin(x) = NaN if x < -1 or x > 1
func Atan2 ¶
Atan2 returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.
func Cos ¶
Cos casts values to float64 and uses native math.Cos to return the cosine of the radian argument x.
func Hypot ¶
Hypot returns Sqrt(p*p + q*q), taking care to avoid unnecessary overflow and underflow.
type Mat3 ¶
type Mat3 [9]Float
Mat3 is a 3x3 matrix in row major order.
m[3*r + c] is the element in the r'th row and c'th column.
func M3Ident ¶
func M3Ident() Mat3
M3Ident returns the 3x3 identity matrix. The identity matrix is a square matrix with the value 1 on its diagonals. The characteristic property of the identity matrix is that any matrix multiplied by it is itself. (MI = M; IN = N)
func (Mat3) Add ¶
Add performs an element-wise addition of two matrices, this is equivalent to iterating over every element of m and adding the corresponding value of m2.
func (Mat3) ApproxEqual ¶
ApproxEqual performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.
func (Mat3) ApproxEqualThreshold ¶
ApproxEqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.
func (Mat3) ApproxFuncEqual ¶
ApproxFuncEqual performs an element-wise approximate equality test between two matrices with a given equality functions, intended to be used with FloatEqualFunc; although and comparison function may be used in practice.
func (Mat3) At ¶
At returns the matrix element at the given row and column. This is equivalent to mat[col * numRow + row] where numRow is constant (E.G. for a Mat3x2 it's equal to 3)
This method is garbage-in garbage-out. For instance, on a Mat4 asking for At(5,0) will work just like At(1,1). Or it may panic if it's out of bounds.
func (Mat3) Col ¶
Col returns a vector representing the corresponding column (starting at col 0). This package makes no distinction between row and column vectors, so it will be a normal VecN for a MxN matrix.
func (Mat3) Cols ¶
Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.
func (Mat3) Det ¶
Det returns the determinant of a matrix. It is a measure of a square matrix's singularity and invertability, among other things. In this library, the determinant is hard coded based on pre-computed cofactor expansion, and uses no loops. Of course, the addition and multiplication must still be done.
func (Mat3) Diag ¶
Diag is a basic operation on a square matrix that simply returns main diagonal (meaning all elements such that row==col).
func (Mat3) Index ¶
Index returns the index of the given row and column, to be used with direct access. E.G. Index(0,0) = 0.
This is a garbage-in garbage-out method. For instance, on a Mat4 asking for the index of (5,0) will work the same as asking for (1,1). Or it may give you a value that will cause a panic if you try to access the array with it if it's truly out of bounds.
func (Mat3) Inv ¶
Inv computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity.
M_inv * M = M * M_inv = I
In this library, the math is precomputed, and uses no loops, though the multiplications, additions, determinant calculation, and scaling are still done. This can still be (relatively) expensive for a 4x4.
This function checks the determinant to see if the matrix is invertible. If the determinant is 0.0, this function returns the zero matrix. However, due to floating point errors, it is entirely plausible to get a false positive or negative. In the future, an alternate function may be written which takes in a pre-computed determinant.
func (Mat3) Mat4 ¶
Mat4 returns a Mat4 from Mat3 by Adding a row and a column with last element being 1.
func (Mat3) Mul ¶
Mul performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.
func (Mat3) MulS ¶
MulS performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.
func (Mat3) Row ¶
Row returns a vector representing the corresponding row (starting at row 0). This package makes no distinction between row and column vectors, so it will be a normal VecM for a MxN matrix.
func (Mat3) Rows ¶
Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.
func (*Mat3) Set ¶
Set sets the corresponding matrix element at the given row and column. This has a pointer receiver because it mutates the matrix.
This method is garbage-in garbage-out. For instance, on a Mat4 asking for Set(5,0,val) will work just like Set(1,1,val). Or it may panic if it's out of bounds.
func (Mat3) Sub ¶
Sub performs an element-wise subtraction of two matrices, this is equivalent to iterating over every element of m and subtracting the corresponding value of m2.
func (Mat3) Trace ¶
Trace is a basic operation on a square matrix that simply sums up all elements on the main diagonal (meaning all elements such that row==col).
type Mat4 ¶
type Mat4 [16]Float
Mat4 is a 4x4 matrix in row major order.
m[4*r + c] is the element in the r'th row and c'th column.
func Ortho ¶
Ortho creates an orthographic matrix https://stackoverflow.com/questions/31839119/projection-and-orthographic-matrices-for-opengl
func Perspective ¶
Perspective generates a Perspective Matrix.
func (Mat4) Add ¶
Add performs an element-wise addition of two matrices, this is equivalent to iterating over every element of m1 and adding the corresponding value of m2.
func (Mat4) ApproxEqual ¶
ApproxEqual performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.
func (Mat4) ApproxEqualThreshold ¶
ApproxEqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.
func (Mat4) ApproxFuncEqual ¶
ApproxFuncEqual performs an element-wise approximate equality test between two matrices with a given equality functions, intended to be used with FloatEqualFunc; although and comparison function may be used in practice.
func (Mat4) Col ¶
Col returns a vector representing the corresponding column (starting at col 0). This package makes no distinction between row and column vectors, so it will be a normal VecN for a MxN matrix.
func (Mat4) Det ¶
Det returns the determinant of a matrix. It is a measure of a square matrix's singularity and invertability, among other things. In this library, the determinant is hard coded based on pre-computed cofactor expansion, and uses no loops. Of course, the addition and multiplication must still be done.
func (Mat4) Diag ¶
Diag is a basic operation on a square matrix that simply returns main diagonal (meaning all elements such that row==col).
func (Mat4) Inv ¶
Inv computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity.
M_inv * M = M * M_inv = I
In this library, the math is precomputed, and uses no loops, though the multiplications, additions, determinant calculation, and scaling are still done. This can still be (relatively) expensive for a 4x4.
This function checks the determinant to see if the matrix is invertible. If the determinant is 0.0, this function returns the zero matrix. However, due to floating point errors, it is entirely plausible to get a false positive or negative. In the future, an alternate function may be written which takes in a pre-computed determinant.
func (Mat4) Mul ¶
Mul performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.
func (Mat4) MulS ¶
MulS performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.
func (Mat4) Row ¶
Row returns a vector representing the corresponding row (starting at row 0). This package makes no distinction between row and column vectors, so it will be a normal VecM for a MxN matrix.
func (Mat4) Sub ¶
Sub performs an element-wise subtraction of two matrices, this is equivalent to iterating over every element of m1 and subtracting the corresponding value of m2.
func (Mat4) Trace ¶
Trace is a basic operation on a square matrix that simply sums up all elements on the main diagonal (meaning all elements such that row==col).
type Quat ¶
type Quat [4]Float
Quat short for quaternion:
https://answers.unity.com/questions/467614/what-is-the-source-code-of-quaternionlookrotation.html
W is [3]
func QAxisAngle ¶
QAxisAngle returns a axis angle quaternion.
func QBetweenV3 ¶
QBetweenV3 returns a quaternion between two vectors.
func QEuler ¶
QEuler returns a quaternion based on those euler angles https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
func QFromAngles ¶
func QFromAngles(a1, a2, a3 Float, order RotationOrder) Quat
QFromAngles returns a rotation quaternion based on the angles.
func (Quat) Slerp ¶
Slerp spherical linear interpolation between two quat https://github.com/toji/gl-matrix/blob/6c0268c89f30090b17bcadade9e7feb7205b85c5/src/quat.js#L296
type Rand ¶
Rand helper function that handlers vec3, vec4 etc..
func (Rand) Float32 ¶
Float32 returns a Float with random values [0, 1] using inner rand generator. if the inner source is nil it will use the global one.
func (Rand) SphereSurface ¶
SphereSurface returns a random surface points on a sphere.
func (Rand) UnitSphere ¶
UnitSphere generate random points in a sphere From: https://karthikkaranth.me/blog/generating-random-points-in-a-sphere/ Still needs improvements as it doesn't seem right yet
type RotationOrder ¶
type RotationOrder int
RotationOrder is the order in which rotations will be transformed for the purposes of QFromAngles.
const ( XYX RotationOrder = iota XYZ XZX XZY YXY YXZ YZY YZX ZYZ ZYX ZXZ ZXY )
The RotationOrder constants represent a series of rotations along the given axes for the use of QFromAngles.
type Vec2 ¶
type Vec2 [2]Float
Vec2 vector2
func (Vec2) MulVec2 ¶
MulVec2 returns a new Vec2 with the multiplication by the corresponding elements of v2.
type Vec3 ¶
type Vec3 [3]Float
Vec3 an Float array of size 3 with methods for vector operations.
func HSV2RGB ¶
HSV2RGB Hue Saturation Value to RGB values are in the range 0-1 and will be clamped to that range.
type Vec4 ¶
type Vec4 [4]Float
Vec4 Float array of size 4 with vector operation methods.
func Color ¶
Color returns a vec4 with the colors value if the number of params is: 0 - returns a zero Vec4 1 - returns a Vec4 with all 3 elements set to param 0 and alpha 1 2 - returns a Vec4 with all 3 elements set to param 0 and alpha to param 1 3 - returns a Vec4 with all 3 elements set to params and alpha 1 4 - returns a Vec4 with all 4 elements set to params.