Struct gamemath::Vec4 [−][src]
pub struct Vec4<T> { pub x: T, pub y: T, pub z: T, pub w: T, }
A four-component Euclidean vector usefull for linear algebra computation in game development and 3D rendering.
Fields
x: T
The X/first component of the vector.
y: T
The Y/second component of the vector.
z: T
The Z/third component of the vector.
w: T
The W/fourth component of the vector.
Methods
impl<T> Vec4<T> where
T: Copy + Debug + PartialEq + Default + Sub<Output = T> + Mul<Output = T> + Add<Output = T>,
[src]
impl<T> Vec4<T> where
T: Copy + Debug + PartialEq + Default + Sub<Output = T> + Mul<Output = T> + Add<Output = T>,
pub fn new(x: T, y: T, z: T, w: T) -> Vec4<T>
[src]
pub fn new(x: T, y: T, z: T, w: T) -> Vec4<T>
Constructs a new Vec4<T>
from three initial values.
Examples
use gamemath::Vec4; let v = Vec4::new(1.0, 5.0, 23.0, -7.0); assert_eq!(v.x, 1.0); assert_eq!(v.y, 5.0); assert_eq!(v.z, 23.0); assert_eq!(v.w, -7.0);
pub fn dot(&self, right: Vec4<T>) -> T
[src]
pub fn dot(&self, right: Vec4<T>) -> T
Calculates the dot/scalar product of two Vec4<T>
s.
The calling object is considered the left value and the argument object is considered the right value.
Examples
use gamemath::Vec4; let v1 = Vec4::new(1.0, 2.0, 3.0, 4.0); let v2 = Vec4::new(5.0, 6.0, 7.0, 8.0); assert_eq!(v1.dot(v2), 70.0); assert_eq!(v2.dot(v1), 70.0);
pub fn fill(&mut self, value: T)
[src]
pub fn fill(&mut self, value: T)
Fills all components of the calling Vec4<T>
with the provided value.
Examples
use gamemath::Vec4; let mut v = Vec4::new(0.0, 0.0, 0.0, 0.0); v.fill(6.0); assert_eq!(v, Vec4::new(6.0, 6.0, 6.0, 6.0));
pub fn length_squared(&self) -> T
[src]
pub fn length_squared(&self) -> T
Calculates the squared length/magnitude/norm of a Vec4<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::Vec4; let v = Vec4::new(1.0, 2.0, 3.0, 4.0); assert_eq!(v.length_squared(), 30.0);
impl Vec4<f32>
[src]
impl Vec4<f32>
pub fn length(&self) -> f32
[src]
pub fn length(&self) -> f32
Calculates the real length/magnitude/norm of a Vec4<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::Vec4; let v = Vec4::new(1.0_f32, 4.0_f32, 4.0_f32, 16.0_f32); assert_eq!(v.length(), 17.0_f32);
pub fn normalized(&self) -> Vec4<f32>
[src]
pub fn normalized(&self) -> Vec4<f32>
Calculates and returns the unit vector representation of a Vec4<f32>
.
This results in an an expensive square root calculation.
Examples
use gamemath::Vec4; let v = Vec4::new(1.0_f32, 2.0_f32, 2.0_f32, 4.0_f32); assert_eq!(v.normalized(), Vec4::new(0.2_f32, 0.4_f32, 0.4_f32, 0.8_f32));
pub fn normalize(&mut self)
[src]
pub fn normalize(&mut self)
Normalizes a Vec4<f32>
into its unit vector representation.
This results in an an expensive square root calculation.
Examples
use gamemath::Vec4; let mut v = Vec4::new(1.0_f32, 2.0_f32, 2.0_f32, 4.0_f32); v.normalize(); assert_eq!(v, Vec4::new(0.2_f32, 0.4_f32, 0.4_f32, 0.8_f32));
impl Vec4<f64>
[src]
impl Vec4<f64>
pub fn length(&self) -> f64
[src]
pub fn length(&self) -> f64
Calculates the real length/magnitude/norm of a Vec4<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::Vec4; let v = Vec4::new(1.0_f64, 4.0_f64, 4.0_f64, 16.0_f64); assert_eq!(v.length(), 17.0_f64);
pub fn normalized(&self) -> Vec4<f64>
[src]
pub fn normalized(&self) -> Vec4<f64>
Calculates and returns the unit vector representation of a Vec4<f64>
.
This results in an an expensive square root calculation.
Examples
use gamemath::Vec4; let v = Vec4::new(1.0_f64, 2.0_f64, 2.0_f64, 4.0_f64); assert_eq!(v.normalized(), Vec4::new(0.2_f64, 0.4_f64, 0.4_f64, 0.8_f64));
pub fn normalize(&mut self)
[src]
pub fn normalize(&mut self)
Normalizes a Vec4<f64>
into its unit vector representation.
This results in an an expensive square root calculation.
Examples
use gamemath::Vec4; let mut v = Vec4::new(1.0_f64, 2.0_f64, 2.0_f64, 4.0_f64); v.normalize(); assert_eq!(v, Vec4::new(0.2_f64, 0.4_f64, 0.4_f64, 0.8_f64));
Trait Implementations
impl<T> From<Vec4<T>> for Vec2<T>
[src]
impl<T> From<Vec4<T>> for Vec2<T>
impl<T> From<Vec4<T>> for Vec3<T>
[src]
impl<T> From<Vec4<T>> for Vec3<T>
impl<T: Clone> Clone for Vec4<T>
[src]
impl<T: Clone> Clone for Vec4<T>
fn clone(&self) -> Vec4<T>
[src]
fn clone(&self) -> Vec4<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T: Copy> Copy for Vec4<T>
[src]
impl<T: Copy> Copy for Vec4<T>
impl<T: Debug> Debug for Vec4<T>
[src]
impl<T: Debug> Debug for Vec4<T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: PartialEq> PartialEq for Vec4<T>
[src]
impl<T: PartialEq> PartialEq for Vec4<T>
fn eq(&self, other: &Vec4<T>) -> bool
[src]
fn eq(&self, other: &Vec4<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Vec4<T>) -> bool
[src]
fn ne(&self, other: &Vec4<T>) -> bool
This method tests for !=
.
impl<T: Default> Default for Vec4<T>
[src]
impl<T: Default> Default for Vec4<T>
impl<T> From<(T, T, T, T)> for Vec4<T>
[src]
impl<T> From<(T, T, T, T)> for Vec4<T>
impl<T: Copy> From<[T; 4]> for Vec4<T>
[src]
impl<T: Copy> From<[T; 4]> for Vec4<T>
impl<T: Default> From<Vec2<T>> for Vec4<T>
[src]
impl<T: Default> From<Vec2<T>> for Vec4<T>
impl<T: Default> From<Vec3<T>> for Vec4<T>
[src]
impl<T: Default> From<Vec3<T>> for Vec4<T>
impl<T: Copy> From<T> for Vec4<T>
[src]
impl<T: Copy> From<T> for Vec4<T>
impl<T> Index<usize> for Vec4<T>
[src]
impl<T> Index<usize> for Vec4<T>
type Output = T
The returned type after indexing.
fn index(&self, index: usize) -> &T
[src]
fn index(&self, index: usize) -> &T
Performs the indexing (container[index]
) operation.
impl<T> IndexMut<usize> for Vec4<T>
[src]
impl<T> IndexMut<usize> for Vec4<T>
fn index_mut(&mut self, index: usize) -> &mut T
[src]
fn index_mut(&mut self, index: usize) -> &mut T
Performs the mutable indexing (container[index]
) operation.
impl<T: Add<Output = T>> Add for Vec4<T>
[src]
impl<T: Add<Output = T>> Add for Vec4<T>
type Output = Vec4<T>
The resulting type after applying the +
operator.
fn add(self, right: Vec4<T>) -> Vec4<T>
[src]
fn add(self, right: Vec4<T>) -> Vec4<T>
Performs the +
operation.
impl<T: AddAssign> AddAssign for Vec4<T>
[src]
impl<T: AddAssign> AddAssign for Vec4<T>
fn add_assign(&mut self, right: Vec4<T>)
[src]
fn add_assign(&mut self, right: Vec4<T>)
Performs the +=
operation.
impl<T: Sub<Output = T>> Sub for Vec4<T>
[src]
impl<T: Sub<Output = T>> Sub for Vec4<T>
type Output = Vec4<T>
The resulting type after applying the -
operator.
fn sub(self, right: Vec4<T>) -> Vec4<T>
[src]
fn sub(self, right: Vec4<T>) -> Vec4<T>
Performs the -
operation.
impl<T: SubAssign> SubAssign for Vec4<T>
[src]
impl<T: SubAssign> SubAssign for Vec4<T>
fn sub_assign(&mut self, right: Vec4<T>)
[src]
fn sub_assign(&mut self, right: Vec4<T>)
Performs the -=
operation.
impl<T: Copy + Mul<Output = T>> Mul<T> for Vec4<T>
[src]
impl<T: Copy + Mul<Output = T>> Mul<T> for Vec4<T>
type Output = Vec4<T>
The resulting type after applying the *
operator.
fn mul(self, right: T) -> Vec4<T>
[src]
fn mul(self, right: T) -> Vec4<T>
Performs the *
operation.
impl<T: Copy + MulAssign> MulAssign<T> for Vec4<T>
[src]
impl<T: Copy + MulAssign> MulAssign<T> for Vec4<T>
fn mul_assign(&mut self, right: T)
[src]
fn mul_assign(&mut self, right: T)
Performs the *=
operation.
impl<T: Neg<Output = T>> Neg for Vec4<T>
[src]
impl<T: Neg<Output = T>> Neg for Vec4<T>
type Output = Vec4<T>
The resulting type after applying the -
operator.
fn neg(self) -> Vec4<T>
[src]
fn neg(self) -> Vec4<T>
Performs the unary -
operation.
impl Mul<Vec4<f32>> for Mat4
[src]
impl Mul<Vec4<f32>> for Mat4
type Output = Vec4<f32>
The resulting type after applying the *
operator.
fn mul(self, vec: Vec4<f32>) -> Vec4<f32>
[src]
fn mul(self, vec: Vec4<f32>) -> Vec4<f32>
Performs the *
operation.
impl From<Vec4<f32>> for Quat
[src]
impl From<Vec4<f32>> for Quat