vec3

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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Zero is the zero vector
	Zero = T{0, 0, 0}

	// One is the unit vector
	One = T{1, 1, 1}

	// UnitX is the unit vector in the X direction (right)
	UnitX = T{1, 0, 0}
	Right = T{1, 0, 0}

	// UnitXN is the unit vector in the negative X direction (left)
	UnitXN = T{-1, 0, 0}
	Left   = T{-1, 0, 0}

	// UnitY is the unit vector in the Y direction (up)
	UnitY = T{0, 1, 0}
	Up    = T{0, 1, 0}

	// UnitYN is the unit vector in the negative Y direction (down)
	UnitYN = T{0, -1, 0}
	Down   = T{0, -1, 0}

	// UnitZ is the unit vector in the Z direction (forward)
	UnitZ   = T{0, 0, 1}
	Forward = T{0, 0, 1}

	// UnitZN is the unit vector in the negative Z direction (backward)
	UnitZN   = T{0, 0, -1}
	Backward = T{0, 0, 1}

	InfPos = T{math.InfPos, math.InfPos, math.InfPos}
	InfNeg = T{math.InfNeg, math.InfNeg, math.InfNeg}
)

Functions

func Distance

func Distance(a, b T) float32

Distance returns the euclidian distance between two points.

func Dot

func Dot(a, b T) float32

Dot returns the dot product of two vectors.

Types

type Array

type Array []T

Array holds an array of 3-component vectors

func (Array) Elements

func (a Array) Elements() int

Elements returns the number of elements in the array

func (Array) Pointer

func (a Array) Pointer() unsafe.Pointer

Pointer returns an unsafe pointer to the first element in the array

func (Array) Size

func (a Array) Size() int

Size return the byte size of an element

type T

type T struct {
	X, Y, Z float32
}

T holds a 3-component vector of 32-bit floats

func Cross

func Cross(a, b T) T

Cross returns the cross product of two vectors.

func Extend

func Extend(v vec2.T, z float32) T

Extend a vec2 to a vec3 by adding a Z component

func FromSlice

func FromSlice(v []float32) T

func Lerp

func Lerp(a, b T, f float32) T

func Max

func Max(a, b T) T

func Mid

func Mid(a, b T) T

func Min

func Min(a, b T) T

func New

func New(x, y, z float32) T

New returns a Vec3 from its components

func New1

func New1(v float32) T

func NewI

func NewI(x, y, z int) T

NewI returns a Vec3 from integer components

func NewI1

func NewI1(v int) T

func Random

func Random(min, max T) T

Random vector, not normalized.

func (T) Abs

func (v T) Abs() T

Abs returns a copy containing the absolute values of the vector components.

func (T) Add

func (v T) Add(v2 T) T

Add each element of the vector with the corresponding element of another vector

func (T) ApproxEqual

func (v T) ApproxEqual(v2 T) bool

func (T) Ceil

func (v T) Ceil() T

Ceil each component of the vector

func (T) Div

func (v T) Div(v2 T) T

Div divides each element of the vector with the corresponding element of another vector

func (T) Floor

func (v T) Floor() T

Floor each components of the vector

func (*T) Invert

func (v *T) Invert()

Invert the vector components

func (*T) Inverted

func (v *T) Inverted() T

Inverted returns an inverted vector

func (T) Length

func (v T) Length() float32

Length returns the length of the vector. See also LengthSqr and Normalize.

func (T) LengthSqr

func (v T) LengthSqr() float32

LengthSqr returns the squared length of the vector. See also Length and Normalize.

func (T) Mul

func (v T) Mul(v2 T) T

Mul multiplies each element of the vector with the corresponding element of another vector

func (*T) Normalize

func (v *T) Normalize()

Normalize normalizes the vector to unit length.

func (T) Normalized

func (v T) Normalized() T

Normalized returns a unit length normalized copy of the vector.

func (T) Round

func (v T) Round() T

Round each component of the vector

func (*T) Scale

func (v *T) Scale(f float32)

Scale the vector by a constant (in-place)

func (T) ScaleI

func (v T) ScaleI(i int) T

ScaleI returns a vector scaled by an integer factor

func (T) Scaled

func (v T) Scaled(f float32) T

Scaled returns a scaled vector

func (T) Slice

func (v T) Slice() [3]float32

Slice converts the vector into a 3-element slice of float32

func (T) String

func (v T) String() string

func (T) Sub

func (v T) Sub(v2 T) T

Sub subtracts each element of the vector with the corresponding element of another vector

func (T) WithX

func (v T) WithX(x float32) T

WithX returns a new vector with the X component set to a given value

func (T) WithY

func (v T) WithY(y float32) T

WithY returns a new vector with the Y component set to a given value

func (T) WithZ

func (v T) WithZ(z float32) T

WithZ returns a new vector with the Z component set to a given value

func (T) XY

func (v T) XY() vec2.T

XY returns a 2-component vector with the X, Y components of this vector

func (T) XZ

func (v T) XZ() vec2.T

XZ returns a 2-component vector with the X, Z components of this vector

func (T) YZ

func (v T) YZ() vec2.T

YZ returns a 2-component vector with the Y, Z components of this vector

Jump to

Keyboard shortcuts

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