vec4

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

Documentation

Index

Constants

This section is empty.

Variables

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

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

	// UnitX returns a unit vector in the X direction
	UnitX = T{1, 0, 0, 0}

	// UnitY returns a unit vector in the Y direction
	UnitY = T{0, 1, 0, 0}

	// UnitZ returns a unit vector in the Z direction
	UnitZ = T{0, 0, 1, 0}

	// UnitW returns a unit vector in the W direction
	UnitW = T{0, 0, 0, 1}

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

Functions

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 4-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, W float32
}

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

func Extend

func Extend(v vec3.T, w float32) T

Extend a vec3 to a vec4 by adding a W component

func Extend2

func Extend2(v vec2.T, z, w float32) T

Extend2 a vec2 to a vec4 by adding the Z and W components

func Max

func Max(a, b T) T

func Min

func Min(a, b T) T

func New

func New(x, y, z, w float32) T

New returns a new vec4 from its components

func Random

func Random(min, max T) T

Random vector, not normalized.

func (T) Abs

func (v T) Abs() T

Abs sets every component of the vector to its absolute value.

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) Div

func (v T) Div(v2 T) T

Div divides each element of the vector with the corresponding element of another 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) Scale

func (v *T) Scale(f float32)

Scale the vector by a constant (in-place)

func (T) Scaled

func (v T) Scaled(f float32) T

Scaled the vector

func (T) Slice

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

Slice converts the vector into a 4-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) XY

func (v T) XY() vec2.T

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

func (T) XYZ

func (v T) XYZ() vec3.T

XYZ returns a 3-component vector with the X, Y, Z components

Jump to

Keyboard shortcuts

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