Struct gamemath::Vec3[][src]

pub struct Vec3<T> {
    pub x: T,
    pub y: T,
    pub z: T,
}

A three-component Euclidean vector usefull for linear algebra computation in game development and 3D rendering.

Fields

The X/first component of the vector.

The Y/second component of the vector.

The Z/third component of the vector.

Methods

impl<T> Vec3<T> where
    T: Copy + Debug + PartialEq + Default + Sub<Output = T> + Mul<Output = T> + Add<Output = T>, 
[src]

Constructs a new Vec3<T> from three initial values.

Examples

use gamemath::Vec3;

let v = Vec3::new(1.0, 5.0, 23.0);

assert_eq!(v.x, 1.0);
assert_eq!(v.y, 5.0);
assert_eq!(v.z, 23.0);

Calculates the dot/scalar product of two Vec3<T>s.

The calling object is considered the left value and the argument object is considered the right value.

Examples

use gamemath::Vec3;

let v1 = Vec3::new(1.0, 2.0, 3.0);
let v2 = Vec3::new(4.0, 5.0, 6.0);

assert_eq!(v1.dot(v2), 32.0);
assert_eq!(v2.dot(v1), 32.0);

Calculates the cross/vector product of two Vec3<T>s.

The calling object is considered the left value and the argument object is considered the right value.

Examples

use gamemath::Vec3;

let v1 = Vec3::new(1.0, 2.0, 3.0);
let v2 = Vec3::new(4.0, 5.0, 6.0);

assert_eq!(v1.cross(v2), Vec3::new(-3.0, 6.0, -3.0));
assert_eq!(v2.cross(v1), Vec3::new(3.0, -6.0, 3.0));

Fills all components of the calling Vec3<T> with the provided value.

Examples

use gamemath::Vec3;

let mut v = Vec3::new(0.0, 0.0, 0.0);

v.fill(6.0);

assert_eq!(v, Vec3::new(6.0, 6.0, 6.0));

Calculates the squared length/magnitude/norm of a Vec3<T>. This saves an expensive square root calculation compared to calculating the actual length, and comparing two squared lengths can therefore often be cheaper than, and yield the same result as, computing two real lengths.

Also usefull for data types that does not implement a square root function, i.e. non-floating-point data types.

Examples

use gamemath::Vec3;

let v = Vec3::new(1.0, 2.0, 3.0);

assert_eq!(v.length_squared(), 14.0);

impl Vec3<f32>
[src]

Calculates the real length/magnitude/norm of a Vec3<f32>. This results in an expensive square root calculation, and you might want to consider using a squared length instead when possible.

Examples

use gamemath::Vec3;

let v = Vec3::new(1.0_f32, 4.0_f32, 8.0_f32);

assert_eq!(v.length(), 9.0_f32);

Calculates and returns the unit vector representation of a Vec3<f32>. This results in an an expensive square root calculation.

Examples

use gamemath::Vec3;

let v = Vec3::new(9.0_f32, 12.0_f32, 20.0_f32);

assert_eq!(v.normalized(), Vec3::new(0.36_f32, 0.48_f32, 0.8_f32));

Normalizes a Vec3<f32> into its unit vector representation. This results in an an expensive square root calculation.

Examples

use gamemath::Vec3;

let mut v = Vec3::new(9.0_f32, 12.0_f32, 20.0_f32);

v.normalize();

assert_eq!(v, Vec3::new(0.36_f32, 0.48_f32, 0.8_f32));

impl Vec3<f64>
[src]

Calculates the real length/magnitude/norm of a Vec3<f64>. This results in an expensive square root calculation, and you might want to consider using a squared length instead when possible.

Examples

use gamemath::Vec3;

let v = Vec3::new(1.0_f64, 4.0_f64, 8.0_f64);

assert_eq!(v.length(), 9.0_f64);

Calculates and returns the unit vector representation of a Vec3<f64>. This results in an an expensive square root calculation.

Examples

use gamemath::Vec3;

let v = Vec3::new(9.0_f64, 12.0_f64, 20.0_f64);

assert_eq!(v.normalized(), Vec3::new(0.36_f64, 0.48_f64, 0.8_f64));

Normalizes a Vec3<f64> into its unit vector representation. This results in an an expensive square root calculation.

Examples

use gamemath::Vec3;

let mut v = Vec3::new(9.0_f64, 12.0_f64, 20.0_f64);

v.normalize();

assert_eq!(v, Vec3::new(0.36_f64, 0.48_f64, 0.8_f64));

Trait Implementations

impl<T> From<Vec3<T>> for Vec2<T>
[src]

Performs the conversion.

impl<T: Clone> Clone for Vec3<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Copy> Copy for Vec3<T>
[src]

impl<T: Debug> Debug for Vec3<T>
[src]

Formats the value using the given formatter. Read more

impl<T: PartialEq> PartialEq for Vec3<T>
[src]

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

This method tests for !=.

impl<T: Default> Default for Vec3<T>
[src]

Returns the "default value" for a type. Read more

impl<T> From<(T, T, T)> for Vec3<T>
[src]

Performs the conversion.

impl<T: Copy> From<[T; 3]> for Vec3<T>
[src]

Performs the conversion.

impl<T: Default> From<Vec2<T>> for Vec3<T>
[src]

Performs the conversion.

impl<T> From<Vec4<T>> for Vec3<T>
[src]

Performs the conversion.

impl<T: Copy> From<T> for Vec3<T>
[src]

Performs the conversion.

impl<T> Index<usize> for Vec3<T>
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl<T> IndexMut<usize> for Vec3<T>
[src]

Performs the mutable indexing (container[index]) operation.

impl<T: Add<Output = T>> Add for Vec3<T>
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T: AddAssign> AddAssign for Vec3<T>
[src]

Performs the += operation.

impl<T: Sub<Output = T>> Sub for Vec3<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<T: SubAssign> SubAssign for Vec3<T>
[src]

Performs the -= operation.

impl<T: Mul<Output = T> + Copy> Mul<T> for Vec3<T>
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T: MulAssign + Copy> MulAssign<T> for Vec3<T>
[src]

Performs the *= operation.

impl<T: Neg<Output = T>> Neg for Vec3<T>
[src]

The resulting type after applying the - operator.

Performs the unary - operation.

impl<T: Default> From<Vec3<T>> for Vec4<T>
[src]

Performs the conversion.

Auto Trait Implementations

impl<T> Send for Vec3<T> where
    T: Send

impl<T> Sync for Vec3<T> where
    T: Sync