xy

package module
v0.0.0-...-80c8da2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: MIT Imports: 2 Imported by: 1

README

XY Spatial Math Module Go Reference

This module provides a spatial math module for Go, useful for graphics programming, is a purego, zero-dependencies port of the Godot Math Variants, AABB, Basis, Plane, Projection, Quaternion, Rect2, Rect2i, Transform2D, Transform3D, Vector2, Vector2i, Vector3, Vector3i, Vector4 and Vector4i.

Used in grow.graphics/gd to represent the aforementioned variant types, has been factored out into its own module so that it can be useful as a general math module for other projects.

Documentation

Index

Constants

View Source
const (
	Pi  = math.Pi
	Tau = math.Pi * 2
)

Variables

This section is empty.

Functions

func Abs

func Abs[T ComponentWise[T]](val T) T

func Absf

func Absf[T ~float32 | ~float64](x T) T

Absf returns the absolute value of the float parameter x (i.e. non-negative value).

func Absi

func Absi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Absi returns the absolute value of the integer parameter x (i.e. non-negative value).

func AngleDifference

func AngleDifference[T ~float32 | ~float64](from, to T) T

AngleDifference returns the difference between the two angles, in the range of [-Pi, +Pi]. When from and to are opposite, returns -Pi if from is smaller than to, or Pi otherwise.

func BezierDerivative

func BezierDerivative[T ~float32 | ~float64](start, control_1, control_2, end, t T) T

BezierDerivative returns the derivative at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.

func BezierInterpolate

func BezierInterpolate[T ~float32 | ~float64](start, control_1, control_2, end, t T) T

BezierInterpolate returns the point at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.

func Ceil

func Ceil[T ComponentWise[T]](val T) T

func Ceilf

func Ceilf[T ~float32 | ~float64](x T) T

Ceilf rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x.

func Ceili

func Ceili[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Ceili rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x.

func Clamp

func Clamp[T ordered](value, min, max T) T

Clamp clamps the value, returning a Variant not less than min and not more than max. Any values that can be compared with the less than and greater than operators will work.

func Clampf

func Clampf[T ~float32 | ~float64](value, min, max T) T

Clampf clamps the value, returning a float not less than min and not more than max.

func Clampi

func Clampi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](value, min, max T) T

Clampi clamps the value, returning an integer not less than min and not more than max.

func Cos

func Cos[T ~float32 | ~float64](x T) T

Cos returns the cosine of angle x in radians.

func Cosh

func Cosh[T ~float32 | ~float64](x T) T

Cosh returns the hyperbolic cosine of x in radians.

func CubicInterpolate

func CubicInterpolate[T ~float32 | ~float64](from, to, pre, post, weight T) T

CubicInterpolate cubic interpolates between two values by the factor defined in weightSee also with pre and post values.

func CubicInterpolateAngle

func CubicInterpolateAngle[T ~float32 | ~float64](from, to, pre, post, weight T) T

CubicInterpolateAngle cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also LerpAngle.

func CubicInterpolateAngleInTime

func CubicInterpolateAngleInTime[T ~float32 | ~float64](from, to, pre, post, weight, to_t, pre_t, post_t T) T

CubicInterpolateAngleInTime cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also LerpAngle.

It can perform smoother interpolation than CubicInterpolate by the time values.

func CubicInterpolateInTime

func CubicInterpolateInTime[T ~float32 | ~float64](from, to, pre, post, weight, to_t, pre_t, post_t T) T

CubicInterpolateInTime cubic interpolates between two values by the factor defined in weight with pre and post values.

It can perform smoother interpolation than cubic_interpolate by the time values.

func DecibelsToLinear

func DecibelsToLinear[T ~float32 | ~float64](db T) T

DecibelsToLinear converts from decibels to linear energy (audio).

func Ease

func Ease[T ~float32 | ~float64](x, curve T) T

Ease returns an "eased" value of x based on an easing function defined with curve. This easing function is based on an exponent. The curve can be any floating-point number, with specific values leading to the following behaviors:

- Lower than -1.0 (exclusive): Ease in-out - 1.0: Linear - Between -1.0 and 0.0 (exclusive): Ease out-in - 0.0: Constant - Between 0.0 to 1.0 (exclusive): Ease out - 1.0: Linear - Greater than 1.0 (exclusive): Ease in

https://raw.githubusercontent.com/godotengine/godot-docs/master/img/ease_cheatsheet.png

See also Smoothstep. If you need to perform more advanced transitions, use [Tween.InterpolateValue].

func Exp

func Exp[T ~float32 | ~float64](x T) T

Exp raises the mathematical constant e to the power of x and returns it. e has an approximate value of 2.71828, and can be obtained with Exp(1).

For exponents to other bases use the method pow.

func Floor

func Floor[T ComponentWise[T]](val T) T

func Floorf

func Floorf[T ~float32 | ~float64](x T) T

Floorf rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.

func Floori

func Floori[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Floori rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.

func Fmod

func Fmod[T ~float32 | ~float64](x, y T) T

Fmod returns the floating-point remainder of x divided by y, keeping the sign of x.

func Fposmod

func Fposmod[T ~float32 | ~float64](x, y T) T

Fposmod returns the floating-point modulus of x divided by y, wrapping equally in positive and negative.

func InverseLerp

func InverseLerp[T ~float32 | ~float64](from, to, weight T) T

InverseLerp returns an interpolation or extrapolation factor considering the range specified in from and to, and the interpolated value specified in weight. The returned value will be between 0.0 and 1.0 if weight is between from and to (inclusive). If weight is located outside this range, then an extrapolation factor will be returned (return value lower than 0.0 or greater than 1.0). Use Clamp on the result of InverseLerp if this is not desired.

func IsApproximatelyEqual

func IsApproximatelyEqual[T ~float32 | ~float64](a, b T) bool

IsApproximatelyEqual returns true if a and b are approximately equal to each other.

Here, "approximately equal" means that a and b are within a small internal epsilon of each other, which scales with the magnitude of the numbers.

Infinity values of the same sign are considered equal.

func IsApproximatelyZero

func IsApproximatelyZero[T ~float32 | ~float64](x T) bool

IsApproximatelyZero Returns true if x is zero or almost zero. The comparison is done using a tolerance calculation with a small internal epsilon. This function is faster than using IsApproximatelyEqual with one value as zero.

func IsFinite

func IsFinite[T ~float32 | ~float64](x T) bool

IsFinite returns whether x is a finite value, i.e. it is not NaN, +INF, or -INF.

func IsInfinity

func IsInfinity[T ~float32 | ~float64](x T) bool

IsInfinity returns whether x is an infinite value, i.e. it is +INF or -INF.

func IsNaN

func IsNaN[T ~float32 | ~float64](x T) bool

IsNaN returns whether x is NaN (not a number).

func Lerp

func Lerp[T Lerpable[T]](a, b T, t float64) T

Lerp linearly interpolates between two values by the factor defined in weight. To perform interpolation, weight should be between 0.0 and 1.0 (inclusive). However, values outside this range are allowed and can be used to perform extrapolation. If this is not desired, use Clamp on the result of this function.

Both from and to must be the same type. Supported types: Vector2, Vector3, Vector4, Quaternion, Basis.

See also InverseLerp which performs the reverse of this operation. To perform eased interpolation with lerp, combine it with Ease or Smoothstep. See also Remap to map a continuous series of values to another.

func LerpAngle

func LerpAngle[T ~float32 | ~float64](from, to, weight T) T

LerpAngle linearly interpolates between two angles (in radians) by a weight value between 0.0 and 1.0. Similar to lerp, but interpolates correctly when the angles wrap around Tau. To perform eased interpolation with LerpAngle, combine it with Ease or Smoothstep.

Note: This function lerps through the shortest path between from and to. However, when these two angles are approximately Pi + k * Tau apart for any integer k, it's not obvious which way they lerp due to floating-point precision errors. For example, LerpAngle(0, Pi, weight) lerps counter-clockwise, while LerpAngle(0, Pi + 5 * Tau, weight) lerps clockwise.

func Lerpf

func Lerpf[T ~float32 | ~float64](from, to, weight T) T

Lerpf linearly interpolates between two values by the factor defined in weight. To perform interpolation, weight should be between 0.0 and 1.0 (inclusive). However, values outside this range are allowed and can be used to perform extrapolation. If this is not desired, use Clampf on the result of this function.

See also InverseLerp which performs the reverse of this operation. To perform eased interpolation with Lerpf, combine it with ease or smoothstep.

func LinearToDecibels

func LinearToDecibels[T ~float32 | ~float64](energy T) T

LinearToDecibels converts from linear energy (audio) to decibels.

func Log

func Log[T ~float32 | ~float64](x T) T

Log returns the natural logarithm of x (base e, with e being approximately 2.71828). This is the amount of time needed to reach a certain level of continuous growth.

Note: This is not the same as the "log" function on most calculators, which uses a base 10 logarithm. To use base 10 logarithm, use Log(x) / Log(10).

Note: The logarithm of 0 returns -inf, while negative values return -NaN.

func MoveToward

func MoveToward[T ~float32 | ~float64](from, to, delta T) T

MoveToward moves from toward to by the delta amount. Will not go past to. Use a negative delta value to move away.

func NearestPowerOfTwo

func NearestPowerOfTwo(x int64) int64

NearestPowerOfTwo returns the nearest power of two to the given value.

Warning: Due to its implementation, this method returns 0 rather than 1 for values less than or equal to 0, with an exception for value being the smallest negative 64-bit integer (-9223372036854775808) in which case the value is returned unchanged.

func PingPong

func PingPong[T ~float32 | ~float64](value, length T) T

PingPong wraps value between 0 and the length. If the limit is reached, the next value the function returns is decreased to the 0 side or increased to the length side (like a triangle wave). If length is less than zero, it becomes positive.

func Posmod

func Posmod[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x, y T) T

Posmod returns the integer modulus of x divided by y that wraps equally in positive and negative.

func Pow

func Pow[T ~float32 | ~float64](base, exp T) T

Pow returns the result of base raised to the power of exp.

func Remap

func Remap[T ~float32 | ~float64](value, istart, istop, ostart, ostop T) T

Remap maps a value from range (istart, istop) to (ostart, ostop). See also Lerp and InverseLerp. If value is outside (istart, istop), then the resulting value will also be outside (ostart, ostop). If this is not desired, use Clamp on the result of this function.

func RotateToward

func RotateToward[T ~float32 | ~float64](from, to, delta T) T

RotateToward rotates from toward to by the delta amount. Will not go past to.

Similar to move_toward, but interpolates correctly when the angles wrap around Tau.

If delta is negative, this function will rotate away from to, toward the opposite angle, and will not go past the opposite angle.

func Round

func Round[T ComponentWise[T]](val T) T

func Roundf

func Roundf[T ~float32 | ~float64](x T) T

Roundf rounds x to the nearest whole number, with halfway cases rounded away from 0.

func Roundi

func Roundi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Roundi rounds x to the nearest whole number, with halfway cases rounded away from 0.

func Sign

func Sign[T ComponentWise[T]](val T) T

func Signf

func Signf[T ~float32 | ~float64](x T) T

Signf returns -1.0 if x is negative, 1.0 if x is positive, and 0.0 if x is zero. For NaN values of x it returns 0.0.

func Signi

func Signi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Signi returns -1 if x is negative, 1 if x is positive, and 0 if x is zero. For NaN values of x it returns 0.

func Sin

func Sin[T ~float32 | ~float64](x T) T

Sin returns the sine of angle x in radians.

func Sinh

func Sinh[T ~float32 | ~float64](x T) T

Sinh returns the hyperbolic sine of x in radians.

func Smoothstep

func Smoothstep[T ~float32 | ~float64](from, to, x T) T

Smoothstep returns the result of smoothly interpolating the value of x between 0 and 1, based on the where x lies with respect to the edges from and to.

The return value is 0 if x <= from, and 1 if x >= to. If x lies between from and to, the returned value follows an S-shaped curve that maps x between 0 and 1.

This S-shaped curve is the cubic Hermite interpolator, given by

(y) = 3*y^2 - 2*y^3 where y = (x-from) / (to-from).

func Snapped

func Snapped[T ComponentWise[T]](val T, by T) T

func Snappedf

func Snappedf[T ~float32 | ~float64](x, step T) T

Snappedf returns the multiple of step that is the closest to x. This can also be used to round a floating point number to an arbitrary number of decimals.

func Snappedi

func Snappedi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x, step T) T

Snappedi returns the multiple of step that is the closest to x. This can also be used to round a floating point number to an arbitrary number of decimals.

func Sqrt

func Sqrt[T ~float32 | ~float64](x T) T

Sqrt returns the square root of x. Where x is negative, the result is NaN.

func StepDecimals

func StepDecimals[T ~float32 | ~float64](x T) int64

StepDecimals returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.

func Tan

func Tan[T ~float32 | ~float64](x T) T

Tan returns the tangent of angle x in radians.

func Tanh

func Tanh[T ~float32 | ~float64](x T) T

Tanh returns the hyperbolic tangent of x in radians.

func Wrapf

func Wrapf[T ~float32 | ~float64](value, min, max T) T

Wrapf value between min and max. Can be used for creating loop-alike behavior or infinite surfaces.

func Wrapi

func Wrapi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](value, min, max T) T

Wrapi value between min and max. Can be used for creating loop-alike behavior or infinite surfaces.

Types

type AABB

type AABB struct {
	Position Vector3
	Size     Vector3
}

AABB consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

It uses floating-point coordinates. The 2D counterpart to AABB is Rect2.

Negative values for size are not supported and will not work for most methods. Use abs to get an AABB with a positive size.

Note: Unlike Rect2, AABB does not have a variant that uses integer coordinates.

func (AABB) Abs

func (a AABB) Abs() AABB

Abs returns an AABB with equivalent position and size, modified so that the most-negative corner is the origin and the size is positive.

func (AABB) Center

func (a AABB) Center() Vector3

Center returns the center of the AABB, which is equal to position + (size / 2).

func (AABB) Encloses

func (a AABB) Encloses(b AABB) bool

Encloses returns true if this AABB completely encloses another one.

func (AABB) End

func (a AABB) End() Vector3

func (AABB) Endpoint

func (a AABB) Endpoint(idx int) Vector3

Endpoint gets the position of the 8 endpoints of the AABB in space.

func (AABB) Expand

func (a AABB) Expand(to Vector3) AABB

Expand returns a copy of this AABB expanded to include a given point.

// position (-3, 2, 0), size (1, 1, 1)
var box = AABB{Vector3{-3,2,0}, Vector3{1,1,1}}
// position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
var box2 = box.Expand(Vector3{0, -1, 2})

func (AABB) Grow

func (a AABB) Grow(by float64) AABB

Grow returns a copy of the AABB grown a given number of units towards all the sides.

func (AABB) HasPoint

func (a AABB) HasPoint(point Vector3) bool

HasPoint returns true if the AABB contains a point. Points on the faces of the AABB are considered included, though float-point precision errors may impact the accuracy of such checks.

Note: This method is not reliable for AABB with a negative size. Use abs to get a positive sized equivalent AABB to check for contained points.

func (AABB) HasSurface

func (a AABB) HasSurface() bool

HasSurface returns true if the AABB has a surface or a length, and false if the AABB is empty (all components of size are zero or negative).

func (AABB) HasVolume

func (a AABB) HasVolume() bool

HasVolume returns true if the AABB has a volume, and false if the AABB is flat, empty, or has a negative size.

func (AABB) Intersection

func (a AABB) Intersection(b AABB) AABB

Intersection returns the intersection between two AABB. An empty AABB (size (0, 0, 0)) is returned on failure.

func (AABB) Intersects

func (a AABB) Intersects(b AABB) bool

Intersects returns true if the AABB overlaps with another.

func (AABB) IntersectsPlane

func (a AABB) IntersectsPlane(plane Plane) bool

IntersectsPlane returns true if the AABB is on both sides of a plane.

func (AABB) IntersectsRay

func (a AABB) IntersectsRay(from, dir Vector3) (clip Vector3, normal Vector3, ok bool)

IntersectsRay returns the point of intersection of the given ray with this AABB along with the normal or false if there is no intersection. Ray length is infinite.

func (AABB) IntesectsSegment

func (a AABB) IntesectsSegment(from, to Vector3) (clip Vector3, normal Vector3, ok bool)

IntesectsSegment returns the point of intersection between from and to along with this AABB along with the normal or false if there is no intersection.

func (AABB) IsAproxximatelyEqual

func (a AABB) IsAproxximatelyEqual(other AABB) bool

IsAproxximatelyEqual returns true if this AABB and other are approximately equal, by running IsApproximatelyEqual on each component.

func (AABB) IsFinite

func (a AABB) IsFinite() bool

IsFinite returns true if this AABB is finite, by calling IsFinite on each component.

func (AABB) LongestAxis

func (a AABB) LongestAxis() Vector3

LongestAxis returns the normalized longest axis of the AABB.

func (AABB) LongestAxisIndex

func (a AABB) LongestAxisIndex() Axis

LongestAxisIndex returns the index of the longest axis of the AABB (according to Axis constants).

func (AABB) LongestAxisSize

func (a AABB) LongestAxisSize() float64

LongestAxisSize returns the scalar length of the longest axis of the AABB.

func (AABB) Merge

func (a AABB) Merge(b AABB) AABB

Merge returns the smallest AABB enclosing both this AABB and b.

func (AABB) Projection

func (a AABB) Projection() Projection

Projection creates a new Projection that scales a given projection to fit around a given AABB in projection space.

func (*AABB) SetEnd

func (a *AABB) SetEnd(end Vector3)

func (AABB) ShortestAxis

func (a AABB) ShortestAxis() Vector3

ShortestAxis returns the normalized shortest axis of the AABB.

func (AABB) ShortestAxisIndex

func (a AABB) ShortestAxisIndex() Axis

ShortestAxisIndex returns the index of the shortest axis of the AABB (according to Axis constants).

func (AABB) ShortestAxisSize

func (a AABB) ShortestAxisSize() float64

ShortestAxisSize returns the scalar length of the shortest axis of the AABB.

func (AABB) Support

func (a AABB) Support(dir Vector3) Vector3

Support returns the vertex of the AABB that's the farthest in a given direction. This point is commonly known as the support point in collision detection algorithms.

func (AABB) Transform

func (a AABB) Transform(t Transform3D) AABB

Transform (multiplies) the AABB by the given Transform3D matrix.

func (AABB) Volume

func (a AABB) Volume() float64

Volume returns the volume of the AABB.

type Axis

type Axis int
const (
	X Axis = iota
	Y
	Z
	W
)

type Basis

type Basis [3]Vector3

Basis is a 3×3 matrix used for representing 3D rotation and scale. Usually used as an orthogonal basis for a Transform3D.

Contains 3 vector fields X, Y and Z as its columns, which are typically interpreted as the local basis vectors of a transformation. For such use, it is composed of a scaling and a rotation matrix, in that order (M = R.S).

Basis can also be accessed as an array of 3D vectors. These vectors are usually orthogonal to each other, but are not necessarily normalized (due to scaling).

func NewBasisLookingAt

func NewBasisLookingAt(target, up Vector3, use_model_front bool) Basis

NewBasisLookingAt creates a Basis with a rotation such that the forward axis (-Z) points towards the target position.

The up axis (+Y) points as close to the up vector as possible while staying perpendicular to the forward axis. The resulting Basis is orthonormalized. The target and up vectors cannot be zero, and cannot be parallel to each other.

If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).

func NewBasisRotatedAround

func NewBasisRotatedAround(axis Vector3, angle Radians) Basis

NewBasisRotatedAround constructs a pure rotation basis matrix, rotated around the given axis by angle (in radians). The axis must be a normalized vector.

func NewBasisScaledBy

func NewBasisScaledBy(scale Vector3) Basis

NewBasisScaledBy constructs a pure scale basis matrix with no rotation or shearing. The scale values are set as the diagonal of the matrix, and the other parts of the matrix are zero.

func (Basis) Determinant

func (b Basis) Determinant() float64

Determinant returns the determinant of the basis matrix. If the basis is uniformly scaled, its determinant is the square of the scale.

A negative determinant means the basis has a negative scale. A zero determinant means the basis isn't invertible, and is usually considered invalid.

func (Basis) EulerAngles

func (b Basis) EulerAngles(order EulerOrder) EulerAngles

EulerAngles returns the basis's rotation in the form of Euler angles. The Euler order depends on the order parameter, by default it uses the YXZ convention: when decomposing, first Z, then X, and Y last. The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).

Consider using the Basis.Quaternion method instead, which returns a Quaternion quaternion instead of EulerAngles.

func (Basis) FLIP_X

func (Basis) FLIP_X() Basis

func (Basis) FLIP_Y

func (Basis) FLIP_Y() Basis

func (Basis) FLIP_Z

func (Basis) FLIP_Z() Basis

func (Basis) IDENTITY

func (Basis) IDENTITY() Basis

func (Basis) Inverse

func (b Basis) Inverse() Basis

Inverse returns the inverse of the matrix.

func (Basis) IsApproximatelyEqual

func (b Basis) IsApproximatelyEqual(other Basis) bool

IsApproximatelyEqual returns true if this basis and b are approximately equal, by calling IsApproximatelyEqual on all vector components.

func (Basis) IsConformal

func (b Basis) IsConformal() bool

IsConformal returns true if the basis is conformal, meaning it preserves angles and distance ratios, and may only be composed of rotation and uniform scale. Returns false if the basis has non-uniform scale or shear/skew. This can be used to validate if the basis is non-distorted, which is important for physics and other use cases.

func (Basis) IsFinite

func (b Basis) IsFinite() bool

IsFinite returns true if this basis is finite, by calling IsFinite on all vector components.

func (Basis) Mul

func (b Basis) Mul(other Basis) Basis

func (Basis) Orthonormalized

func (b Basis) Orthonormalized() Basis

Orthonormalized returns the orthonormalized version of the matrix (useful to call from time to time to avoid rounding error for orthogonal matrices). This performs a Gram-Schmidt orthonormalization on the basis of the matrix.

func (Basis) Quaternion

func (b Basis) Quaternion() Quaternion

Quaternion returns the basis's rotation in the form of a quaternion. See Basis.EulerAngles if you need Euler angles, but keep in mind quaternions should generally be preferred to EulerAngles.

func (Basis) Rotated

func (b Basis) Rotated(axis Vector3, angle Radians) Basis

Rotated returns a copy of the basis rotated around the given axis by the given angle (in radians). The axis must be a normalized vector.

func (Basis) Scale

func (b Basis) Scale() Vector3

Scale assuming that the matrix is the combination of a rotation and scaling, returns the absolute value of scaling factors along each axis.

func (Basis) Scaled

func (b Basis) Scaled(scale Vector3) Basis

Scaled introduce an additional scaling specified by the given 3D scaling factor.

func (*Basis) SetX

func (b *Basis) SetX(x Vector3)

func (*Basis) SetY

func (b *Basis) SetY(y Vector3)

func (*Basis) SetZ

func (b *Basis) SetZ(z Vector3)

func (Basis) Slerp

func (b Basis) Slerp(to Basis, weight float64) Basis

Slerp assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix.

func (Basis) Transform

func (m Basis) Transform(v Vector3) Vector3

func (Basis) Transposed

func (m Basis) Transposed() Basis

Transposed returns the transposed version of the matrix.

func (Basis) TransposedDotX

func (b Basis) TransposedDotX(v Vector3) float64

TransposedDotX returns the transposed dot product with the X axis of the matrix.

func (Basis) TransposedDotY

func (b Basis) TransposedDotY(v Vector3) float64

TransposedDotY returns the transposed dot product with the Y axis of the matrix.

func (Basis) TransposedDotZ

func (b Basis) TransposedDotZ(v Vector3) float64

TransposedDotZ returns the transposed dot product with the Z axis of the matrix.

func (Basis) X

func (b Basis) X() Vector3

func (Basis) Y

func (b Basis) Y() Vector3

func (Basis) Z

func (b Basis) Z() Vector3

type ComponentWise

type ComponentWise[T any] interface {
	Vector2 | Vector2i | Vector3 | Vector3i | Vector4 | Vector4i
	// contains filtered or unexported methods
}

type Degrees

type Degrees float64

Degrees represents an angle in degrees.

func ProjectionFovy

func ProjectionFovy(hfov Degrees, aspect float64) Degrees

ProjectionFovy returns the vertical field of view of the projection (in degrees) associated with the given horizontal field of view (in degrees) and aspect ratio.

func (Degrees) Radians

func (deg Degrees) Radians() Radians

func (Degrees) Vector2

func (deg Degrees) Vector2() Vector2

Vector2 creates a unit Vector2 rotated to the given angle in degrees. This is equivalent to doing angle.Radians().Vector2()

type EulerAngles

type EulerAngles [3]Radians

EulerAngles represents a rotation in 3D space using Euler angles.

func (EulerAngles) Basis

func (e EulerAngles) Basis(order EulerOrder) Basis

Basis constructs a pure rotation Basis matrix from Euler angles in the specified Euler rotation order. By default, use YXZ order (most common). See the EulerOrder enum for possible values.

func (EulerAngles) Quaternion

func (e EulerAngles) Quaternion() Quaternion

Quaternion constructs a Quaternion from Euler angles in YXZ rotation order.

type EulerOrder

type EulerOrder int64
const (
	EulerOrderXYZ EulerOrder = 0
	EulerOrderXZY EulerOrder = 1
	EulerOrderYXZ EulerOrder = 2
	EulerOrderYZX EulerOrder = 3
	EulerOrderZXY EulerOrder = 4
	EulerOrderZYX EulerOrder = 5
)

type Lerpable

type Lerpable[T any] interface {
	Vector2 | Vector3 | Vector4 | Quaternion | Basis
	// contains filtered or unexported methods
}

type Plane

type Plane struct {
	/*
		Normal of the plane, typically a unit vector. Shouldn't be a zero vector as Plane with such normal does not
		represent a valid plane.

		In the scalar equation of the plane ax + by + cz = d, this is the vector (a, b, c), where d is the d property.
	*/
	Normal Vector3
	/*
		D is the distance from the origin to the plane, expressed in terms of normal (according to its direction and magnitude).
		Actual absolute distance from the origin to the plane can be calculated as Abs(d) / normal.Length() (if normal has zero
		length then this Plane does not represent a valid plane).

		In the scalar equation of the plane ax + by + cz = d, this is d, while the (a, b, c) coordinates are represented by the
		normal property.
	*/
	D float
}

Plane represents a normalized plane equation. normal is the normal of the plane (a, b, c normalized), and d is the distance from the origin to the plane (in the direction of "normal"). "Over" or "Above" the plane is considered the side of the plane towards where the normal is pointing.

func NewPlane

func NewPlane(a, b, c Vector3) Plane

NewPlane creates a plane from the three points, given in clockwise order.

func (Plane) Center

func (p Plane) Center() Vector3

GetCenter returns the center of the plane.

func (Plane) DistanceTo

func (p Plane) DistanceTo(point Vector3) float64

DistanceTo returns the shortest distance from the plane to the position point. If the point is above the plane, the distance will be positive. If below, the distance will be negative.

func (Plane) HasPoint

func (p Plane) HasPoint(point Vector3, tolerance float64) bool

HasPoint returns true if point is inside the plane. Comparison uses a custom minimum tolerance threshold.

func (Plane) Intersect3

func (p Plane) Intersect3(b, c Plane) (Vector3, bool)

Intersect3 returns the intersection point of the three planes b, c and this plane. If no intersection is found, false is returned.

func (Plane) IntersectsRay

func (p Plane) IntersectsRay(from, dir Vector3) (Vector3, bool)

IntersectsRay returns the intersection point of a ray consisting of the position from and the direction normal dir with this plane. If no intersection is found, false is returned.

func (Plane) IntersectsSegment

func (p Plane) IntersectsSegment(from, to Vector3) (Vector3, bool)

IntersectsSegment returns the intersection point of a segment from position from to position to with this plane. If no intersection is found, false is returned.

func (Plane) IsApproximatelyEqual

func (p Plane) IsApproximatelyEqual(other Plane) bool

IsApproximatelyEqual returns true if this plane and other are approximately equal, by running IsApproximatelyEqual on each component.

func (Plane) IsFinite

func (p Plane) IsFinite() bool

IsFinite returns true if this plane is finite, by calling IsFinite on each component.

func (Plane) IsPointOver

func (p Plane) IsPointOver(point Vector3) bool

IsPointOver returns true if point is located above the plane.

func (Plane) Normalized

func (p Plane) Normalized() Plane

Normalized returns a copy of the plane, with normalized normal (so it's a unit vector). Returns Plane{0, 0, 0, 0} if normal can't be normalized (it has zero length).

func (Plane) Project

func (p Plane) Project(point Vector3) Vector3

Project returns the orthogonal projection of point into a point in the plane.

func (*Plane) SetX

func (p *Plane) SetX(x float64)

func (*Plane) SetY

func (p *Plane) SetY(y float64)

func (*Plane) SetZ

func (p *Plane) SetZ(z float64)

func (Plane) Transform

func (p Plane) Transform(t Transform3D) Plane

Transform transforms (multiplies) the Plane by the given Transform3D transformation matrix.

func (Plane) X

func (p Plane) X() float64

func (Plane) XY

func (Plane) XY() Plane

func (Plane) XZ

func (Plane) XZ() Plane

func (Plane) Y

func (p Plane) Y() float64

func (Plane) YZ

func (Plane) YZ() Plane

func (Plane) Z

func (p Plane) Z() float64

type Projection

type Projection [4]Vector4

Projection is a 4x4 matrix used for 3D projective transformations. It can represent transformations such as translation, rotation, scaling, shearing, and perspective division. It consists of four Vector4 columns.

For purely linear transformations (translation, rotation, and scale), it is recommended to use Transform3D, as it is more performant and requires less memory.

Generally used for a camera's projection matrix.

func NewProjectionForHeadMountedDisplay

func NewProjectionForHeadMountedDisplay(eye int, aspect, intraocular_dist, display_width, display_to_lens, oversample, z_near, z_far float64) Projection

NewProjectionForHeadMountedDisplay creates a new Projection for projecting positions onto a head-mounted display with the given X:Y aspect ratio, distance between eyes, display width, distance to lens, oversampling factor, and depth clipping planes.

eye creates the projection for the left eye when set to 1, or the right eye when set to 2.

func NewProjectionThatIsOrthogonal

func NewProjectionThatIsOrthogonal(left, right, bottom, top, z_near, z_far float64) Projection

NewProjectionThatIsOrthogonal creates a new Projection that projects positions using an orthogonal projection with the given clipping planes.

func NewProjectionThatIsOrthogonalWithAspectRatio

func NewProjectionThatIsOrthogonalWithAspectRatio(size, aspect, z_near, z_far float64, flip_fov bool) Projection

NewProjectionThatIsOrthogonalWithAspectRatio creates a new Projection that projects positions using an orthogonal projection with the given size, X:Y aspect ratio, and clipping planes.

flip_fov determines whether the projection's field of view is flipped over its diagonal.

func NewProjectionWithDepthCorrection

func NewProjectionWithDepthCorrection(fliy bool) Projection

NewProjectionWithDepthCorrection creates a new Projection that projects positions from a depth range of -1 to 1 to one that ranges from 0 to 1, and flips the projected positions vertically, according to fliy.

func NewProjectionWithFrustum

func NewProjectionWithFrustum(left, right, bottom, top, z_near, z_far float64) Projection

NewProjectionWithFrustum creates a new Projection that projects positions in a frustum with the given clipping planes.

func NewProjectionWithFrustumAspectRatio

func NewProjectionWithFrustumAspectRatio(size, aspect float64, offset Vector2, z_near, z_far float64, flip_fov bool) Projection

NewProjectionWithFrustumAspectRatio creates a new Projection that projects positions in a frustum with the given size, X:Y aspect ratio, offset, and clipping planes.

flip_fov determines whether the projection's field of view is flipped over its diagonal.

func NewProjectionWithPerspective

func NewProjectionWithPerspective(fovy Degrees, aspect, z_near, z_far float64, flip_fov bool) Projection

NewProjectionWithPerspective creates a new Projection that projects positions using a perspective projection with the given Y-axis field of view (in degrees), X:Y aspect ratio, and clipping planes.

flip_fov determines whether the projection's field of view is flipped over its diagonal.

func NewProjectionWithPerspectiveForHeadMountedDisplay

func NewProjectionWithPerspectiveForHeadMountedDisplay(fovy Degrees, aspect, z_near, z_far float64, flip_fov bool, eye int, intraocular_dist, convergence_dist float64) Projection

NewProjectionWithPerspectiveForHeadMountedDisplay creates a new Projection that projects positions using a perspective projection with the given Y-axis field of view (in degrees), X:Y aspect ratio, and clipping distances. The projection is adjusted for a head-mounted display with the given distance between eyes and distance to a point that can be focused on.

eye creates the projection for the left eye when set to 1, or the right eye when set to 2.

flip_fov determines whether the projection's field of view is flipped over its diagonal

func (Projection) AspectRatio

func (p Projection) AspectRatio() float64

AspectRatio returns the X:Y aspect ratio of this Projection's viewport.

func (Projection) Determinant

func (p Projection) Determinant() float64

Determinant returns a scalar value that is the signed factor by which areas are scaled by this matrix. If the sign is negative, the matrix flips the orientation of the area.

The determinant can be used to calculate the invertibility of a matrix or solve linear systems of equations involving the matrix, among other applications.

func (Projection) FarPlaneHalfExtents

func (p Projection) FarPlaneHalfExtents() Vector2

FarPlaneHalfExtents returns the dimensions of the far clipping plane of the projection, divided by two.

func (Projection) FarZ

func (p Projection) FarZ() float64

FarZ returns the distance for this Projection beyond which positions are clipped.

func (Projection) FieldOfView

func (p Projection) FieldOfView() Degrees

FieldOfView returns the horizontal field of view of the projection (in degrees).

func (Projection) FlippedY

func (p Projection) FlippedY() Projection

FlippedY returns a copy of this Projection with the signs of the values of the Y column flipped.

func (Projection) IDENTITY

func (Projection) IDENTITY() Projection

func (Projection) Inverse

func (p Projection) Inverse() Projection

Inverse returns a Projection that performs the inverse of this Projection's projective transformation.

func (Projection) IsOrthogonal

func (p Projection) IsOrthogonal() bool

IsOrthogonal returns true if this Projection performs an orthogonal projection.

func (Projection) JitterOffseted

func (p Projection) JitterOffseted(jitter Vector2) Projection

JitterOffseted returns a Projection with the X and Y values from the given Vector2 added to the first and second values of the final column respectively.

func (Projection) LevelOfDetailMultiplier

func (p Projection) LevelOfDetailMultiplier() float64

LevelOfDetailMultiplier returns the factor by which the visible level of detail is scaled by this Projection.

func (Projection) Mul

func (p Projection) Mul(other Projection) Projection

func (Projection) NearZ

func (p Projection) NearZ() float64

NearZ returns the distance for this Projection before which positions are clipped.

func (Projection) PerspectiveAdjustedNearZ

func (p Projection) PerspectiveAdjustedNearZ(new_near_z float64) Projection

PerspectiveAdjustedNearZ returns a Projection with the near clipping distance adjusted to be new_znear.

Note: The original Projection must be a perspective projection.

func (Projection) PixelsPerMeter

func (p Projection) PixelsPerMeter(pixel_width int64) int64

PixelsPerMeter returns the number of pixels with the given pixel width displayed per meter, after this Projection is applied.

func (Projection) ProjectionPlane

func (p Projection) ProjectionPlane(plane ProjectionPlane) (new_plane Plane)

ProjectionPlane returns the clipping plane of this Projection whose index is given by plane.

plane should be equal to one of PLANE_NEAR, PLANE_FAR, PLANE_LEFT, PLANE_TOP, PLANE_RIGHT, or PLANE_BOTTOM.

func (Projection) Transform3D

func (p Projection) Transform3D() Transform3D

func (Projection) ViewportHalfExtents

func (p Projection) ViewportHalfExtents() Vector2

ViewportHalfExtents returns the dimensions of the viewport plane that this Projection projects positions onto, divided by two.

func (Projection) W

func (p Projection) W() Vector4

func (Projection) X

func (p Projection) X() Vector4

func (Projection) Y

func (p Projection) Y() Vector4

func (Projection) Z

func (p Projection) Z() Vector4

type ProjectionPlane

type ProjectionPlane int
const (
	PlaneNear ProjectionPlane = iota
	PlaneFar
	PlaneLeft
	PlaneTop
	PlaneRight
	PlaneBottom
)

type Quaternion

type Quaternion [4]float

Quaternions are similar to Basis, which implements the matrix representation of rotations. Unlike Basis, which stores rotation, scale, and shearing, quaternions only store rotation.

Quaternions can be parametrized using both an axis-angle pair or Euler angles. Due to their compactness and the way they are stored in memory, certain operations (obtaining axis-angle and performing SLERP, in particular) are more efficient and robust against floating-point errors.

Note: Quaternions need to be normalized before being used for rotation.

func NewQuaternion

func NewQuaternion(arc_from, arc_to Vector3) Quaternion

NewQuaternion constructs a quaternion representing the shortest arc between two points on the surface of a sphere with a radius of 1.0.

func (Quaternion) Add

func (q Quaternion) Add(other Quaternion) Quaternion

func (Quaternion) Addf

func (q Quaternion) Addf(other float64) Quaternion

func (Quaternion) Angle

func (q Quaternion) Angle() Radians

func (Quaternion) AngleTo

func (q Quaternion) AngleTo(other Quaternion) Radians

AngleTo Returns the angle between this quaternion and to. This is the magnitude of the angle you would need to rotate by to get from one to the other.

Note: The magnitude of the floating-point error for this method is abnormally high, so methods such as IsApproximatelyZero will not work reliably.

func (Quaternion) Axis

func (q Quaternion) Axis() Vector3

func (Quaternion) Basis

func (q Quaternion) Basis() Basis

func (Quaternion) Div

func (q Quaternion) Div(other Quaternion) Quaternion

func (Quaternion) Divf

func (q Quaternion) Divf(other float64) Quaternion

func (Quaternion) Dot

func (q Quaternion) Dot(other Quaternion) float64

Dot Returns the dot product of this quaternion and other.

func (Quaternion) EulerAngles

func (q Quaternion) EulerAngles(order EulerOrder) EulerAngles

EulerAngles returns the quaternion's rotation in the form of Euler angles. The Euler order depends on the order parameter, for example using the YXZ convention: since this method decomposes, first Z, then X, and Y last. See the EulerOrder enum for possible values. The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).

func (Quaternion) Exp

func (q Quaternion) Exp() Quaternion

func (Quaternion) IDENTITY

func (Quaternion) IDENTITY() Quaternion

func (Quaternion) Inverse

func (q Quaternion) Inverse() Quaternion

Inverse returns the inverse of the quaternion.

func (Quaternion) IsApproximatelyEqual

func (q Quaternion) IsApproximatelyEqual(other Quaternion) bool

IsApproximatelyEqual returns true if this quaternion and to are approximately equal, by running IsApproximatelyEqual on each component.

func (Quaternion) IsFinite

func (q Quaternion) IsFinite() bool

IsFinite returns true if this quaternion is finite, by calling IsFinite on each component.

func (Quaternion) IsNormalized

func (q Quaternion) IsNormalized() bool

IsNormalized returns whether the quaternion is normalized or not.

func (Quaternion) Length

func (q Quaternion) Length() float64

Length returns the length of the quaternion.

func (Quaternion) LengthSquared

func (q Quaternion) LengthSquared() float64

LengthSquared returns the length of the quaternion, squared.

func (Quaternion) Log

func (q Quaternion) Log() Quaternion

func (Quaternion) Mul

func (q Quaternion) Mul(other Quaternion) Quaternion

func (Quaternion) Mulf

func (q Quaternion) Mulf(other float64) Quaternion

func (Quaternion) Neg

func (q Quaternion) Neg() Quaternion

func (Quaternion) Normalized

func (q Quaternion) Normalized() Quaternion

Normalized returns a copy of the quaternion, normalized to unit length.

func (Quaternion) SetW

func (q Quaternion) SetW(v float64)

func (Quaternion) SetX

func (q Quaternion) SetX(v float64)

func (Quaternion) SetY

func (q Quaternion) SetY(v float64)

func (Quaternion) SetZ

func (q Quaternion) SetZ(v float64)

func (Quaternion) Slerp

func (q Quaternion) Slerp(to Quaternion, weight float64) Quaternion

Slerp returns the result of the spherical linear interpolation between this quaternion and to by amount weight.

Note: Both quaternions must be normalized.

func (Quaternion) Slerpni

func (q Quaternion) Slerpni(to Quaternion, weight float64) Quaternion

Slerpni returns the result of the spherical linear interpolation between this quaternion and to by amount weight, but without checking if the rotation path is not bigger than 90 degrees.

func (Quaternion) SphericalCubicInterpolate

func (q Quaternion) SphericalCubicInterpolate(b, pre_a, post_b Quaternion, weight float64) Quaternion

SphericalCubicInterpolate performs a spherical cubic interpolation between quaternions pre_a, this vector, b, and post_b, by the given amount weight.

func (Quaternion) SphericalCubicInterpolateInTime

func (q Quaternion) SphericalCubicInterpolateInTime(b, pre_a, post_b Quaternion, weight, b_t, pre_a_t, post_b_t float64) Quaternion

SphericalCubicInterpolateInTime performs a spherical cubic interpolation between quaternions pre_a, this vector, b, and post_b, by the given amount weight.

It can perform smoother interpolation than spherical_cubic_interpolate by the time values.

func (Quaternion) Sub

func (q Quaternion) Sub(other Quaternion) Quaternion

func (Quaternion) Subf

func (q Quaternion) Subf(other float64) Quaternion

func (Quaternion) W

func (q Quaternion) W() float64

func (Quaternion) X

func (q Quaternion) X() float64

func (Quaternion) Y

func (q Quaternion) Y() float64

func (Quaternion) Z

func (q Quaternion) Z() float64

type Radians

type Radians float64

Radians represents an angle in radians.

func Acos

func Acos[T ~float32 | ~float64](x T) Radians

Acos returns the arc cosine of x in radians. Use to get the angle of cosine x. x will be clamped between -1.0 and 1.0 (inclusive), in order to prevent acos from returning NaN.

func Acosh

func Acosh[T ~float32 | ~float64](x T) Radians

Acosh returns the hyperbolic arc (also called inverse) cosine of x, returning a value in radians. Use it to get the angle from an angle's cosine in hyperbolic space if x is larger or equal to 1. For values of x lower than 1, it will return 0, in order to prevent acosh from returning NaN.

func Asin

func Asin[T ~float32 | ~float64](x T) Radians

Asin returns the arc sine of x in radians. Use to get the angle of sine x. x will be clamped between -1.0 and 1.0 (inclusive), in order to prevent asin from returning NaN.

func Asinh

func Asinh[T ~float32 | ~float64](x T) Radians

Asinh returns the hyperbolic arc (also called inverse) sine of x, returning a value in radians. Use it to get the angle from an angle's sine in hyperbolic space.

func Atan

func Atan[T ~float32 | ~float64](x T) Radians

Atan returns the arc tangent of x in radians. Use it to get the angle from an angle's tangent in trigonometry. The method cannot know in which quadrant the angle should fall. See atan2 if you have both y and x.

func Atan2

func Atan2[T ~float32 | ~float64](y, x T) Radians

Atan2 returns the arc tangent of y/x in radians. Use to get the angle of tangent y/x. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant.

Important note: The Y coordinate comes first, by convention.

func Atanh

func Atanh[T ~float32 | ~float64](x T) Radians

Atanh returns the hyperbolic arc (also called inverse) tangent of x, returning a value in radians. Use it to get the angle from an angle's tangent in hyperbolic space if x is between -1 and 1 (non-inclusive).

In mathematics, the inverse hyperbolic tangent is only defined for -1 < x < 1 in the real set, so values equal or lower to -1 for x return -INF and values equal or higher than 1 return +INF in order to prevent atanh from returning NaN.

func (Radians) Degrees

func (rad Radians) Degrees() Degrees

Radians converts an angle expressed in radians to degrees.

func (Radians) Vector2

func (angle Radians) Vector2() Vector2

Vector2 creates a unit Vector2 rotated to the given angle in radians. This is equivalent to doing NewVector(Cos(angle),Sin(angle)) or Const(Vector2.Right).Rotated(angle).

type Rect2

type Rect2 struct {
	Position Vector2
	Size     Vector2
}

Rect2 represents an axis-aligned rectangle in a 2D space. It is defined by its position and size, which are Vector2. It is frequently used for fast overlap tests (see intersects). Although Rect2 itself is axis-aligned, it can be combined with Transform2D to represent a rotated or skewed rectangle.

For integer coordinates, use Rect2i. The 3D equivalent to Rect2 is AABB.

Note: Negative values for size are not supported. With negative size, most Rect2 methods do not work correctly. Use abs to get an equivalent Rect2 with a non-negative size.

Note: In a boolean context, a Rect2 evaluates to false if both position and size are zero (equal to Const(Vector2.ZERO)). Otherwise, it always evaluates to true.

func NewRect2

func NewRect2(x, y, width, height float64) Rect2

NewRect2 constructs a Rect2 by setting its position to (x, y), and its size to (width, height).

func (Rect2) Abs

func (r Rect2) Abs() Rect2

Abs returns a Rect2 equivalent to this rectangle, with its width and height modified to be non-negative values, and with its position being the top-left corner of the rectangle.

var rect = NewRect2(25,25,-100,-50)
var absolute = rect.Abs() // absolute is Rect2(-75, -25, 100, 50)

Note: It's recommended to use this method when size is negative, as most other methods in Godot assume that the position is the top-left corner, and the end is the bottom-right corner.

func (Rect2) Area

func (r Rect2) Area() float64

Area returns the rectangle's area. This is equivalent to Size[X] * Size[Y]. See also Rect2.HasArea.

func (Rect2) Center

func (r Rect2) Center() Vector2

Center returns the center point of the rectangle. This is the same as position + (size / 2.0).

func (Rect2) Encloses

func (r Rect2) Encloses(b Rect2) bool

Encloses returns true if this rectangle completely encloses the b rectangle.

func (Rect2) End

func (r Rect2) End() Vector2

End is the ending point. This is usually the bottom-right corner of the rectangle, and is equivalent to position + size.

func (Rect2) Expand

func (r Rect2) Expand(to Vector2) Rect2

Expand returns a copy of this rectangle expanded to align the edges with the given to point, if necessary.

var rect = NewRect2(0, 0, 5, 2)
rect = rect.Expand(Vector2{10, 0}) // rect is now Rect2(0, 0, 10, 2)
rect = rect.Expand(Vector2{-5, 5}) // rect is now Rect2(-5, 0, 10, 5)

func (Rect2) Grow

func (r Rect2) Grow(amount float64) Rect2

Grow returns a copy of this rectangle extended on all sides by the given amount. A negative amount shrinks the rectangle instead. See also Rect2.GrowIndividual and Rect2.GrowSide.

var a = Rect2{4,4,8,8}.Grow(4) // a is Rect2(0, 0, 16, 16)
var b = Rect2{4,4,8,8}.Grow(2) // b is Rect2(-2, -2, 12, 8)

func (Rect2) GrowIndividual

func (r Rect2) GrowIndividual(left, top, right, bottom float64) Rect2

GrowIndividual returns a copy of this rectangle with its left, top, right, and bottom sides extended by the given amounts. Negative values shrink the sides, instead. See also Rect2.Grow and Rect2.GrowSide.

func (Rect2) GrowSide

func (r Rect2) GrowSide(side Side, amount float64) Rect2

GrowSide returns a copy of this rectangle with its side extended by the given amount (see Side constants). A negative amount shrinks the rectangle, instead. See also Rect2.Grow and Rect2.GrowIndividual.

func (Rect2) HasArea

func (r Rect2) HasArea() bool

HasArea returns true if this rectangle has positive width and height. See also [GetArea].

func (Rect2) HasPoint

func (r Rect2) HasPoint(point Vector2) bool

HasPoint returns true if the rectangle contains the given point. By convention, points on the right and bottom edges are not included.

Note: This method is not reliable for Rect2 with a negative size. Use abs first to get a valid rectangle.

func (Rect2) Intersection

func (r Rect2) Intersection(b Rect2) Rect2

Intersection returns the intersection between this rectangle and b. If the rectangles do not intersect, returns an empty Rect2.

var rect1 = Rect2{0, 0, 5, 10}
var rect2 = Rect2{2, 0, 9, 4}

var a = rect1.Intersection(rect2) // a is Rect2(2, 0, 3, 4)

Note: If you only need to know whether two rectangles are overlapping, use Rect2.Intersects, instead.

func (Rect2) Intersects

func (r Rect2) Intersects(b Rect2, include_borders bool) bool

Intersects returns true if this rectangle overlaps with the b rectangle. The edges of both rectangles are excluded, unless include_borders is true.

func (Rect2) IsApproximatelyEqual

func (r Rect2) IsApproximatelyEqual(b Rect2) bool

IsApproximatelyEqual returns true if this rectangle and rect are approximately equal, by calling Vector2.IsApproximatelyEqual on the position and the size.

func (Rect2) IsFinite

func (r Rect2) IsFinite() bool

IsFinite returns true if this rectangle's values are finite, by calling Vector2.IsFinite on the position and the size.

func (Rect2) Merge

func (r Rect2) Merge(b Rect2) Rect2

Merge returns a Rect2 that encloses both this rectangle and b around the edges. See also Rect2.Encloses.

func (Rect2) Projection

func (r Rect2) Projection() Projection

Projection creates a new Projection that projects positions into the given Rect2.

func (Rect2) Rect2i

func (r Rect2) Rect2i() Rect2i

func (*Rect2) SetEnd

func (r *Rect2) SetEnd(end Vector2)

SetEnd sets the ending point. This is usually the bottom-right corner of the rectangle, and is equivalent to position + size. Setting the end point will change the size of the rectangle.

func (Rect2) Transform

func (r Rect2) Transform(t Transform2D) Rect2

Transform inversely transforms (multiplies) the Rect2 by the given Transform2D transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).

rect * transform is equivalent to transform.Inverse() * rect. See Transform2D.Inverse.

For transforming by inverse of an affine transformation (e.g. with scaling) rect.Transform(transform.AffineInverse()) can be used instead. See Transform2D.AffineInverse.

type Rect2i

type Rect2i struct {
	Position Vector2i
	Size     Vector2i
}

Rect2 represents an axis-aligned rectangle in a 2D space, using integer coordinates. It is defined by its position and size, which are Vector2i. Because it does not rotate, it is frequently used for fast overlap tests (see intersects).

For floating-point coordinates, see Rect2.

Note: Negative values for size are not supported. With negative size, most Rect2i methods do not work correctly. Use abs to get an equivalent Rect2i with a non-negative size.

Note: In a boolean context, a Rect2i evaluates to false if both position and size are zero (equal to Const(Vector2i.ZERO)). Otherwise, it always evaluates to true.

func (Rect2i) Abs

func (r Rect2i) Abs() Rect2i

Abs returns a Rect2 equivalent to this rectangle, with its width and height modified to be non-negative values, and with its position being the top-left corner of the rectangle.

var rect = NewRect2(25,25,-100,-50)
var absolute = rect.Abs() // absolute is Rect2(-75, -25, 100, 50)

Note: It's recommended to use this method when size is negative, as most other methods in Godot assume that the position is the top-left corner, and the end is the bottom-right corner.

func (Rect2i) Area

func (r Rect2i) Area() int64

Area returns the rectangle's area. This is equivalent to Size[X] * Size[Y]. See also Rect2.HasArea.

func (Rect2i) Center

func (r Rect2i) Center() Vector2i

Center returns the center point of the rectangle. This is the same as position + (size / 2.0).

func (Rect2i) Encloses

func (r Rect2i) Encloses(b Rect2i) bool

Encloses returns true if this rectangle completely encloses the b rectangle.

func (Rect2i) End

func (r Rect2i) End() Vector2i

End is the ending point. This is usually the bottom-right corner of the rectangle, and is equivalent to position + size.

func (Rect2i) Expand

func (r Rect2i) Expand(to Vector2i) Rect2i

Expand returns a copy of this rectangle expanded to align the edges with the given to point, if necessary.

var rect = NewRect2(0, 0, 5, 2)
rect = rect.Expand(Vector2{10, 0}) // rect is now Rect2(0, 0, 10, 2)
rect = rect.Expand(Vector2{-5, 5}) // rect is now Rect2(-5, 0, 10, 5)

func (Rect2i) Grow

func (r Rect2i) Grow(amount int64) Rect2i

Grow returns a copy of this rectangle extended on all sides by the given amount. A negative amount shrinks the rectangle instead. See also Rect2.GrowIndividual and Rect2.GrowSide.

var a = Rect2{4,4,8,8}.Grow(4) // a is Rect2(0, 0, 16, 16)
var b = Rect2{4,4,8,8}.Grow(2) // b is Rect2(-2, -2, 12, 8)

func (Rect2i) GrowIndividual

func (r Rect2i) GrowIndividual(left, top, right, bottom int64) Rect2i

GrowIndividual returns a copy of this rectangle with its left, top, right, and bottom sides extended by the given amounts. Negative values shrink the sides, instead. See also Rect2.Grow and Rect2.GrowSide.

func (Rect2i) GrowSide

func (r Rect2i) GrowSide(side Side, amount int64) Rect2i

GrowSide returns a copy of this rectangle with its side extended by the given amount (see Side constants). A negative amount shrinks the rectangle, instead. See also Rect2.Grow and Rect2.GrowIndividual.

func (Rect2i) HasArea

func (r Rect2i) HasArea() bool

HasArea returns true if this rectangle has positive width and height. See also [GetArea].

func (Rect2i) HasPoint

func (r Rect2i) HasPoint(point Vector2i) bool

HasPoint returns true if the rectangle contains the given point. By convention, points on the right and bottom edges are not included.

Note: This method is not reliable for Rect2 with a negative size. Use abs first to get a valid rectangle.

func (Rect2i) Intersection

func (r Rect2i) Intersection(b Rect2i) Rect2i

Intersection returns the intersection between this rectangle and b. If the rectangles do not intersect, returns an empty Rect2.

var rect1 = Rect2{0, 0, 5, 10}
var rect2 = Rect2{2, 0, 9, 4}

var a = rect1.Intersection(rect2) // a is Rect2(2, 0, 3, 4)

Note: If you only need to know whether two rectangles are overlapping, use Rect2.Intersects, instead.

func (Rect2i) Intersects

func (r Rect2i) Intersects(b Rect2i, include_borders bool) bool

Intersects returns true if this rectangle overlaps with the b rectangle. The edges of both rectangles are excluded, unless include_borders is true.

func (Rect2i) Merge

func (r Rect2i) Merge(b Rect2i) Rect2i

Merge returns a Rect2 that encloses both this rectangle and b around the edges. See also Rect2.Encloses.

func (Rect2i) Rect2

func (r Rect2i) Rect2() Rect2

func (*Rect2i) SetEnd

func (r *Rect2i) SetEnd(end Vector2i)

SetEnd sets the ending point. This is usually the bottom-right corner of the rectangle, and is equivalent to position + size. Setting the end point will change the size of the rectangle.

type Side

type Side int64
const (
	SideLeft   Side = 0
	SideTop    Side = 1
	SideRight  Side = 2
	SideBottom Side = 3
)

type Transform2D

type Transform2D [3]Vector2

Transform2D is a 2×3 matrix (2 rows, 3 columns) used for 2D linear transformations. It can represent transformations such as translation, rotation, and scaling. It consists of three Vector2 values: x, y, and the origin.

For more information, read the "Matrices and transforms" documentation article.

func NewTransform2D

func NewTransform2D(rotation Radians, scale Vector2, skew Radians, position Vector2) Transform2D

NewTransform2D constructs a new Transform2D from the given rotation and position.

func (Transform2D) AffineInverse

func (t Transform2D) AffineInverse() Transform2D

AffineInverse returns the inverse of the transform, under the assumption that the basis is invertible (must have non-zero determinant).

func (Transform2D) BasisTransform

func (t Transform2D) BasisTransform(v Vector2) Vector2

BasisTransform returns a vector transformed (multiplied) by the basis matrix.

This method does not account for translation (the origin vector).

func (Transform2D) Determinant

func (t Transform2D) Determinant() float64

Determinant returns the determinant of the basis matrix. If the basis is uniformly scaled, then its determinant equals the square of the scale factor.

A negative determinant means the basis was flipped, so one part of the scale is negative. A zero determinant means the basis isn't invertible, and is usually considered invalid.

func (Transform2D) FLIP_X

func (t Transform2D) FLIP_X() Transform2D

func (Transform2D) FLIP_Y

func (t Transform2D) FLIP_Y() Transform2D

func (Transform2D) IDENTITY

func (t Transform2D) IDENTITY() Transform2D

func (Transform2D) InterpolateWith

func (t Transform2D) InterpolateWith(b Transform2D, weight float64) Transform2D

InterpolateWith returns a transform interpolated between this transform and another by a given weight (on the range of 0.0 to 1.0).

func (Transform2D) Inverse

func (t Transform2D) Inverse() Transform2D

Inverse returns the inverse of the transform, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not). Use affine_inverse for non-orthonormal transforms (e.g. with scaling).

func (Transform2D) InverseBasisTransform

func (t Transform2D) InverseBasisTransform(v Vector2) Vector2

InverseBasisTransform returns a vector transformed (multiplied) by the inverse basis matrix, under the assumption that the basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).

This method does not account for translation (the origin vector).

transform.InverseBasisTransform(vector) is equivalent to transform.Inverse().BasisTransform(vector). See Transform2D.Inverse.

For non-orthonormal transforms (e.g. with scaling) transform.AffineInverse().BasisTransform(vector) can be used instead. See Transform2D.AffineInverse.

func (Transform2D) IsApproximatelyEqual

func (t Transform2D) IsApproximatelyEqual(xform Transform2D) bool

IsApproximatelyEqual returns true if this transform and xform are approximately equal, by running Vector2.IsApproximatelyEqual on each component.

func (Transform2D) IsConformal

func (t Transform2D) IsConformal() bool

IsConformal returns true if the transform's basis is conformal, meaning it preserves angles and distance ratios, and may only be composed of rotation and uniform scale. Returns false if the transform's basis has non-uniform scale or shear/skew. This can be used to validate if the transform is non-distorted, which is important for physics and other use cases.

func (Transform2D) IsFinite

func (t Transform2D) IsFinite() bool

IsFinite returns true if this transform is finite, by calling Vector2.IsFinite on each component.

func (Transform2D) LookingAt

func (t Transform2D) LookingAt(target Vector2) Transform2D

LookingAt returns a copy of the transform rotated such that the rotated X-axis points towards the target position.

Operations take place in global space.

func (Transform2D) Mul

func (t Transform2D) Mul(other Transform2D) Transform2D

func (Transform2D) Origin

func (t Transform2D) Origin() Vector2

Origin returns the transform's origin (translation).

func (Transform2D) Orthonormalized

func (t Transform2D) Orthonormalized() Transform2D

Orthonormalized returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors (scale of 1 or -1).

func (Transform2D) Rotated

func (t Transform2D) Rotated(angle Radians) Transform2D

Rotated returns a copy of the transform rotated by the given angle (in radians).

This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the left, i.e., R * X.

This can be seen as transforming with respect to the global/parent frame.

func (Transform2D) RotatedLocal

func (t Transform2D) RotatedLocal(angle Radians) Transform2D

RotatedLocal returns a copy of the transform rotated by the given angle (in radians).

This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the right, i.e., X * R.

This can be seen as transforming with respect to the local frame.

func (Transform2D) Rotation

func (t Transform2D) Rotation() Radians

Rotation returns the transform's rotation.

func (Transform2D) Scale

func (t Transform2D) Scale() Vector2

Scale returns the transform's scale.

func (Transform2D) Scaled

func (t Transform2D) Scaled(scale Vector2) Transform2D

Scaled returns a copy of the transform scaled by the given scale factor.

This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the left, i.e., S * X.

This can be seen as transforming with respect to the global/parent frame.

func (Transform2D) ScaledLocal

func (t Transform2D) ScaledLocal(scale Vector2) Transform2D

ScaledLocal returns a copy of the transform scaled by the given scale factor.

This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the right, i.e., X * S.

This can be seen as transforming with respect to the local frame.

func (*Transform2D) SetOrigin

func (t *Transform2D) SetOrigin(o Vector2)

func (*Transform2D) SetX

func (t *Transform2D) SetX(x Vector2)

func (*Transform2D) SetY

func (t *Transform2D) SetY(y Vector2)

func (Transform2D) Skew

func (t Transform2D) Skew() Radians

Skew returns the transform's skew (in radians)

func (Transform2D) Translated

func (t Transform2D) Translated(offset Vector2) Transform2D

Translated returns a copy of the transform translated by the given offset.

This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the left, i.e., T * X.

This can be seen as transforming with respect to the global/parent frame.

func (Transform2D) TranslatedLocal

func (t Transform2D) TranslatedLocal(offset Vector2) Transform2D

TranslatedLocal returns a copy of the transform translated by the given offset.

This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the right, i.e., X * T.

This can be seen as transforming with respect to the local frame.

func (Transform2D) X

func (t Transform2D) X() Vector2

func (Transform2D) Y

func (t Transform2D) Y() Vector2

type Transform3D

type Transform3D struct {
	Basis  Basis
	Origin Vector3
}

Transform3D is a 3×4 matrix (3 rows, 4 columns) used for 3D linear transformations. It can represent transformations such as translation, rotation, and scaling. It consists of a basis (first 3 columns) and a Vector3 for the origin (last column).

func (Transform3D) AffineInverse

func (t Transform3D) AffineInverse() Transform3D

AffineInverse returns the inverse of the transform, under the assumption that the basis is invertible (must have non-zero determinant).

func (Transform3D) FLIP_X

func (Transform3D) FLIP_X() Transform3D

func (Transform3D) FLIP_Y

func (Transform3D) FLIP_Y() Transform3D

func (Transform3D) FLIP_Z

func (Transform3D) FLIP_Z() Transform3D

func (Transform3D) IDENTITY

func (Transform3D) IDENTITY() Transform3D

func (Transform3D) InterpolateWith

func (t Transform3D) InterpolateWith(other Transform3D, weight float64) Transform3D

InterpolateWith returns a transform interpolated between this transform and another by a given weight (on the range of 0.0 to 1.0).

func (Transform3D) Inverse

func (t Transform3D) Inverse() Transform3D

Inverse returns the inverse of the transform, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not). Use affine_inverse for non-orthonormal transforms (e.g. with scaling).

func (Transform3D) IsApproximatelyEqual

func (t Transform3D) IsApproximatelyEqual(other Transform3D) bool

IsApproximatelyEqual returns true if this transform and xform are approximately equal, by running IsApproximatelyEqual on each component.

func (Transform3D) IsFinite

func (t Transform3D) IsFinite() bool

IsFinite returns true if this transform is finite, by calling IsFinite on each component.

func (Transform3D) LookingAt

func (t Transform3D) LookingAt(target, up Vector3, use_model_front bool) Transform3D

LookingAt returns a copy of the transform rotated such that the forward axis (-Z) points towards the target position.

The up axis (+Y) points as close to the up vector as possible while staying perpendicular to the forward axis. The resulting transform is orthonormalized. The existing rotation, scale, and skew information from the original transform is discarded. The target and up vectors cannot be zero, cannot be parallel to each other, and are defined in global/parent space.

If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).

func (Transform3D) Mul

func (t Transform3D) Mul(other Transform3D) Transform3D

func (Transform3D) Orthonormalized

func (t Transform3D) Orthonormalized() Transform3D

Orthonormalized returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors (scale of 1 or -1).

func (Transform3D) Projection

func (t Transform3D) Projection() Projection

func (Transform3D) Rotated

func (t Transform3D) Rotated(axis Vector3, phi Radians) Transform3D

Rotated returns a copy of the transform rotated around the given axis by the given angle (in radians).

The axis must be a normalized vector.

This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the left, i.e., R * X.

This can be seen as transforming with respect to the global/parent frame.

func (Transform3D) RotatedLocal

func (t Transform3D) RotatedLocal(axis Vector3, phi Radians) Transform3D

RotatedLocal returns a copy of the transform rotated around the given axis by the given angle (in radians).

The axis must be a normalized vector.

This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the right, i.e., X * R.

This can be seen as transforming with respect to the local frame.

func (Transform3D) Scaled

func (t Transform3D) Scaled(scale Vector3) Transform3D

Scaled returns a copy of the transform scaled by the given scale factor.

This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the left, i.e., S * X.

This can be seen as transforming with respect to the global/parent frame.

func (Transform3D) ScaledLocal

func (t Transform3D) ScaledLocal(scale Vector3) Transform3D

ScaledLocal returns a copy of the transform scaled by the given scale factor.

This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the right, i.e., X * S.

This can be seen as transforming with respect to the local frame.

func (Transform3D) Translated

func (t Transform3D) Translated(offset Vector3) Transform3D

Translated returns a copy of the transform translated by the given offset.

This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the left, i.e., T * X.

This can be seen as transforming with respect to the global/parent frame.

func (Transform3D) TranslatedLocal

func (t Transform3D) TranslatedLocal(offset Vector3) Transform3D

TranslatedLocal returns a copy of the transform translated by the given offset.

This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the right, i.e., X * T.

This can be seen as transforming with respect to the local frame.

type Vector2

type Vector2 [2]float

Vector2 is a 2-element structure that can be used to represent 2D coordinates or any other pair of numeric values.

It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike [Float] which is always 64-bit. If double precision is needed, compile the engine with the option precision=double.

See Vector2i for its integer counterpart.

Note: In a boolean context, a Vector2 will evaluate to false if it's equal to Vector2{0, 0}. Otherwise, a Vector2 will always evaluate to true.

func NewVector2

func NewVector2(x, y float64) Vector2

NewVector2 constructs a new Vector2 from the given x and y.

func (Vector2) Abs

func (v Vector2) Abs() Vector2

Abs returns a new vector with all components in absolute values (i.e. positive).

func (Vector2) Add

func (v Vector2) Add(other Vector2) Vector2

func (Vector2) Addf

func (v Vector2) Addf(other float64) Vector2

func (Vector2) Angle

func (v Vector2) Angle() Radians

Angle Returns this vector's angle with respect to the positive X axis, or (1, 0) vector, in radians.

For example, Const(Vector2.Right).Angle() will return zero, Const(Vector2.Down).Angle() will return PI / 2 (a quarter turn, or 90 degrees), and Vector2(1, -1).Angle() will return -Pi / 4 (a negative eighth turn, or -45 degrees).

Illustration of the returned angle. https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle.png

Equivalent to the result of Atan2 when called with the vector's y and x as parameters:

Atan2(y, x).

func (Vector2) AngleTo

func (v Vector2) AngleTo(to Vector2) Radians

AngleTo Returns the angle to the given vector, in radians.

Illustration of the returned angle. https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to.png

func (Vector2) AngleToPoint

func (v Vector2) AngleToPoint(to Vector2) Radians

AngleToPoint returns the angle between the line connecting the two points and the X axis, in radians. a.AngleToPoint(b) is equivalent of doing (b - a).Angle().

Illustration of the returned angle. https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to_point.png

func (Vector2) Aspect

func (v Vector2) Aspect() float64

Aspect returns the aspect ratio of this vector, the ratio of x to y.

func (Vector2) BezierDerivative

func (v Vector2) BezierDerivative(control1, control2, end Vector2, t float64) Vector2

BezierDerivative returns the derivative at the given t on the Bézier curve defined by this vector and the given control_1, control_2, and end points.

func (Vector2) BezierInterpolate

func (v Vector2) BezierInterpolate(control1, control2, end Vector2, t float64) Vector2

BezierInterpolate returns the point at the given t on the Bézier curve defined by this vector and the given control_1, control_2, and end points.

func (Vector2) Bounce

func (v Vector2) Bounce(n Vector2) Vector2

Bounce returns a new vector "bounced off" from a plane defined by the given normal.

func (Vector2) Ceil

func (v Vector2) Ceil() Vector2

Ceil returns a new vector with all components rounded up (towards positive infinity).

func (Vector2) Clamp

func (v Vector2) Clamp(from, to Vector2) Vector2

Clamp returns a new vector with all components clamped to the given min and max.

func (Vector2) Cross

func (v Vector2) Cross(other Vector2) float64

Cross returns the 2D analog of the cross product for this vector and with.

This is the signed area of the parallelogram formed by the two vectors. If the second vector is clockwise from the first vector, then the cross product is the positive area. If counter-clockwise, the cross product is the negative area.

Note: Cross product is not defined in 2D mathematically. This method embeds the 2D vectors in the XY plane of 3D space and uses their cross product's Z component as the analog.

func (Vector2) CubicInterpolate

func (v Vector2) CubicInterpolate(b, preA, postB Vector2, weight float64) Vector2

CubicInterpolate performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

func (Vector2) CubicInterpolateInTime

func (v Vector2) CubicInterpolateInTime(b, preA, postB Vector2, weight, b_t, pre_a_t, post_b_t float64) Vector2

CubicInterpolateInTime performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

It can perform smoother interpolation than cubic_interpolate by the time values.

func (Vector2) DOWN

func (v Vector2) DOWN() Vector2

func (Vector2) DirectionTo

func (v Vector2) DirectionTo(to Vector2) Vector2

DirectionTo returns the normalized vector pointing from this vector to to. This is equivalent to using (b - a).Normalized().

func (Vector2) DistanceSquaredTo

func (v Vector2) DistanceSquaredTo(to Vector2) float64

DistanceSquaredTo returns the squared distance between this vector and to.

This method runs faster than distance_to, so prefer it if you need to compare vectors or need the squared distance for some formula.

func (Vector2) DistanceTo

func (v Vector2) DistanceTo(to Vector2) float64

DistanceTo returns the distance between this vector and to.

func (Vector2) Div

func (v Vector2) Div(other Vector2) Vector2

func (Vector2) Divf

func (v Vector2) Divf(other float64) Vector2

func (Vector2) Dot

func (v Vector2) Dot(other Vector2) float64

Dot returns the dot product of this vector and with. This can be used to compare the angle between two vectors. For example, this can be used to determine whether an enemy is facing the player.

The dot product will be 0 for a straight angle (90 degrees), greater than 0 for angles narrower than 90 degrees and lower than 0 for angles wider than 90 degrees.

When using unit (normalized) vectors, the result will always be between -1.0 (180 degree angle) when the vectors are facing opposite directions, and 1.0 (0 degree angle) when the vectors are aligned.

Note: Vector2.Dot(a,b) is equivalent to Vector2.Dot(b,a)

func (Vector2) Floor

func (v Vector2) Floor() Vector2

Floor returns a new vector with all components rounded down (towards negative infinity).

func (Vector2) INF

func (v Vector2) INF() Vector2

func (Vector2) IsApproximatelyEqual

func (v Vector2) IsApproximatelyEqual(to Vector2) bool

IsAproximatelyEqual returns true if this vector and to are approximately equal, by running [IsAproximatelyEqual] on each component.

func (Vector2) IsApproximatelyZero

func (v Vector2) IsApproximatelyZero() bool

IsAproximatelyZero returns true if this vector is approximately equal to Vector2.Zero.

func (Vector2) IsFinite

func (v Vector2) IsFinite() bool

IsFinite returns true if this vector is finite, by calling IsFinite on each component.

func (Vector2) IsNormalized

func (v Vector2) IsNormalized() bool

IsNormalized returns true if the vector is normalized, i.e. its length is approximately equal to 1.

func (Vector2) LEFT

func (v Vector2) LEFT() Vector2

func (Vector2) Length

func (v Vector2) Length() float64

Length returns the length (magnitude) of this vector.

func (Vector2) LengthSquared

func (v Vector2) LengthSquared() float64

LengthSquared returns the squared length (squared magnitude) of this vector.

func (Vector2) Lerp

func (v Vector2) Lerp(to Vector2, weight float64) Vector2

Lerp returns the result of the linear interpolation between this vector and to by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

func (Vector2) LimitLength

func (v Vector2) LimitLength(length float64) Vector2

LimitLength returns the vector with a maximum length by limiting its length to length.

func (Vector2) MaxAxis

func (v Vector2) MaxAxis() Axis

MaxAxis returns the axis of the vector's highest value. See Axis constants. If all components are equal, this method returns X.

func (Vector2) MinAxis

func (v Vector2) MinAxis() Axis

MinAxis returns the axis of the vector's lowest value. See Axis constants. If all components are equal, this method returns Y.

func (Vector2) MoveToward

func (v Vector2) MoveToward(to Vector2, delta float64) Vector2

MoveToward returns a new vector moved toward to by the fixed delta amount. Will not go past the final value.

func (Vector2) Mul

func (v Vector2) Mul(other Vector2) Vector2

func (Vector2) Mulf

func (v Vector2) Mulf(other float64) Vector2

func (Vector2) Neg

func (v Vector2) Neg() Vector2

func (Vector2) Normalized

func (v Vector2) Normalized() Vector2

Normalized returns the result of scaling the vector to unit length. Equivalent to v / v.Length(). See also is_normalized.

Note: This function may return incorrect values if the input vector length is near zero.

func (Vector2) ONE

func (v Vector2) ONE() Vector2

func (Vector2) Orthogonal

func (v Vector2) Orthogonal() Vector2

Orthogonal returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.

func (Vector2) Posmod

func (v Vector2) Posmod(mod float64) Vector2

Posmode returns a vector composed of the Fposmod of this vector's components and [Mod].

func (Vector2) PosmodVector

func (v Vector2) PosmodVector(mod Vector2) Vector2

Posmod returns a vector composed of the Fposmod of this vector's components and [Mod].

func (Vector2) Project

func (v Vector2) Project(b Vector2) Vector2

Project returns the result of projecting the vector onto the given vector b.

func (Vector2) RIGHT

func (v Vector2) RIGHT() Vector2

func (Vector2) Reflect

func (v Vector2) Reflect(n Vector2) Vector2

Reflect returns the result of reflecting the vector from a line defined by the given direction vector n.

func (Vector2) Rotated

func (v Vector2) Rotated(by Radians) Vector2

Rotated returns the result of rotating this vector by angle (in radians).

func (Vector2) Round

func (v Vector2) Round() Vector2

Round returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.

func (*Vector2) SetX

func (v *Vector2) SetX(x float64)

func (*Vector2) SetY

func (v *Vector2) SetY(y float64)

func (Vector2) Sign

func (v Vector2) Sign() Vector2

Sign returns a new vector with each component set to 1.0 if it's positive, -1.0 if it's negative, and 0.0 if it's zero. The result is identical to calling Signf on each component.

func (Vector2) Slerp

func (v Vector2) Slerp(to Vector2, weight Radians) Vector2

Slerp returns the result of spherical linear interpolation between this vector and to, by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

This method also handles interpolating the lengths if the input vectors have different lengths. For the special case of one or both input vectors having zero length, this method behaves like lerp.

func (Vector2) Slide

func (v Vector2) Slide(n Vector2) Vector2

Slide returns the result of sliding the vector along a plane defined by the given normal.

func (Vector2) Snapped

func (v Vector2) Snapped(step Vector2) Vector2

Snapped returns a new vector with all components snapped to the nearest multiple of step.

func (Vector2) Sub

func (v Vector2) Sub(other Vector2) Vector2

func (Vector2) Subf

func (v Vector2) Subf(other float64) Vector2

func (Vector2) Transform

func (v Vector2) Transform(t Transform2D) Vector2

func (Vector2) UP

func (v Vector2) UP() Vector2

func (Vector2) Vector2i

func (v Vector2) Vector2i() Vector2i

Vector2i constructs a new Vector2i from the given Vector2 by truncating components' fractional parts (rounding towards zero). For a different behavior consider passing the result of Vector2.Ceil, Vector2.Floor or Vector2.Round to this constructor instead.

func (Vector2) X

func (v Vector2) X() float64

func (Vector2) Y

func (v Vector2) Y() float64

func (Vector2) ZERO

func (v Vector2) ZERO() Vector2

type Vector2i

type Vector2i [2]int32

Vector2i is a 2-element structure that can be used to represent 2D grid coordinates or any other pair of integers.

It uses integer coordinates and is therefore preferable to Vector2 when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector2 this cannot be configured with an engine build option. Use [Int] or [PackedInt64Array] if 64-bit values are needed.

Note: In a boolean context, a Vector2i will evaluate to false if it's equal to Vector2i{0, 0}. Otherwise, a Vector2i will always evaluate to true.

func (Vector2i) Abs

func (v Vector2i) Abs() Vector2i

Abs returns a new vector with all components in absolute values (i.e. positive).

func (Vector2i) Add

func (v Vector2i) Add(other Vector2i) Vector2i

func (Vector2i) Addi

func (v Vector2i) Addi(other int64) Vector2i

func (Vector2i) Aspect

func (v Vector2i) Aspect() float64

Aspect returns the aspect ratio of this vector, the ratio of x to y.

func (Vector2i) Clamp

func (v Vector2i) Clamp(min, max Vector2i) Vector2i

Clamp returns a new vector with all components clamped between the components of min and max, by running clamp on each component.

func (Vector2i) DOWN

func (v Vector2i) DOWN() Vector2i

func (Vector2i) Div

func (v Vector2i) Div(other Vector2i) Vector2i

func (Vector2i) Divi

func (v Vector2i) Divi(other int64) Vector2i

func (Vector2i) LEFT

func (v Vector2i) LEFT() Vector2i

func (Vector2i) Length

func (v Vector2i) Length() float64

Length returns the length (magnitude) of this vector.

func (Vector2i) LengthSquared

func (v Vector2i) LengthSquared() int64

LengthSquared returns the squared length (squared magnitude) of this vector.

This method runs faster than length, so prefer it if you need to compare vectors or need the squared distance for some formula.

func (Vector2i) MAX

func (v Vector2i) MAX() Vector2i

func (Vector2i) MIN

func (v Vector2i) MIN() Vector2i

func (Vector2i) MaxAxis

func (v Vector2i) MaxAxis() Axis

MaxAxis returns the axis of the vector's highest value. See Axis constants. If all components are equal, this method returns X.

func (Vector2i) MinAxis

func (v Vector2i) MinAxis() Axis

MinAxis returns the axis of the vector's lowest value. See Axis constants. If all components are equal, this method returns Y.

func (Vector2i) Mod

func (v Vector2i) Mod(other Vector2i) Vector2i

func (Vector2i) Modi

func (v Vector2i) Modi(other int64) Vector2i

func (Vector2i) Mul

func (v Vector2i) Mul(other Vector2i) Vector2i

func (Vector2i) Muli

func (v Vector2i) Muli(other int64) Vector2i

func (Vector2i) Neg

func (v Vector2i) Neg() Vector2i

func (Vector2i) ONE

func (v Vector2i) ONE() Vector2i

func (Vector2i) RIGHT

func (v Vector2i) RIGHT() Vector2i

func (Vector2i) SetX

func (v Vector2i) SetX(x int64)

func (Vector2i) SetY

func (v Vector2i) SetY(y int64)

func (Vector2i) Sign

func (v Vector2i) Sign() Vector2i

Sign returns a new vector with each component set to 1 if it's positive, -1 if it's negative, and 0 if it's zero. The result is identical to calling Signi on each component.

func (Vector2i) Snapped

func (v Vector2i) Snapped(step Vector2i) Vector2i

Snapped returns a new vector with each component snapped to the closest multiple of the corresponding component in step.

func (Vector2i) Sub

func (v Vector2i) Sub(other Vector2i) Vector2i

func (Vector2i) Subi

func (v Vector2i) Subi(other int64) Vector2i

func (Vector2i) UP

func (v Vector2i) UP() Vector2i

func (Vector2i) Vector2

func (v Vector2i) Vector2() Vector2

Vector2 constructs a new Vector2 from Vector2i.

func (Vector2i) X

func (v Vector2i) X() int64

func (Vector2i) Y

func (v Vector2i) Y() int64

func (Vector2i) ZERO

func (v Vector2i) ZERO() Vector2i

"Constants"

type Vector3

type Vector3 [3]float

Vector3 is a 3-element structure that can be used to represent 3D coordinates or any other triplet of numeric values.

It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike [Float] which is always 64-bit. If double precision is needed, compile the engine with the option precision=double.

See Vector3i for its integer counterpart.

Note: In a boolean context, a Vector3 will evaluate to false if it's equal to Vector3{0, 0, 0}. Otherwise, a Vector3 will always evaluate to true.

func NewVector3

func NewVector3(x, y, z float64) Vector3

NewVector3 constructs a new Vector3 from the given x, y, and z.

func (Vector3) Abs

func (v Vector3) Abs() Vector3

Abs returns a new vector with all components in absolute values (i.e. positive).

func (Vector3) Add

func (v Vector3) Add(other Vector3) Vector3

func (Vector3) Addf

func (v Vector3) Addf(other float64) Vector3

func (Vector3) AngleTo

func (v Vector3) AngleTo(to Vector3) Radians

AngleTo returns the unsigned minimum angle to the given vector, in radians.

func (Vector3) BACK

func (Vector3) BACK() Vector3

func (Vector3) BezierDerivative

func (v Vector3) BezierDerivative(control1, control2, end Vector3, t float64) Vector3

BezierDerivative returns the derivative at the given t on the Bézier curve defined by this vector and the given control_1, control_2, and end points.

func (Vector3) BezierInterpolate

func (v Vector3) BezierInterpolate(control1, control2, end Vector3, t float64) Vector3

BezierInterpolate returns the point at the given t on the Bézier curve defined by this vector and the given control_1, control_2, and end points.

func (Vector3) Bounce

func (v Vector3) Bounce(n Vector3) Vector3

Bounce returns the vector "bounced off" from a plane defined by the given normal.

func (Vector3) Ceil

func (v Vector3) Ceil() Vector3

Ceil returns a new vector with all components rounded up (towards positive infinity).

func (Vector3) Clamp

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

Clamp returns a new vector with all components clamped between the components of min and max, by running Clampf on each component.

func (Vector3) Cross

func (v Vector3) Cross(with Vector3) Vector3

Cross returns the cross product of this vector and with.

func (Vector3) CubicInterpolate

func (v Vector3) CubicInterpolate(b, preA, postB Vector3, weight float64) Vector3

CubicInterpolate performs a cubic interpolation between this vector and b using pre_a and post_b as handles and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

func (Vector3) CubicInterpolateInTime

func (v Vector3) CubicInterpolateInTime(b, preA, postB Vector3, weight, b_t, pre_a_t, post_b_t float64) Vector3

CubicInterpolateInTime performs a cubic interpolation between this vector and b using pre_a and post_b as handles and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

It can perform smoother interpolation than Vector3.CubicInterpolate by the time values.

func (Vector3) DOWN

func (Vector3) DOWN() Vector3

func (Vector3) DirectionTo

func (v Vector3) DirectionTo(to Vector3) Vector3

DirectionTo returns the normalized vector pointing from this vector to to. This is equivalent to using (b - a).Normalized().

func (Vector3) DistanceSquaredTo

func (v Vector3) DistanceSquaredTo(to Vector3) float64

DistanceSquaredTo returns the squared distance between this vector and to.

This method runs faster than Vector3.DistanceTo, so prefer it if you need to compare vectors or need the squared distance for some formula.

func (Vector3) DistanceTo

func (v Vector3) DistanceTo(to Vector3) float64

DistanceTo returns the distance between this vector and to.

func (Vector3) Div

func (v Vector3) Div(other Vector3) Vector3

func (Vector3) Divf

func (v Vector3) Divf(other float64) Vector3

func (Vector3) Dot

func (v Vector3) Dot(with Vector3) float64

Dot returns the dot product of this vector and with. This can be used to compare the angle between two vectors. For example, this can be used to determine whether an enemy is facing the player.

The dot product will be 0 for a straight angle (90 degrees), greater than 0 for angles narrower than 90 degrees and lower than 0 for angles wider than 90 degrees.

When using unit (normalized) vectors, the result will always be between -1.0 (180 degree angle) when the vectors are facing opposite directions, and 1.0 (0 degree angle) when the vectors are aligned.

Note: a.Dot(b) is equivalent to b.Dot(a).

func (Vector3) FORWARD

func (Vector3) FORWARD() Vector3

func (Vector3) Floor

func (v Vector3) Floor() Vector3

Floor returns a new vector with all components rounded down (towards negative infinity).

func (Vector3) INF

func (Vector3) INF() Vector3

func (Vector3) Inverse

func (v Vector3) Inverse() Vector3

Inverse returns the inverse of the vector. This is the same as Vector3{1/v[X],1/v[Y],1/v[Z]}.

func (Vector3) IsApproximatelyEqual

func (v Vector3) IsApproximatelyEqual(other Vector3) bool

IsApproximatelyEqual returns true if this vector and other are approximately equal, by running IsApproximatelyEqual on each component.

func (Vector3) IsApproximatelyZero

func (v Vector3) IsApproximatelyZero() bool

IsApproximatelyZero returns true if this vector is approximately equal to zero, by running IsApproximatelyZero on each component.

func (Vector3) IsFinite

func (v Vector3) IsFinite() bool

IsFinite returns true if this vector's values are finite, by running IsFinite on each component.

func (Vector3) IsNormalized

func (v Vector3) IsNormalized() bool

IsNormalized Returns true if the vector is normalized, i.e. its length is approximately equal to 1.

func (Vector3) LEFT

func (Vector3) LEFT() Vector3

func (Vector3) Length

func (v Vector3) Length() float64

Length the length (magnitude) of this vector.

func (Vector3) LengthSquared

func (v Vector3) LengthSquared() float64

LengthSquared returns the squared length (squared magnitude) of this vector.

This method runs faster than length, so prefer it if you need to compare vectors or need the squared distance for some formula.

func (Vector3) Lerp

func (v Vector3) Lerp(to Vector3, weight float64) Vector3

Lerp returns the result of the linear interpolation between this vector and to by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

func (Vector3) LimitLength

func (v Vector3) LimitLength(length float64) Vector3

LimitLength returns the vector with a maximum length by limiting its length to length.

func (Vector3) MODEL_BOTTOM

func (Vector3) MODEL_BOTTOM() Vector3

func (Vector3) MODEL_FRONT

func (Vector3) MODEL_FRONT() Vector3

func (Vector3) MODEL_LEFT

func (Vector3) MODEL_LEFT() Vector3

func (Vector3) MODEL_REAR

func (Vector3) MODEL_REAR() Vector3

func (Vector3) MODEL_RIGHT

func (Vector3) MODEL_RIGHT() Vector3

func (Vector3) MODEL_TOP

func (Vector3) MODEL_TOP() Vector3

func (Vector3) MaxAxis

func (v Vector3) MaxAxis() Axis

MaxAxis returns the axis of the vector's highest value. See Axis constants. If all components are equal, this method returns X.

func (Vector3) MinAxis

func (v Vector3) MinAxis() Axis

MinAxis returns the axis of the vector's lowest value. See Axis constants. If all components are equal, this method returns Z.

func (Vector3) MoveToward

func (v Vector3) MoveToward(to Vector3, delta float64) Vector3

MoveToward returns a new vector moved toward to by the fixed delta amount. Will not go past the final value.

func (Vector3) Mul

func (v Vector3) Mul(other Vector3) Vector3

func (Vector3) Mulf

func (v Vector3) Mulf(other float64) Vector3

func (Vector3) Neg

func (v Vector3) Neg() Vector3

func (Vector3) Normalized

func (v Vector3) Normalized() Vector3

Normalized returns the result of scaling the vector to unit length. Equivalent to v / v.Length(). See also Vector3.IsNormalized.

Note: This function may return incorrect values if the input vector length is near zero.

func (Vector3) ONE

func (Vector3) ONE() Vector3

func (Vector3) OctahedronDecode

func (v Vector3) OctahedronDecode(uv Vector2) Vector3

OctahedronDecode returns the Vector3 from an octahedral-compressed form created using OctahedronEncode (stored as a Vector2).

func (Vector3) OctahedronEncode

func (v Vector3) OctahedronEncode() Vector2

OctahedronEncode returns the octahedral-encoded (oct32) form of this Vector3 as a Vector2. Since a Vector2 occupies 1/3 less memory compared to Vector3, this form of compression can be used to pass greater amounts of normalized [Vector3]s without increasing storage or memory requirements. See also Vector3.OctahedronDecode.

Note: OctahedronEncode can only be used for normalized vectors. OctahedronEncode does not check whether this Vector3 is normalized, and will return a value that does not decompress to the original value if the Vector3 is not normalized.

Note: Octahedral compression is lossy, although visual differences are rarely perceptible in real world scenarios.

func (Vector3) Outer

func (v Vector3) Outer(with Vector3) Basis

Outer returns the outer product with with.

func (Vector3) Posmodf

func (v Vector3) Posmodf(mod float64) Vector3

Posmodf returns a vector composed of the Fposmod of this vector's components and mod.

func (Vector3) Posmodv

func (v Vector3) Posmodv(mod Vector3) Vector3

Posmodv returns a vector composed of the Fposmod of this vector's components and mod.

func (Vector3) Project

func (v Vector3) Project(b Vector3) Vector3

Project returns the result of projecting the vector onto the given vector b.

func (Vector3) RIGHT

func (Vector3) RIGHT() Vector3

func (Vector3) Reflect

func (v Vector3) Reflect(n Vector3) Vector3

Reflect returns the result of reflecting the vector from a plane defined by the given normal n.

func (Vector3) Rotated

func (v Vector3) Rotated(axis Vector3, angle Radians) Vector3

Rotated returns the result of rotating this vector around a given axis by angle (in radians). The axis must be a normalized vector.

func (Vector3) Round

func (v Vector3) Round() Vector3

Round returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.

func (*Vector3) SetX

func (v *Vector3) SetX(x float64)

func (*Vector3) SetY

func (v *Vector3) SetY(y float64)

func (*Vector3) SetZ

func (v *Vector3) SetZ(z float64)

func (Vector3) SignedAngleTo

func (v Vector3) SignedAngleTo(to Vector3, axis Vector3) Radians

SignedAngleTo returns the signed angle to the given vector, in radians. The sign of the angle is positive in a counter-clockwise direction and negative in a clockwise direction when viewed from the side specified by the axis.

func (Vector3) Slerp

func (v Vector3) Slerp(to Vector3, weight float64) Vector3

Slerp returns the result of spherical linear interpolation between this vector and to, by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

This method also handles interpolating the lengths if the input vectors have different lengths. For the special case of one or both input vectors having zero length, this method behaves like lerp.

func (Vector3) Slide

func (v Vector3) Slide(n Vector3) Vector3

Slide returns a new vector slid along a plane defined by the given normal.

func (Vector3) Snapped

func (v Vector3) Snapped(step Vector3) Vector3

Snapped returns a new vector with each component snapped to the nearest multiple of the corresponding component in step. This can also be used to round the components to an arbitrary number of decimals.

func (Vector3) Sub

func (v Vector3) Sub(other Vector3) Vector3

func (Vector3) Subf

func (v Vector3) Subf(other float64) Vector3

func (Vector3) Transform

func (v Vector3) Transform(t Transform3D) Vector3

func (Vector3) UP

func (Vector3) UP() Vector3

func (Vector3) Vector3i

func (v Vector3) Vector3i() Vector3i

func (Vector3) X

func (v Vector3) X() float64

func (Vector3) Y

func (v Vector3) Y() float64

func (Vector3) Z

func (v Vector3) Z() float64

func (Vector3) ZERO

func (Vector3) ZERO() Vector3

"Constants"

type Vector3i

type Vector3i [3]int32

Vector3i is A 3-element structure that can be used to represent 3D grid coordinates or any other triplet of integers.

It uses integer coordinates and is therefore preferable to Vector3 when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector3 this cannot be configured with an engine build option. Use [Int] or [PackedInt64Array] if 64-bit values are needed.

Note: In a boolean context, a Vector3i will evaluate to false if it's equal to Vector3i{0, 0, 0}. Otherwise, a Vector3i will always evaluate to true.

func (Vector3i) Abs

func (v Vector3i) Abs() Vector3i

Abs returns a new vector with all components in absolute values (i.e. positive).

func (Vector3i) Add

func (v Vector3i) Add(other Vector3i) Vector3i

func (Vector3i) Addi

func (v Vector3i) Addi(other int64) Vector3i

func (Vector3i) BACK

func (Vector3i) BACK() Vector3i

func (Vector3i) Clamp

func (v Vector3i) Clamp(min, max Vector3i) Vector3i

Clamp returns a new vector with all components clamped between the components of min and max, by running Clampi on each component.

func (Vector3i) DOWN

func (Vector3i) DOWN() Vector3i

func (Vector3i) Div

func (v Vector3i) Div(other Vector3i) Vector3i

func (Vector3i) Divi

func (v Vector3i) Divi(other int64) Vector3i

func (Vector3i) FORWARD

func (Vector3i) FORWARD() Vector3i

func (Vector3i) LEFT

func (Vector3i) LEFT() Vector3i

func (Vector3i) Length

func (v Vector3i) Length() float64

Length returns the length (magnitude) of this vector.

func (Vector3i) LengthSquared

func (v Vector3i) LengthSquared() int64

LengthSquared returns the squared length (squared magnitude) of this vector.

This method runs faster than length, so prefer it if you need to compare vectors or need the squared distance for some formula.

func (Vector3i) MAX

func (Vector3i) MAX() Vector3i

func (Vector3i) MIN

func (Vector3i) MIN() Vector3i

func (Vector3i) MaxAxis

func (v Vector3i) MaxAxis() Axis

MaxAxis returns the axis of the vector's highest value. See Axis constants. If all components are equal, this method returns X.

func (Vector3i) MinAxis

func (v Vector3i) MinAxis() Axis

MinAxis returns the axis of the vector's lowest value. See Axis constants. If all components are equal, this method returns Z.

func (Vector3i) Mod

func (v Vector3i) Mod(other Vector3i) Vector3i

func (Vector3i) Modi

func (v Vector3i) Modi(other int64) Vector3i

func (Vector3i) Mul

func (v Vector3i) Mul(other Vector3i) Vector3i

func (Vector3i) Muli

func (v Vector3i) Muli(other int64) Vector3i

func (Vector3i) Neg

func (v Vector3i) Neg() Vector3i

func (Vector3i) ONE

func (Vector3i) ONE() Vector3i

func (Vector3i) RIGHT

func (Vector3i) RIGHT() Vector3i

func (*Vector3i) SetX

func (v *Vector3i) SetX(x int64)

func (*Vector3i) SetY

func (v *Vector3i) SetY(y int64)

func (*Vector3i) SetZ

func (v *Vector3i) SetZ(z int64)

func (Vector3i) Sign

func (v Vector3i) Sign() Vector3i

Sign returns a new vector with each component set to 1 if it's positive, -1 if it's negative, and 0 if it's zero. The result is identical to calling Signi on each component.

func (Vector3i) Snapped

func (v Vector3i) Snapped(step Vector3i) Vector3i

Snapped returns a new vector with each component snapped to the closest multiple of the corresponding component in step.

func (Vector3i) Sub

func (v Vector3i) Sub(other Vector3i) Vector3i

func (Vector3i) Subi

func (v Vector3i) Subi(other int64) Vector3i

func (Vector3i) UP

func (Vector3i) UP() Vector3i

func (Vector3i) Vector3

func (v Vector3i) Vector3() Vector3

func (Vector3i) X

func (v Vector3i) X() int64

func (Vector3i) Y

func (v Vector3i) Y() int64

func (Vector3i) Z

func (v Vector3i) Z() int64

func (Vector3i) ZERO

func (Vector3i) ZERO() Vector3i

"Constants"

type Vector4

type Vector4 [4]float

Vector4 A 4-element structure that can be used to represent 4D coordinates or any other quadruplet of numeric values.

It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike float which is always 64-bit. If double precision is needed, compile the engine with the option precision=double.

See Vector4i for its integer counterpart.

Note: In a boolean context, a Vector4 will evaluate to false if it's equal to Vector4{0, 0, 0, 0}. Otherwise, a Vector4 will always evaluate to true.

func NewVector4

func NewVector4(x, y, z, w float64) Vector4

NewVector4 constructs a new Vector4 from the given x, y, z, and w.

func (Vector4) Abs

func (v Vector4) Abs() Vector4

Abs returns a new vector with all components in absolute values (i.e. positive).

func (Vector4) Add

func (v Vector4) Add(other Vector4) Vector4

func (Vector4) Addf

func (v Vector4) Addf(other float64) Vector4

func (Vector4) Ceil

func (v Vector4) Ceil() Vector4

Ceil returns a new vector with all components rounded up (towards positive infinity).

func (Vector4) Clamp

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

Clamp returns a new vector with all components clamped between the components of min and max, by running Clampf on each component.

func (Vector4) CubicInterpolate

func (v Vector4) CubicInterpolate(b, pre_a, post_b Vector4, weight float64) Vector4

CubicInterpolate performs a cubic interpolation between this vector and b using pre_a and post_b as handles and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

func (Vector4) CubicInterpolateInTime

func (v Vector4) CubicInterpolateInTime(b, pre_a, post_b Vector4, weight, b_t, pre_a_t, post_b_t float64) Vector4

CubicInyerpolateInTime performs a cubic interpolation between this vector and b using pre_a and post_b as handles and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

It can perform smoother interpolation than cubic_interpolate by the time values.

func (Vector4) DirectionTo

func (v Vector4) DirectionTo(to Vector4) Vector4

DirectionTo returns the normalized vector pointing from this vector to to. This is equivalent to using (b - a).Normalized().

func (Vector4) DistanceSquaredTo

func (v Vector4) DistanceSquaredTo(to Vector4) float64

DistanceSquaredTo returns the squared distance between this vector and to.

This method runs faster than DistanceTo, so prefer it if you need to compare vectors or need the squared distance for some formula.

func (Vector4) DistanceTo

func (v Vector4) DistanceTo(to Vector4) float64

DistanceTo returns the distance between this vector and to.

func (Vector4) Div

func (v Vector4) Div(other Vector4) Vector4

func (Vector4) Divf

func (v Vector4) Divf(other float64) Vector4

func (Vector4) Dot

func (v Vector4) Dot(b Vector4) float64

Dot returns the dot product of this vector and b.

func (Vector4) Floor

func (v Vector4) Floor() Vector4

Floor returns a new vector with all components rounded down (towards negative infinity).

func (Vector4) INF

func (Vector4) INF() Vector4

func (Vector4) Inverse

func (v Vector4) Inverse() Vector4

Inverse returns the inverse of the vector. This is the same as

Vector4{1.0 / v[X], 1.0 / v[Y], 1.0 / v[Z], 1.0 / v[W]}.

func (Vector4) IsApproximatelyEqual

func (v Vector4) IsApproximatelyEqual(to Vector4) bool

IsApproximatelyEqual returns true if this vector and to are approximately equal, by running IsApproximatelyEqual on each component.

func (Vector4) IsApproximatelyZero

func (v Vector4) IsApproximatelyZero() bool

IsApproximatelyZero returns true if this vector's values are approximately zero, by running IsApproximatelyZero on each component.

This method is faster than using is_equal_approx with one value as a zero vector.

func (Vector4) IsFinite

func (v Vector4) IsFinite() bool

IsFinite returns true if this vector is finite, by calling IsFinite on each component.

func (Vector4) IsNormalized

func (v Vector4) IsNormalized() bool

IsNormalized returns true if this vector is normalized, by checking if its length is approximately 1.0.

func (Vector4) Length

func (v Vector4) Length() float64

Length returns the length (magnitude) of this vector.

func (Vector4) LengthSquared

func (v Vector4) LengthSquared() float64

LengthSquared returns the squared length (squared magnitude) of this vector.

func (Vector4) Lerp

func (v Vector4) Lerp(to Vector4, weight float64) Vector4

Lerp returns the result of the linear interpolation between this vector and to by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

func (Vector4) MaxAxis

func (v Vector4) MaxAxis() Axis

MaxAxis returns the axis of the vector's highest value. See Axis constants. If all components are equal, this method returns X.

func (Vector4) MinAxis

func (v Vector4) MinAxis() Axis

MinAxis returns the axis of the vector's lowest value. See Axis constants. If all components are equal, this method returns W.

func (Vector4) Mul

func (v Vector4) Mul(other Vector4) Vector4

func (Vector4) Mulf

func (v Vector4) Mulf(other float64) Vector4

func (Vector4) Neg

func (v Vector4) Neg() Vector4

func (Vector4) Normalized

func (v Vector4) Normalized() Vector4

Normalized returns the result of scaling the vector to unit length. Equivalent to v / v.length(). See also Vector4.IsNormalized.

Note: This function may return incorrect values if the input vector length is near zero.

func (Vector4) ONE

func (Vector4) ONE() Vector4

func (Vector4) Posmodf

func (v Vector4) Posmodf(mod float64) Vector4

Posmod returns a vector composed of the Fposmod of this vector's components and mod.

func (Vector4) Posmodv

func (v Vector4) Posmodv(mod Vector4) Vector4

Posmod returns a vector composed of the Fposmod of this vector's components and modv's components.

func (Vector4) Round

func (v Vector4) Round() Vector4

Round returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.

func (*Vector4) SetW

func (v *Vector4) SetW(w float64)

func (*Vector4) SetX

func (v *Vector4) SetX(x float64)

func (*Vector4) SetY

func (v *Vector4) SetY(y float64)

func (*Vector4) SetZ

func (v *Vector4) SetZ(z float64)

func (Vector4) Sign

func (v Vector4) Sign() Vector4

Sign returns a new vector with each component set to 1.0 if it's positive, -1.0 if it's negative, and 0.0 if it's zero. The result is identical to calling Signf on each component.

func (Vector4) Snapped

func (v Vector4) Snapped(step Vector4) Vector4

Snapped returns a new vector with all components snapped to the nearest multiple of step. This can also be used to round the components to an arbitrary number of decimals.

func (Vector4) Sub

func (v Vector4) Sub(other Vector4) Vector4

func (Vector4) Subf

func (v Vector4) Subf(other float64) Vector4

func (Vector4) Transform

func (v Vector4) Transform(p Projection) Vector4

Transform transform transforms (multiplies) the Vector4 by the given Projection's transformation matrix.

func (Vector4) Vector4i

func (v Vector4) Vector4i() Vector4i

func (Vector4) W

func (v Vector4) W() float64

func (Vector4) X

func (v Vector4) X() float64

func (Vector4) Y

func (v Vector4) Y() float64

func (Vector4) Z

func (v Vector4) Z() float64

func (Vector4) ZERO

func (Vector4) ZERO() Vector4

type Vector4i

type Vector4i [4]int32

Vector4i is a 4-element structure that can be used to represent 4D grid coordinates or any other quadruplet of integers.

It uses integer coordinates and is therefore preferable to Vector4 when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector4 this cannot be configured with an engine build option. Use [Int] or [PackedInt64Array] if 64-bit values are needed.

Note: In a boolean context, a Vector4i will evaluate to false if it's equal to Vector4i{0, 0, 0, 0}. Otherwise, a Vector3i will always evaluate to true.

func (Vector4i) Abs

func (v Vector4i) Abs() Vector4i

Abs returns a new vector with all components in absolute values (i.e. positive).

func (Vector4i) Add

func (v Vector4i) Add(other Vector4i) Vector4i

func (Vector4i) Addi

func (v Vector4i) Addi(other int64) Vector4i

func (Vector4i) Clamp

func (v Vector4i) Clamp(min, max Vector4i) Vector4i

Clamp returns a new vector with all components clamped between the components of min and max, by running Clampi on each component.

func (Vector4i) Div

func (v Vector4i) Div(other Vector4i) Vector4i

func (Vector4i) Divi

func (v Vector4i) Divi(other int64) Vector4i

func (Vector4i) Length

func (v Vector4i) Length() float64

Length returns the length (magnitude) of this vector.

func (Vector4i) LengthSquared

func (v Vector4i) LengthSquared() int64

LengthSquared returns the squared length (squared magnitude) of this vector.

This method runs faster than Vector4i.Length, so prefer it if you need to compare vectors or need the squared distance for some formula.

func (Vector4i) MAX

func (Vector4i) MAX() Vector4i

func (Vector4i) MIN

func (Vector4i) MIN() Vector4i

func (Vector4i) MaxAxis

func (v Vector4i) MaxAxis() Axis

MaxAxis returns the axis of the vector's highest value. See Axis constants. If all components are equal, this method returns X.

func (Vector4i) MinAxis

func (v Vector4i) MinAxis() Axis

MinAxis returns the axis of the vector's lowest value. See Axis constants. If all components are equal, this method returns W.

func (Vector4i) Mod

func (v Vector4i) Mod(other Vector4i) Vector4i

func (Vector4i) Modi

func (v Vector4i) Modi(other int64) Vector4i

func (Vector4i) Mul

func (v Vector4i) Mul(other Vector4i) Vector4i

func (Vector4i) Muli

func (v Vector4i) Muli(other int64) Vector4i

func (Vector4i) Neg

func (v Vector4i) Neg() Vector4i

func (Vector4i) ONE

func (Vector4i) ONE() Vector4i

func (*Vector4i) SetW

func (v *Vector4i) SetW(w int64)

func (*Vector4i) SetX

func (v *Vector4i) SetX(x int64)

func (*Vector4i) SetY

func (v *Vector4i) SetY(y int64)

func (*Vector4i) SetZ

func (v *Vector4i) SetZ(z int64)

func (Vector4i) Sign

func (v Vector4i) Sign() Vector4i

Sign returns a new vector with each component set to 1 if it's positive, -1 if it's negative, and 0 if it's 0. The result is identical to running Signi on each component.

func (Vector4i) Snapped

func (v Vector4i) Snapped(step Vector4i) Vector4i

Snapped returns a new vector with each component snapped to the nearest multiple of step.

func (Vector4i) Sub

func (v Vector4i) Sub(other Vector4i) Vector4i

func (Vector4i) Subi

func (v Vector4i) Subi(other int64) Vector4i

func (Vector4i) Vector4

func (v Vector4i) Vector4() Vector4

func (Vector4i) W

func (v Vector4i) W() int64

func (Vector4i) X

func (v Vector4i) X() int64

func (Vector4i) Y

func (v Vector4i) Y() int64

func (Vector4i) Z

func (v Vector4i) Z() int64

func (Vector4i) ZERO

func (Vector4i) ZERO() Vector4i

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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