Struct Vec3

Source
#[repr(C)]
pub struct Vec3 { pub x: f32, pub y: f32, pub z: f32, }
Expand description

A vector with 3 components: x, y, z. This can represent a point in space, a directional vector, or any other sort of value with 3 dimensions to it!

StereoKit uses a right-handed coordinate system, where +x is to the right, +y is upwards, and -z is forward. https://stereokit.net/Pages/StereoKit/Vec3.html

see also glam::Vec3

§Examples

use stereokit_rust::maths::Vec3;

let vec3        = Vec3::new(1.0, 2.0, 3.0);
let vec3a       = Vec3 { x: 1.0, y: 2.0, z:3.0 };
let vec3b       = Vec3::X + Vec3::Y * 2.0;
let vec3c: Vec3 = [1.0, 2.0, 3.0].into();

assert_eq!(vec3, vec3a);
assert_eq!(vec3a + vec3b,                   Vec3 { x: 2.0, y: 4.0, z: 3.0 });
assert_eq!(vec3c,                           Vec3 { x: 1.0, y: 2.0, z: 3.0 });
assert_eq!(vec3a.length_sq(),               14.0);
assert_eq!(vec3a.magnitude(),               (14.0f32).sqrt());
assert!   (vec3a.get_normalized().length() - 1.0 < f32::EPSILON);
assert_eq!(Vec3::angle_between(Vec3::X, Vec3::Y), 90.0);
assert_eq!(Vec3::dot(Vec3::X, Vec3::Y), 0.0);

Fields§

§x: f32§y: f32§z: f32

Implementations§

Source§

impl Vec3

Source

pub const FORWARD: Self = Self::NEG_Z

StereoKit uses a right-handed coordinate system, which means that forward is looking down the -Z axis! This value is the same as new Vec3(0,0,-1). This is NOT the same as UnitZ! https://stereokit.net/Pages/StereoKit/Vec3/Forward.html

Source

pub const ONE: Self

Shorthand for a vector where all values are 1! Same as new Vec3(1,1,1). https://stereokit.net/Pages/StereoKit/Vec3/One.html

Source

pub const NEG_ONE: Self

Shorthand for a vector where all values are -1! Same as new Vec3(-1,-1,-1).

Source

pub const RIGHT: Self = Self::X

When looking forward, this is the direction to the right! In StereoKit, this is the same as new Vec3(1,0,0) https://stereokit.net/Pages/StereoKit/Vec3/Right.html

Source

pub const X: Self

A normalized Vector that points down the X axis, this is the same as new Vec3(1,0,0). https://stereokit.net/Pages/StereoKit/Vec3/UnitX.html

Source

pub const Y: Self

A normalized Vector that points down the Y axis, this is the same as new Vec3(0,1,0). https://stereokit.net/Pages/StereoKit/Vec3/UnitY.html

Source

pub const Z: Self

A normalized Vector that points down the Z axis, this is the same as new Vec3(0,0,1). This is NOT the same as Forward! https://stereokit.net/Pages/StereoKit/Vec3/UnitZ.html

Source

pub const NEG_X: Self

A normalized Vector that points up the Z axis, this is the same as new Vec3(0,0,-1).

Source

pub const NEG_Y: Self

A normalized Vector that points up the Y axis, this is the same as new Vec3(0,-1,0).

Source

pub const NEG_Z: Self

A normalized Vector that points up the Z axis, this is the same as new Vec3(0,0,-1). This is the same as Forward!

Source

pub const UP: Self = Self::Y

A vector representing the up axis. In StereoKit, this is the same as new Vec3(0,1,0). https://stereokit.net/Pages/StereoKit/Vec3/Up.html

Source

pub const ZERO: Vec3

Shorthand for a vector where all values are 0! Same as new Vec3(0,0,0). https://stereokit.net/Pages/StereoKit/Vec3/Zero.html

Source

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

Creates a vector from x, y, and z values! StereoKit uses a right-handed metric coordinate system, where +x is to the right, +y is upwards, and -z is forward. https://stereokit.net/Pages/StereoKit/Vec3/Vec3.html

Source

pub fn in_radius(&self, point: Self, radius: f32) -> bool

Checks if a point is within a certain radius of this one. This is an easily readable shorthand of the squared distance check. https://stereokit.net/Pages/StereoKit/Vec3/InRadius.html

  • point- The point to check against.
  • radius - The radius to check within.

Returns true if the points are within radius of each other, false not.

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
let vec3_b = Vec3::new(2.0, 4.0, 6.0);
assert_eq!(vec3_a.in_radius(vec3_b, 5.0), true);
assert_eq!(vec3_a.in_radius(vec3_b, 2.0), false);
Source

pub fn normalize(&mut self)

Turns this vector into a normalized vector (vector with a length of 1) from the current vector. Will not work properly if the vector has a length of zero. Vec3::get_normalized is faster. https://stereokit.net/Pages/StereoKit/Vec3/Normalize.html

§Examples
use stereokit_rust::maths::Vec3;

let mut vec3_a = Vec3::new(1.0, 2.0, 3.0);
vec3_a.normalize();
assert_eq!(vec3_a, Vec3::new(0.26726124, 0.5345225, 0.8017837));
Source

pub fn length(&self) -> f32

This is the length, or magnitude of the vector! The distance from the origin to this point. Uses f32::sqrt, so it’s not dirt cheap or anything. https://stereokit.net/Pages/StereoKit/Vec3/Length.html

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.length(), 3.7416575);
Source

pub fn length_sq(&self) -> f32

This is the squared length 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/Vec3/LengthSq.html

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.length_sq(), 14.0);
Source

pub fn magnitude(&self) -> f32

Magnitude is the length of the vector! The distance from the origin to this point. Uses f32::sqrt, so it’s not dirt cheap or anything. https://stereokit.net/Pages/StereoKit/Vec3/Magnitude.html

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.length(), 3.7416575);
Source

pub fn magnitude_squared(&self) -> f32

This is the squared 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/Vec3/MagnitudeSq.html

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.magnitude_squared(), 14.0);
Source

pub fn get_normalized(&self) -> Self

Creates a normalized vector (vector with a length of 1) from the current vector. Will not work properly if the vector has a length of zero. https://stereokit.net/Pages/StereoKit/Vec3/Normalized.html

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.get_normalized(), Vec3::new(0.26726124, 0.5345225, 0.8017837));
Source

pub fn x0z(&self) -> Self

This returns a Vec3 that has been flattened to 0 on the Y axis. No other changes are made. https://stereokit.net/Pages/StereoKit/Vec3/X0Z.html

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.x0z(), Vec3::new(1.0, 0.0, 3.0));
Source

pub fn xy0(&self) -> Self

This returns a Vec3 that has been flattened to 0 on the Z axis. No other changes are made. https://stereokit.net/Pages/StereoKit/Vec3/XY0.html

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.xy0(), Vec3::new(1.0, 2.0, 0.0));
Source

pub fn xy1(&self) -> Self

This returns a Vec3 that has been set to 1 on the Z axis. No other changes are made https://stereokit.net/Pages/StereoKit/Vec3/XY1.html

§Examples
use stereokit_rust::maths::Vec3;

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.xy1(), Vec3::new(1.0, 2.0, 1.0));
Source

pub fn xy(&self) -> Vec2

This extracts the Vec2 from the X and Y axes. https://stereokit.net/Pages/StereoKit/Vec3.html

§Examples
use stereokit_rust::maths::{Vec2, Vec3};

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.xy(), Vec2::new(1.0, 2.0));
Source

pub fn yz(&self) -> Vec2

This extracts the Vec2 from the Y and Z axes. https://stereokit.net/Pages/StereoKit/Vec3/YZ.html

§Examples
use stereokit_rust::maths::{Vec2, Vec3};

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.yz(), Vec2::new(2.0, 3.0));
Source

pub fn xz(&self) -> Vec2

This extracts the Vec2 from the X and Z axes. https://stereokit.net/Pages/StereoKit/Vec3.html

§Examples
use stereokit_rust::maths::{Vec2, Vec3};

let vec3_a = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(vec3_a.xz(), Vec2::new(1.0, 3.0));
Source

pub fn angle_between(a: Self, b: Self) -> f32

Calculates the angle between two vectors in degrees! Vectors do not need to be normalized, and the result will always be positive. https://stereokit.net/Pages/StereoKit/Vec3/AngleBetween.html

  • a - The first, initial vector, A. Does not need to be normalized.
  • b - The second vector, B, that we’re finding the angle to. Does not need to be normalized.

Returns a positive angle between two vectors in degrees!

§Examples
use stereokit_rust::maths::Vec3;

let vec3_b = Vec3::new(0.0, 1.0, 0.0);
assert_eq!(Vec3::angle_between(Vec3::X, vec3_b), 90.0);

let vec3_c = Vec3::new(-1.0, 0.0, 0.0);
assert_eq!(Vec3::angle_between(Vec3::X, vec3_c), 180.0);

let vec3_d = Vec3::new(1.0, 0.0, 1.0);
assert_eq!(Vec3::angle_between(Vec3::X, vec3_d), 45.0);
Source

pub fn angle_xy(angle_deg: f32, z: f32) -> Vec3

Creates a vector that points out at the given 2D angle! This creates the vector on the XY plane, and allows you to specify a constant z value. https://stereokit.net/Pages/StereoKit/Vec3/AngleXY.html

  • angle_deg - The angle in degrees, starting from the (1,0) at 0, and continuing to (0,1) at 90, etc.
  • z - The constant Z value for this vector.

Returns a vector pointing at the given angle! If z is zero, this will be a normalized vector (vector with a length of 1).

§Examples
use stereokit_rust::maths::Vec3;

let angle = 45.0;
let z = 0.0;
let vector = Vec3::angle_xy(angle, z);
assert_eq!(vector, Vec3::new(0.70710677, 0.70710677, 0.0));
Source

pub fn angle_xz(angle_deg: f32, y: f32) -> Self

Creates a vector that points out at the given 2D angle! This creates the vector on the XZ plane, and allows you to specify a constant y value. https://stereokit.net/Pages/StereoKit/Vec3/AngleXZ.html

  • angle_deg - The angle in degrees, starting from the (1,0) at 0, and continuing to (0,1) at 90, etc.
  • y - The constant Y value for this vector.

Returns A Vector pointing at the given angle! If y is zero, this will be a normalized vector (vector with a length of 1).

§Examples
use stereokit_rust::maths::Vec3;
let vec = Vec3::angle_xz(90.0, 0.0);
assert_eq!(vec, Vec3::new(0.0, 0.0, 1.0));
Source

pub fn cross(a: Self, b: Self) -> Self

The cross product of two vectors! https://stereokit.net/Pages/StereoKit/Vec3/Cross.html

  • a - The first vector.
  • b - The second vector.

Returns is not a unit vector, even if both ‘a’ and ‘b’ are unit vectors. see also vec3_cross

§Examples
 use stereokit_rust::maths::Vec3;

 // Test case 1: Basic cross product
 let a = Vec3::new(1.0, 0.0, 0.0);
 let b = Vec3::new(0.0, 1.0, 0.0);
 let result = Vec3::cross(a, b);
 assert_eq!(result, Vec3::new(0.0, 0.0, 1.0));

 // Test case 2: Cross product in different direction
 let a = Vec3::new(0.0, 1.0, 0.0);
 let b = Vec3::new(1.0, 0.0, 0.0);
 let result = Vec3::cross(a, b);
 assert_eq!(result, Vec3::new(0.0, 0.0, -1.0));

 // Test case 3: Cross product with non-unit vectors
 let a = Vec3::new(2.0, 0.0, 0.0);
 let b = Vec3::new(0.0, 3.0, 0.0);
 let result = Vec3::cross(a, b);
 assert_eq!(result, Vec3::new(0.0, 0.0, 6.0));

 // Test case 4: Cross product of parallel vectors
 let a = Vec3::new(1.0, 0.0, 0.0);
 let b = Vec3::new(2.0, 0.0, 0.0);
 let result = Vec3::cross(a, b);
 assert_eq!(result, Vec3::ZERO);

 // Test case 5: cross product of orthogonal vector
 let a = Vec3::new(1.0, 2.0, 3.0);
 let b = Vec3::new(4.0, 5.0, 6.0);
 let result = Vec3::cross(a,b);
 assert_eq!(result, Vec3::new(-3.0, 6.0, -3.0));

 // Test case 6: cross product of orthogonal vector
 let a = Vec3::new(4.0, 5.0, 6.0);
 let b = Vec3::new(1.0, 2.0, 3.0);
 let result = Vec3::cross(a,b);
 assert_eq!(result, Vec3::new(3.0, -6.0, 3.0));
Source

pub fn direction(to: Self, from: Self) -> Self

Creates a normalized delta vector that points out from an origin point to a target point! https://stereokit.net/Pages/StereoKit/Vec3/Direction.html

  • to - The target point.
  • from - The origin point.

Returns direction from one point to another.

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
let direction = Vec3::direction(a, b);
assert_eq!(direction, Vec3 { x: -0.57735026, y: -0.57735026, z: -0.57735026 });
Source

pub fn distance(a: Self, b: Self) -> f32

Calculates the distance between two points in space! Make sure they’re in the same coordinate space! Uses a Sqrt, so it’s not blazing fast, prefer DistanceSq when possible. https://stereokit.net/Pages/StereoKit/Vec3/Distance.html

  • a - The first point.
  • b - The second point.

Returns the distance between the two points.

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3 { x: 1.0, y: 2.0, z: 3.0 };
let b = Vec3 { x: 4.0, y: 5.0, z: 6.0 };
let distance = Vec3::distance(a, b);
assert_eq!(distance, 5.196152);
Source

pub fn distance_sq(a: Self, b: Self) -> f32

Calculates the distance between two points in space, but leaves them squared! Make sure they’re in the same coordinate space! This is a fast function :) https://stereokit.net/Pages/StereoKit/Vec3/DistanceSq.html

  • a - The first point.
  • b - The second point.

Returns the distance between the two points, but squared.

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
let distance = Vec3::distance_sq(a, b);
assert_eq!(distance, 27.0);
Source

pub fn dot(a: Self, b: Self) -> f32

The dot product is an extremely useful operation! One major use is to determine how similar two vectors are. If the vectors are Unit vectors (magnitude/length of 1), then the result will be 1 if the vectors are the same, -1 if they’re opposite, and a gradient in-between with 0 being perpendicular. See Freya Holmer’s excellent visualization of this concept https://stereokit.net/Pages/StereoKit/Vec3/Dot.html

  • a - The first vector.
  • b - The second vector.

Returns the dot product of the two vectors.

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 0.0, 1.0);
let b = Vec3::new(1.0, 1.0, 0.0);
let dot_product = Vec3::dot(a, b);
assert_eq!(dot_product, 1.0);
Source

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/Vec3/Lerp.html

  • a - First item in the blend, or ‘0.0’ blend.
  • b - Second item in the blend, or ‘1.0’ blend.
  • blend - The blend value between 0 and 1. Can be outside this range, it’ll just interpolate outside of the a, b range.

Returns a blend value between 0 and 1. Can be outside this range, it’ll just interpolate outside of the a, b range.

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
let blend = 0.25;
let result = Vec3::lerp(a, b, blend);
assert_eq!(result, Vec3::new(1.75, 2.75, 3.75));
Source

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/Vec3/Max.html

  • a - Order isn’t important here.
  • b - Order isn’t important here.

Returns the maximum value for each corresponding vector pair.

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 6.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
let result = Vec3::max(a, b);
assert_eq!(result, Vec3::new(4.0, 6.0, 6.0));
Source

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/Vec3/Min.html

  • a - Order isn’t important here.
  • b - Order isn’t important here.

Returns the minimum value for each corresponding vector pair.

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 1.0, 6.0);
let result = Vec3::min(a, b);
assert_eq!(result, Vec3::new(1.0, 1.0, 3.0));
Source

pub fn perpendicular_right(forward: Self, up: Self) -> Self

Exactly the same as Vec3.Cross, but has some naming mnemonics for getting the order right when trying to find a perpendicular vector using the cross product. This’ll also make it more obvious to read if that’s what you’re actually going for when crossing vectors! If you consider a forward vector and an up vector, then the direction to the right is pretty trivial to imagine in relation to those vectors! https://stereokit.net/Pages/StereoKit/Vec3/PerpendicularRight.html

  • forward - What way are you facing?
  • up - Which direction is up?

Returns your direction to the right! Result is -not- a unit vector, even if both ‘forward’ and ‘up’ are unit vectors.

§Examples
use stereokit_rust::maths::Vec3;

let forward = Vec3::new(0.0, 0.0, -1.0);
let up = Vec3::new(0.0, 1.0, 0.0);
let right = Vec3::perpendicular_right(forward, up);
assert_eq!(right, Vec3::new(1.0, 0.0, 0.0));

// The same with constants:
let forward = Vec3::FORWARD;
let up = Vec3::UP;
let right = Vec3::perpendicular_right(forward, up);
assert_eq!(right, Vec3::RIGHT);
Source

pub fn abs(&self) -> Self

Returns a vector where each element is the absolute value of the corresponding element. https://stereokit.net/Pages/StereoKit/Vec3/Abs.html

§Examples
use stereokit_rust::maths::Vec3;

let v = Vec3::new(-1.0, 2.0, -3.0);
assert_eq!(v.abs(), Vec3::new(1.0, 2.0, 3.0));
Source

pub const fn to_array(&self) -> [f32; 3]

get an array

§Examples
use stereokit_rust::maths::Vec3;

let v = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(v.to_array(), [1.0, 2.0, 3.0]);

Trait Implementations§

Source§

impl Add for Vec3

Adds matching components together. Commutative. https://stereokit.net/Pages/StereoKit/Vec3/op_Addition.html

Source§

fn add(self, rhs: Self) -> Self::Output

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
let c = a + b;
assert_eq!(c, Vec3::new(5.0, 7.0, 9.0));
Source§

type Output = Vec3

The resulting type after applying the + operator.
Source§

impl AddAssign for Vec3

Adds matching components together. Commutative. https://stereokit.net/Pages/StereoKit/Vec3/op_Addition.html

Source§

fn add_assign(&mut self, rhs: Self)

§Examples
use stereokit_rust::maths::Vec3;

let mut a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
a += b;
assert_eq!(a, Vec3::new(5.0, 7.0, 9.0));
Source§

impl Clone for Vec3

Source§

fn clone(&self) -> Vec3

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Vec3

Source§

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

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

impl Default for Vec3

Source§

fn default() -> Vec3

Returns the “default value” for a type. Read more
Source§

impl Display for Vec3

Source§

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]” https://stereokit.net/Pages/StereoKit/Vec3/ToString.html

§Examples
use stereokit_rust::maths::Vec3;

let v = Vec3::new(1.0, 2.0, 3.0);
assert_eq!(v.to_string(), "[x:1, y:2, z:3]");
Source§

impl Div<Vec3> for f32

Source§

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

§Examples
use stereokit_rust::maths::Vec3;

let v = Vec3::new(1.0, 2.0, 3.0);
let v = v / Vec3::new(2.0, 2.0, 2.0);
assert_eq!(v, Vec3::new(0.5, 1.0, 1.5));
Source§

type Output = Vec3

The resulting type after applying the / operator.
Source§

impl Div<f32> for Vec3

Source§

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

§Examples
use stereokit_rust::maths::Vec3;

let v = Vec3::new(1.0, 2.0, 3.0);
let v = v / 2.0;
assert_eq!(v, Vec3::new(0.5, 1.0, 1.5));
Source§

type Output = Vec3

The resulting type after applying the / operator.
Source§

impl Div for Vec3

Source§

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

§Examples
use stereokit_rust::maths::Vec3;

let v = Vec3::new(1.0, 2.0, 3.0) / Vec3::new(2.0, 2.0, 2.0);
assert_eq!(v, Vec3::new(0.5, 1.0, 1.5));
Source§

type Output = Vec3

The resulting type after applying the / operator.
Source§

impl DivAssign<f32> for Vec3

Source§

fn div_assign(&mut self, rhs: f32)

§Examples
use stereokit_rust::maths::Vec3;

let mut v = Vec3::new(1.0, 2.0, 3.0);
v /= 2.0;
assert_eq!(v, Vec3::new(0.5, 1.0, 1.5));
Source§

impl DivAssign for Vec3

Source§

fn div_assign(&mut self, rhs: Self)

§Examples
use stereokit_rust::maths::Vec3;

let mut v = Vec3::new(1.0, 2.0, 3.0);
v /= Vec3::new(2.0, 2.0, 2.0);
assert_eq!(v, Vec3::new(0.5, 1.0, 1.5));
Source§

impl From<[f32; 3]> for Vec3

Source§

fn from(val: [f32; 3]) -> Self

Converts to this type from the input type.
Source§

impl From<Vec3> for [f32; 3]

Source§

fn from(val: Vec3) -> Self

Converts to this type from the input type.
Source§

impl From<Vec3> for Vec3

Source§

fn from(val: Vec3) -> Self

Converts to this type from the input type.
Source§

impl From<Vec3> for Vec3

Source§

fn from(val: Vec3) -> Self

Converts to this type from the input type.
Source§

impl Mul<Matrix> for Vec3

Multiplies the vector by the Matrix! Since only a 1x4 vector can be multiplied against a 4x4 matrix, this uses ‘1’ for the 4th element, so the result will also include translation! To exclude translation, use Matrix.transform_normal. https://stereokit.net/Pages/StereoKit/Matrix/op_Multiply.html

Source§

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

§Examples
use stereokit_rust::maths::{Vec3, Matrix};

let transform = Matrix::t([1.0, 2.0, 3.0]);
let point = Vec3::new(1.0, 1.0, 1.0);

let transformed_point = point * transform;
assert_eq!(transformed_point, Vec3::new(2.0, 3.0, 4.0));
Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

impl Mul<Vec3> for Bounds

This operator will create a new Bounds that has been properly scaled up by the Vec3. This does affect the center position of the Bounds. https://stereokit.net/Pages/StereoKit/Bounds/op_Multiply.html

Source§

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

§Examples
use stereokit_rust::maths::{Vec3, Bounds};

let bounds = Bounds::from_corners( Vec3::ZERO, Vec3::ONE);

let bounds_scaled = bounds * Vec3::new(1.0, 2.0, 3.0);
assert_eq!(bounds_scaled.center, Vec3::new(0.5, 1.0, 1.5));
assert_eq!(bounds_scaled.dimensions, Vec3::new(1.0, 2.0, 3.0));
Source§

type Output = Bounds

The resulting type after applying the * operator.
Source§

impl Mul<Vec3> for Matrix

Multiplies the vector by the Matrix! Since only a 1x4 vector can be multiplied against a 4x4 matrix, this uses ‘1’ for the 4th element, so the result will also include translation! To exclude translation, use Matrix.transform_normal. https://stereokit.net/Pages/StereoKit/Matrix/op_Multiply.html

Source§

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

§Examples
use stereokit_rust::maths::{Vec3, Matrix};

let transform = Matrix::t([1.0, 2.0, 3.0]);
let point = Vec3::new(1.0, 1.0, 1.0);

let transformed_point = transform * point;
assert_eq!(transformed_point, Vec3::new(2.0, 3.0, 4.0));
Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

impl Mul<Vec3> for Quat

This rotates a point around the origin by the Quat. https://stereokit.net/Pages/StereoKit/Quat/op_Multiply.html

see also quat_mul_vec

Source§

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

§Examples
use stereokit_rust::maths::{Quat, Vec3};

let q = Quat::from_angles(0.0, 90.0, 0.0);
let v = Vec3::new(1.0, 0.0, 0.0);
assert_eq!(q * v, Vec3::new(0.0, 0.0, -1.0));
Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

impl Mul<Vec3> 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/Vec3/op_Multiply.html

Source§

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

§Examples
use stereokit_rust::maths::Vec3;

let a = 2.0 * Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(2.0, 4.0, 6.0);
assert_eq!(a, b);
Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

impl Mul<f32> for Vec3

A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec3/op_Multiply.html

Source§

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

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = a * 2.0;
assert_eq!(b, Vec3::new(2.0, 4.0, 6.0));
Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

impl Mul for Vec3

A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec3/op_Multiply.html

Source§

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

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
let c = a * b;
assert_eq!(c, Vec3::new(4.0, 10.0, 18.0));
Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

impl MulAssign<Matrix> for Vec3

Multiplies the vector by the Matrix! Since only a 1x4 vector can be multiplied against a 4x4 matrix, this uses ‘1’ for the 4th element, so the result will also include translation! To exclude translation, use Matrix.transform_normal. https://stereokit.net/Pages/StereoKit/Matrix/op_Multiply.html

Source§

fn mul_assign(&mut self, rhs: Matrix)

§Examples
use stereokit_rust::maths::{Vec3, Matrix};

let mut point = Vec3::new(1.0, 1.0, 1.0);
let transform = Matrix::t([1.0, 2.0, 3.0]);

point *= transform;
assert_eq!(point, Vec3::new(2.0, 3.0, 4.0));
Source§

impl MulAssign<Vec3> for Bounds

This operator will create a new Bounds that has been properly scaled up by the Vec3. This does affect the center position of the Bounds. https://stereokit.net/Pages/StereoKit/Bounds/op_Multiply.html

Source§

fn mul_assign(&mut self, rhs: Vec3)

§Examples
use stereokit_rust::maths::{Vec3, Bounds};

let mut bounds = Bounds::from_corners( Vec3::ZERO, Vec3::ONE);

bounds *= Vec3::new(1.0, 2.0, 3.0);
assert_eq!(bounds.center, Vec3::new(0.5, 1.0, 1.5));
assert_eq!(bounds.dimensions, Vec3::new(1.0, 2.0, 3.0));
Source§

impl MulAssign<f32> for Vec3

A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec3/op_Multiply.html

Source§

fn mul_assign(&mut self, rhs: f32)

§Examples
use stereokit_rust::maths::Vec3;

let mut a = Vec3::new(1.0, 2.0, 3.0);
a *= 2.0;
assert_eq!(a, Vec3::new(2.0, 4.0, 6.0));
Source§

impl MulAssign for Vec3

A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative. https://stereokit.net/Pages/StereoKit/Vec3/op_Multiply.html

Source§

fn mul_assign(&mut self, rhs: Self)

§Examples
use stereokit_rust::maths::Vec3;

let mut a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
a *= b;
assert_eq!(a, Vec3::new(4.0, 10.0, 18.0));
Source§

impl Neg for Vec3

Vector negation, returns a vector where each component has been negated. https://stereokit.net/Pages/StereoKit/Vec3/op_UnaryNegation.html

Source§

fn neg(self) -> Self::Output

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = -a;
assert_eq!(b, Vec3::new(-1.0, -2.0, -3.0));
Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

impl PartialEq for Vec3

Warning: Equality with a precision of 0.1 millimeter

Source§

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

Warning: Equality with a precision of 0.1 millimeter

§Example
use stereokit_rust::maths::Vec3;
assert_eq!(
             Vec3 { x: 0.045863353, y: 0.030000005, z: 0.0 } ,
             Vec3 { x: 0.045863353, y: 0.030000005, z: 0.0 } );
use stereokit_rust::maths::Vec3;
assert_ne!(
             Vec3 { x: 10.045863353, y: 0.030000005, z: 0.0 } ,
             Vec3 { x: 0.045863353, y: 0.030000005, z: 0.0 } );
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for Vec3

Source§

fn sub(self, rhs: Self) -> Self::Output

§Examples
use stereokit_rust::maths::Vec3;

let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);
let c = a - b;
assert_eq!(c, Vec3::new(-3.0, -3.0, -3.0));
Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

impl SubAssign for Vec3

Subtracts matching components from eachother. Not commutative. https://stereokit.net/Pages/StereoKit/Vec3/op_Subtraction.html

Source§

fn sub_assign(&mut self, rhs: Vec3)

§Examples
use stereokit_rust::maths::Vec3;

let mut a = Vec3::new(1.0, 3.0, 1.0);
let b = Vec3::new(0.5, 0.5, 0.5);
a -= b;
assert_eq!(a, Vec3::new(0.5, 2.5, 0.5));
Source§

impl Copy 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 UnwindSafe for Vec3

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more