#[repr(C)]pub struct Vector3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
Expand description
Vector used for 3D math using floating point coordinates.
3-element structure that can be used to represent positions in 3D space or any other triple 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.
See Vector3i
for its integer counterpart.
Fields§
§x: f32
The vector’s X component.
y: f32
The vector’s Y component.
z: f32
The vector’s Z component.
Implementations§
§impl Vector3
impl Vector3
pub const LEFT: Vector3 = _
pub const LEFT: Vector3 = _
Unit vector in -X direction. Can be interpreted as left in an untransformed 3D world.
pub const RIGHT: Vector3 = _
pub const RIGHT: Vector3 = _
Unit vector in +X direction. Can be interpreted as right in an untransformed 3D world.
pub const DOWN: Vector3 = _
pub const DOWN: Vector3 = _
Unit vector in -Y direction. Typically interpreted as down in a 3D world.
pub const FORWARD: Vector3 = _
pub const FORWARD: Vector3 = _
Unit vector in -Z direction. Can be interpreted as “into the screen” in an untransformed 3D world.
pub const BACK: Vector3 = _
pub const BACK: Vector3 = _
Unit vector in +Z direction. Can be interpreted as “out of the screen” in an untransformed 3D world.
pub const fn from_vector3i(v: Vector3i) -> Vector3
pub const fn from_vector3i(v: Vector3i) -> Vector3
Constructs a new Vector3
from a Vector3i
.
pub fn angle_to(self, to: Vector3) -> f32
pub fn bounce(self, normal: Vector3) -> Vector3
pub fn ceil(self) -> Vector3
pub fn clamp(self, min: Vector3, max: Vector3) -> Vector3
pub fn cross(self, with: Vector3) -> Vector3
pub fn direction_to(self, to: Vector3) -> Vector3
pub fn distance_squared_to(self, to: Vector3) -> f32
pub fn distance_to(self, to: Vector3) -> f32
pub fn dot(self, with: Vector3) -> f32
pub fn floor(self) -> Vector3
pub fn inverse(self) -> Vector3
pub fn is_finite(self) -> bool
pub fn is_normalized(self) -> bool
pub fn length_squared(self) -> f32
pub fn limit_length(self, length: Option<f32>) -> Vector3
pub fn max_axis_index(self) -> Vector3Axis
pub fn min_axis_index(self) -> Vector3Axis
pub fn move_toward(self, to: Vector3, delta: f32) -> Vector3
pub fn project(self, b: Vector3) -> Vector3
pub fn reflect(self, normal: Vector3) -> Vector3
pub fn round(self) -> Vector3
pub fn signed_angle_to(self, to: Vector3, axis: Vector3) -> f32
pub fn slerp(self, to: Vector3, weight: f32) -> Vector3
pub fn slerp(self, to: Vector3, weight: f32) -> Vector3
Returns the spherical linear interpolation between the vector and to
by the weight
amount.
The variable weight
is representing the amount of interpolation, which is on the range of
0.0 to 1.0.
Length is also interpolated in the case that the input vectors have different lengths. If both
input vectors have zero length or are collinear to each other, the method instead behaves like
Vector3::lerp
.
pub fn slide(self, normal: Vector3) -> Vector3
pub fn rotated(self, axis: Vector3, angle: f32) -> Vector3
pub fn rotated(self, axis: Vector3, angle: f32) -> Vector3
Returns this vector rotated around axis
by angle
radians. axis
must be normalized.
§Panics
If axis
is not normalized.
pub fn coords(&self) -> (f32, f32, f32)
§impl Vector3
impl Vector3
§impl Vector3
impl Vector3
pub fn normalized(self) -> Vector3
pub fn normalized(self) -> Vector3
Returns the vector scaled to unit length. Equivalent to self / self.length()
. See
also is_normalized()
.
If the vector is zero, the result is also zero.
§impl Vector3
impl Vector3
pub fn lerp(self, other: Vector3, weight: f32) -> Vector3
pub fn bezier_derivative( self, control_1: Vector3, control_2: Vector3, end: Vector3, t: f32 ) -> Vector3
pub fn bezier_interpolate( self, control_1: Vector3, control_2: Vector3, end: Vector3, t: f32 ) -> Vector3
pub fn cubic_interpolate( self, b: Vector3, pre_a: Vector3, post_b: Vector3, weight: f32 ) -> Vector3
pub fn cubic_interpolate_in_time( self, b: Vector3, pre_a: Vector3, post_b: Vector3, weight: f32, b_t: f32, pre_a_t: f32, post_b_t: f32 ) -> Vector3
pub fn is_zero_approx(self) -> bool
pub fn posmod(self, pmod: f32) -> Vector3
pub fn posmodv(self, modv: Vector3) -> Vector3
pub fn sign(self) -> Vector3
pub fn snapped(self, step: Vector3) -> Vector3
Trait Implementations§
§impl AddAssign for Vector3
impl AddAssign for Vector3
§fn add_assign(&mut self, rhs: Vector3)
fn add_assign(&mut self, rhs: Vector3)
+=
operation. Read more§impl DivAssign<f32> for Vector3
impl DivAssign<f32> for Vector3
§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/=
operation. Read more§impl DivAssign for Vector3
impl DivAssign for Vector3
§fn div_assign(&mut self, rhs: Vector3)
fn div_assign(&mut self, rhs: Vector3)
/=
operation. Read more§impl Export for Vector3
impl Export for Vector3
§fn default_export_info() -> PropertyHintInfo
fn default_export_info() -> PropertyHintInfo
§impl Extend<Vector3> for PackedVector3Array
impl Extend<Vector3> for PackedVector3Array
Extends aPackedVector3Array
with the contents of an iterator
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector3>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector3>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)§impl FromGodot for Vector3
impl FromGodot for Vector3
§fn try_from_godot(
via: <Vector3 as GodotConvert>::Via
) -> Result<Vector3, ConvertError>
fn try_from_godot( via: <Vector3 as GodotConvert>::Via ) -> Result<Vector3, ConvertError>
§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl FromIterator<Vector3> for PackedVector3Array
impl FromIterator<Vector3> for PackedVector3Array
Creates a PackedVector3Array
from an iterator.
§fn from_iter<I>(iter: I) -> PackedVector3Arraywhere
I: IntoIterator<Item = Vector3>,
fn from_iter<I>(iter: I) -> PackedVector3Arraywhere
I: IntoIterator<Item = Vector3>,
§impl GodotConvert for Vector3
impl GodotConvert for Vector3
§impl Index<Vector3Axis> for Vector3
impl Index<Vector3Axis> for Vector3
§impl IndexMut<Vector3Axis> for Vector3
impl IndexMut<Vector3Axis> for Vector3
§fn index_mut(&mut self, axis: Vector3Axis) -> &mut f32
fn index_mut(&mut self, axis: Vector3Axis) -> &mut f32
container[index]
) operation. Read more§impl Mul<Vector3> for Transform3D
impl Mul<Vector3> for Transform3D
§impl MulAssign<f32> for Vector3
impl MulAssign<f32> for Vector3
§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*=
operation. Read more§impl MulAssign for Vector3
impl MulAssign for Vector3
§fn mul_assign(&mut self, rhs: Vector3)
fn mul_assign(&mut self, rhs: Vector3)
*=
operation. Read more§impl SubAssign for Vector3
impl SubAssign for Vector3
§fn sub_assign(&mut self, rhs: Vector3)
fn sub_assign(&mut self, rhs: Vector3)
-=
operation. Read more