math

package
v0.0.0-...-b5e2f65 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2017 License: MIT Imports: 9 Imported by: 6

Documentation

Index

Constants

View Source
const (
	VEC2 = "VEC2"
	VEC3 = "VEC3"
	VEC4 = "VEC4"
	MAT2 = "MAT2"
	MAT3 = "MAT3"
	MAT4 = "MAT4"
	QUAT = "QUAT"
)
View Source
const Pi = math.Pi

Variables

View Source
var (
	Black = NewColor(0, 0, 0, 1)
	White = NewColor(1, 1, 1, 1)
	Red   = NewColor(1, 0, 0, 1)
	Green = NewColor(0, 1, 0, 1)
	Blue  = NewColor(0, 0, 1, 1)
	Gray  = NewColor(0.5, 0.5, 0.5, 1)
)
View Source
var (
	EmptyQuat = Quat(defaultQW, defaultQVecX, defaultQVecY, defaultQVecZ)
)
View Source
var Infinity = float32(math.Inf(1))
View Source
var NoXOfSizeError = xrror.Xrror("No %s of size %d is possible").Out
View Source
var (
	// vector x,y,z to matrice raw[12,13,14]
	TranslateMxPos = []MxPos{
		{0, 0, 3},
		{1, 1, 3},
		{2, 2, 3},
	}
)

Functions

func Abs

func Abs(v float32) float32

func Acos

func Acos(v float32) float32

func Asin

func Asin(v float32) float32

func Atan

func Atan(v float32) float32

func Atan2

func Atan2(y, x float32) float32

func Ceil

func Ceil(v float32) float32

func Clamp

func Clamp(x, a, b float32) float32

Clamp value to range <a, b>

func ClampBotton

func ClampBotton(x, a float32) float32

Clamp value to range <a, inf>

func ClampInt

func ClampInt(x, a, b int) int

func Cos

func Cos(v float32) float32

func DegToRad

func DegToRad(degrees float32) float32

func DisableMemoryPooling

func DisableMemoryPooling()

func Floor

func Floor(v float32) float32

func Inf

func Inf(sign int) float32

func IsNaN

func IsNaN(v float32) bool

func Max

func Max(a, b float32) float32

func Min

func Min(a, b float32) float32

func Mod

func Mod(a, b float32) float32

func Module

func Module(L *lua.Lua) lua.Module

func NaN

func NaN() float32

func NewColor

func NewColor(r, g, b, a float32) *color

func NewHex

func NewHex(color uint) *color

func Pf32

func Pf32(L *l.LState, pos int) float32

TODO: proper LNumber formatting, now its either or bullshit take your pick TODO: this is not that cool

func Pow

func Pow(a, b float32) float32

func Quat

func Quat(w, x, y, z float32) *quaternion

func QuatUnp

func QuatUnp(v ...float32) *quaternion

func RadToDeg

func RadToDeg(radians float32) float32

func Round

func Round(v float32) float32

func Sin

func Sin(v float32) float32

func Sqrt

func Sqrt(v float32) float32

func Tan

func Tan(v float32) float32

Types

type AF32

type AF32 []float32

array of float32

func NewAF32

func NewAF32(size, capacity int) AF32

func (*AF32) Append

func (a *AF32) Append(v ...float32)

func (*AF32) Bytes

func (a *AF32) Bytes() int

Bytes returns the size of the array in bytes

func (*AF32) Len

func (a *AF32) Len() int

Len returns the number of float32 elements in the array

func (AF32) Set

func (a AF32) Set(pos int, v ...float32)

func (*AF32) Size

func (a *AF32) Size() int

Size returns the number of float32 elements in the array

type AU32

type AU32 []uint32

array of uint32

func NewAU32

func NewAU32(size, capacity int) AU32

func (*AU32) Append

func (a *AU32) Append(v ...uint32)

func (*AU32) Bytes

func (a *AU32) Bytes() int

Bytes returns the size of the array in bytes

func (*AU32) Len

func (a *AU32) Len() int

Len returns the number of uint32 elements in the array

func (AU32) Set

func (a AU32) Set(pos int, v ...uint32)

func (*AU32) Size

func (a *AU32) Size() int

Size returns the number of uint32 elements in the array

type Color

type Color interface {
	Raw() []float32
	Set(...float32)
	SetHex(uint)
	R() float32
	G() float32
	B() float32
	A() float32
	Add(Color)
	AddScalar(float32)
	Mul(Color)
	MulScalar(float32)
	//Lerp
	Equals(Color) bool
	Clone() Color
}

type Getter

type Getter interface {
	Get(int) float32
	GetStr(string) float32
}

type Length

type Length interface {
	RawLen() int
	Len() float32
}

type Manipulator

type Manipulator interface {
	Raw() []float32
	Update(...float32)
}

type MatRxC

type MatRxC struct {
	// contains filtered or unexported fields
}

func Mat2

func Mat2(v ...float32) *MatRxC

func Mat3

func Mat3(v ...float32) *MatRxC

func Mat4

func Mat4(v ...float32) *MatRxC

func (*MatRxC) Add

func (m *MatRxC) Add(o Matrice) Matrice

func (*MatRxC) Cols

func (m *MatRxC) Cols() int

func (*MatRxC) Compose

func (m *MatRxC) Compose(translate, rotate, scale []float32) Matrice

func (*MatRxC) Decompose

func (m *MatRxC) Decompose(translate, scale Vector, rotate Quaternion) Matrice

func (*MatRxC) Determinant

func (m *MatRxC) Determinant() float32

TODO: rewrite to perform algorithmically based on len of underlying array values or other available details

func (*MatRxC) Frustrum

func (m *MatRxC) Frustrum(left, right, bottom, top, near, far float32) Matrice

func (*MatRxC) Get

func (m *MatRxC) Get(row, col int) float32

func (*MatRxC) GetStr

func (m *MatRxC) GetStr(k1, k2 string) float32

string row and column starting from 1, e.g. string 1,1 will pull 0,0 from the underlying array

func (*MatRxC) Len

func (m *MatRxC) Len() float32

same as RawLen, until determined if or how to do otherwise

func (*MatRxC) LookAt

func (m *MatRxC) LookAt(eye, target, up Vector) Matrice

func (*MatRxC) MulMatrice

func (m *MatRxC) MulMatrice(o Matrice) Matrice

func (*MatRxC) MulScalar

func (m *MatRxC) MulScalar(c float32) Matrice

func (*MatRxC) MulVec

func (m *MatRxC) MulVec(o Vector) Vector

func (*MatRxC) Orthographic

func (m *MatRxC) Orthographic(left, right, top, bottom, near, far float32) Matrice

func (*MatRxC) Perspective

func (m *MatRxC) Perspective(fov, aspect, near, far float32) Matrice

func (*MatRxC) Raw

func (m *MatRxC) Raw() []float32

func (*MatRxC) RawLen

func (m *MatRxC) RawLen() int

length of the underlying raw array

func (*MatRxC) Rotate

func (m *MatRxC) Rotate(q Quaternion) Matrice

func (*MatRxC) Rows

func (m *MatRxC) Rows() int

func (*MatRxC) Scale

func (m *MatRxC) Scale(v Vector) Matrice

func (*MatRxC) Set

func (m *MatRxC) Set(row, col int, val float32)

func (*MatRxC) SetStr

func (m *MatRxC) SetStr(k1, k2 string, v float32)

string row and column starting from 1, e.g. string 1,1,val will push 0,0,val to the underlying array

func (*MatRxC) Sub

func (m *MatRxC) Sub(o Matrice) Matrice

func (*MatRxC) Tag

func (m *MatRxC) Tag() string

func (*MatRxC) Trace

func (m *MatRxC) Trace() float32

func (*MatRxC) Translate

func (m *MatRxC) Translate(v Vector) Matrice

func (*MatRxC) Transpose

func (m *MatRxC) Transpose() Matrice

func (*MatRxC) Update

func (m *MatRxC) Update(v ...float32)

caution: will update the underlying array of values with whatever you provide, contingent on index (you cannot bring in more items than already exists in array)

type MathType

type MathType interface {
	Tag() string
}

type Matrice

type Matrice interface {
	MathType
	Manipulator
	MultiGetter
	MultiSetter
	Length
	Add(Matrice) Matrice
	Cols() int
	Compose([]float32, []float32, []float32) Matrice
	Decompose(Vector, Vector, Quaternion) Matrice
	Determinant() float32
	LookAt(Vector, Vector, Vector) Matrice
	MulMatrice(Matrice) Matrice
	MulScalar(float32) Matrice
	MulVec(Vector) Vector
	Orthographic(float32, float32, float32, float32, float32, float32) Matrice
	Perspective(float32, float32, float32, float32) Matrice
	Rotate(Quaternion) Matrice
	Rows() int
	Scale(Vector) Matrice
	Sub(Matrice) Matrice
	Transpose() Matrice
	Trace() float32
}

func ExpectedMatrice

func ExpectedMatrice(k string, v interface{}) (Matrice, bool)

func IdentityMatrix

func IdentityMatrix(k string) Matrice

func MatOfSize

func MatOfSize(sz int, m []float32) (Matrice, error)

func MultiplyMatrices

func MultiplyMatrices(a, b Matrice) Matrice

func ToMatrice

func ToMatrice(L *l.LState, v l.LValue) Matrice

func UnpackToMat

func UnpackToMat(L *l.LState, from int, k string, ignore bool) Matrice

type MultiGetter

type MultiGetter interface {
	Get(int, int) float32
	GetStr(string, string) float32
}

type MultiSetter

type MultiSetter interface {
	Set(int, int, float32)
	SetStr(string, string, float32)
}

type MxPos

type MxPos struct {
	Correspondence, Row, Column int
}

type Quaternion

type Quaternion interface {
	MathType
	Manipulator
	Getter
	Setter
	Length
	Clone() Quaternion
	Conjugate() Quaternion
	Inverse() Quaternion
	Mul(Quaternion) Quaternion
	Normalize() Quaternion
}

func ExpectedQuat

func ExpectedQuat(v interface{}) (Quaternion, bool)

func SetQuatFromAxisAngle

func SetQuatFromAxisAngle(q Quaternion, ax Vector, an float32) Quaternion

func SetQuatFromEuler

func SetQuatFromEuler(q Quaternion, v Vector) Quaternion

func SetQuatFromRotationMatrix

func SetQuatFromRotationMatrix(q Quaternion, m Matrice) Quaternion

func SetQuatFromUnitVectors

func SetQuatFromUnitVectors(q Quaternion, from, to Vector) Quaternion

func UnpackToQuat

func UnpackToQuat(L *l.LState, from int, ignore bool) Quaternion

type Setter

type Setter interface {
	Set(int, float32)
	SetStr(string, float32)
}

type VecN

type VecN struct {
	// contains filtered or unexported fields
}

func NewVecN

func NewVecN(tag string, n int) *VecN

func NewVecNFrom

func NewVecNFrom(tag string, initial []float32) *VecN

func Vec2

func Vec2(x, y float32) *VecN

func Vec3

func Vec3(x, y, z float32) *VecN

func Vec4

func Vec4(x, y, z, w float32) *VecN

func VecUnp

func VecUnp(v ...float32) *VecN

func (*VecN) Add

func (v *VecN) Add(o Vector) Vector

func (*VecN) Clone

func (v *VecN) Clone() Vector

func (*VecN) Cross

func (v *VecN) Cross(o Vector) Vector

func (*VecN) Dot

func (v *VecN) Dot(o Vector) float32

func (*VecN) Get

func (v *VecN) Get(i int) float32

func (*VecN) GetStr

func (v *VecN) GetStr(k string) float32

func (*VecN) Len

func (v *VecN) Len() float32

func (*VecN) Mul

func (v *VecN) Mul(c float32) Vector

func (*VecN) Normalize

func (v *VecN) Normalize() Vector

func (*VecN) Raw

func (v *VecN) Raw() []float32

func (*VecN) RawLen

func (v *VecN) RawLen() int

func (*VecN) Rotate

func (v *VecN) Rotate(q Quaternion) Vector

func (*VecN) Set

func (v *VecN) Set(i int, val float32)

func (*VecN) SetStr

func (v *VecN) SetStr(k string, val float32)

func (*VecN) Sub

func (v *VecN) Sub(o Vector) Vector

func (*VecN) Tag

func (v *VecN) Tag() string

func (*VecN) Update

func (v *VecN) Update(in ...float32)

type Vector

type Vector interface {
	MathType
	Manipulator
	Getter
	Setter
	Length
	Add(Vector) Vector
	Clone() Vector
	Cross(Vector) Vector
	Dot(Vector) float32
	Mul(float32) Vector
	Normalize() Vector
	Rotate(Quaternion) Vector
	Sub(Vector) Vector
}

func CrossVectors

func CrossVectors(a, b Vector) Vector

func ExpectedVector

func ExpectedVector(k string, v interface{}) (Vector, bool)

func MultiplyMatriceVector

func MultiplyMatriceVector(m Matrice, v Vector) Vector

func SetMatriceFromVector

func SetMatriceFromVector(m Matrice, v Vector, ps ...MxPos) Vector

func SetVectorFromMatrice

func SetVectorFromMatrice(v Vector, m Matrice, ps ...MxPos) Vector

func SetVectorFromQuaternion

func SetVectorFromQuaternion(v Vector, q Quaternion) Vector

func SetVectorFromRotationMatrix

func SetVectorFromRotationMatrix(v Vector, m Matrice) Vector

func ToVector

func ToVector(L *l.LState, v l.LValue) Vector

func UnpackToVec

func UnpackToVec(L *l.LState, from int, k string, ignore bool) Vector

func VecOfSize

func VecOfSize(sz int, f []float32) (Vector, error)

Jump to

Keyboard shortcuts

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