#[repr(C)]
pub struct Vector3 { pub x: f32, pub y: f32, pub z: f32, }
Expand description

3D vector class.

See also Vector3 in the Godot API doc.

Fields§

§x: f32§y: f32§z: f32

Implementations§

source§

impl Vector3

Helper methods for Vector3.

See the official Godot documentation.

source

pub const ZERO: Self = _

The zero vector.

source

pub const ONE: Self = _

A vector with all components set to 1. Typically used for scaling.

source

pub const INF: Self = _

A vector with all components set to +infinity.

source

pub const LEFT: Self = _

Unit vector in -X direction.

source

pub const RIGHT: Self = _

Unit vector in +X direction.

source

pub const UP: Self = _

Unit vector in +Y direction.

source

pub const DOWN: Self = _

Unit vector in -Y direction.

source

pub const FORWARD: Self = _

Unit vector in -Z direction.

source

pub const BACK: Self = _

Unit vector in +Z direction.

source

pub const fn new(x: f32, y: f32, z: f32) -> Self

Returns a Vector3 with the given components.

source

pub fn abs(self) -> Self

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

source

pub fn angle_to(self, to: Self) -> f32

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

source

pub fn bounce(self, n: Self) -> Self

Returns the vector “bounced off” from a plane defined by the given normal.

source

pub fn ceil(self) -> Self

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

source

pub fn cross(self, b: Self) -> Self

Returns the cross product of this vector and b.

source

pub fn cubic_interpolate(self, b: Self, pre_a: Self, post_b: Self, t: f32) -> Self

Performs a cubic interpolation between vectors pre_a, a, b, post_b (a is current), by the given amount t. t is on the range of 0.0 to 1.0, representing the amount of interpolation.

source

pub fn direction_to(self, other: Vector3) -> Vector3

Returns the normalized vector pointing from this vector to other.

source

pub fn distance_squared_to(self, other: Vector3) -> f32

Returns the squared distance to other.

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

source

pub fn distance_to(self, other: Vector3) -> f32

Returns the distance to other.

source

pub fn dot(self, other: Self) -> f32

Returns the dot product of this vector and b. 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).

source

pub fn floor(self) -> Self

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

source

pub fn inverse(self) -> Self

Returns the inverse of the vector. This is the same as Vector3::new(1.0 / self.x, 1.0 / self.y, 1.0 / self.z).

source

pub fn is_equal_approx(self, v: Self) -> bool

Returns true if this vector and v are approximately equal, by running relative_eq on each component.

source

pub fn is_normalized(self) -> bool

Returns true if the vector is normalized, and false otherwise.

source

pub fn length(self) -> f32

Returns the length (magnitude) of this vector.

source

pub fn length_squared(self) -> f32

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.

source

pub fn linear_interpolate(self, b: Self, t: f32) -> Self

Returns the result of the linear interpolation between this vector and b by amount t. t is on the range of 0.0 to 1.0, representing the amount of interpolation.

source

pub fn max_axis(self) -> Axis

Returns the axis of the vector’s largest value. See Axis enum.

If multiple components are equal, this method returns in preferred order Axis::X, Axis::Y, Axis::Z.

source

pub fn min_axis(self) -> Axis

Returns the axis of the vector’s smallest value. See Axis enum.

If multiple components are equal, this method returns in preferred order Axis::X, Axis::Y, Axis::Z.

source

pub fn move_toward(self, to: Self, delta: f32) -> Self

Moves this vector toward to by the fixed delta amount.

source

pub fn normalized(self) -> Self

Returns the vector scaled to unit length. Equivalent to v / v.length().

source

pub fn outer(self, b: Self) -> Basis

Returns the outer product with b.

source

pub fn posmod(self, rem: f32) -> Self

Returns a vector composed of the rem_euclid of this vector’s components and mod.

source

pub fn posmodv(self, remv: Self) -> Self

Returns a vector composed of the rem_euclid of this vector’s components and remv components.

source

pub fn project(self, b: Self) -> Self

Returns this vector projected onto another vector b.

source

pub fn reflect(self, n: Self) -> Self

Returns this vector reflected from a plane defined by the given normal.

source

pub fn rotated(self, axis: Self, phi: f32) -> Self

Rotates this vector around a given axis by phi radians. The axis must be a normalized vector.

source

pub fn round(self) -> Self

Returns this vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.

source

pub fn sign(self) -> Self

Returns a vector with each component set to one or negative one, depending on the signs of this vector’s components, or zero if the component is zero, by calling signum on each component.

source

pub fn slerp(self, b: Self, t: f32) -> Self

Returns the result of spherical linear interpolation between this vector and b, by amount t. t is on the range of 0.0 to 1.0, representing the amount of interpolation.

Note: Both vectors must be normalized.

source

pub fn slide(self, n: Self) -> Self

Returns this vector slid along a plane defined by the given normal.

source

pub fn snapped(self, by: Self) -> Self

Returns this vector with each component snapped to the nearest multiple of step. This can also be used to round to an arbitrary number of decimals.

source

pub fn to_diagonal_matrix(self) -> Basis

Returns a diagonal matrix with the vector as main diagonal.

This is equivalent to a Basis with no rotation or shearing and this vector’s components set as the scale.

Trait Implementations§

source§

impl Add<Vector3> for Vector3

§

type Output = Vector3

The resulting type after applying the + operator.
source§

fn add(self, with: Self) -> Self

Performs the + operation. Read more
source§

impl AddAssign<Vector3> for Vector3

source§

fn add_assign(&mut self, with: Self)

Performs the += operation. Read more
source§

impl AsRef<[f32; 3]> for Vector3

source§

fn as_ref(&self) -> &[f32; 3]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Vector3

source§

fn clone(&self) -> Vector3

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl CoerceFromVariant for Vector3

source§

impl Debug for Vector3

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Vector3

source§

fn default() -> Vector3

Returns the “default value” for a type. Read more
source§

impl Div<Vector3> for Vector3

§

type Output = Vector3

The resulting type after applying the / operator.
source§

fn div(self, with: Self) -> Self

Performs the / operation. Read more
source§

impl Div<f32> for Vector3

§

type Output = Vector3

The resulting type after applying the / operator.
source§

fn div(self, with: f32) -> Self

Performs the / operation. Read more
source§

impl DivAssign<Vector3> for Vector3

source§

fn div_assign(&mut self, with: Self)

Performs the /= operation. Read more
source§

impl DivAssign<f32> for Vector3

source§

fn div_assign(&mut self, with: f32)

Performs the /= operation. Read more
source§

impl Export for Vector3

§

type Hint = NoHint

A type-specific hint type that is valid for the type being exported. Read more
source§

fn export_info(_hint: Option<Self::Hint>) -> ExportInfo

Returns ExportInfo given an optional typed hint.
source§

impl FromVariant for Vector3

source§

impl Mul<Vector3> for Basis

§

type Output = Vector3

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self::Output) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Vector3> for Quat

source§

fn mul(self, with: Vector3) -> Vector3

Returns a vector transformed (multiplied) by this quaternion. This is the same as xform

Note: The quaternion must be normalized.

§

type Output = Vector3

The resulting type after applying the * operator.
source§

impl Mul<Vector3> for Vector3

§

type Output = Vector3

The resulting type after applying the * operator.
source§

fn mul(self, with: Self) -> Self

Performs the * operation. Read more
source§

impl Mul<Vector3> for f32

§

type Output = Vector3

The resulting type after applying the * operator.
source§

fn mul(self, with: Self::Output) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<f32> for Vector3

§

type Output = Vector3

The resulting type after applying the * operator.
source§

fn mul(self, with: f32) -> Self

Performs the * operation. Read more
source§

impl MulAssign<Vector3> for Vector3

source§

fn mul_assign(&mut self, with: Self)

Performs the *= operation. Read more
source§

impl MulAssign<f32> for Vector3

source§

fn mul_assign(&mut self, with: f32)

Performs the *= operation. Read more
source§

impl Neg for Vector3

§

type Output = Vector3

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl PartialEq<Vector3> for Vector3

source§

fn eq(&self, other: &Vector3) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Sub<Vector3> for Vector3

§

type Output = Vector3

The resulting type after applying the - operator.
source§

fn sub(self, with: Self) -> Self

Performs the - operation. Read more
source§

impl SubAssign<Vector3> for Vector3

source§

fn sub_assign(&mut self, with: Self)

Performs the -= operation. Read more
source§

impl ToVariant for Vector3

source§

impl Copy for Vector3

source§

impl PoolElement for Vector3

source§

impl StructuralPartialEq for Vector3

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere
    T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.