Documentation ¶
Overview ¶
Package GLaM provides mathematical types and operations for use with OpenGL.
Index ¶
- type IVec2
- type IVec3
- type IVec4
- type Mat4
- func Identity() Mat4
- func LookAt(eye, center, up Vec3) Mat4
- func MakeMat4(a, e, i, m, b, f, j, n, c, g, k, o, d, h, l, p float32) Mat4
- func NewMat4(a, e, i, m, b, f, j, n, c, g, k, o, d, h, l, p float32) *Mat4
- func Orthographic(zoom, aspectRatio, near, far float32) Mat4
- func OrthographicFrustum(left, right, bottom, top, near, far float32) Mat4
- func Perspective(fieldOfView, aspectRatio, near, far float32) Mat4
- func PerspectiveFrustum(left, right, bottom, top, near, far float32) Mat4
- func Rotation(angle float32, axis Vec3) Mat4
- func Scale(t Vec3) Mat4
- func Translation(t Vec3) Mat4
- func Zeros() Mat4
- func (r *Mat4) Multiply(m, o *Mat4)
- func (m *Mat4) Rotation(angle float32, axis Vec3)
- func (matrix *Mat4) SetTo(a, e, i, m, b, f, j, n, c, g, k, o, d, h, l, p float32)
- func (m *Mat4) SetToOrthographic(zoom, aspectRatio, near, far float32)
- func (m *Mat4) SetToOrthographicFrustum(left, right, bottom, top, near, far float32)
- func (m *Mat4) SetToPerspective(fieldOfView, aspectRatio, near, far float32)
- func (m *Mat4) SetToPerspectiveFrustum(left, right, bottom, top, near, far float32)
- func (m *Mat4) SetToTranslation(t Vec3)
- func (m *Mat4) Times(o *Mat4) Mat4
- type Vec2
- func (a *Vec2) Add(b Vec2)
- func (a *Vec2) Divide(s float32)
- func (a Vec2) Dot(b Vec2) float32
- func (a Vec2) Homogenized() Vec3
- func (a Vec2) HomogenizedAsDirection() Vec3
- func (a Vec2) Inverse() Vec2
- func (a *Vec2) Invert()
- func (a Vec2) Length() float32
- func (a Vec2) Minus(b Vec2) Vec2
- func (a *Vec2) Multiply(s float32)
- func (a *Vec2) Normalize()
- func (a Vec2) Normalized() Vec2
- func (a Vec2) Plus(b Vec2) Vec2
- func (a Vec2) Slash(s float32) Vec2
- func (a *Vec2) Subtract(b Vec2)
- func (a Vec2) Times(s float32) Vec2
- type Vec3
- func (a *Vec3) Add(b Vec3)
- func (a Vec3) Cross(b Vec3) Vec3
- func (a Vec3) Dehomogenized() Vec2
- func (a *Vec3) Divide(s float32)
- func (a Vec3) Dot(b Vec3) float32
- func (a Vec3) Homogenized() Vec4
- func (a Vec3) HomogenizedAsDirection() Vec4
- func (a Vec3) Inverse() Vec3
- func (a *Vec3) Invert()
- func (a Vec3) Length() float32
- func (a Vec3) Minus(b Vec3) Vec3
- func (a *Vec3) Multiply(s float32)
- func (a *Vec3) Normalize()
- func (a Vec3) Normalized() Vec3
- func (a Vec3) Plus(b Vec3) Vec3
- func (a Vec3) Slash(s float32) Vec3
- func (a *Vec3) Subtract(b Vec3)
- func (a Vec3) Times(s float32) Vec3
- type Vec4
- func (a *Vec4) Add(b Vec4)
- func (a Vec4) Dehomogenized() Vec3
- func (a *Vec4) Divide(s float32)
- func (a Vec4) Dot(b Vec4) float32
- func (a Vec4) Inverse() Vec4
- func (a *Vec4) Invert()
- func (a Vec4) Length() float32
- func (a Vec4) Minus(b Vec4) Vec4
- func (a *Vec4) Multiply(s float32)
- func (a *Vec4) Normalize()
- func (a Vec4) Normalized() Vec4
- func (a Vec4) Plus(b Vec4) Vec4
- func (a Vec4) Slash(s float32) Vec4
- func (a *Vec4) Subtract(b Vec4)
- func (a Vec4) Times(s float32) Vec4
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mat4 ¶
type Mat4 [16]float32
`Mat4` is a single-precision matrix with 4 columns and 4 rows.
Note: matrices are stored in column-major order, so when writing literals remember to use the transpose.
func LookAt ¶
`LookAt` returns a transform from world space into the specific eye space that the projective matrix functions (Perspective, OrthographicFrustum, ...) are designed to expect.
See also `Perspective` and `OrthographicFrustum`.
func MakeMat4 ¶
`MakeMat4` returns a matrix. The elements are stored in alphabetical order (column-major order).
See also `NewMat4` and `SetTo`.
func NewMat4 ¶
`NewMat4` allocates and returns a new matrix. The elements are stored in alphabetical order (column-major order).
See also `MakeMat4` and `SetTo`.
func Orthographic ¶
`Orthographic` returns an orthographic (parallel) projection matrix. `zoom` is the height of the projection plane.
See also `SetToOrthographic`, `OrthographicFrustum` and `SetToOrthographicFrustum`.
func OrthographicFrustum ¶
`OrthographicFrustum` returns an orthographic (parallel) projection matrix.
See also `SetToOrthographicFrustum`, `Orthographic` and `SetToOrthographic`.
func Perspective ¶
`Perspective` returns a perspective projection matrix.
See also `SetToPerspective`, `PerspectiveFrustum` and `SetToPerspectiveFrustum`.
func PerspectiveFrustum ¶
`PerspectiveFrustum` returns a perspective projection matrix.
See also `SetToPerspectiveFrustum`, `Perspective` and `SetToPerspective`.
func (*Mat4) Multiply ¶
`Multiply` sets `r` to the matrix product of `m` and `o`.
`r` must not be `m` or `o`.
See also `Multiply`, `TimesVec` and `MultiplyVec`.
func (*Mat4) SetTo ¶
`SetTo` initializes `matrix`. The elements are stored in alphabetical order (column-major order).
See also `NewMat4` and `SetTo`.
func (*Mat4) SetToOrthographic ¶
`SetToOrthographic` sets `m` to an orthographic (parallel) projection matrix. `zoom` is the height of the projection plane.
See also `Orthographic`, `OrthographicFrustum` and `SetToOrthographicFrustum`.
func (*Mat4) SetToOrthographicFrustum ¶
`SetToOrthographicFrustum` returns an orthographic (parallel) projection matrix.
See also `OrthographicFrustum`, `Orthographic` and `SetToOrthographic`.
func (*Mat4) SetToPerspective ¶
`SetToPerspective` sets `m` to a perspective projection matrix.
See also `Perspective`, `PerspectiveFrustum` and `SetToPerspectiveFrustum`.
func (*Mat4) SetToPerspectiveFrustum ¶
`SetToPerspectiveFrustum` sets `m` to a perspective projection matrix.
See also `PerspectiveFrustum`, `Perspective` and `SetToPerspective`.
func (*Mat4) SetToTranslation ¶
`SetToTranslation` sets `m` to a translation matrix.
See also `Translation`.
type Vec2 ¶
`Vec2` is a single-precision vector with 2 components..
func (*Vec2) Divide ¶
`Divide` sets `a` to the division of `a` by the scalar `s`. `s` must be non-zero.
More efficient than `Slash`.
func (Vec2) Homogenized ¶
`Homogenized` returns the homogeneous coordinates of `a`.
func (Vec2) HomogenizedAsDirection ¶
`HomogenizedAsDirection` returns the homogeneous coordinates of a point at infinity in the direction of `a`.
func (*Vec2) Invert ¶
func (a *Vec2) Invert()
`Invert` sets `a` to its inverse.
More efficient than `Inverse`.
func (*Vec2) Multiply ¶
`Multiply` sets `a` to the product of `a` with the scalar `s`.
More efficient than `Times`.
func (*Vec2) Normalize ¶
func (a *Vec2) Normalize()
`Normalize` sets `a` to `a/|a|` (i.e. normalizes `a`). `a` must be non-zero.
More efficitent than `Normalized`.
func (Vec2) Normalized ¶
`Normalized` return `a/|a|` (i.e. the normalization of `a`). `a` must be non-zero.
See also `Normalize`.
func (Vec2) Slash ¶
`Slash` returns the division of `a` by the scalar `s`. `s` must be non-zero.
See also `Divide`.
type Vec3 ¶
`Vec3` is a single-precision vector with 3 components.
Example ¶
var a Vec3 b := Vec3{1.1, 2.2, 3.3} c := b.Plus(Vec3{4.4, 5.5, 6.6}) d := b d.Add(Vec3{4.4, 5.5, 6.6}) e := b.Slash(2.2) f := e.Homogenized() g := b g.Normalize() fmt.Printf("a == %#v\n", a) fmt.Printf("b == %#v\n", b) fmt.Printf("c == %#v\n", c) fmt.Printf("d == %#v\n", d) fmt.Printf("e == %#v\n", e) fmt.Printf("f == %#v\n", f) fmt.Printf("g == %#v\n", g)
Output: a == glam.Vec3{X:0, Y:0, Z:0} b == glam.Vec3{X:1.1, Y:2.2, Z:3.3} c == glam.Vec3{X:5.5, Y:7.7, Z:9.9} d == glam.Vec3{X:5.5, Y:7.7, Z:9.9} e == glam.Vec3{X:0.5, Y:1, Z:1.5} f == glam.Vec4{X:0.5, Y:1, Z:1.5, W:1} g == glam.Vec3{X:0.26726127, Y:0.53452253, Z:0.8017838}
func (Vec3) Dehomogenized ¶
`Returns` the dehomogenization of `a` (perspective divide). `a.Z` must be non-zero.
func (*Vec3) Divide ¶
`Divide` sets `a` to the division of `a` by the scalar `s`. `s` must be non-zero.
More efficient than `Slash`.
func (Vec3) Homogenized ¶
`Homogenized` returns the homogeneous coordinates of `a`.
func (Vec3) HomogenizedAsDirection ¶
`HomogenizedAsDirection` returns the homogeneous coordinates of a point at infinity in the direction of `a`.
func (*Vec3) Invert ¶
func (a *Vec3) Invert()
`Invert` sets `a` to its inverse.
More efficient than `Inverse`.
func (*Vec3) Multiply ¶
`Multiply` sets `a` to the product of `a` with the scalar `s`. More efficient than `Times`.
func (*Vec3) Normalize ¶
func (a *Vec3) Normalize()
`Normalize` sets `a` to `a/|a|` (i.e. normalizes `a`). `a` must be non-zero.
More efficitent than `Normalized`.
func (Vec3) Normalized ¶
`Normalized` return `a/|a|` (i.e. the normalization of `a`). `a` must be non-zero.
See also `Normalize`.
func (Vec3) Slash ¶
`Slash` returns the division of `a` by the scalar `s`. `s` must be non-zero.
See also `Divide`.
type Vec4 ¶
`Vec4` is single-precision vector with 4 components.
Example ¶
var a Vec4 b := Vec4{1.1, 2.2, 3.3, 4.4} c := b.Plus(Vec4{5.5, 6.6, 7.7, 8.8}) d := b d.Add(Vec4{5.5, 6.6, 7.7, 8.8}) e := b.Slash(2.2) f := e.Dehomogenized() g := b g.Normalize() fmt.Printf("a == %#v\n", a) fmt.Printf("b == %#v\n", b) fmt.Printf("c == %#v\n", c) fmt.Printf("d == %#v\n", d) fmt.Printf("e == %#v\n", e) fmt.Printf("f == %#v\n", f) fmt.Printf("g == %#v\n", g)
Output: a == glam.Vec4{X:0, Y:0, Z:0, W:0} b == glam.Vec4{X:1.1, Y:2.2, Z:3.3, W:4.4} c == glam.Vec4{X:6.6, Y:8.8, Z:11, W:13.200001} d == glam.Vec4{X:6.6, Y:8.8, Z:11, W:13.200001} e == glam.Vec4{X:0.5, Y:1, Z:1.5, W:2} f == glam.Vec3{X:0.25, Y:0.5, Z:0.75} g == glam.Vec4{X:0.18257418, Y:0.36514837, Z:0.5477226, W:0.73029673}
func (Vec4) Dehomogenized ¶
`Dehomogenized` returns the dehomogenization of `a` (perspective divide). `a.W` must be non-zero.
func (*Vec4) Divide ¶
`Divide` sets `a` to the division of `a` by the scalar `s`. `s` must be non-zero.
More efficient than `Slash`.
func (*Vec4) Invert ¶
func (a *Vec4) Invert()
`Invert` sets `a` to its inverse. More efficient than `Inverse`.
func (*Vec4) Multiply ¶
`Multiply` sets `a` to the product of `a` with the scalar `s`. More efficient than `Times`.
func (*Vec4) Normalize ¶
func (a *Vec4) Normalize()
`Normalize` sets `a` to `a/|a|` (i.e. normalizes `a`). `a` must be non-zero.
More efficitent than `Normalized`.
func (Vec4) Normalized ¶
`Normalized` return `a/|a|` (i.e. the normalization of `a`). `a` must be non-zero.
See also `Normalize`.
func (Vec4) Slash ¶
`Slash` returns the division of `a` by the scalar `s`. `s` must be non-zero.
See also `Divide`.