pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}Expand description
A len-3 column vector.
Fields§
§x: f32§y: f32§z: f32Implementations§
Source§impl Vec3
impl Vec3
pub const fn new(x: f32, y: f32, z: f32) -> Self
pub const fn new_zero() -> Self
pub const fn x() -> Self
pub const fn y() -> Self
pub const fn z() -> Self
Sourcepub fn from_slice(slice: &[f32]) -> Result<Self, BufError>
pub fn from_slice(slice: &[f32]) -> Result<Self, BufError>
Construct from the first 3 values in a slice: &[x, y, z].
pub fn splat(val: f32) -> Self
Sourcepub fn truncate_n(&self, n: usize) -> Vec2
pub fn truncate_n(&self, n: usize) -> Vec2
Returns this vector with the nth element removed (0-based). For example: truncate_n(0) => drops .x, returns Vec2(y, z) truncate_n(1) => drops .y, returns Vec2(x, z) truncate_n(2) => drops .z, returns Vec2(x, y)
Sourcepub fn any_perpendicular(&self) -> Self
pub fn any_perpendicular(&self) -> Self
Returns an arbitrary unit vector perpendicular to it.
pub fn min(self, other: Self) -> Self
pub fn max(self, other: Self) -> Self
Source§impl Vec3
impl Vec3
Sourcepub fn hadamard_product(self, rhs: Self) -> Self
pub fn hadamard_product(self, rhs: Self) -> Self
Calculates the Hadamard product (element-wise multiplication).
Sourcepub fn magnitude_squared(self) -> f32
pub fn magnitude_squared(self) -> f32
Returns the vector magnitude squared
Sourcepub fn to_normalized(self) -> Self
pub fn to_normalized(self) -> Self
Returns the normalized version of the vector.
Sourcepub fn project_to_plane(self, plane_norm: Self) -> Self
pub fn project_to_plane(self, plane_norm: Self) -> Self
Project a vector onto a plane defined by its normal vector. Assumes self and plane_norm
are unit vectors.
Sourcepub fn project_to_vec(self, other: Self) -> Self
pub fn project_to_vec(self, other: Self) -> Self
Projects this vector onto another vector.
Source§impl Vec3
impl Vec3
Sourcepub fn to_bytes_uniform(&self) -> [u8; 16]
pub fn to_bytes_uniform(&self) -> [u8; 16]
Convert to a byte array, e.g. for sending to a GPU. Note that this function pads with an extra 4 bytes, IOC with the hardware 16-byte alignment requirement. This assumes we’re using this in a uniform; Vertexes don’t use padding.
Sourcepub fn to_bytes(&self) -> [u8; 12]
pub fn to_bytes(&self) -> [u8; 12]
Convert to a native-endian byte array, e.g. for sending to a GPU.
pub fn to_le_bytes(&self) -> [u8; 12]
pub fn from_le_bytes(v: &[u8]) -> Self
Trait Implementations§
Source§impl AddAssign<f32> for Vec3
impl AddAssign<f32> for Vec3
Source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
+= operation. Read moreSource§impl AddAssign for Vec3
impl AddAssign for Vec3
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl DivAssign<f32> for Vec3
impl DivAssign<f32> for Vec3
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl Mul<Vec3> for Quaternion
impl Mul<Vec3> for Quaternion
Source§fn mul(self, rhs: Vec3) -> Self::Output
fn mul(self, rhs: Vec3) -> Self::Output
Returns the multiplication of a Quaternion with a vector. This is a normal Quaternion multiplication where the vector is treated as a Quaternion with a W element value of zero. The Quaternion is post- multiplied by the vector.
Source§type Output = Quaternion
type Output = Quaternion
* operator.Source§impl MulAssign<f32> for Vec3
impl MulAssign<f32> for Vec3
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl SubAssign<f32> for Vec3
impl SubAssign<f32> for Vec3
Source§fn sub_assign(&mut self, rhs: f32)
fn sub_assign(&mut self, rhs: f32)
-= operation. Read moreSource§impl SubAssign for Vec3
impl SubAssign for Vec3
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more