Struct citro3d::math::FVec

source ·
pub struct FVec<const N: usize>(/* private fields */);
Expand description

A vector of f32s.

§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<const N: usize> FVec<N>

source

pub fn x(self) -> f32

The vector’s x component (also called the i component of ijk[r]).

source

pub fn y(self) -> f32

The vector’s y component (also called the j component of ijk[r]).

source

pub fn z(self) -> f32

The vector’s i component (also called the k component of ijk[r]).

source§

impl FVec<4>

source

pub fn w(self) -> f32

The vector’s w component (also called r for the real component of ijk[r]).

source

pub fn from_raw(raw: C3D_FVec) -> Self

source

pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self

Create a new FVec4 from its components.

§Example
let v = FVec4::new(1.0, 2.0, 3.0, 4.0);
source

pub fn splat(v: f32) -> Self

Create a new FVec4, setting each component to v.

§Example
let v = FVec4::splat(1.0);
assert_abs_diff_eq!(v, FVec4::new(1.0, 1.0, 1.0, 1.0));
source

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));
source

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

pub fn magnitude(self) -> f32

The magnitude of the vector.

§Example
let v = FVec4::splat(1.0);
assert_abs_diff_eq!(v.magnitude(), 2.0);
source

pub fn normalize(self) -> Self

Normalize the vector to a magnitude of 1.0.

§Example
let v = FVec4::new(1.0, 2.0, 2.0, 4.0);
assert_abs_diff_eq!(v.normalize(), FVec4::new(0.2, 0.4, 0.4, 0.8));
source§

impl FVec<3>

source

pub fn new(x: f32, y: f32, z: f32) -> Self

Create a new FVec3 from its components.

§Example
let v = FVec3::new(1.0, 2.0, 3.0);
source

pub fn splat(v: f32) -> Self

Create a new FVec3, setting each component to the given v.

§Example
let v = FVec3::splat(1.0);
source

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);
source

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));
source

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);
source

pub fn magnitude(self) -> f32

The magnitude of the vector.

§Example
let v = FVec3::splat(3.0f32.sqrt());
assert_abs_diff_eq!(v.magnitude(), 3.0);
source

pub fn normalize(self) -> Self

Normalize the vector to a magnitude of 1.0.

§Example
let v = FVec3::splat(1.0);
assert_abs_diff_eq!(v.normalize(), FVec3::splat(1.0 / 3.0_f32.sqrt()));

Trait Implementations§

source§

impl<const N: usize> Clone for FVec<N>

source§

fn clone(&self) -> FVec<N>

Returns a copy of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const N: usize> Debug for FVec<N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const N: usize> Div<f32> for FVec<N>
where FVec<N>: Mul<f32>,

§

type Output = <FVec<N> as Mul<f32>>::Output

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
source§

impl From<FVec<3>> for Vec3

Available on crate feature glam only.
source§

fn from(value: FVec3) -> Self

Converts to this type from the input type.
source§

impl From<FVec<4>> for Uniform

source§

fn from(value: FVec4) -> Self

Converts to this type from the input type.
source§

impl From<FVec<4>> for Vec4

Available on crate feature glam only.
source§

fn from(value: FVec4) -> Self

Converts to this type from the input type.
source§

impl Mul<FVec<3>> for &Matrix4

§

type Output = FVec<4>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: FVec3) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<FVec<4>> for &Matrix4

§

type Output = FVec<4>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: FVec4) -> Self::Output

Performs the * operation. Read more
source§

impl<const N: usize> PartialEq for FVec<N>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const N: usize> Copy for FVec<N>

source§

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.