Documentation ¶
Overview ¶
Package glm declares many linear algrebric types to do computer geometry. The matrices are column major (same as OpenGL) and all the angles are in radians. It is based off github.com/go-gl/mathgl version but has a very different API to take advantage of cache locality. This makes this library generally faster to execute but harder to read and write. It also uses a native math library for float32.
Index ¶
- Variables
- func CartesianToCylindrical(coord Vec3) (rho, phi, z float32)
- func CartesianToSpherical(coord Vec3) (r, theta, phi float32)
- func Clamp(a, low, high float32) float32
- func CylindricalToSpherical(rho, phi, z float32) (r, theta, phi2 float32)
- func DegToRad(angle float32) float32
- func Extract3DScale(m *Mat4) (x, y, z float32)
- func ExtractMaxScale(m *Mat4) float32
- func FloatEqual(a, b float32) bool
- func FloatEqualThreshold(a, b, epsilon float32) bool
- func IsClamped(a, low, high float32) bool
- func LocalToWorldDirnIn(local *Vec3, transform *Mat3x4, dst *Vec3)
- func LocalToWorldIn(local *Vec3, transform *Mat3x4, dst *Vec3)
- func RadToDeg(angle float32) float32
- func Round(v float32, precision int) float32
- func ScalarTripleProduct(v0, v1, v2 *Vec3) float32
- func SetMax(a, b *float32)
- func SetMin(a, b *float32)
- func SphericalToCylindrical(r, theta, phi float32) (rho, phi2, z float32)
- func WorldToLocalDirnIn(world *Vec3, transform *Mat3x4, dst *Vec3)
- func WorldToLocalIn(world *Vec3, transform *Mat3x4, dst *Vec3)
- type Mat2
- func (m1 *Mat2) Abs() Mat2
- func (m1 *Mat2) AbsOf(m2 *Mat2)
- func (m1 *Mat2) AbsSelf()
- func (m1 *Mat2) Add(m2 *Mat2) Mat2
- func (m1 *Mat2) AddOf(m2, m3 *Mat2)
- func (m1 *Mat2) AddWith(m2 *Mat2)
- func (m1 *Mat2) At(row, col int) float32
- func (m1 *Mat2) Col(col int) Vec2
- func (Mat2) ColLen() int
- func (m1 *Mat2) Cols() (col0, col1 Vec2)
- func (m1 *Mat2) Det() float32
- func (m1 *Mat2) Diag() Vec2
- func (m1 *Mat2) Equal(m2 *Mat2) bool
- func (m1 *Mat2) EqualThreshold(m2 *Mat2, threshold float32) bool
- func (m1 *Mat2) Ident()
- func (Mat2) Index(row, col int) int
- func (m1 *Mat2) Inverse() Mat2
- func (m1 *Mat2) InverseOf(m2 *Mat2)
- func (m1 *Mat2) Invert()
- func (m1 *Mat2) Mat3() Mat3
- func (m1 *Mat2) Mat4() Mat4
- func (m1 *Mat2) Mul(c float32) Mat2
- func (m1 *Mat2) Mul2(m2 *Mat2) Mat2
- func (m1 *Mat2) Mul2Of(m2, m3 *Mat2)
- func (m1 *Mat2) Mul2With(m2 *Mat2)
- func (m1 *Mat2) Mul2x1(m2 *Vec2) Vec2
- func (m1 *Mat2) MulOf(m2 *Mat2, c float32)
- func (m1 *Mat2) MulWith(c float32)
- func (m1 *Mat2) Row(row int) Vec2
- func (Mat2) RowLen() int
- func (m1 *Mat2) Rows() (row0, row1 Vec2)
- func (m1 *Mat2) Set(row, col int, value float32)
- func (m1 *Mat2) SetCol(col int, v *Vec2)
- func (m1 *Mat2) SetRow(row int, v *Vec2)
- func (m1 *Mat2) String() string
- func (m1 *Mat2) Sub(m2 *Mat2) Mat2
- func (m1 *Mat2) SubOf(m2, m3 *Mat2)
- func (m1 *Mat2) SubWith(m2 *Mat2)
- func (m1 *Mat2) Trace() float32
- func (m1 *Mat2) Transpose()
- func (m1 *Mat2) TransposeOf(m2 *Mat2)
- func (m1 *Mat2) Transposed() Mat2
- type Mat2x3
- func (m1 *Mat2x3) Abs() Mat2x3
- func (m1 *Mat2x3) Add(m2 *Mat2x3) Mat2x3
- func (m1 *Mat2x3) At(row, col int) float32
- func (m1 *Mat2x3) Col(col int) Vec2
- func (Mat2x3) ColLen() int
- func (m1 *Mat2x3) Cols() (col0, col1, col2 Vec2)
- func (m1 *Mat2x3) Det() float32
- func (m1 *Mat2x3) Equal(m2 *Mat2x3) bool
- func (m1 *Mat2x3) EqualThreshold(m2 *Mat2x3, threshold float32) bool
- func (m1 *Mat2x3) Ident()
- func (Mat2x3) Index(row, col int) int
- func (m1 *Mat2x3) Inverse() Mat2x3
- func (m1 *Mat2x3) Mat2() Mat2
- func (m1 *Mat2x3) Mat2In(m2 *Mat2)
- func (m1 *Mat2x3) Mat3() Mat3
- func (m1 *Mat2x3) Mat3In(m2 *Mat3)
- func (m1 *Mat2x3) Mul(c float32) Mat2x3
- func (m1 *Mat2x3) Mul2x1(v1 *Vec2) Vec2
- func (m1 *Mat2x3) Mul2x1In(v1, dst *Vec2)
- func (m1 *Mat2x3) Mul2x3(m2 *Mat2x3) Mat2x3
- func (m1 *Mat2x3) Mul2x3Of(m2, m3 *Mat2x3)
- func (m1 *Mat2x3) Mul2x3With(m2 *Mat2x3)
- func (m1 *Mat2x3) Mul3(m2 *Mat3) Mat2x3
- func (m1 *Mat2x3) Mul3x1(v1 *Vec3) Vec2
- func (m1 *Mat2x3) Row(row int) Vec3
- func (Mat2x3) RowLen() int
- func (m1 *Mat2x3) Rows() (row0, row1 Vec3)
- func (m1 *Mat2x3) Set(row, col int, value float32)
- func (m1 *Mat2x3) SetCol(col int, v *Vec2)
- func (m1 *Mat2x3) SetRow(row int, v *Vec3)
- func (m1 *Mat2x3) String() string
- func (m1 *Mat2x3) Sub(m2 *Mat2x3) Mat2x3
- type Mat3
- func Diag3(v *Vec3) Mat3
- func HomogRotate2D(angle float32) Mat3
- func Ident3() Mat3
- func Mat3FromCols(col0, col1, col2 *Vec3) Mat3
- func Mat3FromRows(row0, row1, row2 *Vec3) Mat3
- func Mat4Normal(m *Mat4) Mat3
- func Rotate3DX(angle float32) Mat3
- func Rotate3DY(angle float32) Mat3
- func Rotate3DZ(angle float32) Mat3
- func Scale2D(scaleX, scaleY float32) Mat3
- func Translate2D(Tx, Ty float32) Mat3
- func (m1 *Mat3) Abs() Mat3
- func (m1 *Mat3) AbsOf(m2 *Mat3)
- func (m1 *Mat3) AbsSelf()
- func (m1 *Mat3) Add(m2 *Mat3) Mat3
- func (m1 *Mat3) AddOf(m2, m3 *Mat3)
- func (m1 *Mat3) AddWith(m2 *Mat3)
- func (m1 *Mat3) At(row, col int) float32
- func (m1 *Mat3) Col(col int) Vec3
- func (Mat3) ColLen() int
- func (m1 *Mat3) Cols() (col0, col1, col2 Vec3)
- func (m1 *Mat3) Det() float32
- func (m1 *Mat3) Diag() Vec3
- func (m1 *Mat3) Equal(m2 *Mat3) bool
- func (m1 *Mat3) EqualThreshold(m2 *Mat3, threshold float32) bool
- func (m1 *Mat3) Ident()
- func (Mat3) Index(row, col int) int
- func (m1 *Mat3) Inverse() Mat3
- func (m1 *Mat3) InverseOf(m2 *Mat3)
- func (m1 *Mat3) Invert()
- func (m1 *Mat3) Mat2() Mat2
- func (m1 *Mat3) Mat2x3() Mat2x3
- func (m1 *Mat3) Mat3x4() Mat3x4
- func (m1 *Mat3) Mat4() Mat4
- func (m1 *Mat3) Mul(c float32) Mat3
- func (m1 *Mat3) Mul3(m2 *Mat3) Mat3
- func (m1 *Mat3) Mul3Of(m2, m3 *Mat3)
- func (m1 *Mat3) Mul3With(m2 *Mat3)
- func (m1 *Mat3) Mul3x1(m2 *Vec3) Vec3
- func (m1 *Mat3) Mul3x1In(m2, dst *Vec3)
- func (m1 *Mat3) Mul3x1Transpose(v *Vec3) Vec3
- func (m1 *Mat3) MulOf(m2 *Mat3, c float32)
- func (m1 *Mat3) MulWith(c float32)
- func (m1 *Mat3) Row(row int) Vec3
- func (Mat3) RowLen() int
- func (m1 *Mat3) Rows() (row0, row1, row2 Vec3)
- func (m1 *Mat3) Set(row, col int, value float32)
- func (m1 *Mat3) SetCol(col int, v *Vec3)
- func (m1 *Mat3) SetOrientation(q1 *Quat)
- func (m1 *Mat3) SetRow(row int, v *Vec3)
- func (m1 *Mat3) String() string
- func (m1 *Mat3) Sub(m2 *Mat3) Mat3
- func (m1 *Mat3) SubOf(m2, m3 *Mat3)
- func (m1 *Mat3) SubWith(m2 *Mat3)
- func (m1 *Mat3) Trace() float32
- func (m1 *Mat3) Transpose()
- func (m1 *Mat3) TransposeOf(m2 *Mat3)
- func (m1 *Mat3) Transposed() Mat3
- type Mat3x4
- func (m1 *Mat3x4) Abs() Mat3x4
- func (m1 *Mat3x4) Add(m2 *Mat3x4) Mat3x4
- func (m1 *Mat3x4) At(row, col int) float32
- func (m1 *Mat3x4) Col(col int) Vec3
- func (Mat3x4) ColLen() int
- func (m1 *Mat3x4) Cols() (col0, col1, col2, col3 Vec3)
- func (m1 *Mat3x4) Det() float32
- func (m1 *Mat3x4) Equal(m2 *Mat3x4) bool
- func (m1 *Mat3x4) EqualThreshold(m2 *Mat3x4, threshold float32) bool
- func (m1 *Mat3x4) GetAxis(i int) Vec3
- func (m1 *Mat3x4) Ident()
- func (Mat3x4) Index(row, col int) int
- func (m1 *Mat3x4) Inverse() Mat3x4
- func (m1 *Mat3x4) Mat4() Mat4
- func (m1 *Mat3x4) Mat4In(m2 *Mat4)
- func (m1 *Mat3x4) Mul(c float32) Mat3x4
- func (m1 *Mat3x4) Mul3x1(v1 *Vec3) Vec3
- func (m1 *Mat3x4) Mul3x1In(v1, dst *Vec3)
- func (m1 *Mat3x4) Mul3x4(m2 *Mat3x4) Mat3x4
- func (m1 *Mat3x4) Mul3x4Of(m2, m3 *Mat3x4)
- func (m1 *Mat3x4) Mul3x4With(m2 *Mat3x4)
- func (m1 *Mat3x4) Mul4(m2 *Mat4) Mat3x4
- func (m1 *Mat3x4) Mul4x1(v1 *Vec4) Vec3
- func (m1 *Mat3x4) Row(row int) Vec4
- func (Mat3x4) RowLen() int
- func (m1 *Mat3x4) Rows() (row0, row1, row2 Vec4)
- func (m1 *Mat3x4) Set(row, col int, value float32)
- func (m1 *Mat3x4) SetCol(col int, v *Vec3)
- func (m1 *Mat3x4) SetOrientationAndPos(q1 *Quat, v1 *Vec3)
- func (m1 *Mat3x4) SetRow(row int, v *Vec4)
- func (m1 *Mat3x4) String() string
- func (m1 *Mat3x4) Sub(m2 *Mat3x4) Mat3x4
- func (m1 *Mat3x4) Transform(v1 *Vec3) Vec3
- func (m1 *Mat3x4) TransformDirection(v1 *Vec3) Vec3
- func (m1 *Mat3x4) TransformDirectionIn(v1, dst *Vec3)
- func (m1 *Mat3x4) TransformIn(v1, dst *Vec3)
- func (m1 *Mat3x4) TransformInverse(v1 *Vec3) Vec3
- func (m1 *Mat3x4) TransformInverseDirection(v1 *Vec3) Vec3
- func (m1 *Mat3x4) TransformInverseDirectionIn(v1, dst *Vec3)
- func (m1 *Mat3x4) TransformInverseIn(v1, dst *Vec3)
- type Mat4
- func Diag4(v *Vec4) Mat4
- func Frustum(left, right, bottom, top, near, far float32) Mat4
- func HomogRotate3D(angle float32, axis *Vec3) Mat4
- func HomogRotate3DX(angle float32) Mat4
- func HomogRotate3DY(angle float32) Mat4
- func HomogRotate3DZ(angle float32) Mat4
- func Ident4() Mat4
- func LookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ float32) Mat4
- func LookAtV(eye, center, up *Vec3) Mat4
- func Mat4FromCols(col0, col1, col2, col3 *Vec4) Mat4
- func Mat4FromRows(row0, row1, row2, row3 *Vec4) Mat4
- func Ortho(left, right, bottom, top, near, far float32) Mat4
- func Ortho2D(left, right, bottom, top float32) Mat4
- func Perspective(fovy, aspect, near, far float32) Mat4
- func Scale3D(scaleX, scaleY, scaleZ float32) Mat4
- func Translate3D(Tx, Ty, Tz float32) Mat4
- func (m1 *Mat4) Abs() Mat4
- func (m1 *Mat4) AbsOf(m2 *Mat4)
- func (m1 *Mat4) AbsSelf()
- func (m1 *Mat4) Add(m2 *Mat4) Mat4
- func (m1 *Mat4) AddOf(m2, m3 *Mat4)
- func (m1 *Mat4) AddWith(m2 *Mat4)
- func (m1 *Mat4) At(row, col int) float32
- func (m1 *Mat4) Col(col int) Vec4
- func (Mat4) ColLen() int
- func (m1 *Mat4) Cols() (col0, col1, col2, col3 Vec4)
- func (m1 *Mat4) Det() float32
- func (m1 *Mat4) Diag() Vec4
- func (m1 *Mat4) Equal(m2 *Mat4) bool
- func (m1 *Mat4) EqualThreshold(m2 *Mat4, threshold float32) bool
- func (m1 *Mat4) Ident()
- func (Mat4) Index(row, col int) int
- func (m1 *Mat4) Inverse() Mat4
- func (m1 *Mat4) InverseOf(m2 *Mat4)
- func (m1 *Mat4) Invert()
- func (m1 *Mat4) Mat2() Mat2
- func (m1 *Mat4) Mat3() Mat3
- func (m1 *Mat4) Mat3x4() Mat3x4
- func (m1 *Mat4) Mul(c float32) Mat4
- func (m1 *Mat4) Mul4(m2 *Mat4) Mat4
- func (m1 *Mat4) Mul4Of(m2, m3 *Mat4)
- func (m1 *Mat4) Mul4With(m2 *Mat4)
- func (m1 *Mat4) Mul4x1(m2 *Vec4) Vec4
- func (m1 *Mat4) MulOf(m2 *Mat4, c float32)
- func (m1 *Mat4) MulWith(c float32)
- func (m1 *Mat4) Row(row int) Vec4
- func (Mat4) RowLen() int
- func (m1 *Mat4) Rows() (row0, row1, row2, row3 Vec4)
- func (m1 *Mat4) Set(row, col int, value float32)
- func (m1 *Mat4) SetCol(col int, v *Vec4)
- func (m1 *Mat4) SetRow(row int, v *Vec4)
- func (m1 *Mat4) String() string
- func (m1 *Mat4) Sub(m2 *Mat4) Mat4
- func (m1 *Mat4) SubOf(m2, m3 *Mat4)
- func (m1 *Mat4) SubWith(m2 *Mat4)
- func (m1 *Mat4) Trace() float32
- func (m1 *Mat4) Transpose()
- func (m1 *Mat4) TransposeOf(m2 *Mat4)
- func (m1 *Mat4) Transposed() Mat4
- type Quat
- func AnglesToQuat(angle1, angle2, angle3 float32, order RotationOrder) Quat
- func Mat4ToQuat(m *Mat4) Quat
- func QuatBetweenVectors(start, dest *Vec3) Quat
- func QuatIdent() Quat
- func QuatLerp(q1, q2 *Quat, amount float32) Quat
- func QuatLookAtV(eye, center, up *Vec3) Quat
- func QuatNlerp(q1, q2 *Quat, amount float32) Quat
- func QuatRotate(angle float32, axis *Vec3) Quat
- func QuatSlerp(q1, q2 *Quat, amount float32) Quat
- func (q1 *Quat) Add(q2 *Quat) Quat
- func (q1 *Quat) AddOf(q2, q3 *Quat)
- func (q1 *Quat) AddScaledVec(f float32, v1 *Vec3)
- func (q1 *Quat) AddWith(q2 *Quat)
- func (q1 *Quat) Conjugate()
- func (q1 *Quat) ConjugateOf(q2 *Quat)
- func (q1 *Quat) Conjugated() Quat
- func (q1 *Quat) Dot(q2 *Quat) float32
- func (q1 *Quat) Equal(q2 *Quat) bool
- func (q1 *Quat) EqualThreshold(q2 *Quat, epsilon float32) bool
- func (q1 *Quat) I() float32
- func (q1 *Quat) Iden()
- func (q1 *Quat) Inverse() Quat
- func (q1 *Quat) InverseOf(q2 *Quat)
- func (q1 *Quat) Invert()
- func (q1 *Quat) J() float32
- func (q1 *Quat) K() float32
- func (q1 *Quat) Len() float32
- func (q1 *Quat) Mat3() Mat3
- func (q1 *Quat) Mat4() Mat4
- func (q1 *Quat) Mul(q2 *Quat) Quat
- func (q1 *Quat) MulOf(q2, q3 *Quat)
- func (q1 *Quat) MulWith(q2 *Quat)
- func (q1 *Quat) Norm() float32
- func (q1 *Quat) Normalize()
- func (q1 *Quat) Normalized() Quat
- func (q1 *Quat) OrientationEqual(q2 *Quat) bool
- func (q1 *Quat) OrientationEqualThreshold(q2 *Quat, epsilon float32) bool
- func (q1 *Quat) Rotate(v *Vec3) Vec3
- func (q1 *Quat) Scale(c float32) Quat
- func (q1 *Quat) ScaleOf(c float32, q2 *Quat)
- func (q1 *Quat) ScaleWith(c float32)
- func (q1 *Quat) SetNormalizedOf(q2 *Quat)
- func (q1 *Quat) Sub(q2 *Quat) Quat
- func (q1 *Quat) SubOf(q2, q3 *Quat)
- func (q1 *Quat) SubWith(q2 *Quat)
- func (q1 *Quat) X() float32
- func (q1 *Quat) Y() float32
- func (q1 *Quat) Z() float32
- type RotationOrder
- type Transform
- func (t *Transform) Concatenate(t2 *Transform)
- func (t *Transform) Iden()
- func (t *Transform) LocalToWorld(v *Vec3) Vec3
- func (t *Transform) Mat4() Mat4
- func (t *Transform) Normal() Mat3
- func (t *Transform) Pointer() unsafe.Pointer
- func (t *Transform) RotateQuat(q *Quat)
- func (t *Transform) SetRotateQuat(q *Quat)
- func (t *Transform) SetTranslate3f(x, y, z float32)
- func (t *Transform) SetTranslateVec3(v *Vec3)
- func (t *Transform) String() string
- func (t *Transform) Translate3f(x, y, z float32)
- func (t *Transform) TranslateVec3(v *Vec3)
- func (t *Transform) WorldToLocal(v *Vec3) Vec3
- type Transform2D
- func (t *Transform2D) Concatenate(t2 *Transform2D)
- func (t *Transform2D) Iden()
- func (t *Transform2D) LocalToWorld(v *Vec2) Vec2
- func (t *Transform2D) Mat3() Mat3
- func (t *Transform2D) Pointer() unsafe.Pointer
- func (t *Transform2D) Rotate(angle float32)
- func (t *Transform2D) SetRotate(angle float32)
- func (t *Transform2D) SetTranslate2f(x, y float32)
- func (t *Transform2D) SetTranslateVec2(v *Vec2)
- func (t *Transform2D) String() string
- func (t *Transform2D) Translate2f(x, y float32)
- func (t *Transform2D) TranslateVec2(v *Vec2)
- func (t *Transform2D) WorldToLocal(v *Vec2) Vec2
- type Vec2
- func (v1 *Vec2) Add(v2 *Vec2) Vec2
- func (v1 *Vec2) AddOf(v2, v3 *Vec2)
- func (v1 *Vec2) AddScaledVec(c float32, v2 *Vec2)
- func (v1 *Vec2) AddWith(v2 *Vec2)
- func (v1 *Vec2) ComponentProduct(v2 *Vec2) Vec2
- func (v1 *Vec2) ComponentProductOf(v2, v3 *Vec2)
- func (v1 *Vec2) ComponentProductWith(v2 *Vec2)
- func (v1 *Vec2) Cross(v2 *Vec2) float32
- func (v1 *Vec2) Dot(v2 *Vec2) float32
- func (v1 *Vec2) Dotf(x, y float32) float32
- func (v1 Vec2) Elem() (x, y float32)
- func (v1 *Vec2) Equal(v2 *Vec2) bool
- func (v1 *Vec2) EqualThreshold(v2 *Vec2, threshold float32) bool
- func (v1 *Vec2) Inverse() Vec2
- func (v1 *Vec2) Invert()
- func (v1 *Vec2) Len() float32
- func (v1 *Vec2) Len2() float32
- func (v1 *Vec2) Mul(c float32) Vec2
- func (v1 *Vec2) MulOf(c float32, v2 *Vec2)
- func (v1 *Vec2) MulWith(c float32)
- func (v1 *Vec2) Normalize()
- func (v1 *Vec2) Normalized() Vec2
- func (v1 *Vec2) OuterProd2(v2 *Vec2) Mat2
- func (v1 *Vec2) Perp() Vec2
- func (v1 *Vec2) SetNormalizeOf(v2 *Vec2)
- func (v1 *Vec2) SetPerp()
- func (v1 *Vec2) String() string
- func (v1 *Vec2) Sub(v2 *Vec2) Vec2
- func (v1 *Vec2) SubOf(v2, v3 *Vec2)
- func (v1 *Vec2) SubWith(v2 *Vec2)
- func (v1 *Vec2) Vec3(z float32) Vec3
- func (v1 *Vec2) Vec4(z, w float32) Vec4
- func (v1 Vec2) X() float32
- func (v1 Vec2) Y() float32
- func (v1 *Vec2) Zero()
- type Vec3
- func CylindricalToCartesian(rho, phi, z float32) Vec3
- func LocalToWorld(local *Vec3, transform *Mat3x4) Vec3
- func LocalToWorldDirn(local *Vec3, transform *Mat3x4) Vec3
- func NormalizeVec3(v Vec3) Vec3
- func Project(obj *Vec3, modelview, projection *Mat4, initialX, initialY, width, height int) Vec3
- func SphericalToCartesian(r, theta, phi float32) Vec3
- func TransformCoordinate(v *Vec3, m *Mat4) Vec3
- func TransformNormal(v *Vec3, m *Mat4) Vec3
- func UnProject(win *Vec3, modelview, projection *Mat4, initialX, initialY, width, height int) Vec3
- func WorldToLocal(world *Vec3, transform *Mat3x4) Vec3
- func WorldToLocalDirn(world *Vec3, transform *Mat3x4) Vec3
- func (v1 *Vec3) Add(v2 *Vec3) Vec3
- func (v1 *Vec3) AddOf(v2, v3 *Vec3)
- func (v1 *Vec3) AddScaledVec(c float32, v2 *Vec3)
- func (v1 *Vec3) AddWith(v2 *Vec3)
- func (v1 *Vec3) ComponentProduct(v2 *Vec3) Vec3
- func (v1 *Vec3) ComponentProductOf(v2, v3 *Vec3)
- func (v1 *Vec3) ComponentProductWith(v2 *Vec3)
- func (v1 *Vec3) Cross(v2 *Vec3) Vec3
- func (v1 *Vec3) CrossOf(v2, v3 *Vec3)
- func (v1 *Vec3) CrossWith(v2 *Vec3)
- func (v1 *Vec3) Dot(v2 *Vec3) float32
- func (v1 *Vec3) Dotf(x, y, z float32) float32
- func (v1 Vec3) Elem() (x, y, z float32)
- func (v1 *Vec3) Equal(v2 *Vec3) bool
- func (v1 *Vec3) EqualThreshold(v2 *Vec3, threshold float32) bool
- func (v1 *Vec3) Inverse() Vec3
- func (v1 *Vec3) Invert()
- func (v1 *Vec3) Len() float32
- func (v1 *Vec3) Len2() float32
- func (v1 *Vec3) Mul(c float32) Vec3
- func (v1 *Vec3) MulOf(c float32, v2 *Vec3)
- func (v1 *Vec3) MulWith(c float32)
- func (v1 *Vec3) Normalize()
- func (v1 *Vec3) Normalized() Vec3
- func (v1 *Vec3) OuterProd3(v2 *Vec3) Mat3
- func (v1 *Vec3) SetNormalizeOf(v2 *Vec3)
- func (v1 *Vec3) String() string
- func (v1 *Vec3) Sub(v2 *Vec3) Vec3
- func (v1 *Vec3) SubOf(v2, v3 *Vec3)
- func (v1 *Vec3) SubWith(v2 *Vec3)
- func (v1 *Vec3) Vec2() Vec2
- func (v1 *Vec3) Vec4(w float32) Vec4
- func (v1 Vec3) X() float32
- func (v1 Vec3) Y() float32
- func (v1 Vec3) Z() float32
- func (v1 *Vec3) Zero()
- type Vec4
- func (v1 *Vec4) Add(v2 *Vec4) Vec4
- func (v1 *Vec4) AddOf(v2, v3 *Vec4)
- func (v1 *Vec4) AddScaledVec(c float32, v2 *Vec4)
- func (v1 *Vec4) AddWith(v2 *Vec4)
- func (v1 *Vec4) ComponentProduct(v2 *Vec4) Vec4
- func (v1 *Vec4) ComponentProductOf(v2, v3 *Vec4)
- func (v1 *Vec4) ComponentProductWith(v2 *Vec4)
- func (v1 *Vec4) Dot(v2 *Vec4) float32
- func (v1 *Vec4) Dotf(x, y, z, w float32) float32
- func (v1 Vec4) Elem() (x, y, z, w float32)
- func (v1 *Vec4) Equal(v2 *Vec4) bool
- func (v1 *Vec4) EqualThreshold(v2 *Vec4, threshold float32) bool
- func (v1 *Vec4) Inverse() Vec4
- func (v1 *Vec4) Invert()
- func (v1 *Vec4) Len() float32
- func (v1 *Vec4) Len2() float32
- func (v1 *Vec4) Mul(c float32) Vec4
- func (v1 *Vec4) MulOf(c float32, v2 *Vec4)
- func (v1 *Vec4) MulWith(c float32)
- func (v1 *Vec4) Normalize()
- func (v1 *Vec4) Normalized() Vec4
- func (v1 *Vec4) SetNormalizeOf(v2 *Vec4)
- func (v1 *Vec4) String() string
- func (v1 *Vec4) Sub(v2 *Vec4) Vec4
- func (v1 *Vec4) SubOf(v2, v3 *Vec4)
- func (v1 *Vec4) SubWith(v2 *Vec4)
- func (v1 *Vec4) Vec2() Vec2
- func (v1 *Vec4) Vec3() Vec3
- func (v1 Vec4) W() float32
- func (v1 Vec4) X() float32
- func (v1 Vec4) Y() float32
- func (v1 Vec4) Z() float32
- func (v1 *Vec4) Zero()
- Bugs
Constants ¶
This section is empty.
Variables ¶
var ( // MinNormal is the smallest normal value possible. MinNormal = float32(1.1754943508222875e-38) // 1 / 2**(127 - 1) // MinValue is the smallest non zero value possible. MinValue = float32(math.SmallestNonzeroFloat32) // MaxValue is the highest value a float32 can have. MaxValue = float32(math.MaxFloat32) // InfPos is the positive infinity value. InfPos = float32(math.Inf(1)) // InfNeg is the positive infinity value. InfNeg = float32(math.Inf(-1)) // NaN is a shortcut for not a number NaN = float32(math.NaN()) )
var Epsilon float32 = 1e-10
Epsilon is some tiny value that determines how precisely equal we want our floats to be. This is exported and left as a variable in case you want to change the default threshold for the purposes of certain methods (e.g. Unproject uses the default epsilon when determining if the determinant is "close enough" to zero to mean there's no inverse).
This is, obviously, not mutex protected so be **absolutely sure** that no functions using Epsilon are being executed when you change this.
Functions ¶
func CartesianToCylindrical ¶
CartesianToCylindrical converts 3-dimensional cartesian coordinates (x,y,z) to cylindrical coordinates with radial distance r, azimuth phi, and height z.
func CartesianToSpherical ¶
CartesianToSpherical converts 3-dimensional cartesian coordinates (x,y,z) to spherical coordinates with radius r, inclination theta, and azimuth phi.
func Clamp ¶
Clamp takes in a value and two thresholds. If the value is smaller than the low threshold, it returns the low threshold. If it's bigger than the high threshold it returns the high threshold. Otherwise it returns the value.
func CylindricalToSpherical ¶
CylindricalToSpherical converts cylindrical coordinates with radial distance r, azimuth phi, and height z to spherical coordinates with radius r, inclination theta, and azimuth phi.
func Extract3DScale ¶
Extract3DScale extracts the 3d scaling from a homogeneous matrix.
func ExtractMaxScale ¶
ExtractMaxScale extracts the maximum scaling from a homogeneous matrix.
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
func IsClamped ¶
IsClamped checks if a is clamped between low and high as if Clamp(a, low, high) had been called.
In most cases it's probably better to just call Clamp without checking this since it's relatively cheap.
func LocalToWorldDirnIn ¶
LocalToWorldDirnIn is a memory friendly version of LocalToWorldDirn.
func LocalToWorldIn ¶
LocalToWorldIn is the same as LocalToWorld but with destination vector.
func Round ¶
Round shortens a float32 value to a specified precision (number of digits after the decimal point) with "round half up" tie-braking rule. Half-way values (23.5) are always rounded up (24).
func ScalarTripleProduct ¶
ScalarTripleProduct returns Dot(v1, Cross(v2,v3)), its also called the box or mixed product.
func SphericalToCylindrical ¶
SphericalToCylindrical converts spherical coordinates with radius r, inclination theta, and azimuth phi to cylindrical coordinates with radial distance r, azimuth phi, and height z.
func WorldToLocalDirnIn ¶
WorldToLocalDirnIn is a memory friendly version of WorldToLocalDirn.
func WorldToLocalIn ¶
WorldToLocalIn is a memory friendly version of WorldToLocal.
Types ¶
type Mat2 ¶
type Mat2 [4]float32
Mat2 represents a column major 2x2 matrix.
func Diag2 ¶
Diag2 creates a diagonal matrix from the entries of the input vector. That is, for each pointer for row==col, vector[row] is the entry. Otherwise it's 0.
func Mat2FromCols ¶
Mat2FromCols builds a new matrix from column vectors.
func Mat2FromRows ¶
Mat2FromRows builds a new matrix from row vectors. The resulting matrix will still be in column major order, but this can be good for hand-building matrices.
func Rotate2D ¶
Rotate2D returns a rotation Matrix about a angle in 2-D space. Specifically about the origin. It is a 2x2 matrix, if you need a 3x3 for Homogeneous math (e.g. composition with a Translation matrix) see HomogRotate2D.
func (*Mat2) 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 (*Mat2) 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 (*Mat2) Cols ¶
Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.
func (*Mat2) Det ¶
Det returns the determinant of a matrix. The determinant 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 (*Mat2) Diag ¶
Diag is a basic operation on a square matrix that simply returns main diagonal (meaning all elements such that row==col).
func (*Mat2) Equal ¶
Equal performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.
func (*Mat2) EqualThreshold ¶
EqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.
func (Mat2) Index ¶
Index returns the index of the given row and column. Used to directly access the array.
func (*Mat2) Inverse ¶
Inverse computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity. Return the zero matrix if the determinant is zero.
func (*Mat2) Invert ¶
func (m1 *Mat2) Invert()
Invert is the same as Inverse but it acts on the caller.
func (*Mat2) Mat3 ¶
Mat3 returns the mat3 values in the top-left corner and the rest filled with the identity matrix values.
[m0 m2 0] [m1 m3 0] [ 0 0 1]
func (*Mat2) Mat4 ¶
Mat4 returns the mat2 values in the top-left corner and the rest filled with the identity matrix values.
[m0 m2 0 0] [m1 m3 0 0] [ 0 0 1 0] [ 0 0 0 1]
func (*Mat2) Mul ¶
Mul performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.
func (*Mat2) Mul2 ¶
Mul2 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 (*Mat2) Mul2x1 ¶
Mul2x1 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 (*Mat2) 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 (*Mat2) Rows ¶
Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.
func (*Mat2) 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 (*Mat2) 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).
func (*Mat2) Transpose ¶
func (m1 *Mat2) Transpose()
Transpose transpose this matrix with itself as destination. For any MxN matrix the transpose is an NxM matrix with the rows swapped with the columns. For instance the transpose of the Mat3x2 is a Mat2x3 like so:
[[a b]] [[a c e]] [[c d]] = [[b d f]] [[e f]]
func (*Mat2) TransposeOf ¶
TransposeOf is a memory friendly version of Transposed.
func (*Mat2) Transposed ¶
Transposed produces the transpose of this matrix. For any MxN matrix the transpose is an NxM matrix with the rows swapped with the columns. For instance the transpose of the Mat3x2 is a Mat2x3 like so:
[[a b]] [[a c e]] [[c d]] = [[b d f]] [[e f]]
type Mat2x3 ¶
type Mat2x3 [6]float32
Mat2x3 is a 2 row 3 column matrix.
func Mat2x3FromCols ¶
Mat2x3FromCols builds a new matrix from column vectors.
func Mat2x3FromRows ¶
Mat2x3FromRows builds a new matrix from row vectors. The resulting matrix will still be in column major order, but this can be good for hand-building matrices.
func (*Mat2x3) 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 (*Mat2x3) 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 (*Mat2x3) Cols ¶
Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.
func (*Mat2x3) Equal ¶
Equal performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.
func (*Mat2x3) EqualThreshold ¶
EqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.
func (Mat2x3) Index ¶
Index returns the index of the given row and column. Used to directly access the array.
func (*Mat2x3) Inverse ¶
Inverse is a cheat function that returns the inverse of this matrix as if it was a 3x3 matrix.
func (*Mat2x3) Mul ¶
Mul performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.
func (*Mat2x3) Mul2x1 ¶
Mul2x1 is a cheat function that assumes the last row is [0 0 1] and the vectors last coordinate is 1. It's used in the physics engine to transform coordinates.
func (*Mat2x3) Mul2x1In ¶
Mul2x1In is a memory friendly version of Mul3x1, its declaration differs from the rest of the memory utility function to keep the api clean.
func (*Mat2x3) Mul2x3 ¶
Mul2x3 is a cheat function that assumes the last row of both matrices is [0 0 1] and performs a 3x3 matrix multiplication.
func (*Mat2x3) Mul2x3With ¶
Mul2x3With is a memory friendly version of Mul2x3.
func (*Mat2x3) Mul3 ¶
Mul3 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 (*Mat2x3) Mul3x1 ¶
Mul3x1 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 (*Mat2x3) 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 (*Mat2x3) Rows ¶
Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.
type Mat3 ¶
type Mat3 [9]float32
Mat3 represents a column major 3x3 matrix.
func Diag3 ¶
Diag3 creates a diagonal matrix from the entries of the input vector. That is, for each pointer for row==col, vector[row] is the entry. Otherwise it's 0.
Another way to think about it is that the identity is this function where the every vector element is 1.
func HomogRotate2D ¶
HomogRotate2D is the same as Rotate2D, except homogeneous (3x3 with the extra row/col being all zeroes with a one in the bottom right).
func Mat3FromCols ¶
Mat3FromCols builds a new matrix from column vectors.
func Mat3FromRows ¶
Mat3FromRows builds a new matrix from row vectors. The resulting matrix will still be in column major order, but this can be good for hand-building matrices.
func Mat4Normal ¶
Mat4Normal calculates the Normal of the Matrix (aka the inverse transpose)
func Rotate3DX ¶
Rotate3DX returns a 3x3 (non-homogeneous) Matrix that rotates by angle about the X-axis.
Where c is cos(angle) and s is sin(angle)
[1 0 0] [0 c -s] [0 s c]
func Rotate3DY ¶
Rotate3DY returns a 3x3 (non-homogeneous) Matrix that rotates by angle about the Y-axis.
Where c is cos(angle) and s is sin(angle)
[c 0 s] [0 1 0] [s 0 c]
func Rotate3DZ ¶
Rotate3DZ returns a 3x3 (non-homogeneous) Matrix that rotates by angle about the Z-axis.
Where c is cos(angle) and s is sin(angle)
[c -s 0] [s c 0] [0 0 1]
func Translate2D ¶
Translate2D returns a homogeneous (3x3 for 2D-space) Translation matrix that moves a point by Tx units in the x-direction and Ty units in the y-direction
[[1, 0, Tx]] [[0, 1, Ty]] [[0, 0, 1 ]]
func (*Mat3) 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 (*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. The determinant 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) Equal ¶
Equal performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.
func (*Mat3) EqualThreshold ¶
EqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.
func (Mat3) Index ¶
Index returns the index of the given row and column. Used to directly access the array.
func (*Mat3) Inverse ¶
Inverse computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity. Return the zero matrix if the determinant is zero.
func (*Mat3) Mat4 ¶
Mat4 returns the mat3 values in the top-left corner and the rest filled with the identity matrix values.
[m0 m3 m6 0] [m1 m4 m7 0] [m2 m5 m8 0] [ 0 0 0 1]
func (*Mat3) Mul ¶
Mul 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) Mul3 ¶
Mul3 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) Mul3x1 ¶
Mul3x1 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) Mul3x1Transpose ¶
Mul3x1Transpose is the same as Mul3x1 except it uses the inplace transpose of this matrix.
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) SetOrientation ¶
SetOrientation sets this matrix to the orientation matrix represented by that quaternion.
func (*Mat3) 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 (*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).
func (*Mat3) Transpose ¶
func (m1 *Mat3) Transpose()
Transpose is a memory friendly version of Transposed.
func (*Mat3) TransposeOf ¶
TransposeOf is a memory friendly version of Transposed.
func (*Mat3) Transposed ¶
Transposed produces the transpose of this matrix. For any MxN matrix the transpose is an NxM matrix with the rows swapped with the columns. For instance the transpose of the Mat3x2 is a Mat2x3 like so:
[[a b]] [[a c e]] [[c d]] = [[b d f]] [[e f]]
type Mat3x4 ¶
type Mat3x4 [12]float32
Mat3x4 is a 3 row 4 column matrix.
func Mat3x4FromCols ¶
Mat3x4FromCols builds a new matrix from column vectors.
func Mat3x4FromRows ¶
Mat3x4FromRows builds a new matrix from row vectors. The resulting matrix will still be in column major order, but this can be good for hand-building matrices.
func (*Mat3x4) 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 (*Mat3x4) 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 (*Mat3x4) Cols ¶
Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.
func (*Mat3x4) Det ¶
Det on 3x4 matrix is a cheat, it assumes the last row is [0 0 0 1].
[a d g j] [b e h k] [c f i l] [0 0 0 1]
aei - afh - bdi + bfg + cdh - ceg
func (*Mat3x4) Equal ¶
Equal performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.
func (*Mat3x4) EqualThreshold ¶
EqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.
func (*Mat3x4) GetAxis ¶
GetAxis return one of the axis of the matrix. i needs to be between 0 and 3 or else this will panic
func (Mat3x4) Index ¶
Index returns the index of the given row and column. Used to directly access the array.
func (*Mat3x4) Inverse ¶
Inverse is a cheat function that returns the inverse of this matrix as if it was a 4x4 matrix.
func (*Mat3x4) Mul ¶
Mul performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.
func (*Mat3x4) Mul3x1 ¶
Mul3x1 is a cheat function that assumes the last row is [0 0 0 1] and the vectors last coordinate is 1. It's used in the physics engine to transform coordinates.
func (*Mat3x4) Mul3x1In ¶
Mul3x1In is a memory friendly version of Mul3x1, its declaration differs from the rest of the memory utility function to keep the api clean.
func (*Mat3x4) Mul3x4 ¶
Mul3x4 is a cheat function that assumes the last row of both matrices is [0 0 0 1] and performs a 4x4 matrix multiplication.
func (*Mat3x4) Mul3x4With ¶
Mul3x4With is a memory friendly version of Mul3x4.
func (*Mat3x4) Mul4 ¶
Mul4 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 (*Mat3x4) Mul4x1 ¶
Mul4x1 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 (*Mat3x4) 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 (*Mat3x4) Rows ¶
Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.
func (*Mat3x4) SetOrientationAndPos ¶
SetOrientationAndPos sets this matrix to represent this quaternion's orientation and this vector's position.
func (*Mat3x4) 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 (*Mat3x4) Transform ¶
Transform is really just calling Mul3x1 but for the physics engine we'll redeclare it that way.
func (*Mat3x4) TransformDirection ¶
TransformDirection transforms the given direction by this inner rotation matrix.
func (*Mat3x4) TransformDirectionIn ¶
TransformDirectionIn is a memory friendly version of TransformDirection.
func (*Mat3x4) TransformIn ¶
TransformIn is really just calling Mul3x1In but for the physics engine we'll redeclare it that way.
func (*Mat3x4) TransformInverse ¶
TransformInverse will transform v1 by using shortcut. Like assuming that the 4th column is a translation and that the inner 3x3 matrix is a rotation matrix (meaning that we can use the transpose.
func (*Mat3x4) TransformInverseDirection ¶
TransformInverseDirection uses the fact that the inner 3x3 matrix is a rotation matrix to use the transpose to do the inverse of TransformDirection.
func (*Mat3x4) TransformInverseDirectionIn ¶
TransformInverseDirectionIn is a memory friendly version of TransformInverseDirection.
func (*Mat3x4) TransformInverseIn ¶
TransformInverseIn is a memory friendly version of TransformInverse.
type Mat4 ¶
type Mat4 [16]float32
Mat4 represents a column major 4x4 matrix.
func Diag4 ¶
Diag4 creates a diagonal matrix from the entries of the input vector. That is, for each pointer for row==col, vector[row] is the entry. Otherwise it's 0.
Another way to think about it is that the identity is this function where the every vector element is 1.
func Frustum ¶
Frustum returns a Mat4 representing a frustrum transform (squared pyramid with the top cut off)
func HomogRotate3D ¶
HomogRotate3D creates a 3D rotation Matrix that rotates by (radian) angle about some arbitrary axis given by a Vector. It produces a homogeneous matrix.
Where c is cos(angle) and s is sin(angle), and x, y, and z are the first, second, and third elements of the axis vector (respectively):
[[ x^2(1-c)+c, xy(1-c)-zs, xz(1-c)+ys, 0 ]] [[ xy(1-c)+zs, y^2(1-c)+c, yz(1-c)-xs, 0 ]] [[ xz(1-c)-ys, yz(1-c)+xs, z^2(1-c)+c, 0 ]] [[ 0 , 0 , 0 , 1 ]]
func HomogRotate3DX ¶
HomogRotate3DX is the same as Rotate3DX, except homogeneous (4x4 with the extra row/col being all zeroes with a one in the bottom right).
func HomogRotate3DY ¶
HomogRotate3DY is the same as Rotate3DY, except homogeneous (4x4 with the extra row/col being all zeroes with a one in the bottom right).
func HomogRotate3DZ ¶
HomogRotate3DZ is the same as Rotate3DZ, except homogeneous (4x4 with the extra row/col being all zeroes with a one in the bottom right).
func Mat4FromCols ¶
Mat4FromCols builds a new matrix from column vectors.
func Mat4FromRows ¶
Mat4FromRows builds a new matrix from row vectors. The resulting matrix will still be in column major order, but this can be good for hand-building matrices.
func Ortho ¶
Ortho returns a Mat4 that represents a orthographic projection from the given arguments.
func Ortho2D ¶
Ortho2D is equivalent to Ortho with the near and far planes being -1 and 1, respectively.
func Perspective ¶
Perspective returns a Mat4 representing a perspective projection of the given arguments.
func Scale3D ¶
Scale3D creates a homogeneous 3D scaling matrix. [scaleX 0 0 0] [0 scaleY 0 0] [0 0 scaleZ 0] [0 0 0 1]
func Translate3D ¶
Translate3D returns a homogeneous (4x4 for 3D-space) Translation matrix that moves a point by Tx units in the x-direction, Ty units in the y-direction, and Tz units in the z-direction.
[[1, 0, 0, Tx]] [[0, 1, 0, Ty]] [[0, 0, 1, Tz]] [[0, 0, 0, 1 ]]
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) 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) Cols ¶
Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.
func (*Mat4) Det ¶
Det returns the determinant of a matrix. The determinant 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) Equal ¶
Equal performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.
func (*Mat4) EqualThreshold ¶
EqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.
func (Mat4) Index ¶
Index returns the index of the given row and column. Used to directly access the array.
func (*Mat4) Inverse ¶
Inverse computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity. Return the zero matrix if the determinant is zero.
func (*Mat4) Mat2 ¶
Mat2 returns the upper 2x2 matrix.
[m0 m4 ? ?] [m1 m5 ? ?] [ ? ? ? ?] [ ? ? ? ?]
func (*Mat4) Mat3 ¶
Mat3 returns returns the upper 3x3 matrix.
[m0 m4 m8 ?] [m1 m5 m9 ?] [m2 m6 m10 ?] [ ? ? ? ?]
func (*Mat4) Mat3x4 ¶
Mat3x4 returns the top 3x4 matrix.
[m0 m4 m7 m10] [m1 m5 m8 m11] [m2 m6 m9 m12] [ ? ? ? ?]
func (*Mat4) Mul ¶
Mul 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) Mul4 ¶
Mul4 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) Mul4x1 ¶
Mul4x1 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) 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) Rows ¶
Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.
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).
func (*Mat4) Transpose ¶
func (m1 *Mat4) Transpose()
Transpose is a memory friendly version of Transposed.
func (*Mat4) TransposeOf ¶
TransposeOf is a memory friendly version of Transposed.
func (*Mat4) Transposed ¶
Transposed produces the transpose of this matrix. For any MxN matrix the transpose is an NxM matrix with the rows swapped with the columns. For instance the transpose of the Mat3x2 is a Mat2x3 like so:
[[a b]] [[a c e]] [[c d]] = [[b d f]] [[e f]]
type Quat ¶
Quat is a Quaternion. A Quaternion is an extension of the imaginary numbers. In 3D graphics we mostly use it as a cheap way of representing rotation since quaternions are cheaper to multiply by, and easier to interpolate than matrices.
A Quaternion has two parts: W, the so-called scalar component, and "V", the vector component. The vector component is considered to be the part in 3D space, while W (loosely interpreted) is its 4D coordinate. i² = j² = k² = ijk
func AnglesToQuat ¶
func AnglesToQuat(angle1, angle2, angle3 float32, order RotationOrder) Quat
AnglesToQuat performs a rotation in the specified order. If the order is not a valid RotationOrder, this function will panic.
The rotation "order" is more of an axis descriptor. For instance XZX would tell the function to interpret angle1 as a rotation about the X axis, angle2 about the Z axis, and angle3 about the X axis again.
func Mat4ToQuat ¶
Mat4ToQuat converts a pure rotation matrix into a quaternion
func QuatBetweenVectors ¶
QuatBetweenVectors calculates the rotation between two vectors
func QuatIdent ¶
func QuatIdent() Quat
QuatIdent return the identity quaternion. The quaternion identity: W=1; V=(0,0,0).
As with all identities, multiplying any quaternion by this will yield the same quaternion you started with.
func QuatLookAtV ¶
QuatLookAtV creates a rotation from an eye vector to a center vector
It assumes the front of the rotated object at Z- and up at Y+
func QuatNlerp ¶
QuatNlerp is *N*ormalized *L*inear Int*erp*olation between two Quaternions. Cheaper than Slerp and usually just as good. This is literally Lerp with Normalize() called on it.
Unlike Slerp, constant velocity isn't maintained, but it's much faster and Nlerp(q1,q2) and Nlerp(q2,q1) return the same path. You should probably use this more often unless you're suffering from choppiness due to the non-constant velocity problem.
func QuatRotate ¶
QuatRotate creates an angle from an axis and an angle relative to that axis.
This is cheaper than HomogRotate3D.
func QuatSlerp ¶
QuatSlerp is *S*pherical *L*inear Int*erp*olation, a method of interpolating between two quaternions. This always takes the straightest path on the sphere between the two quaternions, and maintains constant velocity.
However, it's expensive and QuatSlerp(q1,q2) is not the same as QuatSlerp(q2,q1)
func (*Quat) Add ¶
Add adds two quaternions. It's no more complicated than adding their W and V components.
func (*Quat) AddScaledVec ¶
AddScaledVec takes an input vector and scaled it by f then adds that rotation to q1.
func (*Quat) AddWith ¶
AddWith is a memory friendly version of Add. In quaternion cases you COULD use AddOf with q1 twice: q1.AddOf(&q1,&q2). This is here just for API consistency.
func (*Quat) Conjugate ¶
func (q1 *Quat) Conjugate()
Conjugate is a memory friendly version of Conjugated. q1 = conjugate(q1)
func (*Quat) ConjugateOf ¶
ConjugateOf is a memory friendly version of Conjugated. q1 = conjugate(q2)
func (*Quat) Conjugated ¶
Conjugated returns the conjugate of a quaternion. Equivalent to Quat{q1.W, q1.V.Mul(-1)}
func (*Quat) Equal ¶
Equal returns whether the quaternions are approximately equal, as if FloatEqual was called on each matching element.
func (*Quat) EqualThreshold ¶
EqualThreshold returns whether the quaternions are approximately equal with a given tolerance, as if FloatEqualThreshold was called on each matching element with the given epsilon.
func (*Quat) Inverse ¶
Inverse returns the inverse of a quaternion. The inverse is equivalent to the conjugate divided by the square of the length.
This method computes the square norm by directly adding the sum of the squares of all terms instead of actually squaring q1.Len(), both for performance and precision.
func (*Quat) Len ¶
Len returns the Length of the quaternion, also known as its Norm. This is the same thing as the Len of a Vec4.
func (*Quat) Mat3 ¶
Mat3 returns the homogeneous 3D rotation matrix corresponding to the quaternion.
func (*Quat) Mat4 ¶
Mat4 returns the homogeneous 3D rotation matrix corresponding to the quaternion. with last row and last column as [0 0 0 1]
func (*Quat) Mul ¶
Mul multiplies two quaternions. This can be seen as a rotation. Note that Multiplication is NOT commutative, meaning q1.Mul(q2) does not necessarily equal q2.Mul(q1).
func (*Quat) MulWith ¶
MulWith is a memory friendly version of Mul. Use this when you want q1 both as dest and arg.
func (*Quat) Normalized ¶
Normalized Normalizes the quaternion, returning its versor (unit quaternion).
func (*Quat) OrientationEqual ¶
OrientationEqual returns whether the quaternions represents the same orientation.
Different values can represent the same orientation (q == -q) because quaternions avoid singularities and discontinuities involved with rotation in 3 dimensions by adding extra dimensions.
func (*Quat) OrientationEqualThreshold ¶
OrientationEqualThreshold returns whether the quaternions represents the same orientation with a given tolerance.
func (*Quat) Rotate ¶
Rotate rotates a vector by the rotation this quaternion represents. This will result in a 3D vector. Strictly speaking, this is equivalent to q1.v.q* where the "."" is quaternion multiplication and v is interpreted as a quaternion with W 0 and V v. In code: q1.Mul(Quat{0,v}).Mul(q1.Conjugate()), and then retrieving the imaginary (vector) part.
In practice, we hand-compute this in the general case and simplify to save a few operations.
func (*Quat) SetNormalizedOf ¶
SetNormalizedOf Normalizes the quaternion, returning its versor (unit quaternion).
func (*Quat) Sub ¶
Sub subtracts two quaternions. It's no more complicated than subtracting their W and V components.
type RotationOrder ¶
type RotationOrder int
RotationOrder is the order in which rotations will be transformed for the purposes of AnglesToQuat
const ( XYX RotationOrder = iota XYZ XZX XZY YXY YXZ YZY YZX ZYZ ZYX ZXZ ZXY )
All the possible rotation orders quaternion can take.
type Transform ¶
type Transform Mat4
Transform is a utility type used to aggregate transformations. Transform concatenation, like matrix multiplication, is not commutative.
func NewTransform ¶
func NewTransform() Transform
NewTransform returns a new, initialized transform.
func (*Transform) Concatenate ¶
Concatenate Transform t2 into t.
func (*Transform) Iden ¶
func (t *Transform) Iden()
Iden sets this transform to the identity transform. You NEED to call this EXCEPT IF: - You get your transform from NewTransform - You're gonna call Set* BEFORE Translate* or Rotate*
func (*Transform) LocalToWorld ¶
LocalToWorld transform a given point and returns the world point that this transform generates.
func (*Transform) Mat4 ¶
Mat4 simply returns the Mat4 associated with this Transform. This effectively makes a copy.
func (*Transform) Normal ¶
Normal returns the normal matrix of this transform, this is used in most light shading algorithms.
func (*Transform) Pointer ¶
Pointer returns the pointer to the first element of the underlying 4x4 matrix. This is can be passed directly to OpenGL function.
func (*Transform) RotateQuat ¶
RotateQuat rotates this transform by q.
func (*Transform) SetRotateQuat ¶
SetRotateQuat rotates this transform by q.
func (*Transform) SetTranslate3f ¶
SetTranslate3f sets the transform to a translate transform of {x, y, z}.
func (*Transform) SetTranslateVec3 ¶
SetTranslateVec3 sets the transform to a translate transform of v.
func (*Transform) Translate3f ¶
Translate3f concatenates a translation to this transform of {x, y, z}.
func (*Transform) TranslateVec3 ¶
TranslateVec3 concatenates a translation to this transform of v.
func (*Transform) WorldToLocal ¶
WorldToLocal transform a given point and returns the local point that this transform generates.
type Transform2D ¶
type Transform2D Mat3
Transform2D is a utility type used to aggregate transformations. Transform concatenation, like matrix multiplication, is not commutative.
func NewTransform2D ¶
func NewTransform2D() Transform2D
NewTransform2D returns a new, initialized transform.
func (*Transform2D) Concatenate ¶
func (t *Transform2D) Concatenate(t2 *Transform2D)
Concatenate Transform t2 into t.
func (*Transform2D) Iden ¶
func (t *Transform2D) Iden()
Iden sets this transform to the identity transform. You NEED to call this EXCEPT IF: - You get your transform from NewTransform - You're gonna call Set* BEFORE Translate* or Rotate*
func (*Transform2D) LocalToWorld ¶
func (t *Transform2D) LocalToWorld(v *Vec2) Vec2
LocalToWorld transform a given point and returns the world point that this transform generates.
func (*Transform2D) Mat3 ¶
func (t *Transform2D) Mat3() Mat3
Mat3 simply returns the Mat3 associated with this Transform. This effectively makes a copy.
func (*Transform2D) Pointer ¶
func (t *Transform2D) Pointer() unsafe.Pointer
Pointer returns the pointer to the first element of the underlying 4x4 matrix. This is can be passed directly to OpenGL function.
func (*Transform2D) Rotate ¶
func (t *Transform2D) Rotate(angle float32)
Rotate concatenates a rotation of angle (radian).
func (*Transform2D) SetRotate ¶
func (t *Transform2D) SetRotate(angle float32)
SetRotate sets the transform to a rotate transform of angle (radian).
func (*Transform2D) SetTranslate2f ¶
func (t *Transform2D) SetTranslate2f(x, y float32)
SetTranslate2f sets the transform to a translate transform of {x, y, z}.
func (*Transform2D) SetTranslateVec2 ¶
func (t *Transform2D) SetTranslateVec2(v *Vec2)
SetTranslateVec2 sets the transform to a translate transform of v.
func (*Transform2D) String ¶
func (t *Transform2D) String() string
String return a string that represents this transform (a mat4).
func (*Transform2D) Translate2f ¶
func (t *Transform2D) Translate2f(x, y float32)
Translate2f concatenates a translation to this transform of {x, y, z}.
func (*Transform2D) TranslateVec2 ¶
func (t *Transform2D) TranslateVec2(v *Vec2)
TranslateVec2 concatenates a translation to this transform of v.
func (*Transform2D) WorldToLocal ¶
func (t *Transform2D) WorldToLocal(v *Vec2) Vec2
WorldToLocal transform a given point and returns the local point that this transform generates.
type Vec2 ¶
type Vec2 [2]float32
Vec2 is the representation of a vector with 2 components.
func NormalizeVec2 ¶
NormalizeVec2 normalizes given vector. shortcut for when you don't want to use pointers.
func (*Vec2) AddScaledVec ¶
AddScaledVec is a shortcut for v1 += c*v2
func (*Vec2) ComponentProduct ¶
ComponentProduct returns {v1[0]*v2[0],v1[1]*v2[1], ... v1[n]*v2[n]}. It's equivalent to v3 := v1 * v2
func (*Vec2) ComponentProductOf ¶
ComponentProductOf is equivalent to v1 = v2*v3
func (*Vec2) ComponentProductWith ¶
ComponentProductWith is equivalent to v1 = v1*v2
func (*Vec2) Dot ¶
Dot returns the dot product of this vector with another. There are multiple ways to describe this value. One is the multiplication of their lengths and cos(theta) where theta is the angle between the vectors: v1.v2 = |v1||v2|cos(theta).
The other (and what is actually done) is the sum of the element-wise multiplication of all elements. So for instance, two Vec3s would yield v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2].
This means that the dot product of a vector and itself is the square of its Len (within the bounds of floating points error).
The dot product is roughly a measure of how closely two vectors are to pointing in the same direction. If both vectors are normalized, the value will be -1 for opposite pointing, one for same pointing, and 0 for perpendicular vectors.
func (*Vec2) Dotf ¶
Dotf is the same as Dot but takes 2 float32 as input instead (API convinience function)
func (*Vec2) Equal ¶
Equal takes in a vector and does an element-wise approximate float comparison as if FloatEqual had been used
func (*Vec2) EqualThreshold ¶
EqualThreshold takes in a threshold for comparing two floats, and uses it to do an element-wise comparison of the vector to another.
func (*Vec2) Invert ¶
func (v1 *Vec2) Invert()
Invert changes the sign of every component of this vector.
func (*Vec2) Len ¶
Len returns the vector's length. Note that this is NOT the dimension of the vector (len(v)), but the mathematical length. This is equivalent to the square root of the sum of the squares of all elements. E.G. for a Vec2 it's math.Hypot(v[0], v[1]).
func (*Vec2) Len2 ¶
Len2 returns the square of the length, this function is used when optimising out the sqrt operation.
func (*Vec2) Normalize ¶
func (v1 *Vec2) Normalize()
Normalize is the same as Normalize but doesn't return a new vector.
func (*Vec2) Normalized ¶
Normalized normalizes the vector. Normalization is (1/|v|)*v, making this equivalent to v.Scale(1/v.Len()). If the len is 0.0, this function will return an infinite value for all elements due to how floating point division works in Go (n/0.0 = math.Inf(Sign(n))).
Normalization makes a vector's Len become 1.0 (within the margin of floating point error), while maintaining its directionality.
(Can be seen here: http://play.golang.org/p/Aaj7SnbqIp )
func (*Vec2) OuterProd2 ¶
OuterProd2 does the vector outer product of two vectors. The outer product produces an 2x2 matrix. E.G. a Vec2 * Vec2 = Mat2.
The outer product can be thought of as the "opposite" of the Dot product. The Dot product treats both vectors like matrices oriented such that the left one has N columns and the right has N rows. So Vec3.Vec3 = Mat1x3*Mat3x1 = Mat1 = Scalar.
The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.
func (*Vec2) SetNormalizeOf ¶
SetNormalizeOf sets this vector as v2 normalized. v1 = normalize(v2).
func (Vec2) X ¶
X is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.
type Vec3 ¶
type Vec3 [3]float32
Vec3 is the representation of a vector with 3 components.
func CylindricalToCartesian ¶
CylindricalToCartesian converts cylindrical coordinates with radial distance r, azimuth phi, and height z to cartesian coordinates (x,y,z).
func LocalToWorld ¶
LocalToWorld applies the transform matrix to the local vector. Its a shortcut when using 3x4 matrices.
func LocalToWorldDirn ¶
LocalToWorldDirn transforms this direction by this matrix.
func NormalizeVec3 ¶
NormalizeVec3 normalizes given vector. shortcut for when you don't want to use pointers.
func Project ¶
Project transforms a set of coordinates from object space (in obj) to window coordinates (with depth)
Window coordinates are continuous, not discrete, so you won't get exact pixel locations without rounding.
func SphericalToCartesian ¶
SphericalToCartesian converts spherical coordinates with radius r, inclination theta, and azimuth phi to cartesian coordinates (x,y,z).
func TransformCoordinate ¶
TransformCoordinate multiplies a 3D vector by a transformation given by the homogeneous 4D matrix m, applying any translation. If this transformation is non-affine, it will project this vector onto the plane w=1 before returning the result.
This is similar to saying you're transforming and projecting a point.
This is effectively equivalent to the GLSL code
vec4 r = (m * vec4(v,1.)); r = r/r.w; vec3 newV = r[0]yz;
func TransformNormal ¶
TransformNormal multiplies a 3D vector by a transformation given by the homogeneous 4D matrix m, NOT applying any translations.
This is similar to saying you're applying a transformation to a direction or normal. Rotation still applies (as does scaling), but translating a direction or normal is meaningless.
This is effectively equivalent to the GLSL code
vec4 r = (m * vec4(v,0.)); vec3 newV = r[0]yz
func UnProject ¶
UnProject transforms a set of window coordinates to object space. If your MVP matrix is not invertible this will return garbage.
Note that the projection may not be perfect if you use strict pixel locations rather than the exact values given by Project.
func WorldToLocal ¶
WorldToLocal applies the inverse of the transform to the vector.
func WorldToLocalDirn ¶
WorldToLocalDirn inverse transforms this direction by this matrix.
func (*Vec3) AddScaledVec ¶
AddScaledVec is a shortcut for v1 += c*v2
func (*Vec3) ComponentProduct ¶
ComponentProduct returns {v1[0]*v2[0],v1[1]*v2[1], ... v1[n]*v2[n]}. It's equivalent to v3 := v1 * v2
func (*Vec3) ComponentProductOf ¶
ComponentProductOf is equivalent to v1 = v2*v3
func (*Vec3) ComponentProductWith ¶
ComponentProductWith is equivalent to v1 = v1*v2
func (*Vec3) Cross ¶
Cross is an operation only defined on 3D vectors, commonly referred to as "the cross product". It is equivalent to Vec3{v1[1]*v2[2]-v1[2]*v2[1], v1[2]*v2[0]-v1[0]*v2[2], v1[0]*v2[1] - v1[1]*v2[0]}. Another interpretation is that it's the vector whose magnitude is |v1||v2|sin(theta) where theta is the angle between v1 and v2.
The cross product is most often used for finding surface normals. The cross product of vectors will generate a vector that is perpendicular to the plane they form.
Technically, a generalized cross product exists as an "(N-1)ary" operation (that is, the 4D cross product requires 3 4D vectors). But the binary 3D (and 7D) cross product is the most important. It can be considered the area of a parallelogram with sides v1 and v2.
Like the dot product, the cross product is roughly a measure of directionality. Two normalized perpendicular vectors will return a vector with a magnitude of 1.0 or -1.0 and two parallel vectors will return a vector with magnitude 0.0. The cross product is "anticommutative" meaning v1.Cross(v2) = -v2.Cross(v1), this property can be useful to know when finding normals, as taking the wrong cross product can lead to the opposite normal of the one you want.
func (*Vec3) Dot ¶
Dot returns the dot product of this vector with another. There are multiple ways to describe this value. One is the multiplication of their lengths and cos(theta) where theta is the angle between the vectors: v1.v2 = |v1||v2|cos(theta).
The other (and what is actually done) is the sum of the element-wise multiplication of all elements. So for instance, two Vec3s would yield v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2].
This means that the dot product of a vector and itself is the square of its Len (within the bounds of floating points error).
The dot product is roughly a measure of how closely two vectors are to pointing in the same direction. If both vectors are normalized, the value will be -1 for opposite pointing, one for same pointing, and 0 for perpendicular vectors.
func (*Vec3) Dotf ¶
Dotf is the same as Dot but takes 3 float32 as input instead (API convinience function)
func (*Vec3) Equal ¶
Equal takes in a vector and does an element-wise approximate float comparison as if FloatEqual had been used
func (*Vec3) EqualThreshold ¶
EqualThreshold takes in a threshold for comparing two floats, and uses it to do an element-wise comparison of the vector to another.
func (*Vec3) Invert ¶
func (v1 *Vec3) Invert()
Invert changes the sign of every component of this vector.
func (*Vec3) Len ¶
Len returns the vector's length. Note that this is NOT the dimension of the vector (len(v)), but the mathematical length. This is equivalent to the square root of the sum of the squares of all elements. E.G. for a Vec2 it's math.Hypot(v[0], v[1]).
func (*Vec3) Len2 ¶
Len2 returns the square of the length, this function is used when optimising out the sqrt operation.
func (*Vec3) Normalize ¶
func (v1 *Vec3) Normalize()
Normalize is the same as Normalize but doesn't return a new vector.
func (*Vec3) Normalized ¶
Normalized normalizes the vector. Normalization is (1/|v|)*v, making this equivalent to v.Scale(1/v.Len()). If the len is 0.0, this function will return an infinite value for all elements due to how floating point division works in Go (n/0.0 = math.Inf(Sign(n))).
Normalization makes a vector's Len become 1.0 (within the margin of floating point error), while maintaining its directionality.
(Can be seen here: http://play.golang.org/p/Aaj7SnbqIp )
func (*Vec3) OuterProd3 ¶
OuterProd3 does the vector outer product of two vectors. The outer product produces an 3x3 matrix. E.G. a Vec3 * Vec3 = Mat3.
The outer product can be thought of as the "opposite" of the Dot product. The Dot product treats both vectors like matrices oriented such that the left one has N columns and the right has N rows. So Vec3.Vec3 = Mat1x3*Mat3x1 = Mat1 = Scalar.
The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.
func (*Vec3) SetNormalizeOf ¶
SetNormalizeOf sets this vector as v2 normalized. v1 = normalize(v2).
func (*Vec3) String ¶
String returns a pretty string for this vector. eg. {-1.00000, 0.00000, 0.00000}
func (*Vec3) Vec2 ¶
Vec2 return a Vec2 from the first 2 components of this Vec3. Similar to GLSL
vec2(v3);
func (Vec3) X ¶
X is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.
func (Vec3) Y ¶
Y is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.
type Vec4 ¶
type Vec4 [4]float32
Vec4 is the representation of a vector with 4 components.
func NormalizeVec4 ¶
NormalizeVec4 normalizes given vector. shortcut for when you don't want to use pointers.
func (*Vec4) AddScaledVec ¶
AddScaledVec is a shortcut for v1 += c*v2
func (*Vec4) ComponentProduct ¶
ComponentProduct returns {v1[0]*v2[0],v1[1]*v2[1], ... v1[n]*v2[n]}. It's equivalent to v3 := v1 * v2
func (*Vec4) ComponentProductOf ¶
ComponentProductOf is equivalent to v1 = v2*v3
func (*Vec4) ComponentProductWith ¶
ComponentProductWith is equivalent to v1 = v1*v2
func (*Vec4) Dot ¶
Dot returns the dot product of this vector with another. There are multiple ways to describe this value. One is the multiplication of their lengths and cos(theta) where theta is the angle between the vectors: v1.v2 = |v1||v2|cos(theta).
The other (and what is actually done) is the sum of the element-wise multiplication of all elements. So for instance, two Vec3s would yield v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2].
This means that the dot product of a vector and itself is the square of its Len (within the bounds of floating points error).
The dot product is roughly a measure of how closely two vectors are to pointing in the same direction. If both vectors are normalized, the value will be -1 for opposite pointing, one for same pointing, and 0 for perpendicular vectors.
func (*Vec4) Dotf ¶
Dotf is the same as Dot but takes 4 float32 as input instead (API convinience function)
func (*Vec4) Equal ¶
Equal takes in a vector and does an element-wise approximate float comparison as if FloatEqual had been used
func (*Vec4) EqualThreshold ¶
EqualThreshold takes in a threshold for comparing two floats, and uses it to do an element-wise comparison of the vector to another.
func (*Vec4) Invert ¶
func (v1 *Vec4) Invert()
Invert changes the sign of every component of this vector.
func (*Vec4) Len ¶
Len returns the vector's length. Note that this is NOT the dimension of the vector (len(v)), but the mathematical length. This is equivalent to the square root of the sum of the squares of all elements. E.G. for a Vec2 it's math.Hypot(v[0], v[1]).
func (*Vec4) Len2 ¶
Len2 returns the square of the length, this function is used when optimising out the sqrt operation.
func (*Vec4) Normalize ¶
func (v1 *Vec4) Normalize()
Normalize is the same as Normalize but doesn't return a new vector.
func (*Vec4) Normalized ¶
Normalized normalizes the vector. Normalization is (1/|v|)*v, making this equivalent to v.Scale(1/v.Len()). If the len is 0.0, this function will return an infinite value for all elements due to how floating point division works in Go (n/0.0 = math.Inf(Sign(n))).
Normalization makes a vector's Len become 1.0 (within the margin of floating point error), while maintaining its directionality.
(Can be seen here: http://play.golang.org/p/Aaj7SnbqIp )
func (*Vec4) SetNormalizeOf ¶
SetNormalizeOf sets this vector as v2 normalized. v1 = normalize(v2).
func (*Vec4) String ¶
String returns a pretty string for this vector. eg. {-1.00000, 0.00000, 0.00000, 0.00000}
func (*Vec4) Vec2 ¶
Vec2 return a Vec2 from the first 2 components of this Vec4. Similar to GLSL
vec2(v4);
func (*Vec4) Vec3 ¶
Vec3 return a Vec3 from the first 3 components of this Vec4. Similar to GLSL
vec3(v4);
func (Vec4) W ¶
W is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.
func (Vec4) X ¶
X is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.
func (Vec4) Y ¶
Y is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.
Notes ¶
Bugs ¶
the current implementation currently inverse the matrix on every call ... that may not be the most efficient.
the current implementation currently inverse the matrix on every call ... that may not be the most efficient.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
flops
|
|
32/flops
Package flops defines a bunch of floating point comparison operations.
|
Package flops defines a bunch of floating point comparison operations. |
64/flops
Package flops defines a bunch of floating point comparison operations.
|
Package flops defines a bunch of floating point comparison operations. |