Documentation ¶
Index ¶
- Constants
- Variables
- func ApproxEq(v1, v2, epsilon float64) bool
- func Clamp(n, min, max float64) float64
- func Lerp(from float64, to float64, t float64) float64
- func LerpC(from color.RGBA, to color.RGBA, t float64) color.RGBA
- func Max(xs ...float64) float64
- func Min(xs ...float64) float64
- type Matrix
- func (m Matrix) Add(n Matrix) Matrix
- func (m Matrix) Det() float64
- func (m Matrix) Eq(n Matrix) bool
- func (m Matrix) Get(i, j int) float64
- func (m Matrix) Inv() Matrix
- func (m Matrix) MulM(n Matrix) Matrix
- func (m Matrix) MulV(v Vector) Vector
- func (m Matrix) Set(i, j int, v float64)
- func (m Matrix) Sub(n Matrix) Matrix
- func (m Matrix) T() Matrix
- type Quaternion
- type TransformContext
- func (ctx *TransformContext) ModelMatrix() Matrix
- func (ctx *TransformContext) ResetContext()
- func (ctx *TransformContext) Rotate(dir Vector, angle float64)
- func (ctx *TransformContext) RotateX(angle float64)
- func (ctx *TransformContext) RotateY(angle float64)
- func (ctx *TransformContext) RotateZ(angle float64)
- func (ctx *TransformContext) Scale(sx, sy, sz float64)
- func (ctx *TransformContext) Translate(tx, ty, tz float64)
- type Vector
- func (v Vector) Add(u Vector) Vector
- func (v Vector) Apply(m Matrix) Vector
- func (v Vector) Cross(u Vector) Vector
- func (v Vector) Dot(u Vector) float64
- func (v Vector) Eq(u Vector) bool
- func (v Vector) IsZero() bool
- func (v Vector) Len() float64
- func (v Vector) Pos() Vector
- func (v Vector) Scale(x, y, z, w float64) Vector
- func (v Vector) Sub(u Vector) Vector
- func (v Vector) Translate(x, y, z float64) Vector
- func (v Vector) Unit() Vector
- func (v Vector) Vec() Vector
Constants ¶
const DefaultEpsilon = 1e-7
DefaultEpsilon is a default epsilon value for computation.
Variables ¶
var ( // MatI is an identity matrix MatI = Matrix{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, } // MatZero is a zero matrix MatZero = Matrix{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } )
var ( Cos = math.Cos Sin = math.Sin Tan = math.Tan Abs = math.Abs Atan = math.Atan Atan2 = math.Atan2 Pi = math.Pi MaxInt64 = math.MaxInt64 MaxFloat64 = math.MaxFloat64 Round = math.Round Floor = math.Floor Log2 = math.Log2 Pow = math.Pow Sqrt = math.Sqrt IsNaN = math.IsNaN Modf = math.Modf )
Functions ¶
Types ¶
type Matrix ¶
type Matrix struct { // This is the best implementation that benefits from compiler // optimization, which exports all elements of a 4x4 Matrix. // See benchmarks at https://golang.design/research/pointer-params/. X00, X01, X02, X03 float64 X10, X11, X12, X13 float64 X20, X21, X22, X23 float64 X30, X31, X32, X33 float64 }
Matrix represents a 4x4 matrix
func ViewportMatrix ¶
ViewportMatrix returns the viewport matrix.
func (Matrix) MulM ¶
Mul implements matrix multiplication for two 4x4 matrices and assigns the result to this.
func (Matrix) MulV ¶
MulVec implements matrix vector multiplication and returns the resulting vector.
type Quaternion ¶
func NewQuaternion ¶
func NewQuaternion(a, b, c, d float64) Quaternion
func (Quaternion) Mul ¶
func (q Quaternion) Mul(p Quaternion) Quaternion
func (Quaternion) ToRoMat ¶
func (q Quaternion) ToRoMat() Matrix
type TransformContext ¶
type TransformContext struct {
// contains filtered or unexported fields
}
TransformContext is a transformation context (model matrix) that accumulates applied transformation matrices (multiplied from left side).
context is a persistant status for the given mesh and can be reused for each of the rendering frame unless the mesh intentionally calls ResetContext() method.
func (*TransformContext) ModelMatrix ¶
func (ctx *TransformContext) ModelMatrix() Matrix
func (*TransformContext) ResetContext ¶
func (ctx *TransformContext) ResetContext()
func (*TransformContext) Rotate ¶
func (ctx *TransformContext) Rotate(dir Vector, angle float64)
func (*TransformContext) RotateX ¶
func (ctx *TransformContext) RotateX(angle float64)
func (*TransformContext) RotateY ¶
func (ctx *TransformContext) RotateY(angle float64)
func (*TransformContext) RotateZ ¶
func (ctx *TransformContext) RotateZ(angle float64)
func (*TransformContext) Scale ¶
func (ctx *TransformContext) Scale(sx, sy, sz float64)
Scale sets the scale matrix.
func (*TransformContext) Translate ¶
func (ctx *TransformContext) Translate(tx, ty, tz float64)
SetTranslate sets the translate matrix.
type Vector ¶
type Vector struct {
X, Y, Z, W float64
}
Vector uses homogeneous coordinates (x, y, z, w) that represents either a point or a vector.
func (Vector) Apply ¶
ApplyMatrix applies 4x4 matrix and 4x1 vector multiplication. the given matrix multiplies v from the left.
func (Vector) Cross ¶
Cross implements cross product for two given vectors and assign the result to this.
func (Vector) IsZero ¶
IsZero asserts the x, y, z components of the given vector, and returns true if it is a zero vector or point.