Struct gdnative_core::core_types::Vector3
source · Expand description
3D vector class.
See also Vector3 in the Godot API doc.
Fields§
§x: f32
§y: f32
§z: f32
Implementations§
source§impl Vector3
impl Vector3
Helper methods for Vector3
.
See the official Godot documentation
.
sourcepub fn abs(self) -> Self
pub fn abs(self) -> Self
Returns a new vector with all components in absolute values (i.e. positive).
sourcepub fn angle_to(self, to: Self) -> f32
pub fn angle_to(self, to: Self) -> f32
Returns the minimum angle to the given vector, in radians.
sourcepub fn bounce(self, n: Self) -> Self
pub fn bounce(self, n: Self) -> Self
Returns the vector “bounced off” from a plane defined by the given normal.
sourcepub fn ceil(self) -> Self
pub fn ceil(self) -> Self
Returns a new vector with all components rounded up (towards positive infinity).
sourcepub fn cubic_interpolate(self, b: Self, pre_a: Self, post_b: Self, t: f32) -> Self
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.
sourcepub fn direction_to(self, other: Vector3) -> Vector3
pub fn direction_to(self, other: Vector3) -> Vector3
Returns the normalized vector pointing from this vector to other
.
sourcepub fn distance_squared_to(self, other: Vector3) -> f32
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.
sourcepub fn distance_to(self, other: Vector3) -> f32
pub fn distance_to(self, other: Vector3) -> f32
Returns the distance to other
.
sourcepub fn dot(self, other: Self) -> f32
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).
sourcepub fn floor(self) -> Self
pub fn floor(self) -> Self
Returns a new vector with all components rounded down (towards negative infinity).
sourcepub fn inverse(self) -> Self
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)
.
sourcepub fn is_equal_approx(self, v: Self) -> bool
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.
sourcepub fn is_normalized(self) -> bool
pub fn is_normalized(self) -> bool
Returns true
if the vector is normalized, and false
otherwise.
sourcepub fn length_squared(self) -> f32
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.
sourcepub fn linear_interpolate(self, b: Self, t: f32) -> Self
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.
sourcepub fn max_axis(self) -> Axis
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
.
sourcepub fn min_axis(self) -> Axis
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
.
sourcepub fn move_toward(self, to: Self, delta: f32) -> Self
pub fn move_toward(self, to: Self, delta: f32) -> Self
Moves this vector toward to
by the fixed delta
amount.
sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
Returns the vector scaled to unit length. Equivalent to v / v.length()
.
sourcepub fn posmod(self, rem: f32) -> Self
pub fn posmod(self, rem: f32) -> Self
Returns a vector composed of the rem_euclid
of this vector’s components and mod
.
sourcepub fn posmodv(self, remv: Self) -> Self
pub fn posmodv(self, remv: Self) -> Self
Returns a vector composed of the rem_euclid
of this vector’s components and remv
components.
sourcepub fn reflect(self, n: Self) -> Self
pub fn reflect(self, n: Self) -> Self
Returns this vector reflected from a plane defined by the given normal.
sourcepub fn rotated(self, axis: Self, phi: f32) -> Self
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.
sourcepub fn round(self) -> Self
pub fn round(self) -> Self
Returns this vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
sourcepub fn sign(self) -> Self
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.
sourcepub fn slerp(self, b: Self, t: f32) -> Self
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.
sourcepub fn slide(self, n: Self) -> Self
pub fn slide(self, n: Self) -> Self
Returns this vector slid along a plane defined by the given normal.
sourcepub fn snapped(self, by: Self) -> Self
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.
sourcepub fn to_diagonal_matrix(self) -> Basis
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 AddAssign<Vector3> for Vector3
impl AddAssign<Vector3> for Vector3
source§fn add_assign(&mut self, with: Self)
fn add_assign(&mut self, with: Self)
+=
operation. Read moresource§impl CoerceFromVariant for Vector3
impl CoerceFromVariant for Vector3
fn coerce_from_variant(v: &Variant) -> Self
source§impl DivAssign<Vector3> for Vector3
impl DivAssign<Vector3> for Vector3
source§fn div_assign(&mut self, with: Self)
fn div_assign(&mut self, with: Self)
/=
operation. Read moresource§impl DivAssign<f32> for Vector3
impl DivAssign<f32> for Vector3
source§fn div_assign(&mut self, with: f32)
fn div_assign(&mut self, with: f32)
/=
operation. Read moresource§impl Export for Vector3
impl Export for Vector3
source§fn export_info(_hint: Option<Self::Hint>) -> ExportInfo
fn export_info(_hint: Option<Self::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.source§impl FromVariant for Vector3
impl FromVariant for Vector3
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl MulAssign<Vector3> for Vector3
impl MulAssign<Vector3> for Vector3
source§fn mul_assign(&mut self, with: Self)
fn mul_assign(&mut self, with: Self)
*=
operation. Read moresource§impl MulAssign<f32> for Vector3
impl MulAssign<f32> for Vector3
source§fn mul_assign(&mut self, with: f32)
fn mul_assign(&mut self, with: f32)
*=
operation. Read moresource§impl PartialEq<Vector3> for Vector3
impl PartialEq<Vector3> for Vector3
source§impl SubAssign<Vector3> for Vector3
impl SubAssign<Vector3> for Vector3
source§fn sub_assign(&mut self, with: Self)
fn sub_assign(&mut self, with: Self)
-=
operation. Read more