math32

package
v0.0.0-...-8cd6797 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package math32 implements basic math functions which operate directly on float32 numbers without casting and contains types of common entities used in 3D Graphics such as vectors, matrices, quaternions and others.

Index

Constants

View Source
const Pi = math.Pi

Variables

View Source
var Infinity = float32(math.Inf(1))

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 clamps x to the provided closed interval [a, b]

func ClampInt

func ClampInt(x, a, b int) int

ClampInt clamps x to the provided closed interval [a, b]

func ContainsPoint

func ContainsPoint(point, a, b, c *Vector3) bool

ContainsPoint returns whether a triangle contains a point.

func Cos

func Cos(v float32) float32

func DegToRad

func DegToRad(degrees float32) float32

DegToRad converts a number from degrees to radians

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 NaN

func NaN() float32

func Pow

func Pow(a, b float32) float32

func RadToDeg

func RadToDeg(radians float32) float32

RadToDeg converts a number from radians to degrees

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 ArrayF32

type ArrayF32 []float32

ArrayF32 is a slice of float32 with additional convenience methods

func NewArrayF32

func NewArrayF32(size, capacity int) ArrayF32

NewArrayF32 creates a returns a new array of floats with the specified initial size and capacity

func (*ArrayF32) Append

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

Append appends any number of values to the array

func (*ArrayF32) AppendColor

func (a *ArrayF32) AppendColor(v ...*Color)

AppendColor appends any number of Color to the array

func (*ArrayF32) AppendColor4

func (a *ArrayF32) AppendColor4(v ...*Color4)

AppendColor4 appends any number of Color4 to the array

func (*ArrayF32) AppendVector2

func (a *ArrayF32) AppendVector2(v ...*Vector2)

AppendVector2 appends any number of Vector2 to the array

func (*ArrayF32) AppendVector3

func (a *ArrayF32) AppendVector3(v ...*Vector3)

AppendVector3 appends any number of Vector3 to the array

func (*ArrayF32) AppendVector4

func (a *ArrayF32) AppendVector4(v ...*Vector4)

AppendVector4 appends any number of Vector4 to the array

func (*ArrayF32) Bytes

func (a *ArrayF32) Bytes() int

Bytes returns the size of the array in bytes

func (ArrayF32) GetColor

func (a ArrayF32) GetColor(pos int, v *Color)

GetColor stores in the specified Color the values from the array starting at the specified pos

func (ArrayF32) GetColor4

func (a ArrayF32) GetColor4(pos int, v *Color4)

GetColor4 stores in the specified Color the values from the array starting at the specified pos

func (ArrayF32) GetMatrix4

func (a ArrayF32) GetMatrix4(pos int, m *Matrix4)

GetMatrix4 stores in the specified Matrix4 the values from the array starting at the specified pos.

func (ArrayF32) GetVector2

func (a ArrayF32) GetVector2(pos int, v *Vector2)

GetVector2 stores in the specified Vector2 the values from the array starting at the specified pos.

func (ArrayF32) GetVector3

func (a ArrayF32) GetVector3(pos int, v *Vector3)

GetVector3 stores in the specified Vector3 the values from the array starting at the specified pos.

func (ArrayF32) GetVector4

func (a ArrayF32) GetVector4(pos int, v *Vector4)

GetVector4 stores in the specified Vector4 the values from the array starting at the specified pos.

func (*ArrayF32) Len

func (a *ArrayF32) Len() int

Len returns the number of float32 elements in the array It is equivalent to Size()

func (ArrayF32) Set

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

Set sets the values of the array starting at the specified pos from the specified values

func (ArrayF32) SetColor

func (a ArrayF32) SetColor(pos int, v *Color)

SetColor sets the values of the array at the specified pos from the RGB values of the specified Color

func (ArrayF32) SetColor4

func (a ArrayF32) SetColor4(pos int, v *Color4)

SetColor4 sets the values of the array at the specified pos from the RGBA values of specified Color4

func (ArrayF32) SetVector2

func (a ArrayF32) SetVector2(pos int, v *Vector2)

SetVector2 sets the values of the array at the specified pos from the XY values of the specified Vector2

func (ArrayF32) SetVector3

func (a ArrayF32) SetVector3(pos int, v *Vector3)

SetVector3 sets the values of the array at the specified pos from the XYZ values of the specified Vector3

func (ArrayF32) SetVector4

func (a ArrayF32) SetVector4(pos int, v *Vector4)

SetVector4 sets the values of the array at the specified pos from the XYZ values of the specified Vector4

func (*ArrayF32) Size

func (a *ArrayF32) Size() int

Size returns the number of float32 elements in the array

func (ArrayF32) ToFloat32

func (a ArrayF32) ToFloat32() []float32

ToFloat32 converts this array to an array of float32

type ArrayU32

type ArrayU32 []uint32

ArrayU32 is a slice of uint32 with additional convenience methods

func NewArrayU32

func NewArrayU32(size, capacity int) ArrayU32

NewArrayU32 creates a returns a new array of uint32 with the specified initial size and capacity

func (*ArrayU32) Append

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

Append appends n elements to the array updating the slice if necessary

func (*ArrayU32) Bytes

func (a *ArrayU32) Bytes() int

Bytes returns the size of the array in bytes

func (*ArrayU32) Len

func (a *ArrayU32) Len() int

Len returns the number of float32 elements in the array

func (*ArrayU32) Size

func (a *ArrayU32) Size() int

Size returns the number of float32 elements in the array

func (ArrayU32) ToUint32

func (a ArrayU32) ToUint32() []uint32

ToUint32 converts this array to an array of uint32

type Box2

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

Box2 represents a 2D bounding box defined by two points: the point with minimum coordinates and the point with maximum coordinates.

func NewBox2

func NewBox2(min, max *Vector2) *Box2

NewBox2 creates and returns a pointer to a new Box2 defined by its minimum and maximum coordinates.

func (*Box2) Center

func (b *Box2) Center(optionalTarget *Vector2) *Vector2

Center calculates the center point of this bounding box and stores its pointer to optionalTarget, if not nil, and also returns it.

func (*Box2) ClampPoint

func (b *Box2) ClampPoint(point *Vector2, optionalTarget *Vector2) *Vector2

ClampPoint calculates a new point which is the specified point clamped inside this box. Stores the pointer to this new point into optionaTarget, if not nil, and also returns it.

func (*Box2) ContainsBox

func (b *Box2) ContainsBox(other *Box2) bool

ContainsBox returns if this bounding box contains other box.

func (*Box2) ContainsPoint

func (b *Box2) ContainsPoint(point *Vector2) bool

ContainsPoint returns if this bounding box contains the specified point.

func (*Box2) Copy

func (b *Box2) Copy(box *Box2) *Box2

Copy copy other to this bounding box. Returns pointer to this updated bounding box.

func (*Box2) DistanceToPoint

func (b *Box2) DistanceToPoint(point *Vector2) float32

DistanceToPoint returns the distance from this box to the specified point.

func (*Box2) Empty

func (b *Box2) Empty() bool

Empty returns if this bounding box is empty.

func (*Box2) Equals

func (b *Box2) Equals(other *Box2) bool

Equals returns if this box is equal to other

func (*Box2) ExpandByPoint

func (b *Box2) ExpandByPoint(point *Vector2) *Box2

ExpandByPoint may expand this bounding box to include the specified point. Returns pointer to this updated bounding box.

func (*Box2) ExpandByScalar

func (b *Box2) ExpandByScalar(scalar float32) *Box2

ExpandByScalar expands this bounding box by the specified scalar. Returns pointer to this updated bounding box.

func (*Box2) ExpandByVector

func (b *Box2) ExpandByVector(vector *Vector2) *Box2

ExpandByVector expands this bounding box by the specified vector. Returns pointer to this updated bounding box.

func (*Box2) Intersect

func (b *Box2) Intersect(other *Box2) *Box2

Intersect sets this box to the intersection with other box. Returns pointer to this updated bounding box.

func (*Box2) IsIntersectionBox

func (b *Box2) IsIntersectionBox(other *Box2) bool

IsIntersectionBox returns if other box intersects this one.

func (*Box2) MakeEmpty

func (b *Box2) MakeEmpty() *Box2

MakeEmpty set this bounding box to empty. Returns pointer to this updated bounding box.

func (*Box2) Set

func (b *Box2) Set(min, max *Vector2) *Box2

Set sets this bounding box minimum and maximum coordinates. Returns pointer to this updated bounding box.

func (*Box2) SetFromCenterAndSize

func (b *Box2) SetFromCenterAndSize(center, size *Vector2) *Box2

SetFromCenterAndSize set this bounding box from a center point and size. Size is a vector from the minimum point to the maximum point. Returns pointer to this updated bounding box.

func (*Box2) SetFromPoints

func (b *Box2) SetFromPoints(points []*Vector2) *Box2

SetFromPoints set this bounding box from the specified array of points. Returns pointer to this updated bounding box.

func (*Box2) Size

func (b *Box2) Size(optionalTarget *Vector2) *Vector2

Size calculates the size of this bounding box: the vector from its minimum point to its maximum point. Store pointer to the calculated size into optionalTarget, if not nil, and also returns it.

func (*Box2) Translate

func (b *Box2) Translate(offset *Vector2) *Box2

Translate translates the position of this box by offset. Returns pointer to this updated box.

func (*Box2) Union

func (b *Box2) Union(other *Box2) *Box2

Union set this box to the union with other box. Returns pointer to this updated bounding box.

type Box3

type Box3 struct {
	Min Vector3
	Max Vector3
}

Box3 represents a 3D bounding box defined by two points: the point with minimum coordinates and the point with maximum coordinates.

func NewBox3

func NewBox3(min, max *Vector3) *Box3

NewBox3 creates and returns a pointer to a new Box3 defined by its minimum and maximum coordinates.

func (*Box3) ApplyMatrix4

func (b *Box3) ApplyMatrix4(m *Matrix4) *Box3

ApplyMatrix4 applies the specified matrix to the vertices of this bounding box. Returns pointer to this updated bounding box.

func (*Box3) Center

func (b *Box3) Center(optionalTarget *Vector3) *Vector3

Center calculates the center point of this bounding box and stores its pointer to optionalTarget, if not nil, and also returns it.

func (*Box3) ClampPoint

func (b *Box3) ClampPoint(point *Vector3, optionalTarget *Vector3) *Vector3

ClampPoint calculates a new point which is the specified point clamped inside this box. Stores the pointer to this new point into optionaTarget, if not nil, and also returns it.

func (*Box3) Clone

func (b *Box3) Clone() *Box3

Clone creates and returns a pointer to copy of this bounding box

func (*Box3) ContainsBox

func (b *Box3) ContainsBox(box *Box3) bool

ContainsBox returns if this bounding box contains other box.

func (*Box3) ContainsPoint

func (b *Box3) ContainsPoint(point *Vector3) bool

ContainsPoint returns if this bounding box contains the specified point.

func (*Box3) Copy

func (b *Box3) Copy(other *Box3) *Box3

Copy copy other to this bounding box. Returns pointer to this updated bounding box.

func (*Box3) DistanceToPoint

func (b *Box3) DistanceToPoint(point *Vector3) float32

DistanceToPoint returns the distance from this box to the specified point.

func (*Box3) Empty

func (b *Box3) Empty() bool

Empty returns if this bounding box is empty.

func (*Box3) Equals

func (b *Box3) Equals(other *Box3) bool

Equals returns if this box is equal to other

func (*Box3) ExpandByPoint

func (b *Box3) ExpandByPoint(point *Vector3) *Box3

ExpandByPoint may expand this bounding box to include the specified point. Returns pointer to this updated bounding box.

func (*Box3) ExpandByScalar

func (b *Box3) ExpandByScalar(scalar float32) *Box3

ExpandByScalar expands this bounding box by the specified scalar. Returns pointer to this updated bounding box.

func (*Box3) ExpandByVector

func (b *Box3) ExpandByVector(vector *Vector3) *Box3

ExpandByVector expands this bounding box by the specified vector. Returns pointer to this updated bounding box.

func (*Box3) GetBoundingSphere

func (b *Box3) GetBoundingSphere(optionalTarget *Sphere) *Sphere

GetBoundingSphere creates a bounding sphere to this bounding box. Store its pointer into optionalTarget, if not nil, and also returns it.

func (*Box3) Intersect

func (b *Box3) Intersect(other *Box3) *Box3

Intersect sets this box to the intersection with other box. Returns pointer to this updated bounding box.

func (*Box3) IsIntersectionBox

func (b *Box3) IsIntersectionBox(other *Box3) bool

IsIntersectionBox returns if other box intersects this one.

func (*Box3) MakeEmpty

func (b *Box3) MakeEmpty() *Box3

MakeEmpty set this bounding box to empty. Returns pointer to this updated bounding box.

func (*Box3) Set

func (b *Box3) Set(min, max *Vector3) *Box3

Set sets this bounding box minimum and maximum coordinates. Returns pointer to this updated bounding box.

func (*Box3) SetFromCenterAndSize

func (b *Box3) SetFromCenterAndSize(center, size *Vector3) *Box3

SetFromCenterAndSize set this bounding box from a center point and size. Size is a vector from the minimum point to the maximum point. Returns pointer to this updated bounding box.

func (*Box3) SetFromPoints

func (b *Box3) SetFromPoints(points []Vector3) *Box3

SetFromPoints set this bounding box from the specified array of points. Returns pointer to this updated bounding box.

func (*Box3) Size

func (b *Box3) Size(optionalTarget *Vector3) *Vector3

Size calculates the size of this bounding box: the vector from its minimum point to its maximum point. Store pointer to the calculated size into optionalTarget, if not nil, and also returns it.

func (*Box3) Translate

func (b *Box3) Translate(offset *Vector3) *Box3

Translate translates the position of this box by offset. Returns pointer to this updated box.

func (*Box3) Union

func (b *Box3) Union(other *Box3) *Box3

Union set this box to the union with other box. Returns pointer to this updated bounding box.

type Color

type Color struct {
	R float32
	G float32
	B float32
}

Color describes an RGB color

func ColorName

func ColorName(name string) Color

ColorName returns a Color with the specified standard web color name (case insensitive). Returns black color if the specified color name not found

func IsColorName

func IsColorName(name string) (Color, bool)

IsColorName returns if the specified name is valid color name

func NewColor

func NewColor(name string) *Color

NewColor creates and returns a pointer to a new Color with the specified web standard color name (case insensitive). Returns nil if the color name not found

func NewColorHex

func NewColorHex(color uint) *Color

NewColorHex creates and returns a pointer to a new color with its RGB components from the specified hex value

func (*Color) Add

func (c *Color) Add(other *Color) *Color

Add adds to each RGB component of this color the correspondent component of other color Returns pointer to this updated color

func (*Color) AddColors

func (c *Color) AddColors(color1, color2 *Color) *Color

AddColors adds to each RGB component of this color the correspondent component of color1 and color2 Returns pointer to this updated color

func (*Color) AddScalar

func (c *Color) AddScalar(s float32) *Color

AddScalar adds the specified scalar value to each RGB component of this color Returns pointer to this updated color

func (*Color) Equals

func (c *Color) Equals(other *Color) bool

Equals returns if this color is equal to other

func (*Color) Lerp

func (c *Color) Lerp(color *Color, alpha float32) *Color

Lerp linear sets this color as the linear interpolation of itself with the specified color for the specified alpha. Returns pointer to this updated color

func (*Color) Multiply

func (c *Color) Multiply(other *Color) *Color

Multiply multiplies each RGB component of this color by other Returns pointer to this updated color

func (*Color) MultiplyScalar

func (c *Color) MultiplyScalar(v float32) *Color

MultiplyScalar multiplies each RGB component of this color by the specified scalar. Returns pointer to this updated color

func (*Color) Set

func (c *Color) Set(r, g, b float32) *Color

Set sets this color individual R,G,B components

func (*Color) SetHex

func (c *Color) SetHex(value uint) *Color

SetHex sets the color RGB components from the specified integer interpreted as a color hex number

func (*Color) SetName

func (c *Color) SetName(name string) *Color

SetName sets the color RGB components from the specified standard web color name

type Color4

type Color4 struct {
	R float32
	G float32
	B float32
	A float32
}

Color4 describes an RGBA color

func Color4Name

func Color4Name(name string, alpha ...float32) Color4

Color4Name returns a Color4 with the specified standard web color name and an optional alpha channel value.

func NewColor4

func NewColor4(name string, alpha ...float32) *Color4

NewColor4 creates and returns a pointer to a new Color4 with the specified standard web color name (case insensitive) and an optional alpha channel value. Returns nil if the specified color name not found

func (*Color4) Add

func (c *Color4) Add(other *Color4) *Color4

Add adds to each RGBA component of this color the correspondent component of other color Returns pointer to this updated color

func (*Color4) FromColor

func (c *Color4) FromColor(other *Color, alpha float32)

FromColor sets this Color4 fields from Color and an alpha

func (*Color4) MultiplyScalar

func (c *Color4) MultiplyScalar(v float32) *Color4

MultiplyScalar multiplies each RGBA component of this color by the specified scalar. Returns pointer to this updated color

func (*Color4) Set

func (c *Color4) Set(r, g, b, a float32) *Color4

Set sets this color individual R,G,B,A components Returns pointer to this updated color

func (*Color4) SetHex

func (c *Color4) SetHex(value uint) *Color4

SetHex sets the color RGB components from the specified integer interpreted as a color hex number Alpha component is not modified Returns pointer to this updated color

func (*Color4) SetName

func (c *Color4) SetName(name string) *Color4

SetName sets the color RGB components from the specified standard web color name Returns pointer to this updated color

func (*Color4) ToColor

func (c *Color4) ToColor() Color

ToColor returns a Color with this Color4 RGB components

type Curve

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

Curve constructs an array of Vector3

func NewBezierCubic

func NewBezierCubic(origin, control1, control2, destination *Vector3, npoints int) *Curve

NewBezierCubic creates and returns a pointer to a new curve Uses Vector3 pointers origin, control1, control2, and destination to calculate with int npoints as the desired number of points along the curve

func NewBezierQuadratic

func NewBezierQuadratic(origin, control, destination *Vector3, npoints int) *Curve

NewBezierQuadratic creates and returns a pointer to a new curve Uses Vector3 pointers origin, control, and destination to calculate with int npoints as the desired number of points along the curve

func NewCatmullRomSpline

func NewCatmullRomSpline(points []*Vector3, npoints int, closed bool) *Curve

NewCatmullRomSpline creates and returns a pointer to a new curve Uses array of Vector3 pointers with int npoints as the desired number of points between supplied points Use Boolean closed with true to close the start and end points

func NewHermiteSpline

func NewHermiteSpline(origin, tangent1, destination, tangent2 *Vector3, npoints int) *Curve

NewHermiteSpline creates and returns a pointer to a new curve Uses Vector3 pointers origin, tangent1, destination, and tangent2 to calculate with int npoints as the desired number of points along the curve

func (*Curve) Continue

func (c *Curve) Continue(other *Curve) *Curve

Continue combines two curves creates and returns a pointer to a new curve combined curves are unaffected

func (*Curve) GetLength

func (c *Curve) GetLength() float32

func (*Curve) GetPoints

func (c *Curve) GetPoints() []Vector3

func (*Curve) SetLength

func (c *Curve) SetLength()

type Frustum

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

Frustum represents a frustum

func NewFrustum

func NewFrustum(p0, p1, p2, p3, p4, p5 *Plane) *Frustum

NewFrustum returns a pointer to a new Frustum object

func NewFrustumFromMatrix

func NewFrustumFromMatrix(m *Matrix4) *Frustum

NewFrustumFromMatrix creates and returns a Frustum based on the provided matrix

func (*Frustum) Clone

func (f *Frustum) Clone() *Frustum

Clone returns a pointer to a new Frustum object with the same planes as the original

func (*Frustum) ContainsPoint

func (f *Frustum) ContainsPoint(point *Vector3) bool

ContainsPoint determines whether the frustum contains the specified point

func (*Frustum) Copy

func (f *Frustum) Copy(frustum *Frustum) *Frustum

Copy modifies the receiver frustum to match the provided frustum

func (*Frustum) IntersectsBox

func (f *Frustum) IntersectsBox(box *Box3) bool

IntersectsBox determines whether the specified box is intersecting the frustum

func (*Frustum) IntersectsSphere

func (f *Frustum) IntersectsSphere(sphere *Sphere) bool

IntersectsSphere determines whether the specified sphere is intersecting the frustum

func (*Frustum) Set

func (f *Frustum) Set(p0, p1, p2, p3, p4, p5 *Plane) *Frustum

Set sets the frustum's planes

func (*Frustum) SetFromMatrix

func (f *Frustum) SetFromMatrix(m *Matrix4) *Frustum

SetFromMatrix sets the frustum's planes based on the specified Matrix4

type Line3

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

Line3 represents a 3D line segment defined by a start and an end point.

func NewLine3

func NewLine3(start, end *Vector3) *Line3

NewLine3 creates and returns a pointer to a new Line3 with the specified start and end points.

func (*Line3) ApplyMatrix4

func (l *Line3) ApplyMatrix4(matrix *Matrix4) *Line3

ApplyMatrix4 applies the specified matrix to this line segment start and end points. Returns pointer to this updated line segment.

func (*Line3) Center

func (l *Line3) Center(optionalTarget *Vector3) *Vector3

Center calculates this line segment center point. Store its pointer into optionalTarget, if not nil, and also returns it.

func (*Line3) Clone

func (l *Line3) Clone() *Line3

Clone creates and returns a pointer to a copy of this line segment.

func (*Line3) Copy

func (l *Line3) Copy(other *Line3) *Line3

Copy copy other line segment to this one. Returns pointer to this updated line segment.

func (*Line3) Delta

func (l *Line3) Delta(optionalTarget *Vector3) *Vector3

Delta calculates the vector from the start to end point of this line segment. Store its pointer in optionalTarget, if not nil, and also returns it.

func (*Line3) Distance

func (l *Line3) Distance() float32

Distance returns the distance from the start point to the end point.

func (*Line3) DistanceSq

func (l *Line3) DistanceSq() float32

DistanceSq returns the square of the distance from the start point to the end point.

func (*Line3) Equals

func (l *Line3) Equals(other *Line3) bool

Equals returns if this line segement is equal to other.

func (*Line3) Set

func (l *Line3) Set(start, end *Vector3) *Line3

Set sets this line segment start and end points. Returns pointer to this updated line segment.

type Matrix3

type Matrix3 [9]float32

Matrix3 is 3x3 matrix organized internally as column matrix

func NewMatrix3

func NewMatrix3() *Matrix3

NewMatrix3 creates and returns a pointer to a new Matrix3 initialized as the identity matrix.

func (*Matrix3) ApplyToVector3Array

func (m *Matrix3) ApplyToVector3Array(array []float32, offset int, length int) []float32

ApplyToVector3Array multiplies length vectors in the array starting at offset by this matrix. Returns pointer to the updated array. This matrix is unchanged.

func (*Matrix3) Clone

func (m *Matrix3) Clone() *Matrix3

Clone creates and returns a pointer to a copy of this matrix.

func (*Matrix3) Copy

func (m *Matrix3) Copy(src *Matrix3) *Matrix3

Copy copies src matrix into this one. Returns the pointer to this updated matrix.

func (*Matrix3) Determinant

func (m *Matrix3) Determinant() float32

Determinant calculates and returns the determinant of this matrix.

func (*Matrix3) FromArray

func (m *Matrix3) FromArray(array []float32, offset int) *Matrix3

FromArray set this matrix array starting at offset. Returns pointer to this updated matrix.

func (*Matrix3) GetInverse

func (m *Matrix3) GetInverse(src *Matrix3) error

GetInverse sets this matrix to the inverse of the src matrix. If the src matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Matrix3) GetNormalMatrix

func (m *Matrix3) GetNormalMatrix(src *Matrix4) error

GetNormalMatrix set this matrix to the matrix to transform the normal vectors from the src matrix to transform the vertices. If the src matrix cannot be inverted returns error.

func (*Matrix3) Identity

func (m *Matrix3) Identity() *Matrix3

Identity sets this matrix as the identity matrix. Returns the pointer to this updated matrix.

func (*Matrix3) MakeRotationFromQuaternion

func (m *Matrix3) MakeRotationFromQuaternion(q *Quaternion) *Matrix3

MakeRotationFromQuaternion sets this matrix as a rotation matrix from the specified quaternion. Returns pointer to this updated matrix.

func (*Matrix3) Multiply

func (m *Matrix3) Multiply(other *Matrix3) *Matrix3

Multiply multiply this matrix by the other matrix Returns pointer to this updated matrix.

func (*Matrix3) MultiplyMatrices

func (m *Matrix3) MultiplyMatrices(a, b *Matrix3) *Matrix3

MultiplyMatrices multiply matrix a by b storing the result in this matrix. Returns pointer to this updated matrix.

func (*Matrix3) MultiplyScalar

func (m *Matrix3) MultiplyScalar(s float32) *Matrix3

MultiplyScalar multiplies each of this matrix's components by the specified scalar. Returns pointer to this updated matrix.

func (*Matrix3) ScaleColumns

func (m *Matrix3) ScaleColumns(v *Vector3) *Matrix3

ScaleColumns multiplies the matrix columns by the vector components. This can be used when multiplying this matrix by a diagonal matrix if we store the diagonal components as a vector. Returns pointer to this updated matrix.

func (*Matrix3) Set

func (m *Matrix3) Set(n11, n12, n13, n21, n22, n23, n31, n32, n33 float32) *Matrix3

Set sets all the elements of the matrix row by row starting at row1, column1, row1, column2, row1, column3 and so forth. Returns the pointer to this updated Matrix.

func (*Matrix3) SetFromMatrix4

func (m *Matrix3) SetFromMatrix4(src *Matrix4) *Matrix3

SetFromMatrix4 sets the matrix elements based on a Matrix4.

func (*Matrix3) ToArray

func (m *Matrix3) ToArray(array []float32, offset int) []float32

ToArray copies this matrix to array starting at offset. Returns pointer to the updated array.

func (*Matrix3) Transpose

func (m *Matrix3) Transpose() *Matrix3

Transpose transposes this matrix. Returns pointer to this updated matrix.

func (*Matrix3) Zero

func (m *Matrix3) Zero() *Matrix3

Zero sets this matrix as the zero matrix. Returns the pointer to this updated matrix.

type Matrix4

type Matrix4 [16]float32

Matrix4 is 4x4 matrix organized internally as column matrix.

func NewMatrix4

func NewMatrix4() *Matrix4

NewMatrix4 creates and returns a pointer to a new Matrix4 initialized as the identity matrix.

func (*Matrix4) ApplyToVector3Array

func (m *Matrix4) ApplyToVector3Array(array []float32, offset int, length int) []float32

ApplyToVector3Array multiplies length vectors in the array starting at offset by this matrix. Returns pointer to the updated array. This matrix is unchanged.

func (*Matrix4) Clone

func (m *Matrix4) Clone() *Matrix4

Clone creates and returns a pointer to a copy of this matrix.

func (*Matrix4) Compose

func (m *Matrix4) Compose(position *Vector3, quaternion *Quaternion, scale *Vector3) *Matrix4

Compose sets this matrix to a transformation matrix for the specified position, rotation specified by the quaternion and scale. Returns pointer to this updated matrix.

func (*Matrix4) Copy

func (m *Matrix4) Copy(src *Matrix4) *Matrix4

Copy copies src matrix into this one. Returns pointer to this updated matrix.

func (*Matrix4) CopyPosition

func (m *Matrix4) CopyPosition(src *Matrix4) *Matrix4

CopyPosition copies the position elements of the src matrix into this one. Returns pointer to this updated matrix.

func (*Matrix4) Decompose

func (m *Matrix4) Decompose(position *Vector3, quaternion *Quaternion, scale *Vector3) *Matrix4

Decompose updates the position vector, quaternion and scale from this transformation matrix. Returns pointer to this unchanged matrix.

func (*Matrix4) Determinant

func (m *Matrix4) Determinant() float32

Determinant calculates and returns the determinat of this matrix.

func (*Matrix4) ExtractBasis

func (m *Matrix4) ExtractBasis(xAxis, yAxis, zAxis *Vector3) *Matrix4

ExtractBasis updates the specified vectors with the basis vectors of this matrix. Returns pointer to this unchanged matrix.

func (*Matrix4) ExtractRotation

func (m *Matrix4) ExtractRotation(src *Matrix4) *Matrix4

ExtractRotation set this matrix as rotation matrix from the src transformation matrix. Returns pointer to this updated matrix.

func (*Matrix4) FromArray

func (m *Matrix4) FromArray(array []float32, offset int) *Matrix4

FromArray set this matrix elements from the array starting at offset. Returns pointer to this updated matrix.

func (*Matrix4) GetColumn

func (m *Matrix4) GetColumn(i int) *Vector4

GetColumn returns the ith column.

func (*Matrix4) GetColumnVector3

func (m *Matrix4) GetColumnVector3(i int) *Vector3

GetColumn returns the ith column.

func (*Matrix4) GetInverse

func (m *Matrix4) GetInverse(src *Matrix4) error

GetInverse sets this matrix to the inverse of the src matrix. If the src matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Matrix4) GetMaxScaleOnAxis

func (m *Matrix4) GetMaxScaleOnAxis() float32

GetMaxScaleOnAxis returns the maximum scale value of the 3 axes.

func (*Matrix4) GetRow

func (m *Matrix4) GetRow(i int) *Vector4

GetRow returns the ith row.

func (*Matrix4) GetRowVector3

func (m *Matrix4) GetRowVector3(i int) *Vector3

GetRow returns the ith row.

func (*Matrix4) Identity

func (m *Matrix4) Identity() *Matrix4

Identity sets this matrix as the identity matrix. Returns pointer to this updated matrix.

func (*Matrix4) LookAt

func (m *Matrix4) LookAt(eye, target, up *Vector3) *Matrix4

LookAt sets this matrix as view transform matrix with origin at eye, looking at target and using the up vector. Returns pointer to this updated matrix.

func (*Matrix4) MakeBasis

func (m *Matrix4) MakeBasis(xAxis, yAxis, zAxis *Vector3) *Matrix4

MakeBasis sets this matrix basis vectors from the specified vectors. Returns pointer to this updated matrix.

func (*Matrix4) MakeFrustum

func (m *Matrix4) MakeFrustum(left, right, bottom, top, near, far float32) *Matrix4

MakeFrustum sets this matrix to a projection frustum matrix bounded by the specified planes. Returns pointer to this updated matrix.

func (*Matrix4) MakeOrthographic

func (m *Matrix4) MakeOrthographic(left, right, top, bottom, near, far float32) *Matrix4

MakeOrthographic sets this matrix to an orthographic projection matrix bounded by the specified planes. Returns pointer to this updated matrix.

func (*Matrix4) MakePerspective

func (m *Matrix4) MakePerspective(fov, aspect, near, far float32) *Matrix4

MakePerspective sets this matrix to a perspective projection matrix with the specified vertical field of view in degrees, aspect ratio (width/height) and near and far planes. Returns pointer to this updated matrix.

func (*Matrix4) MakeRotationAxis

func (m *Matrix4) MakeRotationAxis(axis *Vector3, angle float32) *Matrix4

MakeRotationAxis sets this matrix to a rotation matrix of the specified angle around the specified axis. Returns pointer to this updated matrix.

func (*Matrix4) MakeRotationFromEuler

func (m *Matrix4) MakeRotationFromEuler(euler *Vector3) *Matrix4

MakeRotationFromEuler set this a matrix as a rotation matrix from the specified euler angles. Returns pointer to this updated matrix.

func (*Matrix4) MakeRotationFromQuaternion

func (m *Matrix4) MakeRotationFromQuaternion(q *Quaternion) *Matrix4

MakeRotationFromQuaternion sets this matrix as a rotation matrix from the specified quaternion. Returns pointer to this updated matrix.

func (*Matrix4) MakeRotationX

func (m *Matrix4) MakeRotationX(theta float32) *Matrix4

MakeRotationX sets this matrix to a rotation matrix of angle theta around the X axis. Returns pointer to this updated matrix.

func (*Matrix4) MakeRotationY

func (m *Matrix4) MakeRotationY(theta float32) *Matrix4

MakeRotationY sets this matrix to a rotation matrix of angle theta around the Y axis. Returns pointer to this updated matrix.

func (*Matrix4) MakeRotationZ

func (m *Matrix4) MakeRotationZ(theta float32) *Matrix4

MakeRotationZ sets this matrix to a rotation matrix of angle theta around the Z axis. Returns pointer to this updated matrix.

func (*Matrix4) MakeScale

func (m *Matrix4) MakeScale(x, y, z float32) *Matrix4

MakeScale sets this matrix to a scale transformation matrix using the specified x, y and z values. Returns pointer to this updated matrix.

func (*Matrix4) MakeTranslation

func (m *Matrix4) MakeTranslation(x, y, z float32) *Matrix4

MakeTranslation sets this matrix to a translation matrix from the specified x, y and z values. Returns pointer to this updated matrix.

func (*Matrix4) Multiply

func (m *Matrix4) Multiply(other *Matrix4) *Matrix4

Multiply multiply this matrix by the other matrix Returns pointer to this updated matrix.

func (*Matrix4) MultiplyMatrices

func (m *Matrix4) MultiplyMatrices(a, b *Matrix4) *Matrix4

MultiplyMatrices computes a * b, storing the result in this matrix. Returns pointer to this updated matrix.

func (*Matrix4) MultiplyScalar

func (m *Matrix4) MultiplyScalar(s float32) *Matrix4

MultiplyScalar multiplies each element of this matrix by the specified scalar. Returns pointer to this updated matrix.

func (*Matrix4) Scale

func (m *Matrix4) Scale(v *Vector3) *Matrix4

Scale multiply the first column of this matrix by the vector X component, the second column by the vector Y component and the third column by the vector Z component. The matrix fourth column is unchanged. Returns pointer to this updated matrix.

func (*Matrix4) Set

func (m *Matrix4) Set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 float32) *Matrix4

Set sets all the elements of this matrix row by row starting at row1, column1, row1, column2, row1, column3 and so forth. Returns pointer to this updated Matrix.

func (*Matrix4) SetPosition

func (m *Matrix4) SetPosition(v *Vector3) *Matrix4

SetPosition sets this transformation matrix position fields from the specified vector v. Returns pointer to this updated matrix.

func (*Matrix4) ToArray

func (m *Matrix4) ToArray(array []float32, offset int) []float32

ToArray copies this matrix elements to array starting at offset. Returns pointer to the updated array.

func (*Matrix4) Transpose

func (m *Matrix4) Transpose() *Matrix4

Transpose transposes this matrix. Returns pointer to this updated matrix.

func (*Matrix4) Zero

func (m *Matrix4) Zero() *Matrix4

Zero sets this matrix as the zero matrix. Returns the pointer to this updated matrix.

type Plane

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

Plane represents a plane in 3D space by its normal vector and a constant. When the the normal vector is the unit vector the constant is the distance from the origin.

func NewPlane

func NewPlane(normal *Vector3, constant float32) *Plane

NewPlane creates and returns a new plane from a normal vector and a constant.

func (*Plane) Clone

func (p *Plane) Clone(plane *Plane) *Plane

Clone creates and returns a pointer to a copy of this plane.

func (*Plane) CoplanarPoint

func (p *Plane) CoplanarPoint(optionalTarget *Vector3) *Vector3

CoplanarPoint sets the optionalTarget to a point in the plane and also returns it. The point set and returned is the closest point from the origin.

func (*Plane) Copy

func (p *Plane) Copy(other *Plane) *Plane

Copy sets this plane to a copy of other. Returns pointer to this updated plane.

func (*Plane) DistanceToPoint

func (p *Plane) DistanceToPoint(point *Vector3) float32

DistanceToPoint returns the distance of this plane from point.

func (*Plane) DistanceToSphere

func (p *Plane) DistanceToSphere(sphere *Sphere) float32

DistanceToSphere returns the distance of this place from the sphere.

func (*Plane) Equals

func (p *Plane) Equals(other *Plane) bool

Equals returns if this plane is equal to other

func (*Plane) IntersectLine

func (p *Plane) IntersectLine(line *Line3, optionalTarget *Vector3) *Vector3

IntersectLine calculates the point in the plane which intersets the specified line. Sets the optionalTarget, if not nil to this point, and also returns it. Returns nil if the line does not intersects the plane.

func (*Plane) IsIntersectionLine

func (p *Plane) IsIntersectionLine(line *Line3) bool

IsIntersectionLine returns the line intersects this plane.

func (*Plane) Negate

func (p *Plane) Negate() *Plane

Negate negates this plane normal. Returns pointer to this updated plane.

func (*Plane) Normalize

func (p *Plane) Normalize() *Plane

Normalize normalizes this plane normal vector and adjusts the constant. Note: will lead to a divide by zero if the plane is invalid. Returns pointer to this updated plane.

func (*Plane) Set

func (p *Plane) Set(normal *Vector3, constant float32) *Plane

Set sets this plane normal vector and constant. Returns pointer to this updated plane.

func (*Plane) SetComponents

func (p *Plane) SetComponents(x, y, z, w float32) *Plane

SetComponents sets this plane normal vector components and constant. Returns pointer to this updated plane.

func (*Plane) SetFromCoplanarPoints

func (p *Plane) SetFromCoplanarPoints(a, b, c *Vector3) *Plane

SetFromCoplanarPoints sets this plane from three coplanar points. Returns pointer to this updated plane.

func (*Plane) SetFromNormalAndCoplanarPoint

func (p *Plane) SetFromNormalAndCoplanarPoint(normal *Vector3, point *Vector3) *Plane

SetFromNormalAndCoplanarPoint sets this plane from a normal vector and a point on the plane. Returns pointer to this updated plane.

func (*Plane) Translate

func (p *Plane) Translate(offset *Vector3) *Plane

Translate translates this plane in the direction of its normal by offset. Returns pointer to this updated plane.

type Quaternion

type Quaternion struct {
	X float32
	Y float32
	Z float32
	W float32
}

Quaternion is quaternion with X,Y,Z and W components.

func NewQuaternion

func NewQuaternion(x, y, z, w float32) *Quaternion

NewQuaternion creates and returns a pointer to a new quaternion from the specified components.

func (*Quaternion) Clone

func (q *Quaternion) Clone() *Quaternion

Clone returns a copy of this quaternion

func (*Quaternion) Conjugate

func (q *Quaternion) Conjugate() *Quaternion

Conjugate sets this quaternion to its conjugate. Returns pointer to this updated quaternion.

func (*Quaternion) Copy

func (q *Quaternion) Copy(other *Quaternion) *Quaternion

Copy copies the other quaternion into this one. Returns pointer to this updated quaternion.

func (*Quaternion) Dot

func (q *Quaternion) Dot(other *Quaternion) float32

Dot returns the dot products of this quaternion with other.

func (*Quaternion) Equals

func (q *Quaternion) Equals(other *Quaternion) bool

Equals returns if this quaternion is equal to other.

func (*Quaternion) FromArray

func (q *Quaternion) FromArray(array []float32, offset int) *Quaternion

FromArray sets this quaternion's components from array starting at offset. Returns pointer to this updated quaternion.

func (*Quaternion) Inverse

func (q *Quaternion) Inverse() *Quaternion

Inverse sets this quaternion to its inverse. Returns pointer to this updated quaternion.

func (*Quaternion) IsIdentity

func (q *Quaternion) IsIdentity() bool

IsIdentity returns it this is an identity quaternion.

func (*Quaternion) Length

func (q *Quaternion) Length() float32

Length returns the length of this quaternion

func (*Quaternion) Multiply

func (q *Quaternion) Multiply(other *Quaternion) *Quaternion

Multiply sets this quaternion to the multiplication of itself by other. Returns pointer to this updated quaternion.

func (*Quaternion) MultiplyQuaternions

func (q *Quaternion) MultiplyQuaternions(a, b *Quaternion) *Quaternion

MultiplyQuaternions set this quaternion to the multiplication of a by b. Returns pointer to this updated quaternion.

func (*Quaternion) Normalize

func (q *Quaternion) Normalize() *Quaternion

Normalize normalizes this quaternion. Returns pointer to this updated quaternion.

func (*Quaternion) NormalizeFast

func (q *Quaternion) NormalizeFast() *Quaternion

NormalizeFast approximates normalizing this quaternion. Works best when the quaternion is already almost-normalized. Returns pointer to this updated quaternion.

func (*Quaternion) Set

func (q *Quaternion) Set(x, y, z, w float32) *Quaternion

Set sets this quaternion's components. Returns pointer to this updated quaternion.

func (*Quaternion) SetFromAxisAngle

func (q *Quaternion) SetFromAxisAngle(axis *Vector3, angle float32) *Quaternion

SetFromAxisAngle sets this quaternion with the rotation specified by the given axis and angle. Returns pointer to this updated quaternion.

func (*Quaternion) SetFromEuler

func (q *Quaternion) SetFromEuler(euler *Vector3) *Quaternion

SetFromEuler sets this quaternion from the specified vector with euler angles for each axis. It is assumed that the Euler angles are in XYZ order. Returns pointer to this updated quaternion.

func (*Quaternion) SetFromRotationMatrix

func (q *Quaternion) SetFromRotationMatrix(m *Matrix4) *Quaternion

SetFromRotationMatrix sets this quaternion from the specified rotation matrix. Returns pointer to this updated quaternion.

func (*Quaternion) SetFromUnitVectors

func (q *Quaternion) SetFromUnitVectors(vFrom, vTo *Vector3) *Quaternion

SetFromUnitVectors sets this quaternion to the rotation from vector vFrom to vTo. The vectors must be normalized. Returns pointer to this updated quaternion.

func (*Quaternion) SetIdentity

func (q *Quaternion) SetIdentity() *Quaternion

SetIdentity sets this quanternion to the identity quaternion. Returns pointer to this updated quaternion.

func (*Quaternion) SetW

func (q *Quaternion) SetW(val float32) *Quaternion

SetW sets this quaternion's W component. Returns pointer to this updated quaternion.

func (*Quaternion) SetX

func (q *Quaternion) SetX(val float32) *Quaternion

SetX sets this quaternion's X component. Returns pointer to this updated quaternion.

func (*Quaternion) SetY

func (q *Quaternion) SetY(val float32) *Quaternion

SetY sets this quaternion's Y component. Returns pointer to this updated quaternion.

func (*Quaternion) SetZ

func (q *Quaternion) SetZ(val float32) *Quaternion

SetZ sets this quaternion's Z component. Returns pointer to this updated quaternion.

func (*Quaternion) Slerp

func (q *Quaternion) Slerp(other *Quaternion, t float32) *Quaternion

Slerp sets this quaternion to another quaternion which is the spherically linear interpolation from this quaternion to other using t. Returns pointer to this updated quaternion.

func (*Quaternion) ToArray

func (q *Quaternion) ToArray(array []float32, offset int) []float32

ToArray copies this quaternions's components to array starting at offset. Returns pointer to this updated array.

type Ray

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

Ray represents an oriented 3D line segment defined by an origin point and a direction vector.

func NewRay

func NewRay(origin *Vector3, direction *Vector3) *Ray

NewRay creates and returns a pointer to a Ray object with the specified origin and direction vectors. If a nil pointer is supplied for any of the parameters, the zero vector will be used.

func (*Ray) ApplyMatrix4

func (ray *Ray) ApplyMatrix4(matrix4 *Matrix4) *Ray

ApplyMatrix4 multiplies this ray origin and direction by the specified matrix4, basically transforming this ray coordinates.

func (*Ray) At

func (ray *Ray) At(t float32, optionalTarget *Vector3) *Vector3

At calculates the point in the ray which is at the specified t distance from the origin along its direction. The calculated point is stored in optionalTarget, if not nil, and also returned.

func (*Ray) Clone

func (ray *Ray) Clone() *Ray

Clone creates and returns a pointer to copy of this ray.

func (*Ray) ClosestPointToPoint

func (ray *Ray) ClosestPointToPoint(point, optionalTarget *Vector3) *Vector3

ClosestPointToPoint calculates the point in the ray which is closest to the specified point. The calculated point is stored in optionalTarget, if not nil, and also returned.

func (*Ray) Copy

func (ray *Ray) Copy(other *Ray) *Ray

Copy copies other ray into this one.

func (*Ray) Direction

func (ray *Ray) Direction() Vector3

Direction returns a copy of this ray current direction.

func (*Ray) DistanceSqToPoint

func (ray *Ray) DistanceSqToPoint(point *Vector3) float32

DistanceSqToPoint returns the smallest squared distance from the ray direction vector to the specified point. If the ray was pointed directly at the point this distance would be 0.

func (*Ray) DistanceSqToSegment

func (ray *Ray) DistanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment *Vector3) float32

DistanceSqToSegment returns the smallest squared distance from this ray to the line segment from v0 to v1. If optionalPointOnRay Vector3 is not nil, it is set with the coordinates of the point on the ray. if optionalPointOnSegment Vector3 is not nil, it is set with the coordinates of the point on the segment.

func (*Ray) DistanceToPlane

func (ray *Ray) DistanceToPlane(plane *Plane) float32

DistanceToPlane returns the distance of this ray origin to its intersection point in the plane. If the ray does not intersects the plane, returns NaN.

func (*Ray) DistanceToPoint

func (ray *Ray) DistanceToPoint(point *Vector3) float32

DistanceToPoint returns the smallest distance from the ray direction vector to the specified point.

func (*Ray) Equals

func (ray *Ray) Equals(other *Ray) bool

Equals returns if this ray is equal to other

func (*Ray) IntersectBox

func (ray *Ray) IntersectBox(box *Box3, optionalTarget *Vector3) *Vector3

IntersectBox calculates the point which is the intersection of this ray with the specified box. The calculated point is stored in optionalTarget, it not nil, and also returned. If no intersection is found the calculated point is set to nil.

func (*Ray) IntersectPlane

func (ray *Ray) IntersectPlane(plane *Plane, optionalTarget *Vector3) *Vector3

IntersectPlane calculates the point which is the intersection of this ray with the specified plane. The calculated point is stored in optionalTarget, if not nil, and also returned. If no intersection is found the calculated point is set to nil.

func (*Ray) IntersectSphere

func (ray *Ray) IntersectSphere(sphere *Sphere, optionalTarget *Vector3) *Vector3

IntersectSphere calculates the point which is the intersection of this ray with the specified sphere. The calculated point is stored in optionalTarget, it not nil, and also returned. If no intersection is found the calculated point is set to nil.

func (*Ray) IntersectTriangle

func (ray *Ray) IntersectTriangle(a, b, c *Vector3, backfaceCulling bool, point *Vector3) bool

IntersectTriangle returns if this ray intersects the triangle with the face defined by points a, b, c. Returns true if it intersects and sets the point parameter with the intersected point coordinates. If backfaceCulling is false it ignores the intersection if the face is not oriented in the ray direction.

func (*Ray) IsIntersectPlane

func (ray *Ray) IsIntersectPlane(plane *Plane) bool

IsIntersectPlane returns if this ray intersects the specified plane.

func (*Ray) IsIntersectionBox

func (ray *Ray) IsIntersectionBox(box *Box3) bool

IsIntersectionBox returns if this ray intersects the specified box.

func (*Ray) IsIntersectionSphere

func (ray *Ray) IsIntersectionSphere(sphere *Sphere) bool

IsIntersectionSphere returns if this ray intersects with the specified sphere.

func (*Ray) Origin

func (ray *Ray) Origin() Vector3

Origin returns a copy of this ray current origin.

func (*Ray) Recast

func (ray *Ray) Recast(t float32) *Ray

Recast sets the new origin of the ray at the specified distance t from its origin along its direction.

func (*Ray) Set

func (ray *Ray) Set(origin, direction *Vector3) *Ray

Set sets the origin and direction vectors of this Ray.

type Sphere

type Sphere struct {
	Center Vector3 // center of the sphere
	Radius float32 // radius of the sphere
}

Sphere represents a 3D sphere defined by its center point and a radius

func NewSphere

func NewSphere(center *Vector3, radius float32) *Sphere

NewSphere creates and returns a pointer to a new sphere with the specified center and radius.

func (*Sphere) ApplyMatrix4

func (s *Sphere) ApplyMatrix4(matrix *Matrix4) *Sphere

ApplyMatrix4 applies the specified matrix transform to this sphere. Returns pointer to this updated sphere.

func (*Sphere) ClampPoint

func (s *Sphere) ClampPoint(point *Vector3, optionalTarget *Vector3) *Vector3

ClampPoint clamps the specified point inside the sphere. If the specified point is inside the sphere, it is the clamped point. Otherwise the clamped point is the the point in the sphere surface in the nearest of the specified point. The clamped point is stored in optionalTarget, if not nil, and returned.

func (*Sphere) ContainsPoint

func (s *Sphere) ContainsPoint(point *Vector3) bool

ContainsPoint returns if this sphere contains the specified point.

func (*Sphere) Copy

func (s *Sphere) Copy(other *Sphere) *Sphere

Copy copy other sphere to this one. Returns pointer to this update sphere.

func (*Sphere) DistanceToPoint

func (s *Sphere) DistanceToPoint(point *Vector3) float32

DistanceToPoint returns the distance from the sphere surface to the specified point.

func (*Sphere) Empty

func (s *Sphere) Empty(sphere *Sphere) bool

Empty checks if this sphere is empty (radius <= 0)

func (*Sphere) GetBoundingBox

func (s *Sphere) GetBoundingBox(optionalTarget *Box3) *Box3

GetBoundingBox calculates a Box3 which bounds this sphere. Update optionalTarget with the calculated Box3, if not nil, and also returns it.

func (*Sphere) IntersectSphere

func (s *Sphere) IntersectSphere(other *Sphere) bool

IntersectSphere returns if other sphere intersects this one.

func (*Sphere) Set

func (s *Sphere) Set(center *Vector3, radius float32) *Sphere

Set sets the center and radius of this sphere. Returns pointer to this update sphere.

func (*Sphere) SetFromPoints

func (s *Sphere) SetFromPoints(points []Vector3, optionalCenter *Vector3) *Sphere

SetFromPoints sets this sphere from the specified points array and optional center. Returns pointer to this update sphere.

func (*Sphere) Translate

func (s *Sphere) Translate(offset *Vector3) *Sphere

Translate translates this sphere by the specified offset. Returns pointer to this updated sphere.

type Spline

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

func NewSpline

func NewSpline(points []Vector3) *Spline

func (*Spline) InitFromArray

func (this *Spline) InitFromArray(a []float32)

type Triangle

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

Triangle represents a triangle made of three vertices.

func NewTriangle

func NewTriangle(a, b, c *Vector3) *Triangle

NewTriangle returns a pointer to a new Triangle object.

func (*Triangle) Area

func (t *Triangle) Area() float32

Area returns the triangle's area.

func (*Triangle) BarycoordFromPoint

func (t *Triangle) BarycoordFromPoint(point, optionalTarget *Vector3) *Vector3

BarycoordFromPoint returns the barycentric coordinates for the specified point.

func (*Triangle) Clone

func (t *Triangle) Clone(triangle *Triangle) *Triangle

Clone clones a triangle.

func (*Triangle) ContainsPoint

func (t *Triangle) ContainsPoint(point *Vector3) bool

ContainsPoint returns whether the triangle contains a point.

func (*Triangle) Copy

func (t *Triangle) Copy(triangle *Triangle) *Triangle

Copy modifies the receiver triangle to match the provided triangle.

func (*Triangle) Equals

func (t *Triangle) Equals(triangle *Triangle) bool

Equals returns whether the triangles are equal in all their vertices.

func (*Triangle) Midpoint

func (t *Triangle) Midpoint(optionalTarget *Vector3) *Vector3

Midpoint returns the triangle's midpoint.

func (*Triangle) Normal

func (t *Triangle) Normal(optionalTarget *Vector3) *Vector3

Normal returns the triangle's normal.

func (*Triangle) Plane

func (t *Triangle) Plane(optionalTarget *Plane) *Plane

Plane returns a Plane object aligned with the triangle.

func (*Triangle) Set

func (t *Triangle) Set(a, b, c *Vector3) *Triangle

Set sets the triangle's three vertices.

func (*Triangle) SetFromPointsAndIndices

func (t *Triangle) SetFromPointsAndIndices(points []*Vector3, i0, i1, i2 int) *Triangle

SetFromPointsAndIndices sets the triangle's vertices based on the specified points and indices.

type Vector2

type Vector2 struct {
	X float32
	Y float32
}

Vector2 is a 2D vector/point with X and Y components.

func NewVec2

func NewVec2() *Vector2

NewVec2 creates and returns a pointer to a new zero-ed Vector2.

func NewVector2

func NewVector2(x, y float32) *Vector2

NewVector2 creates and returns a pointer to a new Vector2 with the specified x and y components

func (*Vector2) Add

func (v *Vector2) Add(other *Vector2) *Vector2

Add adds other vector to this one. Returns the pointer to this updated vector.

func (*Vector2) AddScalar

func (v *Vector2) AddScalar(s float32) *Vector2

AddScalar adds scalar s to each component of this vector. Returns the pointer to this updated vector.

func (*Vector2) AddVectors

func (v *Vector2) AddVectors(a, b *Vector2) *Vector2

AddVectors adds vectors a and b to this one. Returns the pointer to this updated vector.

func (*Vector2) AlmostEquals

func (v *Vector2) AlmostEquals(other *Vector2, tolerance float32) bool

AlmostEquals returns whether the vector is almost equal to another vector within the specified tolerance.

func (*Vector2) Ceil

func (v *Vector2) Ceil() *Vector2

Ceil applies math32.Ceil() to each of this vector's components. Returns the pointer to this updated vector.

func (*Vector2) Clamp

func (v *Vector2) Clamp(min, max *Vector2) *Vector2

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding components of max. Assumes min < max, if this assumption isn't true it will not operate correctly. Returns the pointer to this updated vector.

func (*Vector2) ClampScalar

func (v *Vector2) ClampScalar(minVal, maxVal float32) *Vector2

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal. Returns the pointer to this updated vector.

func (*Vector2) Clone

func (v *Vector2) Clone() *Vector2

Clone returns a copy of this vector

func (*Vector2) Component

func (v *Vector2) Component(index int) float32

Component returns this vector component by its index: 0 for X, 1 for Y

func (*Vector2) Copy

func (v *Vector2) Copy(other *Vector2) *Vector2

Copy copies other vector to this one. It is equivalent to: *v = *other. Returns the pointer to this updated vector.

func (*Vector2) DistanceTo

func (v *Vector2) DistanceTo(other *Vector2) float32

DistanceTo returns the distance of this point to other.

func (*Vector2) DistanceToSquared

func (v *Vector2) DistanceToSquared(other *Vector2) float32

DistanceToSquared returns the distance squared of this point to other.

func (*Vector2) Divide

func (v *Vector2) Divide(other *Vector2) *Vector2

Divide divides each component of this vector by the corresponding one from other vector. Returns the pointer to this updated vector

func (*Vector2) DivideScalar

func (v *Vector2) DivideScalar(scalar float32) *Vector2

DivideScalar divides each component of this vector by the scalar s. If scalar is zero, sets this vector to zero. Returns the pointer to this updated vector.

func (*Vector2) Dot

func (v *Vector2) Dot(other *Vector2) float32

Dot returns the dot product of this vector with other. None of the vectors are changed.

func (*Vector2) Equals

func (v *Vector2) Equals(other *Vector2) bool

Equals returns if this vector is equal to other.

func (*Vector2) Floor

func (v *Vector2) Floor() *Vector2

Floor applies math32.Floor() to each of this vector's components. Returns the pointer to this updated vector.

func (*Vector2) FromArray

func (v *Vector2) FromArray(array []float32, offset int) *Vector2

FromArray sets this vector's components from the specified array and offset Returns the pointer to this updated vector.

func (*Vector2) InTriangle

func (v *Vector2) InTriangle(p0, p1, p2 *Vector2) bool

InTriangle returns whether the vector is inside the specified triangle.

func (*Vector2) Length

func (v *Vector2) Length() float32

Length returns the length of this vector.

func (*Vector2) LengthSq

func (v *Vector2) LengthSq() float32

LengthSq returns the length squared of this vector. LengthSq can be used to compare vectors' lengths without the need to perform a square root.

func (*Vector2) Lerp

func (v *Vector2) Lerp(other *Vector2, alpha float32) *Vector2

Lerp sets each of this vector's components to the linear interpolated value of alpha between ifself and the corresponding other component. Returns the pointer to this updated vector.

func (*Vector2) Max

func (v *Vector2) Max(other *Vector2) *Vector2

Max sets this vector components to the maximum value of itself and other vector. Returns the pointer to this updated vector.

func (*Vector2) Min

func (v *Vector2) Min(other *Vector2) *Vector2

Min sets this vector components to the minimum values of itself and other vector. Returns the pointer to this updated vector.

func (*Vector2) Multiply

func (v *Vector2) Multiply(other *Vector2) *Vector2

Multiply multiplies each component of this vector by the corresponding one from other vector. Returns the pointer to this updated vector.

func (*Vector2) MultiplyScalar

func (v *Vector2) MultiplyScalar(s float32) *Vector2

MultiplyScalar multiplies each component of this vector by the scalar s. Returns the pointer to this updated vector.

func (*Vector2) Negate

func (v *Vector2) Negate() *Vector2

Negate negates each of this vector's components. Returns the pointer to this updated vector.

func (*Vector2) Normalize

func (v *Vector2) Normalize() *Vector2

Normalize normalizes this vector so its length will be 1. Returns the pointer to this updated vector.

func (*Vector2) Round

func (v *Vector2) Round() *Vector2

Round rounds each of this vector's components. Returns the pointer to this updated vector.

func (*Vector2) Set

func (v *Vector2) Set(x, y float32) *Vector2

Set sets this vector X and Y components. Returns the pointer to this updated vector.

func (*Vector2) SetByName

func (v *Vector2) SetByName(name string, value float32)

SetByName sets this vector component value by its case insensitive name: "x" or "y".

func (*Vector2) SetComponent

func (v *Vector2) SetComponent(index int, value float32) *Vector2

SetComponent sets this vector component value by its index: 0 for X, 1 for Y. Returns the pointer to this updated vector

func (*Vector2) SetLength

func (v *Vector2) SetLength(l float32) *Vector2

SetLength sets this vector to have the specified length. Returns the pointer to this updated vector.

func (*Vector2) SetX

func (v *Vector2) SetX(x float32) *Vector2

SetX sets this vector X component. Returns the pointer to this updated Vector.

func (*Vector2) SetY

func (v *Vector2) SetY(y float32) *Vector2

SetY sets this vector Y component. Returns the pointer to this updated vector.

func (*Vector2) Sub

func (v *Vector2) Sub(other *Vector2) *Vector2

Sub subtracts other vector from this one. Returns the pointer to this updated vector.

func (*Vector2) SubScalar

func (v *Vector2) SubScalar(s float32) *Vector2

SubScalar subtracts scalar s from each component of this vector. Returns the pointer to this updated vector.

func (*Vector2) SubVectors

func (v *Vector2) SubVectors(a, b *Vector2) *Vector2

SubVectors sets this vector to a - b. Returns the pointer to this updated vector.

func (*Vector2) ToArray

func (v *Vector2) ToArray(array []float32, offset int) []float32

ToArray copies this vector's components to array starting at offset. Returns the array.

func (*Vector2) Zero

func (v *Vector2) Zero() *Vector2

Zero sets this vector X and Y components to be zero. Returns the pointer to this updated vector.

type Vector3

type Vector3 struct {
	X float32
	Y float32
	Z float32
}

Vector3 is a 3D vector/point with X, Y and Z components.

func BarycoordFromPoint

func BarycoordFromPoint(point, a, b, c, optionalTarget *Vector3) *Vector3

BarycoordFromPoint returns the barycentric coordinates for the specified point.

func NewVec3

func NewVec3() *Vector3

NewVec3 creates and returns a pointer to a new zero-ed Vector3.

func NewVector3

func NewVector3(x, y, z float32) *Vector3

NewVector3 creates and returns a pointer to a new Vector3 with the specified x, y and y components

func Normal

func Normal(a, b, c, optionalTarget *Vector3) *Vector3

Normal returns the triangle's normal.

func (*Vector3) Add

func (v *Vector3) Add(other *Vector3) *Vector3

Add adds other vector to this one. Returns the pointer to this updated vector.

func (*Vector3) AddScalar

func (v *Vector3) AddScalar(s float32) *Vector3

AddScalar adds scalar s to each component of this vector. Returns the pointer to this updated vector.

func (*Vector3) AddVectors

func (v *Vector3) AddVectors(a, b *Vector3) *Vector3

AddVectors adds vectors a and b to this one. Returns the pointer to this updated vector.

func (*Vector3) AlmostEquals

func (v *Vector3) AlmostEquals(other *Vector3, tolerance float32) bool

TODO: implement similar methods for Vector2 and Vector4 AlmostEquals returns whether the vector is almost equal to another vector within the specified tolerance.

func (*Vector3) AngleTo

func (v *Vector3) AngleTo(other *Vector3) float32

AngleTo returns the angle between this vector and other

func (*Vector3) ApplyAxisAngle

func (v *Vector3) ApplyAxisAngle(axis *Vector3, angle float32) *Vector3

ApplyAxisAngle rotates the vector around axis by angle. Returns the pointer to this updated vector.

func (*Vector3) ApplyMatrix3

func (v *Vector3) ApplyMatrix3(m *Matrix3) *Vector3

ApplyMatrix3 multiplies the specified 3x3 matrix by this vector. Returns the pointer to this updated vector.

func (*Vector3) ApplyMatrix4

func (v *Vector3) ApplyMatrix4(m *Matrix4) *Vector3

ApplyMatrix4 multiplies the specified 4x4 matrix by this vector. Returns the pointer to this updated vector.

func (*Vector3) ApplyProjection

func (v *Vector3) ApplyProjection(m *Matrix4) *Vector3

ApplyProjection applies the projection matrix m to this vector Returns the pointer to this updated vector.

func (*Vector3) ApplyQuaternion

func (v *Vector3) ApplyQuaternion(q *Quaternion) *Vector3

ApplyQuaternion transforms this vector by multiplying it by the specified quaternion and then by the quaternion inverse. It basically applies the rotation encoded in the quaternion to this vector. Returns the pointer to this updated vector.

func (*Vector3) Ceil

func (v *Vector3) Ceil() *Vector3

Ceil applies math32.Ceil() to each of this vector's components. Returns the pointer to this updated vector.

func (*Vector3) Clamp

func (v *Vector3) Clamp(min, max *Vector3) *Vector3

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly. Returns the pointer to this updated vector.

func (*Vector3) ClampScalar

func (v *Vector3) ClampScalar(minVal, maxVal float32) *Vector3

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal. Returns the pointer to this updated vector.

func (*Vector3) Clone

func (v *Vector3) Clone() *Vector3

Clone returns a copy of this vector

func (*Vector3) Component

func (v *Vector3) Component(index int) float32

Component returns this vector component by its index: 0 for X, 1 for Y, 2 for Z.

func (*Vector3) Copy

func (v *Vector3) Copy(other *Vector3) *Vector3

Copy copies other vector to this one. It is equivalent to: *v = *other. Returns the pointer to this updated vector.

func (*Vector3) Cross

func (v *Vector3) Cross(other *Vector3) *Vector3

Cross calculates the cross product of this vector with other and returns the result vector.

func (*Vector3) CrossVectors

func (v *Vector3) CrossVectors(a, b *Vector3) *Vector3

CrossVectors calculates the cross product of a and b storing the result in this vector. Returns the pointer to this updated vector.

func (*Vector3) DistanceTo

func (v *Vector3) DistanceTo(other *Vector3) float32

DistanceTo returns the distance of this point to other.

func (*Vector3) DistanceToSquared

func (v *Vector3) DistanceToSquared(other *Vector3) float32

DistanceToSquared returns the distance squared of this point to other.

func (*Vector3) Divide

func (v *Vector3) Divide(other *Vector3) *Vector3

Divide divides each component of this vector by the corresponding one from other vector. Returns the pointer to this updated vector

func (*Vector3) DivideScalar

func (v *Vector3) DivideScalar(scalar float32) *Vector3

DivideScalar divides each component of this vector by the scalar s. If scalar is zero, sets this vector to zero. Returns the pointer to this updated vector.

func (*Vector3) Dot

func (v *Vector3) Dot(other *Vector3) float32

Dot returns the dot product of this vector with other. None of the vectors are changed.

func (*Vector3) Equals

func (v *Vector3) Equals(other *Vector3) bool

Equals returns if this vector is equal to other.

func (*Vector3) Floor

func (v *Vector3) Floor() *Vector3

Floor applies math32.Floor() to each of this vector's components. Returns the pointer to this updated vector.

func (*Vector3) FromArray

func (v *Vector3) FromArray(array []float32, offset int) *Vector3

FromArray sets this vector's components from the specified array and offset Returns the pointer to this updated vector.

func (*Vector3) Length

func (v *Vector3) Length() float32

Length returns the length of this vector.

func (*Vector3) LengthSq

func (v *Vector3) LengthSq() float32

LengthSq returns the length squared of this vector. LengthSq can be used to compare vectors' lengths without the need to perform a square root.

func (*Vector3) Lerp

func (v *Vector3) Lerp(other *Vector3, alpha float32) *Vector3

Lerp sets each of this vector's components to the linear interpolated value of alpha between itself and the corresponding other component. Returns the pointer to this updated vector.

func (*Vector3) Max

func (v *Vector3) Max(other *Vector3) *Vector3

Max sets this vector components to the maximum value of itself and other vector. Returns the pointer to this updated vector.

func (*Vector3) Min

func (v *Vector3) Min(other *Vector3) *Vector3

Min sets this vector components to the minimum values of itself and other vector. Returns the pointer to this updated vector.

func (*Vector3) Multiply

func (v *Vector3) Multiply(other *Vector3) *Vector3

Multiply multiplies each component of this vector by the corresponding one from other vector. Returns the pointer to this updated vector.

func (*Vector3) MultiplyScalar

func (v *Vector3) MultiplyScalar(s float32) *Vector3

MultiplyScalar multiplies each component of this vector by the scalar s. Returns the pointer to this updated vector.

func (*Vector3) MultiplyVectors

func (v *Vector3) MultiplyVectors(a, b *Vector3) *Vector3

MultiplyVectors multiply vectors a and b storing the result in this vector. Returns the pointer to this updated vector.

func (*Vector3) Negate

func (v *Vector3) Negate() *Vector3

Negate negates each of this vector's components. Returns the pointer to this updated vector.

func (*Vector3) Normalize

func (v *Vector3) Normalize() *Vector3

Normalize normalizes this vector so its length will be 1. Returns the pointer to this updated vector.

func (*Vector3) ProjectOnPlane

func (v *Vector3) ProjectOnPlane(planeNormal *Vector3) *Vector3

ProjectOnPlane sets this vector to its projection on the plane specified by its normal vector. Returns the pointer to this updated vector.

func (*Vector3) ProjectOnVector

func (v *Vector3) ProjectOnVector(other *Vector3) *Vector3

ProjectOnVector sets this vector to its projection on other vector. Returns the pointer to this updated vector.

func (*Vector3) RandomTangents

func (v *Vector3) RandomTangents() (*Vector3, *Vector3)

RandomTangents computes and returns two arbitrary tangents to the vector.

func (*Vector3) Reflect

func (v *Vector3) Reflect(normal *Vector3) *Vector3

Reflect sets this vector to its reflection relative to the normal vector. The normal vector is assumed to be normalized. Returns the pointer to this updated vector.

func (*Vector3) Round

func (v *Vector3) Round() *Vector3

Round rounds each of this vector's components. Returns the pointer to this updated vector.

func (*Vector3) Set

func (v *Vector3) Set(x, y, z float32) *Vector3

Set sets this vector X, Y and Z components. Returns the pointer to this updated vector.

func (*Vector3) SetByName

func (v *Vector3) SetByName(name string, value float32)

SetByName sets this vector component value by its case insensitive name: "x", "y", or "z".

func (*Vector3) SetComponent

func (v *Vector3) SetComponent(index int, value float32)

SetComponent sets this vector component value by its index: 0 for X, 1 for Y, 2 for Z. Returns the pointer to this updated vector

func (*Vector3) SetFromMatrixColumn

func (v *Vector3) SetFromMatrixColumn(index int, m *Matrix4) *Vector3

SetFromMatrixColumn set this vector with the column at index of the m matrix. Returns the pointer to this updated vector.

func (*Vector3) SetFromMatrixPosition

func (v *Vector3) SetFromMatrixPosition(m *Matrix4) *Vector3

SetFromMatrixPosition set this vector from the translation coordinates in the specified transformation matrix.

func (*Vector3) SetFromQuaternion

func (v *Vector3) SetFromQuaternion(q *Quaternion) *Vector3

SetFromQuaternion sets this vector components to the Euler angles from the specified quaternion Returns the pointer to this updated vector.

func (*Vector3) SetFromRotationMatrix

func (v *Vector3) SetFromRotationMatrix(m *Matrix4) *Vector3

SetFromRotationMatrix sets this vector components to the Euler angles from the specified pure rotation matrix. Returns the pointer to this updated vector.

func (*Vector3) SetLength

func (v *Vector3) SetLength(l float32) *Vector3

SetLength sets this vector to have the specified length. If the current length is zero, does nothing. Returns the pointer to this updated vector.

func (*Vector3) SetX

func (v *Vector3) SetX(x float32) *Vector3

SetX sets this vector X component. Returns the pointer to this updated Vector.

func (*Vector3) SetY

func (v *Vector3) SetY(y float32) *Vector3

SetY sets this vector Y component. Returns the pointer to this updated vector.

func (*Vector3) SetZ

func (v *Vector3) SetZ(z float32) *Vector3

SetZ sets this vector Z component. Returns the pointer to this updated vector.

func (*Vector3) Sub

func (v *Vector3) Sub(other *Vector3) *Vector3

Sub subtracts other vector from this one. Returns the pointer to this updated vector.

func (*Vector3) SubScalar

func (v *Vector3) SubScalar(s float32) *Vector3

SubScalar subtracts scalar s from each component of this vector. Returns the pointer to this updated vector.

func (*Vector3) SubVectors

func (v *Vector3) SubVectors(a, b *Vector3) *Vector3

SubVectors sets this vector to a - b. Returns the pointer to this updated vector.

func (*Vector3) ToArray

func (v *Vector3) ToArray(array []float32, offset int) []float32

ToArray copies this vector's components to array starting at offset. Returns the array.

func (*Vector3) Vector4

func (v *Vector3) Vector4(w float32) *Vector4

Vector4 returns a new Vector4 based on this vector and the provided w value.

func (*Vector3) Zero

func (v *Vector3) Zero() *Vector3

Zero sets this vector X, Y and Z components to be zero. Returns the pointer to this updated vector.

type Vector4

type Vector4 struct {
	X float32
	Y float32
	Z float32
	W float32
}

Vector4 is a vector/point in homogeneous coordinates with X, Y, Z and W components.

func NewVec4

func NewVec4() *Vector4

NewVec4 creates and returns a pointer to a new zero-ed Vector4 (with W=1).

func NewVector4

func NewVector4(x, y, z, w float32) *Vector4

NewVector4 creates and returns a pointer to a new Vector4

func (*Vector4) Add

func (v *Vector4) Add(other *Vector4) *Vector4

Add adds other vector to this one. Returns the pointer to this updated vector.

func (*Vector4) AddScalar

func (v *Vector4) AddScalar(s float32) *Vector4

AddScalar adds scalar s to each component of this vector. Returns the pointer to this updated vector.

func (*Vector4) AddVectors

func (v *Vector4) AddVectors(a, b *Vector4) *Vector4

AddVectors adds vectors a and b to this one. Returns the pointer to this updated vector.

func (*Vector4) AlmostEquals

func (v *Vector4) AlmostEquals(other *Vector4, tolerance float32) bool

AlmostEquals returns whether the vector is almost equal to another vector within the specified tolerance.

func (*Vector4) ApplyMatrix4

func (v *Vector4) ApplyMatrix4(m *Matrix4) *Vector4

ApplyMatrix4 multiplies the specified 4x4 matrix by this vector. Returns the pointer to this updated vector.

func (*Vector4) Ceil

func (v *Vector4) Ceil() *Vector4

Ceil applies math32.Ceil() to each of this vector's components. Returns the pointer to this updated vector.

func (*Vector4) Clamp

func (v *Vector4) Clamp(min, max *Vector4) *Vector4

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly. Returns the pointer to this updated vector.

func (*Vector4) ClampScalar

func (v *Vector4) ClampScalar(minVal, maxVal float32) *Vector4

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal. Returns the pointer to this updated vector.

func (*Vector4) Clone

func (v *Vector4) Clone() *Vector4

Clone returns a copy of this vector

func (*Vector4) Component

func (v *Vector4) Component(index int) float32

Component returns this vector component by its index: 0 for X, 1 for Y, 2 for Z, 3 for W.

func (*Vector4) Copy

func (v *Vector4) Copy(other *Vector4) *Vector4

Copy copies other vector to this one. Returns the pointer to this updated vector.

func (*Vector4) Divide

func (v *Vector4) Divide(other *Vector4) *Vector4

Divide divides each component of this vector by the corresponding one from other vector. Returns the pointer to this updated vector

func (*Vector4) DivideScalar

func (v *Vector4) DivideScalar(scalar float32) *Vector4

DivideScalar divides each component of this vector by the scalar s. If scalar is zero, sets this vector to zero. Returns the pointer to this updated vector.

func (*Vector4) Dot

func (v *Vector4) Dot(other *Vector4) float32

Dot returns the dot product of this vector with other. None of the vectors are changed.

func (*Vector4) Equals

func (v *Vector4) Equals(other *Vector4) bool

Equals returns if this vector is equal to other.

func (*Vector4) Floor

func (v *Vector4) Floor() *Vector4

Floor applies math32.Floor() to each of this vector's components. Returns the pointer to this updated vector.

func (*Vector4) FromArray

func (v *Vector4) FromArray(array []float32, offset int) *Vector4

FromArray sets this vector's components from the specified array and offset Returns the pointer to this updated vector.

func (*Vector4) Length

func (v *Vector4) Length() float32

Length returns the length of this vector.

func (*Vector4) LengthSq

func (v *Vector4) LengthSq() float32

LengthSq returns the length squared of this vector. LengthSq can be used to compare vectors' lengths without the need to perform a square root.

func (*Vector4) Lerp

func (v *Vector4) Lerp(other *Vector4, alpha float32) *Vector4

Lerp sets each of this vector's components to the linear interpolated value of alpha between ifself and the corresponding other component. Returns the pointer to this updated vector.

func (*Vector4) Max

func (v *Vector4) Max(other *Vector4) *Vector4

Max sets this vector components to the maximum value of itself and other vector. Returns the pointer to this updated vector.

func (*Vector4) Min

func (v *Vector4) Min(other *Vector4) *Vector4

Min sets this vector components to the minimum values of itself and other vector. Returns the pointer to this updated vector.

func (*Vector4) Multiply

func (v *Vector4) Multiply(other *Vector4) *Vector4

Multiply multiplies each component of this vector by the corresponding one from other vector. Returns the pointer to this updated vector.

func (*Vector4) MultiplyScalar

func (v *Vector4) MultiplyScalar(scalar float32) *Vector4

MultiplyScalar multiplies each component of this vector by the scalar s. Returns the pointer to this updated vector.

func (*Vector4) Negate

func (v *Vector4) Negate() *Vector4

Negate negates each of this vector's components. Returns the pointer to this updated vector.

func (*Vector4) Normalize

func (v *Vector4) Normalize() *Vector4

Normalize normalizes this vector so its length will be 1. Returns the pointer to this updated vector.

func (*Vector4) Round

func (v *Vector4) Round() *Vector4

Round rounds each of this vector's components. Returns the pointer to this updated vector.

func (*Vector4) Set

func (v *Vector4) Set(x, y, z, w float32) *Vector4

Set sets this vector X, Y, Z and W components. Returns the pointer to this updated vector.

func (*Vector4) SetAxisAngleFromQuaternion

func (v *Vector4) SetAxisAngleFromQuaternion(q *Quaternion) *Vector4

SetAxisAngleFromQuaternion set this vector to be the axis (x, y, z) and angle (w) of a rotation specified the quaternion q. Assumes q is normalized.

func (*Vector4) SetAxisFromRotationMatrix

func (v *Vector4) SetAxisFromRotationMatrix(m *Matrix4) *Vector4

SetAxisFromRotationMatrix sets this vector to be the axis (x, y, z) and angle (w) of a rotation specified the matrix m. Assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled).

func (*Vector4) SetByName

func (v *Vector4) SetByName(name string, value float32)

SetByName sets this vector component value by its case insensitive name: "x", "y", "z" or "w".

func (*Vector4) SetComponent

func (v *Vector4) SetComponent(index int, value float32) *Vector4

SetComponent sets this vector component value by its index: 0 for X, 1 for Y, 2 for Z, 3 for W. Returns the pointer to this updated vector

func (*Vector4) SetLength

func (v *Vector4) SetLength(l float32) *Vector4

SetLength sets this vector to have the specified length. If the current length is zero, does nothing. Returns the pointer to this updated vector.

func (*Vector4) SetVector3

func (v *Vector4) SetVector3(other *Vector3, w float32) *Vector4

SetVector3 sets this vector from another Vector3 and W

func (*Vector4) SetW

func (v *Vector4) SetW(w float32) *Vector4

SetW sets this vector W component. Returns the pointer to this updated vector.

func (*Vector4) SetX

func (v *Vector4) SetX(x float32) *Vector4

SetX sets this vector X component. Returns the pointer to this updated Vector.

func (*Vector4) SetY

func (v *Vector4) SetY(y float32) *Vector4

SetY sets this vector Y component. Returns the pointer to this updated vector.

func (*Vector4) SetZ

func (v *Vector4) SetZ(z float32) *Vector4

SetZ sets this vector Z component. Returns the pointer to this updated vector.

func (*Vector4) Sub

func (v *Vector4) Sub(other *Vector4) *Vector4

Sub subtracts other vector from this one. Returns the pointer to this updated vector.

func (*Vector4) SubScalar

func (v *Vector4) SubScalar(s float32) *Vector4

SubScalar subtracts scalar s from each component of this vector. Returns the pointer to this updated vector.

func (*Vector4) SubVectors

func (v *Vector4) SubVectors(a, b *Vector4) *Vector4

SubVectors sets this vector to a - b. Returns the pointer to this updated vector.

func (*Vector4) ToArray

func (v *Vector4) ToArray(array []float32, offset int) []float32

ToArray copies this vector's components to array starting at offset. Returns the array.

func (*Vector4) Vector3

func (v *Vector4) Vector3() *Vector3

Vector3 returns a new Vector3 based on this vector, without the w value.

func (*Vector4) Zero

func (v *Vector4) Zero() *Vector4

Zero sets this vector X, Y and Z components to be zero and W to be one. Returns the pointer to this updated vector.

Jump to

Keyboard shortcuts

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