mat4

package
v0.0.0-...-124f97e Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Based on code from github.com/go-gl/mathgl: Copyright 2014 The go-gl Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Based on code from github.com/go-gl/mathgl: Copyright 2014 The go-gl Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

type T f32.Mat4

T holds a 4x4 float32 matrix

func Ident

func Ident() T

Ident returns a new 4x4 identity matrix

func LookAt

func LookAt(eye, center, up vec3.T) T

func Orthographic

func Orthographic(left, right, bottom, top, near, far float32) T

Orthographic generates a left-handed orthographic projection matrix. Outputs depth values in the range [0, 1]

func OrthographicRZ

func OrthographicRZ(left, right, bottom, top, near, far float32) T

OrthographicRZ generates a left-handed orthographic projection matrix. Outputs depth values in the range [1, 0] (reverse Z)

func Perspective

func Perspective(fovy, aspect, near, far float32) T

Perspective generates a left-handed perspective projection matrix with reversed depth. Outputs depth values in the range [0, 1]

func Scale

func Scale(scale vec3.T) T

Scale creates a homogeneous 3D scaling matrix

func Translate

func Translate(translation vec3.T) T

Translate 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

func (*T) Abs

func (m *T) Abs() T

Abs returns the element-wise absolute value of this matrix

func (*T) Add

func (m *T) Add(m2 *T) T

Add performs an element-wise addition of two matrices, this is equivalent to iterating over every element of m and adding the corresponding value of m2.

func (*T) ApproxEqual

func (m *T) ApproxEqual(m2 *T) bool

ApproxEqual performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.

func (*T) ApproxEqualThreshold

func (m *T) ApproxEqualThreshold(m2 *T, threshold float32) bool

ApproxEqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.

func (*T) At

func (m *T) At(row, col int) float32

At returns the matrix element at the given row and column. This is equivalent to mat[col * numRow + row] where numRow is constant (E.G. for a Mat3x2 it's equal to 3)

This method is garbage-in garbage-out. For instance, on a T asking for At(5,0) will work just like At(1,1). Or it may panic if it's out of bounds.

func (*T) Col

func (m *T) Col(col int) vec4.T

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 (*T) Cols

func (m *T) Cols() (col0, col1, col2, col3 vec4.T)

Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.

func (*T) Det

func (m *T) Det() float32

Det returns the determinant of a matrix. It is a measure of a square matrix's singularity and invertability, among other things. In this library, the determinant is hard coded based on pre-computed cofactor expansion, and uses no loops. Of course, the addition and multiplication must still be done.

func (*T) Forward

func (m *T) Forward() vec3.T

Forward extracts the forward vector from a transformation matrix

func (*T) Index

func (m *T) Index(row, col int) int

Index returns the index of the given row and column, to be used with direct access. E.G. Index(0,0) = 0.

func (*T) Invert

func (m *T) Invert() T

Invert computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity.

M_inv * M = M * M_inv = I

In this library, the math is precomputed, and uses no loops, though the multiplications, additions, determinant calculation, and scaling are still done. This can still be (relatively) expensive for a 4x4.

This function checks the determinant to see if the matrix is invertible. If the determinant is 0.0, this function returns the zero matrix. However, due to floating point errors, it is entirely plausible to get a false positive or negative. In the future, an alternate function may be written which takes in a pre-computed determinant.

func (*T) Mul

func (a *T) Mul(b *T) T

Mul performs a "matrix product" between this matrix and another of the same dimension

func (*T) Origin

func (m *T) Origin() vec3.T

Origin extracts origin point of the coordinate system represented by the matrix

func (*T) Right

func (m *T) Right() vec3.T

Right extracts the right vector from a transformation matrix

func (*T) Row

func (m *T) Row(row int) vec4.T

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 (*T) Rows

func (m *T) Rows() (row0, row1, row2, row3 vec4.T)

Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.

func (T) Scale

func (m T) Scale(c float32) T

Scale performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.

func (*T) Set

func (m *T) Set(row, col int, value float32)

Set sets the corresponding matrix element at the given row and column.

func (T) String

func (m T) String() string

String pretty prints the matrix

func (*T) Sub

func (m *T) Sub(m2 *T) T

Sub performs an element-wise subtraction of two matrices, this is equivalent to iterating over every element of m and subtracting the corresponding value of m2.

func (*T) Trace

func (m *T) Trace() float32

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 (*T) TransformDir

func (m *T) TransformDir(v vec3.T) vec3.T

TransformDir transforms a direction vector to world space

func (*T) TransformPoint

func (m *T) TransformPoint(v vec3.T) vec3.T

TransformPoint transforms a point to world space

func (*T) Transpose

func (m *T) Transpose() T

Transpose 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]]

func (*T) Up

func (m *T) Up() vec3.T

Up extracts the up vector from a transformation matrix

func (*T) VMul

func (m *T) VMul(v vec4.T) vec4.T

VMul multiplies a vec4 with the matrix

Jump to

Keyboard shortcuts

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