#[repr(C)]pub struct Vector4 {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}Expand description
Vector used for 4D math using floating point coordinates.
4-element structure that can be used to represent any quadruplet of numeric values.
It uses floating-point coordinates of 32-bit precision, unlike the engine’s float type which
is always 64-bit. The engine can be compiled with the option precision=double to use 64-bit
vectors; use the gdext library with the double-precision feature in that case.
Conversions are provided via various from_* and to_* functions, not via the From trait. This encourages new() as the main way to construct vectors, is explicit about the conversion taking place, needs no type inference, and works in const contexts.
§Navigation to impl blocks within this page
- Constants
- Constructors and general vector functions
- Specialized
Vector4functions - Float-specific functions
- 4D functions
- 3D and 4D functions
- Trait impls + operators
§All vector types
§Godot docs
Fields§
§x: f32The vector’s X component.
y: f32The vector’s Y component.
z: f32The vector’s Z component.
w: f32The vector’s W component.
Implementations§
Source§impl Vector4
§Constructors and general vector functions
The following associated functions and methods are available on all vectors (2D, 3D, 4D; float and int).
impl Vector4
§Constructors and general vector functions
The following associated functions and methods are available on all vectors (2D, 3D, 4D; float and int).
Sourcepub const fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4
Creates a vector with the given components.
Sourcepub const fn from_tuple(tuple: (f32, f32, f32, f32)) -> Vector4
pub const fn from_tuple(tuple: (f32, f32, f32, f32)) -> Vector4
Creates a vector from the given tuple.
Sourcepub const fn from_array(array: [f32; 4]) -> Vector4
pub const fn from_array(array: [f32; 4]) -> Vector4
Creates a vector from the given array.
Sourcepub const fn to_tuple(&self) -> (f32, f32, f32, f32)
pub const fn to_tuple(&self) -> (f32, f32, f32, f32)
Returns a tuple with the components of the vector.
Sourcepub fn abs(self) -> Vector4
pub fn abs(self) -> Vector4
Returns a new vector with all components in absolute values (i.e. positive or zero).
Sourcepub fn clamp(self, min: Vector4, max: Vector4) -> Vector4
pub fn clamp(self, min: Vector4, max: Vector4) -> Vector4
Returns a new vector with all components clamped between the components of min and max.
§Panics
If min > max, min is NaN, or max is NaN.
Sourcepub fn length_squared(self) -> f32
pub fn length_squared(self) -> f32
Squared length (squared magnitude) of this vector.
Runs faster than length(), so prefer it if you need to compare vectors or need the
squared distance for some formula.
Sourcepub fn coord_min(self, other: Vector4) -> Vector4
pub fn coord_min(self, other: Vector4) -> Vector4
Returns a new vector containing the minimum of the two vectors, component-wise.
You may consider using the fully-qualified syntax Vector4::coord_min(a, b) for symmetry.
impl Vector4
§Specialized Vector4 functions
Source§impl Vector4
§Float-specific functions
The following methods are only available on floating-point vectors.
impl Vector4
§Float-specific functions
The following methods are only available on floating-point vectors.
Sourcepub const fn cast_int(self) -> Vector4i
pub const fn cast_int(self) -> Vector4i
Converts to a vector with integer components, using as casts.
Sourcepub fn floor(self) -> Vector4
pub fn floor(self) -> Vector4
Returns a new vector with all components rounded down (towards negative infinity).
Sourcepub fn ceil(self) -> Vector4
pub fn ceil(self) -> Vector4
Returns a new vector with all components rounded up (towards positive infinity).
Sourcepub fn cubic_interpolate(
self,
b: Vector4,
pre_a: Vector4,
post_b: Vector4,
weight: f32,
) -> Vector4
pub fn cubic_interpolate( self, b: Vector4, pre_a: Vector4, post_b: Vector4, weight: f32, ) -> Vector4
Cubic interpolation between self 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.
Sourcepub fn cubic_interpolate_in_time(
self,
b: Vector4,
pre_a: Vector4,
post_b: Vector4,
weight: f32,
b_t: f32,
pre_a_t: f32,
post_b_t: f32,
) -> Vector4
pub fn cubic_interpolate_in_time( self, b: Vector4, pre_a: Vector4, post_b: Vector4, weight: f32, b_t: f32, pre_a_t: f32, post_b_t: f32, ) -> Vector4
Cubic interpolation between self 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.
Sourcepub fn try_direction_to(self, to: Vector4) -> Option<Vector4>
pub fn try_direction_to(self, to: Vector4) -> Option<Vector4>
Returns the normalized vector pointing from this vector to to or None, if self and to are equal.
This is equivalent to using (b - a).try_normalized(). See also direction_to().
Sourcepub fn direction_to(self, to: Vector4) -> Vector4
pub fn direction_to(self, to: Vector4) -> Vector4
⚠️ Returns the normalized vector pointing from this vector to to.
This is equivalent to using (b - a).normalized(). See also try_direction_to().
§Panics
If self and to are equal.
Sourcepub fn distance_squared_to(self, to: Vector4) -> f32
pub fn distance_squared_to(self, to: Vector4) -> f32
Returns the squared distance between this vector and to.
This method runs faster than Self::distance_to, so prefer it if you need to compare vectors or need the squared distance for some formula.
Sourcepub fn distance_to(self, to: Vector4) -> f32
pub fn distance_to(self, to: Vector4) -> f32
Returns the distance between this vector and to.
Sourcepub fn is_normalized(self) -> bool
pub fn is_normalized(self) -> bool
Returns true if the vector is normalized, i.e. its length is approximately equal to 1.
Sourcepub fn is_zero_approx(self) -> bool
pub fn is_zero_approx(self) -> bool
Returns true if this vector’s values are approximately zero.
This method is faster than using approx_eq() with one value as a zero vector.
Sourcepub fn lerp(self, other: Vector4, weight: f32) -> Vector4
pub fn lerp(self, other: Vector4, weight: f32) -> Vector4
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.
Sourcepub fn try_normalized(self) -> Option<Vector4>
pub fn try_normalized(self) -> Option<Vector4>
Returns the vector scaled to unit length or None, if called on a zero vector.
Computes self / self.length(). See also normalized() and is_normalized().
Sourcepub fn normalized(self) -> Vector4
pub fn normalized(self) -> Vector4
⚠️ Returns the vector scaled to unit length.
Computes self / self.length(). See also try_normalized() and is_normalized().
§Panics
If called on a zero vector.
Sourcepub fn normalized_or_zero(self) -> Vector4
pub fn normalized_or_zero(self) -> Vector4
Returns the vector scaled to unit length or Self::ZERO, if called on a zero vector.
Computes self / self.length(). See also try_normalized() and is_normalized().
Sourcepub fn posmod(self, pmod: f32) -> Vector4
pub fn posmod(self, pmod: f32) -> Vector4
Returns a vector composed of the FloatExt::fposmod() of this vector’s components and pmod.
Sourcepub fn posmodv(self, modv: Vector4) -> Vector4
pub fn posmodv(self, modv: Vector4) -> Vector4
Returns a vector composed of the FloatExt::fposmod() of this vector’s components and modv’s components.
Source§impl Vector4
§4D functions
The following methods are only available on 4D vectors (for both float and int).
impl Vector4
§4D functions
The following methods are only available on 4D vectors (for both float and int).
Sourcepub fn max_axis(self) -> Option<Vector4Axis>
pub fn max_axis(self) -> Option<Vector4Axis>
Returns the axis of the vector’s highest value. See Vector4Axis enum. If all components are equal, this method returns None.
To mimic Godot’s behavior, unwrap this function’s result with unwrap_or(Vector4Axis::X).
Sourcepub fn min_axis(self) -> Option<Vector4Axis>
pub fn min_axis(self) -> Option<Vector4Axis>
Returns the axis of the vector’s lowest value. See Vector4Axis enum. If all components are equal, this method returns None.
To mimic Godot’s behavior, unwrap this function’s result with unwrap_or(Vector4Axis::W).
Trait Implementations§
Source§impl AddAssign for Vector4
impl AddAssign for Vector4
Source§fn add_assign(&mut self, rhs: Vector4)
fn add_assign(&mut self, rhs: Vector4)
+= operation. Read moreSource§impl DivAssign<f32> for Vector4
impl DivAssign<f32> for Vector4
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl DivAssign for Vector4
impl DivAssign for Vector4
Source§fn div_assign(&mut self, rhs: Vector4)
fn div_assign(&mut self, rhs: Vector4)
/= operation. Read moreSource§impl DynamicSend for Vector4
impl DynamicSend for Vector4
Source§impl Export for Vector4
impl Export for Vector4
Source§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
Source§impl FromGodot for Vector4
impl FromGodot for Vector4
Source§fn try_from_godot(
via: <Vector4 as GodotConvert>::Via,
) -> Result<Vector4, ConvertError>
fn try_from_godot( via: <Vector4 as GodotConvert>::Via, ) -> Result<Vector4, ConvertError>
Err on failure.Source§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
Source§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant, returning Err on failure.Source§impl GodotConvert for Vector4
impl GodotConvert for Vector4
Source§impl Index<Vector4Axis> for Vector4
impl Index<Vector4Axis> for Vector4
Source§impl IndexMut<Vector4Axis> for Vector4
impl IndexMut<Vector4Axis> for Vector4
Source§impl IntoDynamicSend for Vector4
impl IntoDynamicSend for Vector4
type Target = Vector4
fn into_dynamic_send(self) -> <Vector4 as IntoDynamicSend>::Target
Source§impl Mul<Vector4> for Projection
impl Mul<Vector4> for Projection
Source§impl MulAssign<f32> for Vector4
impl MulAssign<f32> for Vector4
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl MulAssign for Vector4
impl MulAssign for Vector4
Source§fn mul_assign(&mut self, rhs: Vector4)
fn mul_assign(&mut self, rhs: Vector4)
*= operation. Read moreSource§impl SubAssign for Vector4
impl SubAssign for Vector4
Source§fn sub_assign(&mut self, rhs: Vector4)
fn sub_assign(&mut self, rhs: Vector4)
-= operation. Read moreSource§impl ToGodot for Vector4
impl ToGodot for Vector4
Source§type Pass = ByValue
type Pass = ByValue
Source§fn to_godot(&self) -> <Vector4 as GodotConvert>::Via
fn to_godot(&self) -> <Vector4 as GodotConvert>::Via
Source§fn to_godot_owned(&self) -> Self::Via
fn to_godot_owned(&self) -> Self::Via
Source§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
Source§impl Var for Vector4
impl Var for Vector4
fn get_property(&self) -> <Vector4 as GodotConvert>::Via
fn set_property(&mut self, value: <Vector4 as GodotConvert>::Via)
Source§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info, e.g. for enums/newtypes.