linmath

package module
v0.0.0-...-40b6290 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 4 Imported by: 34

README

linmath GoDoc

A small library for linear math as required for computer graphics. This is a Go-lang port of github.com/datenwolf/linmath.h.

linmath.h provides the most used types required programming computer graphice:

vec3 -- 3 element vector of floats
vec4 -- 4 element vector of floats (4th component used for homogenous computations)
mat4x4 -- 4 by 4 elements matrix, computations are done in column major order
quat -- quaternion

The types are deliberately named like the types in GLSL. In fact they are meant to
be used for the client side computations and passing to same typed GLSL uniforms.

License

MIT (re-licensed from the WTFPL).

Documentation

Index

Constants

View Source
const (
	SizeofMat4x4 = int(unsafe.Sizeof(Mat4x4{}))
	SizeofVec4   = int(unsafe.Sizeof(Vec4{}))
	SizeofVec3   = int(unsafe.Sizeof(Vec3{}))
	SizeofVec2   = int(unsafe.Sizeof(Vec2{}))
)

Variables

This section is empty.

Functions

func DegreesToRadians

func DegreesToRadians(angleDegrees float32) float32

DegreesToRadians converts degrees to radians.

func DumpMatrix

func DumpMatrix(m *Mat4x4, note string) string

func DumpQuat

func DumpQuat(q *Quat, note string) string

func DumpVec4

func DumpVec4(v *Vec4, note string) string

func QuatInnerProduct

func QuatInnerProduct(a, b *Quat) (p float32)

func QuatMultInner3

func QuatMultInner3(a, b *Quat) (p float32)

QuatMultInner the same as for Vec3

func RadiansToDegrees

func RadiansToDegrees(angleRadians float32) float32

RadiansToDegrees converts radians to degrees.

func Vec2MultInner

func Vec2MultInner(a, b *Vec2) (p float32)

func Vec3MultInner

func Vec3MultInner(a, b *Vec3) (p float32)

func Vec4MultInner

func Vec4MultInner(a, b *Vec4) (p float32)

func Vec4MultInner3

func Vec4MultInner3(a, b *Vec4) (p float32)

Types

type ArrayFloat32

type ArrayFloat32 []float32

func (ArrayFloat32) Data

func (a ArrayFloat32) Data() []byte

func (ArrayFloat32) Sizeof

func (a ArrayFloat32) Sizeof() int

type ArrayUint16

type ArrayUint16 []uint16

func (ArrayUint16) Data

func (a ArrayUint16) Data() []byte

func (ArrayUint16) Sizeof

func (a ArrayUint16) Sizeof() int

type ArrayVec2

type ArrayVec2 []Vec2

func (ArrayVec2) Data

func (a ArrayVec2) Data() []byte

func (ArrayVec2) Sizeof

func (a ArrayVec2) Sizeof() int

type ArrayVec3

type ArrayVec3 []Vec3

func (ArrayVec3) Data

func (a ArrayVec3) Data() []byte

func (ArrayVec3) Sizeof

func (a ArrayVec3) Sizeof() int

type ArrayVec4

type ArrayVec4 []Vec4

func (ArrayVec4) Data

func (a ArrayVec4) Data() []byte

func (ArrayVec4) Sizeof

func (a ArrayVec4) Sizeof() int

type Mat4x4

type Mat4x4 [4]Vec4

func (*Mat4x4) Add

func (m *Mat4x4) Add(a, b *Mat4x4)

func (*Mat4x4) Data

func (m *Mat4x4) Data() []byte

func (*Mat4x4) Dup

func (m *Mat4x4) Dup(n *Mat4x4)

func (*Mat4x4) Fill

func (m *Mat4x4) Fill(d float32)

func (*Mat4x4) FromQuat

func (m *Mat4x4) FromQuat(q *Quat)

func (*Mat4x4) FromVec3MultOuter

func (m *Mat4x4) FromVec3MultOuter(a, b *Vec3)

func (*Mat4x4) Frustum

func (m *Mat4x4) Frustum(l, r, b, t, n, f float32)

func (*Mat4x4) Identity

func (m *Mat4x4) Identity()

func (*Mat4x4) Invert

func (t *Mat4x4) Invert(m *Mat4x4)

func (*Mat4x4) LookAt

func (m *Mat4x4) LookAt(eye, center, up *Vec3)

func (*Mat4x4) Mult

func (m *Mat4x4) Mult(a, b *Mat4x4)

func (*Mat4x4) MultQuat

func (r *Mat4x4) MultQuat(m *Mat4x4, q *Quat)

func (*Mat4x4) Ortho

func (m *Mat4x4) Ortho(l, r, b, t, n, f float32)

func (*Mat4x4) OrthoNormalize

func (r *Mat4x4) OrthoNormalize(m *Mat4x4)

func (*Mat4x4) Perspective

func (m *Mat4x4) Perspective(y_fov, aspect, n, f float32)

func (*Mat4x4) Rotate

func (r *Mat4x4) Rotate(m *Mat4x4, x, y, z, angle float32)

func (*Mat4x4) RotateX

func (q *Mat4x4) RotateX(m *Mat4x4, angle float32)

func (*Mat4x4) RotateY

func (q *Mat4x4) RotateY(m *Mat4x4, angle float32)

func (*Mat4x4) RotateZ

func (q *Mat4x4) RotateZ(m *Mat4x4, angle float32)

func (*Mat4x4) Scale

func (m *Mat4x4) Scale(a *Mat4x4, k float32)

func (*Mat4x4) ScaleAniso

func (m *Mat4x4) ScaleAniso(a *Mat4x4, x, y, z float32)

func (*Mat4x4) Sub

func (m *Mat4x4) Sub(a, b *Mat4x4)

func (*Mat4x4) Translate

func (m *Mat4x4) Translate(x, y, z float32)

func (*Mat4x4) TranslateInPlace

func (m *Mat4x4) TranslateInPlace(x, y, z float32)

func (*Mat4x4) Transpose

func (m *Mat4x4) Transpose(n *Mat4x4)

type Quat

type Quat [4]float32

func (*Quat) Add

func (r *Quat) Add(a, b *Quat)

func (*Quat) AddVec3

func (r *Quat) AddVec3(a *Quat, v *Vec3)

func (*Quat) Conj

func (r *Quat) Conj(q *Quat)

func (*Quat) FromMat4x4

func (q *Quat) FromMat4x4(m *Mat4x4)

func (*Quat) Identity

func (q *Quat) Identity()

func (*Quat) Len

func (q *Quat) Len() float32

func (*Quat) Mult

func (r *Quat) Mult(p, q *Quat)

func (*Quat) MultCross3

func (r *Quat) MultCross3(a, b *Quat)

MultCross the same as for Vec3

func (*Quat) Norm

func (r *Quat) Norm(q *Quat)

func (*Quat) Scale

func (r *Quat) Scale(q *Quat, s float32)

func (*Quat) Sub

func (r *Quat) Sub(a, b *Quat)

type Vec2

type Vec2 [2]float32

func (*Vec2) Add

func (r *Vec2) Add(a, b *Vec2)

func (*Vec2) Len

func (v *Vec2) Len() float32

func (*Vec2) Max

func (r *Vec2) Max(a, b *Vec2)

func (*Vec2) Min

func (r *Vec2) Min(a, b *Vec2)

func (*Vec2) Norm

func (r *Vec2) Norm(v *Vec2)

func (*Vec2) Scale

func (r *Vec2) Scale(v *Vec2, s float32)

func (*Vec2) Sub

func (r *Vec2) Sub(a, b *Vec2)

type Vec3

type Vec3 [3]float32

func (*Vec3) Add

func (r *Vec3) Add(a, b *Vec3)

func (*Vec3) Len

func (v *Vec3) Len() float32

func (*Vec3) Max

func (r *Vec3) Max(a, b *Vec3)

func (*Vec3) Min

func (r *Vec3) Min(a, b *Vec3)

func (*Vec3) MultCross

func (r *Vec3) MultCross(a, b *Vec3)

func (*Vec3) Norm

func (r *Vec3) Norm(v *Vec3)

func (*Vec3) QuatMultVec3

func (r *Vec3) QuatMultVec3(q *Quat, v *Vec3)

func (*Vec3) Reflect

func (r *Vec3) Reflect(v, n *Vec3)

func (*Vec3) Scale

func (r *Vec3) Scale(v *Vec3, s float32)

func (*Vec3) ScaleQuat

func (r *Vec3) ScaleQuat(q *Quat, s float32)

func (*Vec3) ScaleVec4

func (r *Vec3) ScaleVec4(v *Vec4, s float32)

func (*Vec3) Sub

func (r *Vec3) Sub(a, b *Vec3)

type Vec4

type Vec4 [4]float32

func (*Vec4) Add

func (r *Vec4) Add(a, b *Vec4)

func (*Vec4) Len

func (v *Vec4) Len() float32

func (*Vec4) Mat4x4Col

func (r *Vec4) Mat4x4Col(m *Mat4x4, i int)

func (*Vec4) Mat4x4MultVec4

func (r *Vec4) Mat4x4MultVec4(m *Mat4x4, v Vec4)

func (*Vec4) Mat4x4Row

func (r *Vec4) Mat4x4Row(m *Mat4x4, i int)

func (*Vec4) Max

func (r *Vec4) Max(a, b *Vec4)

func (*Vec4) Min

func (r *Vec4) Min(a, b *Vec4)

func (*Vec4) MultCross

func (r *Vec4) MultCross(a, b *Vec4)

func (*Vec4) Norm

func (r *Vec4) Norm(v *Vec4)

func (*Vec4) QuatMultVec4

func (r *Vec4) QuatMultVec4(q *Quat, v *Vec4)

func (*Vec4) Reflect

func (r *Vec4) Reflect(v, n *Vec4)

func (*Vec4) Scale

func (r *Vec4) Scale(v *Vec4, s float32)

func (*Vec4) Sub

func (r *Vec4) Sub(a, b *Vec4)

func (*Vec4) SubVec3

func (r *Vec4) SubVec3(a *Vec4, b *Vec3)

Jump to

Keyboard shortcuts

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