#[repr(C)]pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}Expand description
A 3-dimensional vector with f32 components.
Vec3 is the workhorse for positions, directions, and scales throughout
the engine. It supports the usual arithmetic operators plus dot, cross,
length, and normalize.
§Examples
use khora_core::math::Vec3;
// Component-wise arithmetic and scalar multiplication.
let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
assert_eq!(a + b, Vec3::new(5.0, 7.0, 9.0));
assert_eq!(a * 2.0, Vec3::new(2.0, 4.0, 6.0));
// Dot product and the right-handed cross product of the basis axes.
assert_eq!(Vec3::X.dot(Vec3::Y), 0.0);
assert_eq!(Vec3::X.cross(Vec3::Y), Vec3::Z);
// Normalizing yields a unit-length direction.
let dir = Vec3::new(0.0, 3.0, 0.0).normalize();
assert_eq!(dir, Vec3::Y);Fields§
§x: f32The x component of the vector.
y: f32The y component of the vector.
z: f32The z component of the vector.
Implementations§
Source§impl Vec3
impl Vec3
Sourcepub const fn new(x: f32, y: f32, z: f32) -> Self
pub const fn new(x: f32, y: f32, z: f32) -> Self
Creates a new Vec3 with the specified components.
Sourcepub fn max_element(self) -> f32
pub fn max_element(self) -> f32
Returns the largest component of the vector (signed).
Useful for major-axis selection in cubemap sampling and bounding-box
checks. Note that this is not the absolute maximum — for that,
call .abs().max_element().
Sourcepub fn min_element(self) -> f32
pub fn min_element(self) -> f32
Returns the smallest component of the vector (signed).
Sourcepub fn length_squared(&self) -> f32
pub fn length_squared(&self) -> f32
Calculates the squared length (magnitude) of the vector.
Sourcepub fn cross(&self, other: Self) -> Self
pub fn cross(&self, other: Self) -> Self
Computes the cross product of this vector and another.
Sourcepub fn distance_squared(&self, other: Self) -> f32
pub fn distance_squared(&self, other: Self) -> f32
Calculates the squared distance between this vector and another.
Sourcepub fn distance(&self, other: Self) -> f32
pub fn distance(&self, other: Self) -> f32
Calculates the distance between this vector and another.
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for Vec3
impl<'__de, __Context> BorrowDecode<'__de, __Context> for Vec3
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Source§impl<'de> Deserialize<'de> for Vec3
impl<'de> Deserialize<'de> for Vec3
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Mul<Vec3> for Quaternion
impl Mul<Vec3> for Quaternion
impl Copy for Vec3
impl Pod for Vec3
impl StructuralPartialEq for Vec3
Auto Trait Implementations§
impl Freeze for Vec3
impl RefUnwindSafe for Vec3
impl Send for Vec3
impl Sync for Vec3
impl Unpin for Vec3
impl UnsafeUnpin for Vec3
impl UnwindSafe for Vec3
Blanket Implementations§
Source§impl<T> AppLifecycle for Twhere
T: ?Sized,
impl<T> AppLifecycle for Twhere
T: ?Sized,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.