f32

package
v0.0.0-...-bdc13ba Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package f32 implements some linear algebra and GL helpers for float32s.

Types defined in this package have methods implementing common mathematical operations. The common form for these functions is

func (dst *T) Op(lhs, rhs *T)

which reads in traditional mathematical notation as

dst = lhs op rhs.

It is safe to use the destination address as the left-hand side, that is, dst *= rhs is dst.Mul(dst, rhs).

WARNING

The interface to this package is not stable. It will change considerably. Only use functions that provide package documentation. Semantics are non-obvious. Be prepared for the package name to change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(byteOrder binary.ByteOrder, values ...float32) []byte

Bytes returns the byte representation of float32 values in the given byte order. byteOrder must be either binary.BigEndian or binary.LittleEndian.

func Cos

func Cos(x float32) float32

func Sin

func Sin(x float32) float32

func Sqrt

func Sqrt(x float32) float32

func Tan

func Tan(x float32) float32

Types

type Affine

type Affine [2]Vec3

An Affine is a 3x3 matrix of float32 values for which the bottom row is implicitly always equal to [0 0 1]. Elements are indexed first by row then column, i.e. m[row][column].

func (*Affine) Eq

func (m *Affine) Eq(n *Affine, epsilon float32) bool

Eq reports whether each component of m is within epsilon of the same component in n.

func (*Affine) Identity

func (m *Affine) Identity()

Identity sets m to be the identity transform.

func (*Affine) Inverse

func (m *Affine) Inverse(p *Affine)

Inverse sets m to be the inverse of p.

func (*Affine) Mul

func (m *Affine) Mul(p, q *Affine)

Mul sets m to be p × q.

func (*Affine) Rotate

func (m *Affine) Rotate(p *Affine, radians float32)

Rotate sets m to a rotation in radians followed by p. It is equivalent to m.Mul(p, affineRotation).

func (*Affine) Scale

func (m *Affine) Scale(p *Affine, x, y float32)

Scale sets m to be a scale followed by p. It is equivalent to m.Mul(p, &Affine{{x,0,0}, {0,y,0}}).

func (Affine) String

func (m Affine) String() string

func (*Affine) Translate

func (m *Affine) Translate(p *Affine, x, y float32)

Translate sets m to be a translation followed by p. It is equivalent to m.Mul(p, &Affine{{1,0,x}, {0,1,y}}).

type Mat3

type Mat3 [3]Vec3

A Mat3 is a 3x3 matrix of float32 values. Elements are indexed first by row then column, i.e. m[row][column].

func (*Mat3) Eq

func (m *Mat3) Eq(n *Mat3, epsilon float32) bool

func (*Mat3) Identity

func (m *Mat3) Identity()

func (*Mat3) Mul

func (m *Mat3) Mul(a, b *Mat3)

Mul stores a × b in m.

func (Mat3) String

func (m Mat3) String() string

type Mat4

type Mat4 [4]Vec4

A Mat4 is a 4x4 matrix of float32 values. Elements are indexed first by row then column, i.e. m[row][column].

func (*Mat4) Eq

func (m *Mat4) Eq(n *Mat4, epsilon float32) bool

func (*Mat4) Identity

func (m *Mat4) Identity()

func (*Mat4) LookAt

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

func (*Mat4) Mul

func (m *Mat4) Mul(a, b *Mat4)

Mul stores a × b in m.

func (*Mat4) Perspective

func (m *Mat4) Perspective(fov Radian, aspect, near, far float32)

Perspective sets m to be the GL perspective matrix.

func (*Mat4) Rotate

func (m *Mat4) Rotate(p *Mat4, angle Radian, axis *Vec3)

Rotate sets m to a rotation in radians around a specified axis, followed by p. It is equivalent to m.Mul(p, affineRotation).

func (*Mat4) Scale

func (m *Mat4) Scale(p *Mat4, x, y, z float32)

Scale sets m to be a scale followed by p. It is equivalent to

m.Mul(p, &Mat4{
	{x, 0, 0, 0},
	{0, y, 0, 0},
	{0, 0, z, 0},
	{0, 0, 0, 1},
}).

func (Mat4) String

func (m Mat4) String() string

func (*Mat4) Translate

func (m *Mat4) Translate(p *Mat4, x, y, z float32)

Translate sets m to be a translation followed by p. It is equivalent to

m.Mul(p, &Mat4{
	{1, 0, 0, x},
	{0, 1, 0, y},
	{0, 0, 1, z},
	{0, 0, 0, 1},
}).

type Radian

type Radian float32

type Vec3

type Vec3 [3]float32

func (*Vec3) Add

func (v *Vec3) Add(v0, v1 *Vec3)

func (*Vec3) Cross

func (v *Vec3) Cross(v0, v1 *Vec3)

func (*Vec3) Dot

func (v *Vec3) Dot(v1 *Vec3) float32

func (*Vec3) Mul

func (v *Vec3) Mul(v0, v1 *Vec3)

func (*Vec3) Normalize

func (v *Vec3) Normalize()

func (Vec3) String

func (v Vec3) String() string

func (*Vec3) Sub

func (v *Vec3) Sub(v0, v1 *Vec3)

type Vec4

type Vec4 [4]float32

func (*Vec4) Add

func (v *Vec4) Add(v0, v1 *Vec4)

func (*Vec4) Dot

func (v *Vec4) Dot(v1 *Vec4) float32

func (*Vec4) Mul

func (v *Vec4) Mul(v0, v1 *Vec4)

func (*Vec4) Normalize

func (v *Vec4) Normalize()

func (Vec4) String

func (v Vec4) String() string

func (*Vec4) Sub

func (v *Vec4) Sub(v0, v1 *Vec4)

Jump to

Keyboard shortcuts

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