Struct gdnative::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
sourceimpl Vector3
impl Vector3
Helper methods for Vector3
.
See the official Godot documentation
.
sourcepub const ONE: Vector3 = Self::new(1.0, 1.0, 1.0)
pub const ONE: Vector3 = Self::new(1.0, 1.0, 1.0)
A vector with all components set to 1. Typically used for scaling.
sourcepub const INF: Vector3 = Self::new(f32::INFINITY, f32::INFINITY, f32::INFINITY)
pub const INF: Vector3 = Self::new(f32::INFINITY, f32::INFINITY, f32::INFINITY)
A vector with all components set to +infinity.
sourcepub const fn new(x: f32, y: f32, z: f32) -> Vector3
pub const fn new(x: f32, y: f32, z: f32) -> Vector3
Returns a Vector3 with the given components.
sourcepub fn abs(self) -> Vector3
pub fn abs(self) -> Vector3
Returns a new vector with all components in absolute values (i.e. positive).
sourcepub fn angle_to(self, to: Vector3) -> f32
pub fn angle_to(self, to: Vector3) -> f32
Returns the minimum angle to the given vector, in radians.
sourcepub fn bounce(self, n: Vector3) -> Vector3
pub fn bounce(self, n: Vector3) -> Vector3
Returns the vector “bounced off” from a plane defined by the given normal.
sourcepub fn ceil(self) -> Vector3
pub fn ceil(self) -> Vector3
Returns a new vector with all components rounded up (towards positive infinity).
sourcepub fn cubic_interpolate(
self,
b: Vector3,
pre_a: Vector3,
post_b: Vector3,
t: f32
) -> Vector3
pub fn cubic_interpolate(
self,
b: Vector3,
pre_a: Vector3,
post_b: Vector3,
t: f32
) -> Vector3
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: Vector3) -> f32
pub fn dot(self, other: Vector3) -> 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) -> Vector3
pub fn floor(self) -> Vector3
Returns a new vector with all components rounded down (towards negative infinity).
sourcepub fn inverse(self) -> Vector3
pub fn inverse(self) -> Vector3
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: Vector3) -> bool
pub fn is_equal_approx(self, v: Vector3) -> 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: Vector3, t: f32) -> Vector3
pub fn linear_interpolate(self, b: Vector3, t: f32) -> Vector3
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: Vector3, delta: f32) -> Vector3
pub fn move_toward(self, to: Vector3, delta: f32) -> Vector3
Moves this vector toward to
by the fixed delta
amount.
sourcepub fn normalized(self) -> Vector3
pub fn normalized(self) -> Vector3
Returns the vector scaled to unit length. Equivalent to v / v.length()
.
sourcepub fn posmod(self, rem: f32) -> Vector3
pub fn posmod(self, rem: f32) -> Vector3
Returns a vector composed of the rem_euclid
of this vector’s components and mod
.
sourcepub fn posmodv(self, remv: Vector3) -> Vector3
pub fn posmodv(self, remv: Vector3) -> Vector3
Returns a vector composed of the rem_euclid
of this vector’s components and remv
components.
sourcepub fn project(self, b: Vector3) -> Vector3
pub fn project(self, b: Vector3) -> Vector3
Returns this vector projected onto another vector b
.
sourcepub fn reflect(self, n: Vector3) -> Vector3
pub fn reflect(self, n: Vector3) -> Vector3
Returns this vector reflected from a plane defined by the given normal.
sourcepub fn rotated(self, axis: Vector3, phi: f32) -> Vector3
pub fn rotated(self, axis: Vector3, phi: f32) -> Vector3
Rotates this vector around a given axis by phi
radians. The axis must be a normalized
vector.
sourcepub fn round(self) -> Vector3
pub fn round(self) -> Vector3
Returns this vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
sourcepub fn sign(self) -> Vector3
pub fn sign(self) -> Vector3
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: Vector3, t: f32) -> Vector3
pub fn slerp(self, b: Vector3, t: f32) -> Vector3
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: Vector3) -> Vector3
pub fn slide(self, n: Vector3) -> Vector3
Returns this vector slid along a plane defined by the given normal.
sourcepub fn snapped(self, by: Vector3) -> Vector3
pub fn snapped(self, by: Vector3) -> Vector3
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
sourceimpl AddAssign<Vector3> for Vector3
impl AddAssign<Vector3> for Vector3
sourcefn add_assign(&mut self, with: Vector3)
fn add_assign(&mut self, with: Vector3)
+=
operation. Read moresourceimpl CoerceFromVariant for Vector3
impl CoerceFromVariant for Vector3
fn coerce_from_variant(v: &Variant) -> Vector3
sourceimpl<'de> Deserialize<'de> for Vector3
impl<'de> Deserialize<'de> for Vector3
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<Vector3, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Vector3, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
sourceimpl DivAssign<Vector3> for Vector3
impl DivAssign<Vector3> for Vector3
sourcefn div_assign(&mut self, with: Vector3)
fn div_assign(&mut self, with: Vector3)
/=
operation. Read moresourceimpl DivAssign<f32> for Vector3
impl DivAssign<f32> for Vector3
sourcefn div_assign(&mut self, with: f32)
fn div_assign(&mut self, with: f32)
/=
operation. Read moresourceimpl Export for Vector3
impl Export for Vector3
sourcefn export_info(_hint: Option<<Vector3 as Export>::Hint>) -> ExportInfo
fn export_info(_hint: Option<<Vector3 as Export>::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl FromVariant for Vector3
impl FromVariant for Vector3
fn from_variant(variant: &Variant) -> Result<Vector3, FromVariantError>
sourceimpl MulAssign<Vector3> for Vector3
impl MulAssign<Vector3> for Vector3
sourcefn mul_assign(&mut self, with: Vector3)
fn mul_assign(&mut self, with: Vector3)
*=
operation. Read moresourceimpl MulAssign<f32> for Vector3
impl MulAssign<f32> for Vector3
sourcefn mul_assign(&mut self, with: f32)
fn mul_assign(&mut self, with: f32)
*=
operation. Read moresourceimpl Serialize for Vector3
impl Serialize for Vector3
sourcefn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
sourceimpl SubAssign<Vector3> for Vector3
impl SubAssign<Vector3> for Vector3
sourcefn sub_assign(&mut self, with: Vector3)
fn sub_assign(&mut self, with: Vector3)
-=
operation. Read more