# vec4

package
Version: v0.0.0-...-aafc44e Latest Latest

Go to latest
Published: May 9, 2018 License: MIT

## Documentation ¶

### Overview ¶

Package vec4 contains a 4 float32 components vector type T and functions.

### Constants ¶

This section is empty.

### Variables ¶

View Source
```var (
// Zero holds a zero vector.
Zero = T{}

// UnitXW holds a vector with X and W set to one.
UnitXW = T{1, 0, 0, 1}
// UnitYW holds a vector with Y and W set to one.
UnitYW = T{0, 1, 0, 1}
// UnitZW holds a vector with Z and W set to one.
UnitZW = T{0, 0, 1, 1}
// UnitW holds a vector with W set to one.
UnitW = T{0, 0, 0, 1}
// UnitXYZW holds a vector with X, Y, Z, W set to one.
UnitXYZW = T{1, 1, 1, 1}

// Red holds the color red.
Red = T{1, 0, 0, 1}
// Green holds the color green.
Green = T{0, 1, 0, 1}
// Blue holds the color blue.
Blue = T{0, 0, 1, 1}
// Black holds the color black.
Black = T{0, 0, 0, 1}
// White holds the color white.
White = T{1, 1, 1, 1}

// MinVal holds a vector with the smallest possible component values.
MinVal = T{-math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, 1}
// MaxVal holds a vector with the highest possible component values.
MaxVal = T{+math.MaxFloat32, +math.MaxFloat32, +math.MaxFloat32, 1}
)```

### Functions ¶

#### func Angle ¶

`func Angle(a, b *T) float32`

Angle returns the angle between two vectors.

#### func Dot ¶

`func Dot(a, b *T) float32`

Dot returns the dot product of two (dived by w) vectors.

#### func Dot4 ¶

`func Dot4(a, b *T) float32`

Dot4 returns the 4 element dot product of two vectors.

### Types ¶

`type ShuffleMask int`
```const (
)```
```const (
)```

#### type T ¶

`type T [4]float32`

T represents a 4 component vector.

`func Add(a, b *T) T`

Add returns the sum of two vectors.

#### func Cross ¶

`func Cross(a, b *T) T`

Cross returns the cross product of two vectors.

#### func From ¶

`func From(other generic.T) T`

From copies a T from a generic.T implementation.

#### func FromVec3 ¶

`func FromVec3(other *vec3.T) T`

FromVec3 returns a vector with the first 3 components copied from a vec3.T.

#### func Interpolate ¶

`func Interpolate(a, b *T, t float32) T`

Interpolate interpolates between a and b at t (0,1).

#### func Parse ¶

`func Parse(s string) (r T, err error)`

#### func Sub ¶

`func Sub(a, b *T) T`

Sub returns the difference of two vectors.

`func (vec *T) Add(v *T) *T`

#### func (*T) AssignVec3 ¶

`func (vec *T) AssignVec3(v *vec3.T) *T`

AssignVec3 assigns v to the first three components and sets the fourth to 1.

#### func (*T) Clamp ¶

`func (vec *T) Clamp(min, max *T) *T`

Clamp clamps the vector's components to be in the range of min to max.

#### func (*T) Clamp01 ¶

`func (vec *T) Clamp01() *T`

Clamp01 clamps the vector's components to be in the range of 0 to 1.

#### func (*T) Clamped ¶

`func (vec *T) Clamped(min, max *T) T`

Clamped returns a copy of the vector with the components clamped to be in the range of min to max.

#### func (*T) Clamped01 ¶

`func (vec *T) Clamped01() T`

Clamped01 returns a copy of the vector with the components clamped to be in the range of 0 to 1.

#### func (*T) Cols ¶

`func (vec *T) Cols() int`

Cols returns the number of columns of the vector.

#### func (*T) DivideByW ¶

`func (vec *T) DivideByW() *T`

DivideByW divides the first three components (XYZ) by the last one (W).

#### func (*T) DividedByW ¶

`func (vec *T) DividedByW() T`

DividedByW returns a copy of the vector with the first three components (XYZ) divided by the last one (W).

#### func (*T) Get ¶

`func (vec *T) Get(col, row int) float32`

Get returns one element of the vector.

#### func (*T) Invert ¶

`func (vec *T) Invert() *T`

Invert inverts the vector.

#### func (*T) Inverted ¶

`func (vec *T) Inverted() T`

Inverted returns an inverted copy of the vector.

#### func (*T) IsZero ¶

`func (vec *T) IsZero() bool`

IsZero checks if all elements of the vector are zero.

#### func (*T) Length ¶

`func (vec *T) Length() float32`

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

#### func (*T) LengthSqr ¶

`func (vec *T) LengthSqr() float32`

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

#### func (*T) Normal ¶

`func (vec *T) Normal() T`

Normal returns an orthogonal vector.

#### func (*T) Normalize ¶

`func (vec *T) Normalize() *T`

Normalize normalizes the vector to unit length.

#### func (*T) Normalized ¶

`func (vec *T) Normalized() T`

Normalized returns a unit length normalized copy of the vector.

#### func (*T) Rows ¶

`func (vec *T) Rows() int`

Rows returns the number of rows of the vector.

#### func (*T) Scale ¶

`func (vec *T) Scale(f float32) *T`

Scale multiplies the first 3 element of the vector by f and returns vec.

#### func (*T) Scaled ¶

`func (vec *T) Scaled(f float32) T`

Scaled returns a copy of vec with the first 3 elements multiplies by f.

#### func (*T) Shuffle ¶

`func (vec *T) Shuffle(mask ShuffleMask) *T`

Shuffle returns the vector with its components shuffled in the order according to mask.

Example:

```vec := vec4.T{1, 2, 3, 4}
vec.Shuffle(vec4.WZYX)
check := vec == T{4, 3, 2, 1} // true
```

#### func (*T) Shuffled ¶

`func (vec *T) Shuffled(mask ShuffleMask) (result T)`

Shuffled returns a copy of the vector with its components shuffled in the order according to mask.

Example:

```vec := vec4.T{1, 2, 3, 4}
check := vec.Shuffled(vec4.WZYX) == T{4, 3, 2, 1} // true
```

#### func (*T) Size ¶

`func (vec *T) Size() int`

Size returns the number elements of the vector.

#### func (*T) Slice ¶

`func (vec *T) Slice() []float32`

Slice returns the elements of the vector as slice.

#### func (*T) String ¶

`func (vec *T) String() string`

#### func (*T) Sub ¶

`func (vec *T) Sub(v *T) *T`

Sub subtracts another vector from vec.

#### func (*T) Vec3 ¶

`func (vec *T) Vec3() vec3.T`

Vec3 returns a vec3.T with the first three components of the vector. See also Vec3DividedByW

#### func (*T) Vec3DividedByW ¶

`func (vec *T) Vec3DividedByW() vec3.T`

Vec3DividedByW returns a vec3.T version of the vector by dividing the first three vector components (XYZ) by the last one (W).