Struct Vec3

Source
pub struct Vec3 {
    pub x: f32,
    pub y: f32,
    pub z: f32,
}
Expand description

3D f32 Vector

Fields§

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

Implementations§

Source§

impl Vec3

Source

pub const DOWN: Vec3

Short for Vec2::new(0.0, -1.0, 0.0)

Source

pub const UP: Vec3

Short for Vec2::new(0.0, 1.0, 0.0)

Source

pub const RIGHT: Vec3

Short for Vec2::new(1.0, 0.0, 0.0)

Source

pub const LEFT: Vec3

Short for Vec2::new(-1.0, 0.0, 0.0)

Source

pub const FORWARD: Vec3

Short for Vec2::new(0.0, 0.0, 1.0)

Source

pub const BACK: Vec3

Short for Vec2::new(0.0, 0.0, -1.0)

Source

pub const ONE: Vec3

Short for Vec2::new(1.0, 1.0, 1.0)

Source

pub const ZERO: Vec3

Short for Vec2::new(0.0, 0.0, 0.0)

Source

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

Source

pub fn set(&mut self, x: f32, y: f32, z: f32)

Sets the values of this vector.

§Examples
use gamevecs::Vec3;
let mut vec = Vec3::new(3.0, 4.0, 6.0);
//set the values
vec.set(4.0, 5.0, 5.0);

assert_eq!(Vec3::new(4.0, 5.0, 5.0), vec);
Source

pub fn magnitude(&self) -> f32

Returns the length (distance to (0|0|0)) of this vector.

§Examples
use gamevecs::Vec3;
let vec = Vec3::new(3.0, 4.0, 12.0);
//get the magnitude
let magnitude = vec.magnitude();

assert_eq!(13.0, magnitude);
Source

pub fn magnitude_squared(&self) -> f32

Returns the squared length of this vector.

§Examples
use gamevecs::Vec3;
let vec = Vec3::new(3.0, 4.0, 12.0);
//get the magnitude
let magnitude = vec.magnitude_squared();

assert_eq!(169.0, magnitude);
Source

pub fn equals(&self, other: Vec3, epsilon: f32) -> bool

Returns true if this vector approximately equals another one.

§Examples
use gamevecs::Vec3;
let vec = Vec3::new(3.000001, 4.000001, 5.000001);
let other_vec = Vec3::new(3.0, 4.0, 5.0);

let equals = vec.equals(other_vec, 1e-5);

assert_eq!(true, equals);
Source

pub fn normalized(&self) -> Vec3

Returns this vector with a magnitude of 1. Used when only the direction of the Vector is important.

§Examples
use gamevecs::Vec3;
let vec1 = Vec3::new(0.0, 0.0, 5.0);

//normalize
let normalized = vec1.normalized();

assert_eq!(Vec3::new(0.0, 0.0, 1.0), normalized);
Source

pub fn distance_to(&self, other: Vec3) -> f32

Returns the distance from this vector to another.

§Examples
use gamevecs::Vec3;
let vec1 = Vec3::new(10.0, 20.0, 0.0);
let vec2 = Vec3::new(5.0, 10.0, 10.0);
//get the distance
let distance = vec1.distance_to(vec2);

assert_eq!(15.0, distance);
Source

pub fn distance_to_squared(&self, other: Vec3) -> f32

Returns the squared distance from this vector to another.

§Examples
use gamevecs::Vec3;
let vec1 = Vec3::new(10.0, 20.0, 0.0);
let vec2 = Vec3::new(5.0, 10.0, 10.0);
//get the distance
let distance: f32 = vec1.distance_to_squared(vec2);

assert_eq!(225.0, distance);
Source

pub fn dot(&self, other: Vec3) -> f32

Returns the dot product of this vector and another one.

§Examples
use gamevecs::Vec3;
let vec1 = Vec3::new(1.0, 2.0, 3.0);
let vec2 = Vec3::new(4.0, 5.0, 6.0);
//get the dot product
let dot_product = vec1.dot(vec2);

assert_eq!(32.0, dot_product);
Source

pub fn cross(&self, other: Vec3) -> Vec3

Returns the cross product of this vector and another one.

§Examples
use gamevecs::Vec3;
let vec1 = Vec3::new(2.0, 3.0, 4.0);
let vec2 = Vec3::new(5.0, 6.0, 7.0);
//get the cross product
let cross_product = vec1.cross(vec2);

assert_eq!(Vec3::new(-3.0, 6.0, -3.0), cross_product);
Source

pub fn angle_between(&self, other: Vec3) -> f32

Returns the angle between this vector and another one.

§Examples
use gamevecs::Vec3;
let vec1 = Vec3::new(1.0, 1.0, 1.0);
let vec2 = Vec3::new(-1.0, -1.0, -1.0);
//get the dot product
let angle = vec1.angle_between(vec2);

assert_eq!(180.0, angle.to_degrees());
Source

pub fn lerp(&self, other: Vec3, t: f32) -> Vec3

Returns the linear interpolation by t between this and another vector. T should be between 0 and 1.

§Examples
use gamevecs::Vec3;
let vec1 = Vec3::new(1.0, 2.0, 4.0);
let other = Vec3::new(3.0, 6.0, 8.0);
//lerp
let new_vec = vec1.lerp(other, 0.5);

assert_eq!(Vec3::new(2.0, 4.0, 6.0), new_vec);
Source

pub fn project(&self, onto: Vec3) -> Vec3

Projects a vector onto another one and returns the result as a new Vec3.

§Examples
use gamevecs::Vec3;
let vec1 = Vec3::new(3.0, 4.0, 5.0);
let vec2 = Vec3::new(1.0, 0.0, 0.0);

//project
let projection = vec1.project(vec2);

assert_eq!(Vec3::new(3.0, 0.0, 0.0), projection);

Trait Implementations§

Source§

impl Add for Vec3

Source§

type Output = Vec3

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Vec3

Source§

fn add_assign(&mut self, rhs: Vec3)

Performs the += operation. Read more
Source§

impl Clone for Vec3

Source§

fn clone(&self) -> Vec3

Returns a copy 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 Display for Vec3

Source§

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

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

impl Div for Vec3

Source§

type Output = Vec3

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl DivAssign for Vec3

Source§

fn div_assign(&mut self, rhs: Vec3)

Performs the /= operation. Read more
Source§

impl Mul for Vec3

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign for Vec3

Source§

fn mul_assign(&mut self, rhs: Vec3)

Performs the *= operation. Read more
Source§

impl Neg for Vec3

Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Vec3

Source§

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

Tests for self and other values to be equal, and is used by ==.
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§

type Output = Vec3

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Vec3

Source§

fn sub_assign(&mut self, rhs: Vec3)

Performs the -= operation. Read more
Source§

impl Copy for Vec3

Source§

impl StructuralPartialEq 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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