#[repr(C)]pub struct Vec4 {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}
Expand description
A vector with 4 components: x, y, z, and w. Can be useful for things like shaders, where the registers are aligned to 4 float vectors.
This is a wrapper on System.Numerics.Vector4, so it’s SIMD optimized, and can be cast to and from implicitly. https://stereokit.net/Pages/StereoKit/Vec4.html
see also glam::Vec4
§Examples
use stereokit_rust::maths::Vec4;
let vec4 = Vec4::new(1.0, 2.0, 3.0, 4.0);
let vec4a = Vec4 { x: 1.0, y: 2.0, z:3.0, w:4.0 };
let vec4b = Vec4::X + Vec4::Y * 2.0;
let vec4c: Vec4 = [1.0, 2.0, 3.0, 4.0].into();
assert_eq!(vec4, vec4a);
assert_eq!(vec4a + vec4b, Vec4 { x: 2.0, y: 4.0, z: 3.0, w: 4.0 });
assert_eq!(vec4c, Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 });
assert_eq!(vec4a.length_sq(), 30.0);
assert_eq!(Vec4::dot(Vec4::X, Vec4::Y), 0.0);
Fields§
§x: f32
§y: f32
§z: f32
§w: f32
Implementations§
Source§impl Vec4
impl Vec4
Sourcepub const X: Vec4
pub const X: Vec4
A normalized Vector that points down the X axis, this is the same as new Vec4(1,0,0,0). https://stereokit.net/Pages/StereoKit/Vec4/UnitX.html
Sourcepub const Y: Vec4
pub const Y: Vec4
A normalized Vector that points down the Y axis, this is the same as new Vec4(0,1,0,0). https://stereokit.net/Pages/StereoKit/Vec4/UnitY.html
Sourcepub const Z: Vec4
pub const Z: Vec4
A normalized Vector that points down the Z axis, this is the same as new Vec4(0,0,1,0). https://stereokit.net/Pages/StereoKit/Vec4/UnitZ.html
Sourcepub const W: Vec4
pub const W: Vec4
A normalized Vector that points down the W axis, this is the same as new Vec4(0,0,0,1). https://stereokit.net/Pages/StereoKit/Vec4/UnitW.html
Sourcepub const NEG_X: Vec4
pub const NEG_X: Vec4
A normalized Vector that points up the X axis, this is the same as new Vec4(1,0,0,0).
Sourcepub const NEG_Y: Vec4
pub const NEG_Y: Vec4
A normalized Vector that points up the Y axis, this is the same as new Vec4(0,1,0,0).
Sourcepub const NEG_Z: Vec4
pub const NEG_Z: Vec4
A normalized Vector that points up the Z axis, this is the same as new Vec4(0,0,1,0).
Sourcepub const NEG_W: Vec4
pub const NEG_W: Vec4
A normalized Vector that points up the W axis, this is the same as new Vec4(0,0,0,1).
Sourcepub fn xy(&self) -> Vec2
pub fn xy(&self) -> Vec2
This extracts the Vec2 from the X and Y axes. https://stereokit.net/Pages/StereoKit/Vec4/XY.html
§Examples
use stereokit_rust::maths::{Vec2, Vec4};
let v = Vec4::new(1.0, 2.0, 3.0, 4.0);
let xy = v.xy();
assert_eq!(xy, Vec2::new(1.0, 2.0));
Sourcepub fn yz(&self) -> Vec2
pub fn yz(&self) -> Vec2
This extracts the Vec2 from the Y and Z axes. https://stereokit.net/Pages/StereoKit/Vec4/YZ.html
§Examples
use stereokit_rust::maths::{Vec2, Vec4};
let v = Vec4::new(1.0, 2.0, 3.0, 4.0);
let yz = v.yz();
assert_eq!(yz, Vec2::new(2.0, 3.0));
Sourcepub fn xz(&self) -> Vec2
pub fn xz(&self) -> Vec2
This extracts the Vec2 from the X and Z axes. https://stereokit.net/Pages/StereoKit/Vec4/XZ.html
§Examples
use stereokit_rust::maths::{Vec2, Vec4};
let v = Vec4::new(1.0, 2.0, 3.0, 4.0);
let xz = v.xz();
assert_eq!(xz, Vec2::new(1.0, 3.0));
Sourcepub fn zw(&self) -> Vec2
pub fn zw(&self) -> Vec2
This extracts the Vec2 from the Z and W axes. https://stereokit.net/Pages/StereoKit/Vec4/ZW.html
§Examples
use stereokit_rust::maths::{Vec2, Vec4};
let v = Vec4::new(1.0, 2.0, 3.0, 4.0);
let zw = v.zw();
assert_eq!(zw, Vec2::new(3.0, 4.0));
Sourcepub fn xyz(&self) -> Vec3
pub fn xyz(&self) -> Vec3
This extracts a Vec3 from the X, Y, and Z axes. https://stereokit.net/Pages/StereoKit/Vec4/XYZ.html
§Examples
use stereokit_rust::maths::{Vec3, Vec4};
let v = Vec4::new(1.0, 2.0, 3.0, 4.0);
let v3 = v.xyz();
assert_eq!(v3, Vec3::new(1.0, 2.0, 3.0));
Sourcepub fn get_as_quat(&self) -> Quat
pub fn get_as_quat(&self) -> Quat
A Vec4 and a Quat are only really different by name and purpose. So, if you need to do Quat math with your Vec4, or visa versa, who am I to judge? https://stereokit.net/Pages/StereoKit/Vec4/Quat.html
§Examples
use stereokit_rust::maths::{Vec4, Quat};
let vec4 = Vec4::new(1.0, 2.0, 3.0, 4.0);
let quat = vec4.get_as_quat();
assert_eq!(quat, Quat::new(1.0, 2.0, 3.0, 4.0));
Sourcepub fn length_sq(&self) -> f32
pub fn length_sq(&self) -> f32
This is the squared length/magnitude of the vector! It skips the Sqrt call, and just gives you the squared version for speedy calculations that can work with it squared. https://stereokit.net/Pages/StereoKit/Vec4.html
§Examples
use stereokit_rust::maths::Vec4;
let v = Vec4::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(v.length_sq(), 30.0);
Sourcepub fn dot(a: Self, b: Self) -> f32
pub fn dot(a: Self, b: Self) -> f32
What’s a dot product do for 4D vectors, you might ask? Well, I’m no mathematician, so hopefully you are! I’ve never used it before. Whatever you’re doing with this function, it’s SIMD fast! https://stereokit.net/Pages/StereoKit/Vec4/Dot.html
a
- The first vector.b
- The second vector.
Returns the dot product of the two vectors.
§Examples
use stereokit_rust::maths::Vec4;
let a = Vec4::new(1.0, 2.0, 3.0, 4.0);
let b = Vec4::new(5.0, 6.0, 7.0, 8.0);
let result = Vec4::dot(a, b);
assert_eq!(result, 70.0);
Sourcepub fn lerp(a: Self, b: Self, blend: f32) -> Self
pub fn lerp(a: Self, b: Self, blend: f32) -> Self
Blends (Linear Interpolation) between two vectors, based on a ‘blend’ value, where 0 is a, and 1 is b. Doesn’t clamp percent for you. https://stereokit.net/Pages/StereoKit/Vec4/Lerp.html
a
- First item in the blend, or ’0.0 blend.b
- Second item in the blend, or ’1.0 blend.blend
- A blend value between 0 and 1. Can be outside this range, it’ll just interpolate outside of the a, b range.
Returns an unclamped blend of a and b.
§Examples
use stereokit_rust::maths::Vec4;
let a = Vec4::new(0.0, 0.0, 0.0, 0.0);
let b = Vec4::new(1.0, 1.0, 1.0, 1.0);
let result = Vec4::lerp(a, b, 0.75);
assert_eq!(result, Vec4::new(0.75, 0.75, 0.75, 0.75));
Sourcepub fn max(a: Self, b: Self) -> Self
pub fn max(a: Self, b: Self) -> Self
Returns a vector where each element is the maximum value for each corresponding pair. https://stereokit.net/Pages/StereoKit/Vec4/Max.html
a
- Order isn’t important here.b
- Order isn’t important here.
Returns a vector where each element is the maximum value for each corresponding pair.
§Examples
use stereokit_rust::maths::Vec4;
let a = Vec4::new(1.0, 2.0, 3.0, 4.0);
let b = Vec4::new(4.0, 3.0, 2.0, 1.0);
let c = Vec4::max(a, b);
assert_eq!(c, Vec4::new(4.0, 3.0, 3.0, 4.0));
Sourcepub fn min(a: Self, b: Self) -> Self
pub fn min(a: Self, b: Self) -> Self
Returns a vector where each element is the minimum value for each corresponding pair. https://stereokit.net/Pages/StereoKit/Vec4/Min.html
a
- Order isn’t important here.b
- Order isn’t important here.
Returns a new vector with the minimum values.
§Examples
use stereokit_rust::maths::Vec4;
let a = Vec4::new(1.0, 2.0, 3.0, 4.0);
let b = Vec4::new(4.0, 3.0, 2.0, 1.0);
let c = Vec4::min(a, b);
assert_eq!(c, Vec4::new(1.0, 2.0, 2.0, 1.0));
Trait Implementations§
Source§impl Add for Vec4
Adds matching components together. Commutative.
https://stereokit.net/Pages/StereoKit/Vec4/op_Addition.html
impl Add for Vec4
Adds matching components together. Commutative. https://stereokit.net/Pages/StereoKit/Vec4/op_Addition.html
Source§impl AddAssign for Vec4
Adds matching components together. Commutative.
https://stereokit.net/Pages/StereoKit/Vec4/op_Addition.html
impl AddAssign for Vec4
Adds matching components together. Commutative. https://stereokit.net/Pages/StereoKit/Vec4/op_Addition.html
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
§Examples
use stereokit_rust::maths::Vec4;
let mut v1 = Vec4::new(1.0, 2.0, 3.0, 4.0);
let v2 = Vec4::new(5.0, 6.0, 7.0, 8.0);
v1 += v2;
assert_eq!(v1, Vec4::new(6.0, 8.0, 10.0, 12.0));
Source§impl Display for Vec4
impl Display for Vec4
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Mostly for debug purposes, this is a decent way to log or inspect the vector in debug mode. Looks like “[x, y, z, w]” https://stereokit.net/Pages/StereoKit/Vec4/ToString.html
§Examples
use stereokit_rust::maths::Vec4;
let v = Vec4::new(1.0, 2.2, 3.0, 4.0);
assert_eq!(format!("{}", v), "[x:1, y:2.2, z:3, w:4]");
Source§impl Div<Vec4> for f32
A component-wise vector division.
https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
impl Div<Vec4> for f32
A component-wise vector division. https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
Source§impl Div<f32> for Vec4
A component-wise vector division.
https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
impl Div<f32> for Vec4
A component-wise vector division. https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
Source§impl Div for Vec4
A component-wise vector division.
https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
impl Div for Vec4
A component-wise vector division. https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
Source§impl DivAssign<f32> for Vec4
A component-wise vector division.
https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
impl DivAssign<f32> for Vec4
A component-wise vector division. https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
§Examples
use stereokit_rust::maths::Vec4;
let mut v = Vec4::new(1.0, 2.0, 3.0, 4.0);
v /= 2.0;
assert_eq!(v, Vec4::new(0.5, 1.0, 1.5, 2.0));
Source§impl DivAssign for Vec4
A component-wise vector division.
https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
impl DivAssign for Vec4
A component-wise vector division. https://stereokit.net/Pages/StereoKit/Vec4/op_Division.html
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
§Examples
use stereokit_rust::maths::*;
let mut a = Vec4::new(1.0, 2.0, 3.0, 4.0);
let b = Vec4::new(2.0, 2.0, 2.0, 2.0);
a /= b;
assert_eq!(a, Vec4::new(0.5, 1.0, 1.5, 2.0));
Source§impl Mul<Matrix> for Vec4
impl Mul<Matrix> for Vec4
see also matrix_transform_pt4
Source§impl Mul<Vec4> for Matrix
impl Mul<Vec4> for Matrix
see also matrix_transform_pt4
Source§impl Mul<Vec4> for f32
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative.
https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
impl Mul<Vec4> for f32
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
Source§impl Mul<f32> for Vec4
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative.
https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
impl Mul<f32> for Vec4
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
Source§impl Mul for Vec4
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative.
https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
impl Mul for Vec4
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
Source§impl MulAssign<Matrix> for Vec4
impl MulAssign<Matrix> for Vec4
see also matrix_transform_pt4
Source§fn mul_assign(&mut self, rhs: Matrix)
fn mul_assign(&mut self, rhs: Matrix)
§Examples
use stereokit_rust::maths::{Vec4, Matrix};
let mut v4 = Vec4::new(1.0, 1.0, 1.0, 1.0);
let transform = Matrix::t([1.0, 2.0, 3.0]);
v4 *= transform;
assert_eq!(v4, Vec4::new(2.0, 3.0, 4.0, 1.0));
Source§impl MulAssign<f32> for Vec4
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative.
https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
impl MulAssign<f32> for Vec4
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
§Examples
use stereokit_rust::maths::Vec4;
let mut a = Vec4::new(1.0, 2.0, 7.0, 5.0);
a *= 2.0;
assert_eq!(a, Vec4::new(2.0, 4.0, 14.0, 10.0));
Source§impl MulAssign for Vec4
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative.
https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
impl MulAssign for Vec4
A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec4/op_Multiply.html
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
§Examples
use stereokit_rust::maths::Vec4;
let mut a = Vec4::new(1.0, 2.0, 3.0, 5.0);
let b = Vec4::new(2.0, 3.0, 4.0, 6.0);
a *= b;
assert_eq!(a, Vec4::new(2.0, 6.0, 12.0, 30.0));
Source§impl Neg for Vec4
Vector negation, returns a vector where each component has been negated.
https://stereokit.net/Pages/StereoKit/Vec4/op_UnaryNegation.html
impl Neg for Vec4
Vector negation, returns a vector where each component has been negated. https://stereokit.net/Pages/StereoKit/Vec4/op_UnaryNegation.html
Source§impl Sub for Vec4
impl Sub for Vec4
Source§impl SubAssign for Vec4
Subtracts matching components from eachother. Not commutative.
https://stereokit.net/Pages/StereoKit/Vec4/op_Subtraction.html
impl SubAssign for Vec4
Subtracts matching components from eachother. Not commutative. https://stereokit.net/Pages/StereoKit/Vec4/op_Subtraction.html
Source§fn sub_assign(&mut self, rhs: Vec4)
fn sub_assign(&mut self, rhs: Vec4)
§Examples
use stereokit_rust::maths::Vec4;
let mut v1 = Vec4::new(1.0, 2.0, 3.0, 4.0);
let v2 = Vec4::new(1.0, 2.0, 3.0, 4.0);
v1 -= v2;
assert_eq!(v1, Vec4::new(0.0, 0.0, 0.0, 0.0));
impl Copy for Vec4
Auto Trait Implementations§
impl Freeze for Vec4
impl RefUnwindSafe for Vec4
impl Send for Vec4
impl Sync for Vec4
impl Unpin for Vec4
impl UnwindSafe for Vec4
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.