Documentation
¶
Overview ¶
Package sprec represents a mathematics library for working with single precision types.
Index ¶
- Constants
- func Abs[T ~float32](value T) T
- func Ceil[T ~float32](value T) T
- func Clamp[T ~float32](value, lower, upper T) T
- func Cos(angle Angle) float32
- func Eq(a, b float32) bool
- func EqEps(a, b, epsilon float32) bool
- func Floor[T ~float32](value T) T
- func IsNegative[T ~float32](value T) bool
- func IsValid[T ~float32](value T) bool
- func Max[T ~float32](a, b T) T
- func Min[T ~float32](a, b T) T
- func Mix[T ~float32](a, b T, amount float32) T
- func Mod(a, b float32) float32
- func MoveTowards[T ~float32](current, target, maxDelta T) T
- func Pow(a, b float32) float32
- func QuatDot(a, b Quat) float32
- func Sign(value float32) float32
- func Sin(angle Angle) float32
- func Smoothstep[T ~float32](lowerEdge, upperEdge, value T) T
- func Sqr[T ~float32](value T) T
- func Sqrt(value float32) float32
- func Step[T ~float32](edge, value T) T
- func Sum[T ~float32](values ...T) T
- func Tan(angle Angle) float32
- func Vec2Cross(a, b Vec2) float32
- func Vec2Dot(a, b Vec2) float32
- func Vec3Dot(a, b Vec3) float32
- func Vec4Dot(a, b Vec4) float32
- type Angle
- func Acos(cs float32) Angle
- func Asin(sn float32) Angle
- func Atan2(y, x float32) Angle
- func Degrees(degrees float32) Angle
- func NormalizeAngle(a Angle) Angle
- func NormalizeAngleNeg(a Angle) Angle
- func NormalizeAnglePos(a Angle) Angle
- func Radians(radians float32) Angle
- func Vec3Angle(a, b Vec3) Angle
- func Vec3ProjectionAngle(a, b, normal Vec3) Angle
- type Mat3
- func ColumnMajorArrayToMat3(values [9]float32) Mat3
- func FastInverseMat3(m Mat3) Mat3
- func IdentityMat3() Mat3
- func InverseMat3(m Mat3) Mat3
- func Mat3MultiProd(first Mat3, others ...Mat3) Mat3
- func Mat3Prod(left, right Mat3) Mat3
- func NewMat3(m11, m12, m13 float32, m21, m22, m23 float32, m31, m32, m33 float32) Mat3
- func OrthoMat3(left, right, top, bottom float32) Mat3
- func RotationMat3(angle Angle) Mat3
- func RowMajorArrayToMat3(values [9]float32) Mat3
- func ScaleMat3(x, y float32) Mat3
- func TransformationMat3(orientX, orientY, translation Vec2) Mat3
- func TranslationMat3(x, y float32) Mat3
- func TransposedMat3(m Mat3) Mat3
- func ZeroMat3() Mat3
- func (m Mat3) Column1() Vec3
- func (m Mat3) Column2() Vec3
- func (m Mat3) Column3() Vec3
- func (m Mat3) ColumnMajorArray() [9]float32
- func (m Mat3) GoString() string
- func (m Mat3) IsInf() bool
- func (m Mat3) IsNaN() bool
- func (m Mat3) OrientationX() Vec2
- func (m Mat3) OrientationY() Vec2
- func (m Mat3) Row1() Vec3
- func (m Mat3) Row2() Vec3
- func (m Mat3) Row3() Vec3
- func (m Mat3) RowMajorArray() [9]float32
- func (m Mat3) Translation() Vec2
- type Mat4
- func ColumnMajorArrayToMat4(values [16]float32) Mat4
- func FastInverseMat4(m Mat4) Mat4
- func IdentityMat4() Mat4
- func InverseMat4(m Mat4) Mat4
- func Mat4MultiProd(first Mat4, others ...Mat4) Mat4
- func Mat4Prod(left, right Mat4) Mat4
- func NewMat4(m11, m12, m13, m14 float32, m21, m22, m23, m24 float32, ...) Mat4
- func OrientationMat4(orientX, orientY, orientZ Vec3) Mat4
- func OrthoMat4(left, right, top, bottom, near, far float32) Mat4
- func PerspectiveMat4(left, right, bottom, top, near, far float32) Mat4
- func RotationMat4(angle Angle, x, y, z float32) Mat4
- func RowMajorArrayToMat4(values [16]float32) Mat4
- func ScaleMat4(x, y, z float32) Mat4
- func TRSMat4(translation Vec3, rotation Quat, scale Vec3) Mat4
- func TransformationMat4(orientX, orientY, orientZ, translation Vec3) Mat4
- func TranslationMat4(x, y, z float32) Mat4
- func TransposedMat4(m Mat4) Mat4
- func ZeroMat4() Mat4
- func (m Mat4) Column1() Vec4
- func (m Mat4) Column2() Vec4
- func (m Mat4) Column3() Vec4
- func (m Mat4) Column4() Vec4
- func (m Mat4) ColumnMajorArray() [16]float32
- func (m Mat4) GoString() string
- func (m Mat4) IsInf() bool
- func (m Mat4) IsNaN() bool
- func (m Mat4) OrientationX() Vec3
- func (m Mat4) OrientationY() Vec3
- func (m Mat4) OrientationZ() Vec3
- func (m Mat4) Rotation() Quat
- func (m Mat4) Row1() Vec4
- func (m Mat4) Row2() Vec4
- func (m Mat4) Row3() Vec4
- func (m Mat4) Row4() Vec4
- func (m Mat4) RowMajorArray() [16]float32
- func (m Mat4) Scale() Vec3
- func (m Mat4) TRS() (Vec3, Quat, Vec3)
- func (m Mat4) Translation() Vec3
- type Quat
- func ConjugateQuat(q Quat) Quat
- func EulerQuat(x, y, z Angle, order RotationOrder) Quat
- func IdentityQuat() Quat
- func InverseQuat(q Quat) Quat
- func NegativeQuat(q Quat) Quat
- func NewQuat(w, x, y, z float32) Quat
- func QuatDiff(second, first Quat, shortest bool) Quat
- func QuatLerp(first, second Quat, t float32) Quat
- func QuatPow(q Quat, pow float32) Quat
- func QuatProd(first, second Quat) Quat
- func QuatScalarProd(q Quat, value float32) Quat
- func QuatScalarQuot(q Quat, value float32) Quat
- func QuatSlerp(first, second Quat, t float32) Quat
- func RotationQuat(angle Angle, direction Vec3) Quat
- func UnitQuat(q Quat) Quat
- func (q Quat) EulerAngles(order RotationOrder) (x Angle, y Angle, z Angle)
- func (q Quat) GoString() string
- func (q Quat) IsIdentity() bool
- func (q Quat) IsInf() bool
- func (q Quat) IsNaN() bool
- func (q Quat) Norm() float32
- func (q Quat) OrientationX() Vec3
- func (q Quat) OrientationY() Vec3
- func (q Quat) OrientationZ() Vec3
- func (q Quat) SqrNorm() float32
- type RotationOrder
- type Vec2
- func AngleVec2Rotation(angle Angle, v Vec2) Vec2
- func ArrayToVec2(array [2]float32) Vec2
- func BasisXVec2() Vec2
- func BasisYVec2() Vec2
- func InverseVec2(vector Vec2) Vec2
- func Mat3Vec2Transformation(mat Mat3, vec Vec2) Vec2
- func NewVec2(x, y float32) Vec2
- func NormalVec2(vector Vec2) Vec2
- func ResizedVec2(vector Vec2, newLength float32) Vec2
- func UnitVec2(vector Vec2) Vec2
- func Vec2Diff(a, b Vec2) Vec2
- func Vec2Lerp(a, b Vec2, t float32) Vec2
- func Vec2MultiDiff(first Vec2, others ...Vec2) Vec2
- func Vec2MultiSum(first Vec2, others ...Vec2) Vec2
- func Vec2Prod(vector Vec2, value float32) Vec2
- func Vec2Quot(vector Vec2, value float32) Vec2
- func Vec2Sum(a, b Vec2) Vec2
- func ZeroVec2() Vec2
- type Vec3
- func ArrayToVec3(array [3]float32) Vec3
- func BasisXVec3() Vec3
- func BasisYVec3() Vec3
- func BasisZVec3() Vec3
- func InverseVec3(vector Vec3) Vec3
- func Mat3Vec3Prod(mat Mat3, vec Vec3) Vec3
- func Mat4Vec3Transformation(mat Mat4, vec Vec3) Vec3
- func NewVec3(x, y, z float32) Vec3
- func NormalVec3(vector Vec3) Vec3
- func QuatVec3Rotation(q Quat, v Vec3) Vec3
- func ResizedVec3(vector Vec3, newLength float32) Vec3
- func UnitVec3(vector Vec3) Vec3
- func Vec3Cross(a, b Vec3) Vec3
- func Vec3Diff(a, b Vec3) Vec3
- func Vec3Lerp(a, b Vec3, t float32) Vec3
- func Vec3MultiDiff(first Vec3, others ...Vec3) Vec3
- func Vec3MultiSum(first Vec3, others ...Vec3) Vec3
- func Vec3Prod(vector Vec3, value float32) Vec3
- func Vec3Projection(vector Vec3, normal Vec3) Vec3
- func Vec3Quot(vector Vec3, value float32) Vec3
- func Vec3Sum(a, b Vec3) Vec3
- func ZeroVec3() Vec3
- type Vec4
- func ArrayToVec4(array [4]float32) Vec4
- func InverseVec4(vector Vec4) Vec4
- func Mat4Vec4Prod(mat Mat4, vec Vec4) Vec4
- func NewVec4(x, y, z, w float32) Vec4
- func Vec4Diff(a, b Vec4) Vec4
- func Vec4Lerp(a, b Vec4, t float32) Vec4
- func Vec4MultiDiff(first Vec4, others ...Vec4) Vec4
- func Vec4MultiSum(first Vec4, others ...Vec4) Vec4
- func Vec4Prod(vector Vec4, value float32) Vec4
- func Vec4Quot(vector Vec4, value float32) Vec4
- func Vec4Sum(a, b Vec4) Vec4
- func ZeroVec4() Vec4
Constants ¶
const ( // RotationOrderLocalXYZ specifies that rotations are applied in the order // of X, Y, Z using a local gizmo (i.e. from the point of view of the object). RotationOrderLocalXYZ = RotationOrderGlobalZYX // RotationOrderLocalXZY specifies that rotations are applied in the order // of X, Z, Y using a local gizmo (i.e. from the point of view of the object). RotationOrderLocalXZY = RotationOrderGlobalYZX // RotationOrderLocalYXZ specifies that rotations are applied in the order // of Y, X, Z using a local gizmo (i.e. from the point of view of the object). RotationOrderLocalYXZ = RotationOrderGlobalZXY // RotationOrderLocalYZX specifies that rotations are applied in the order // of Y, Z, X using a local gizmo (i.e. from the point of view of the object). RotationOrderLocalYZX = RotationOrderGlobalXZY // RotationOrderLocalZXY specifies that rotations are applied in the order // of Z, X, Y using a local gizmo (i.e. from the point of view of the object). RotationOrderLocalZXY = RotationOrderGlobalYXZ // RotationOrderLocalZYX specifies that rotations are applied in the order // of Z, Y, X using a local gizmo (i.e. from the point of view of the object). RotationOrderLocalZYX = RotationOrderGlobalXYZ )
Variables ¶
This section is empty.
Functions ¶
func IsNegative ¶ added in v0.9.0
func MoveTowards ¶ added in v0.15.0
func MoveTowards[T ~float32](current, target, maxDelta T) T
func Smoothstep ¶ added in v0.14.0
func Smoothstep[T ~float32](lowerEdge, upperEdge, value T) T
Types ¶
type Angle ¶
type Angle float32
Angle represents an angle.
func NormalizeAngle ¶ added in v0.12.0
NormalizeAngle normalizes an angle to the range [-Pi..Pi].
func NormalizeAngleNeg ¶ added in v0.14.0
NormalizeAngleNeg normalizes an angle to the range [-Tau..0.0].
func NormalizeAnglePos ¶ added in v0.14.0
NormalizeAnglePos normalizes an angle to the range [0.0..Tau].
func Vec3Angle ¶ added in v0.10.0
Vec3Angle returns the shortest angle between two vectors. It always returns a positive angle.
func Vec3ProjectionAngle ¶ added in v0.10.0
Vec3ProjectionAngle returns the angle between two vectors projected onto a plane defined by a normal vector. Unlike Vec3Angle, this function returns a signed angle and the ordering of the vectors matters.
type Mat3 ¶
func ColumnMajorArrayToMat3 ¶ added in v0.3.0
func FastInverseMat3 ¶
FastInverseMat3 calculates the inverse of the matrix with a few caveats.
The matrix should be a transformation one that was constructed through the multiplication of one or more of the following transformations: identity, translation, rotation.
For all other scenarios (e.g. a scale transformation was used), the InverseMat3 method should be used instead, though it will be slower.
func IdentityMat3 ¶
func IdentityMat3() Mat3
func InverseMat3 ¶
InverseMat3 calculates the inverse of the matrix.
The behavior is undefined if the matrix is not reversible (i.e. has a zero determinant).
func Mat3MultiProd ¶
func RotationMat3 ¶
func RowMajorArrayToMat3 ¶ added in v0.3.0
func TransformationMat3 ¶
func TranslationMat3 ¶
func TransposedMat3 ¶ added in v0.5.0
func (Mat3) ColumnMajorArray ¶ added in v0.3.0
func (Mat3) OrientationX ¶
func (Mat3) OrientationY ¶
func (Mat3) RowMajorArray ¶ added in v0.3.0
func (Mat3) Translation ¶
type Mat4 ¶
type Mat4 struct {
M11, M12, M13, M14 float32
M21, M22, M23, M24 float32
M31, M32, M33, M34 float32
M41, M42, M43, M44 float32
}
func ColumnMajorArrayToMat4 ¶ added in v0.3.0
func FastInverseMat4 ¶
FastInverseMat4 calculates the inverse of the matrix with a few caveats.
The matrix should be a transformation one that was constructed through the multiplication of one or more of the following transformations: identity, translation, rotation.
For all other scenarios (e.g. a scale transformation was used), the InverseMat4 method should be used instead, though it will be slower.
func IdentityMat4 ¶
func IdentityMat4() Mat4
func InverseMat4 ¶
InverseMat4 calculates the inverse of the matrix.
The behavior is undefined if the matrix is not reversible (i.e. has a zero determinant).
func Mat4MultiProd ¶
func OrientationMat4 ¶
func PerspectiveMat4 ¶
func RotationMat4 ¶
func RowMajorArrayToMat4 ¶ added in v0.3.0
func TransformationMat4 ¶
func TranslationMat4 ¶
func TransposedMat4 ¶ added in v0.5.0
func (Mat4) ColumnMajorArray ¶
func (Mat4) OrientationX ¶
func (Mat4) OrientationY ¶
func (Mat4) OrientationZ ¶
func (Mat4) Rotation ¶ added in v0.5.0
Rotation returns the rotation that is represented by this matrix. NOTE: This function assumes that the matrix has identity scale. If you want to get the rotation of a matrix that has non-identity scale, consider using the TRS method.
func (Mat4) RowMajorArray ¶
func (Mat4) Translation ¶
type Quat ¶
func ConjugateQuat ¶
func EulerQuat ¶ added in v0.10.0
func EulerQuat(x, y, z Angle, order RotationOrder) Quat
func IdentityQuat ¶
func IdentityQuat() Quat
func InverseQuat ¶
func NegativeQuat ¶ added in v0.4.0
func QuatScalarProd ¶
func QuatScalarQuot ¶
func RotationQuat ¶
func (Quat) EulerAngles ¶ added in v0.10.0
func (q Quat) EulerAngles(order RotationOrder) (x Angle, y Angle, z Angle)
EulerAngles returns the Euler rotation angles for the given quaternion and rotation order in which it was presumably created.
The rotations are always returned for X, Y, Z axis in that order.
NOTE: This assumes that the quaternion is normalized.
func (Quat) IsIdentity ¶ added in v0.7.0
func (Quat) OrientationX ¶
func (Quat) OrientationY ¶
func (Quat) OrientationZ ¶
type RotationOrder ¶ added in v0.10.0
type RotationOrder uint8
RotationOrder specifies the order in which rotations are applied.
const ( // RotationOrderGlobalXYZ specifies that rotations are applied in the order // of X, Y, Z using a global gizmo. RotationOrderGlobalXYZ RotationOrder = iota // RotationOrderGlobalXZY specifies that rotations are applied in the order // of X, Z, Y using a global gizmo. RotationOrderGlobalXZY // RotationOrderGlobalYXZ specifies that rotations are applied in the order // of Y, X, Z using a global gizmo. RotationOrderGlobalYXZ // RotationOrderGlobalYZX specifies that rotations are applied in the order // of Y, Z, X using a global gizmo. RotationOrderGlobalYZX // RotationOrderGlobalZXY specifies that rotations are applied in the order // of Z, X, Y using a global gizmo. RotationOrderGlobalZXY // RotationOrderGlobalZYX specifies that rotations are applied in the order // of Z, Y, X using a global gizmo. RotationOrderGlobalZYX )
type Vec2 ¶
func AngleVec2Rotation ¶ added in v0.15.0
AngleVec2Rotation rotates a Vec2 by the given angle.
func ArrayToVec2 ¶ added in v0.3.0
func BasisXVec2 ¶
func BasisXVec2() Vec2
func BasisYVec2 ¶
func BasisYVec2() Vec2
func InverseVec2 ¶
func Mat3Vec2Transformation ¶ added in v0.12.0
func NormalVec2 ¶ added in v0.7.0
func ResizedVec2 ¶
func Vec2MultiDiff ¶ added in v0.7.0
func Vec2MultiSum ¶ added in v0.7.0
type Vec3 ¶
func ArrayToVec3 ¶ added in v0.3.0
func BasisXVec3 ¶
func BasisXVec3() Vec3
func BasisYVec3 ¶
func BasisYVec3() Vec3
func BasisZVec3 ¶
func BasisZVec3() Vec3
func InverseVec3 ¶
func Mat3Vec3Prod ¶
func Mat4Vec3Transformation ¶
func NormalVec3 ¶ added in v0.7.0
func QuatVec3Rotation ¶
func ResizedVec3 ¶
func Vec3MultiDiff ¶ added in v0.7.0
func Vec3MultiSum ¶ added in v0.7.0
func Vec3Projection ¶ added in v0.10.0
Vec3Projection returns the specified vector flattened along the specified normal. The normal must be a unit vector. The result is the projection of the vector onto the plane defined by the normal.