pub struct FVec<const N: usize>(/* private fields */);
Expand description
A vector of f32
s.
§Layout
Note that this matches the PICA layout so is actually WZYX, this means using it in vertex data as an attribute it will be reversed
It is guaranteed to have the same layout as citro3d_sys::C3D_FVec
in memory
Implementations§
source§impl FVec<4>
impl FVec<4>
sourcepub fn w(self) -> f32
pub fn w(self) -> f32
The vector’s w
component (also called r
for the real component of ijk[r]
).
sourcepub fn from_raw(raw: C3D_FVec) -> Self
pub fn from_raw(raw: C3D_FVec) -> Self
Wrap a raw citro3d_sys::C3D_FVec
sourcepub fn perspective_divide(self) -> Self
pub fn perspective_divide(self) -> Self
Divide the vector’s XYZ components by its W component.
§Example
let v = FVec4::new(2.0, 4.0, 6.0, 2.0);
assert_abs_diff_eq!(v.perspective_divide(), FVec4::new(1.0, 2.0, 3.0, 1.0));
sourcepub fn dot(self, rhs: Self) -> f32
pub fn dot(self, rhs: Self) -> f32
The dot product of two vectors.
§Example
let v1 = FVec4::new(1.0, 2.0, 3.0, 4.0);
let v2 = FVec4::new(1.0, 0.5, 1.0, 0.5);
assert_abs_diff_eq!(v1.dot(v2), 7.0);
source§impl FVec<3>
impl FVec<3>
sourcepub fn distance(self, rhs: Self) -> f32
pub fn distance(self, rhs: Self) -> f32
The distance between two points in 3D space.
§Example
let l = FVec3::new(1.0, 3.0, 4.0);
let r = FVec3::new(0.0, 1.0, 2.0);
assert_abs_diff_eq!(l.distance(r), 3.0);
sourcepub fn cross(self, rhs: Self) -> Self
pub fn cross(self, rhs: Self) -> Self
The cross product of two 3D vectors.
§Example
let l = FVec3::new(1.0, 0.0, 0.0);
let r = FVec3::new(0.0, 1.0, 0.0);
assert_abs_diff_eq!(l.cross(r), FVec3::new(0.0, 0.0, 1.0));
sourcepub fn dot(self, rhs: Self) -> f32
pub fn dot(self, rhs: Self) -> f32
The dot product of two vectors.
§Example
let l = FVec3::new(1.0, 2.0, 3.0);
let r = FVec3::new(3.0, 2.0, 1.0);
assert_abs_diff_eq!(l.dot(r), 10.0);
Trait Implementations§
impl<const N: usize> Copy for FVec<N>
impl<const N: usize> Eq for FVec<N>
Auto Trait Implementations§
impl<const N: usize> RefUnwindSafe for FVec<N>
impl<const N: usize> Send for FVec<N>
impl<const N: usize> Sync for FVec<N>
impl<const N: usize> Unpin for FVec<N>
impl<const N: usize> UnwindSafe for FVec<N>
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more