pub struct Quaternion<T>(pub T, pub T, pub T, pub T);Expand description
A Quaternion with the format q = (q.0)i + (q.1)j + (q.2)k + (q.3)
Quaternions are usually stored
q = r + ai + bj + ck
in this case however they are stored in the format
q = ai + bj + ck + r
to emphasize the fact that you can essentially use the r value
as a scaler.
Tuple Fields§
§0: T§1: T§2: T§3: TImplementations§
Source§impl<T> Quaternion<T>
impl<T> Quaternion<T>
Sourcepub fn new(a: T, b: T, c: T, r: T) -> Self
pub fn new(a: T, b: T, c: T, r: T) -> Self
Creates a new Quaternion with defined a, b, c, and r values.
§Attributes
a- value multiplied by the imaginary numberiinq = ai + bj + ck + rb- value multiplied by the imaginary numberjinq = ai + bj + ck + rc- value multiplied by the imaginary numberkinq = ai + bj + ck + rr- The real number denotedrinq = ai + bj + ck + r
Sourcepub fn new_vector_real(vector: Vector3<T>, real: T) -> Self
pub fn new_vector_real(vector: Vector3<T>, real: T) -> Self
makes a quaternion from a Vector3 and a given real r value
§Arguments
vector- AVector3which maps out to (a, b, c)real- The r value of the Quaternion
Sourcepub fn new_axis_angle(axis: Vector3<T>, angle: T) -> Self
pub fn new_axis_angle(axis: Vector3<T>, angle: T) -> Self
creates a new quaternion that corresponds to a given rotation around a given axis
§Arguments
axis- TheVector3rotation axisangle- the angle to rotate around that axis
Sourcepub fn identity() -> Self
pub fn identity() -> Self
Returns the identity quaternion that is used for multiplying
§Arguments
zero- the T equivalent of zeroone- the T equivalent of one
Sourcepub fn identity_add() -> Selfwhere
T: Zero,
pub fn identity_add() -> Selfwhere
T: Zero,
Sourcepub fn unit_quaternion(&self) -> Self
pub fn unit_quaternion(&self) -> Self
Sourcepub fn reciprocal(&self) -> Self
pub fn reciprocal(&self) -> Self
pub fn slerp(self, to: Self, time_stamp: T::F32Fmt) -> Self
pub fn sin(self) -> Self
pub fn cos(self) -> Self
pub fn tan(self) -> Self
Source§impl Quaternion<f32>
impl Quaternion<f32>
Sourcepub fn camera_look_at(
pos: Vector3<f32>,
look_at: Vector3<f32>,
) -> Quaternion<f32>
pub fn camera_look_at( pos: Vector3<f32>, look_at: Vector3<f32>, ) -> Quaternion<f32>
Camera Objects look along the -Z axis so the look_at function for a camera object needs to be modified a little. flipping the pos and the look_at should do the trick.
^ Z
|
|
Y• C ------> X
/ \
/ \
/ \§Arguments
pos- AVector3<f32>representing the position of the cameralook_at- AVector3<f32>representing the position the camera is to look at
§Examples
use crate::linear_algebra::Vector3;
let pos = Vector3::new(0.0, 0.0, 0.0);
let look_at = Vector3::new(1.0, 1.0, 1.0);
assert_eq!(camera_look_at(pos, look_at), todo!());pub fn f32_identity() -> Self
Trait Implementations§
Source§impl<T> Add<T> for Quaternion<T>
impl<T> Add<T> for Quaternion<T>
Source§impl<T> Add for Quaternion<T>
impl<T> Add for Quaternion<T>
Source§impl<T: Clone> Clone for Quaternion<T>
impl<T: Clone> Clone for Quaternion<T>
Source§fn clone(&self) -> Quaternion<T>
fn clone(&self) -> Quaternion<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Debug for Quaternion<T>
impl<T> Debug for Quaternion<T>
Source§impl<T> Div<T> for Quaternion<T>
impl<T> Div<T> for Quaternion<T>
Source§impl<T> Div for Quaternion<T>
impl<T> Div for Quaternion<T>
Source§impl<T> F32Fmt for Quaternion<T>
impl<T> F32Fmt for Quaternion<T>
type F32Fmt = Quaternion<<T as F32Fmt>::F32Fmt>
fn intoF32Fmt(self) -> Self::F32Fmt
fn fromF32Fmt(f32_fmt: Self::F32Fmt) -> Self
fn sqrt(self) -> Self
fn cbrt(self) -> Self
fn f32_const_mul(self, constant: f32) -> Self
fn sin_mul(self, mul_by: Self) -> Self
fn cos_mul(self, mul_by: Self) -> Self
fn tan_mul(self, mul_by: Self) -> Self
fn asin_mul(self, _mul_by: Self) -> Self
fn acos_mul(self, _mul_by: Self) -> Self
fn atan_mul(self, _mul_by: Self) -> Self
fn atan2_mul(self, _other: Self, _mul_by: Self) -> Self
fn sinh_mul(self, _mul_by: Self) -> Self
fn cosh_mul(self, _mul_by: Self) -> Self
fn tanh_mul(self, _mul_by: Self) -> Self
Source§impl<T> From<Axes<T>> for Quaternion<T>
impl<T> From<Axes<T>> for Quaternion<T>
Source§impl<T> From<Euler<T>> for Quaternion<T>
impl<T> From<Euler<T>> for Quaternion<T>
Source§impl<T> From<Matrix3<T>> for Quaternion<T>
impl<T> From<Matrix3<T>> for Quaternion<T>
Source§impl<T> From<Quaternion<T>> for [T; 4]where
T: Copy,
impl<T> From<Quaternion<T>> for [T; 4]where
T: Copy,
Source§fn from(other: Quaternion<T>) -> [T; 4]
fn from(other: Quaternion<T>) -> [T; 4]
Converts to this type from the input type.
Source§impl<T> From<Quaternion<T>> for Axes<T>
impl<T> From<Quaternion<T>> for Axes<T>
Source§fn from(q: Quaternion<T>) -> Self
fn from(q: Quaternion<T>) -> Self
Converts to this type from the input type.
Source§impl<T> From<Quaternion<T>> for Euler<T>
impl<T> From<Quaternion<T>> for Euler<T>
Source§fn from(q: Quaternion<T>) -> Self
fn from(q: Quaternion<T>) -> Self
Converts to this type from the input type.
Source§impl<T> From<Quaternion<T>> for Matrix3<T>
impl<T> From<Quaternion<T>> for Matrix3<T>
Source§fn from(other: Quaternion<T>) -> Matrix3<T>
fn from(other: Quaternion<T>) -> Matrix3<T>
Converts to this type from the input type.
Source§impl<T> From<Quaternion<T>> for Rotor<T>
impl<T> From<Quaternion<T>> for Rotor<T>
Source§fn from(q: Quaternion<T>) -> Self
fn from(q: Quaternion<T>) -> Self
Converts to this type from the input type.
Source§impl<T> From<Quaternion<T>> for Vector3<T>where
T: Copy,
impl<T> From<Quaternion<T>> for Vector3<T>where
T: Copy,
Source§fn from(other: Quaternion<T>) -> Vector3<T>
fn from(other: Quaternion<T>) -> Vector3<T>
Converts to this type from the input type.
Source§impl<T> From<Quaternion<T>> for Vector4<T>where
T: Copy,
impl<T> From<Quaternion<T>> for Vector4<T>where
T: Copy,
Source§fn from(other: Quaternion<T>) -> Vector4<T>
fn from(other: Quaternion<T>) -> Vector4<T>
Converts to this type from the input type.
Source§impl<T> From<Rotor<T>> for Quaternion<T>
impl<T> From<Rotor<T>> for Quaternion<T>
Source§impl<T> Mul<T> for Quaternion<T>
impl<T> Mul<T> for Quaternion<T>
Source§impl<T> Mul for Quaternion<T>
impl<T> Mul for Quaternion<T>
Source§impl<T> Neg for Quaternion<T>
impl<T> Neg for Quaternion<T>
Source§impl<T> PartialEq for Quaternion<T>
impl<T> PartialEq for Quaternion<T>
Source§impl<T> Rem<T> for Quaternion<T>
impl<T> Rem<T> for Quaternion<T>
Source§impl<T> Rem for Quaternion<T>
impl<T> Rem for Quaternion<T>
Source§impl<T> Rotation<T> for Quaternion<T>where
T: Construct<T>,
impl<T> Rotation<T> for Quaternion<T>where
T: Construct<T>,
Source§fn look_at_xy(pos: Vector3<T>, look_at: Vector3<T>) -> Self
fn look_at_xy(pos: Vector3<T>, look_at: Vector3<T>) -> Self
§Examples
use crate::linear_algebra::Vector3;
let pos = Vector3::new(0.0, 0.0, 0.0);
let look_at = Vector3::new(1.0, 1.0, 1.0);
assert_eq!(camera_look_at(pos, look_at), Quaternion::new());Source§fn camera_look_at_xy(pos: Vector3<T>, look_at: Vector3<T>) -> Self
fn camera_look_at_xy(pos: Vector3<T>, look_at: Vector3<T>) -> Self
§Examples
use crate::linear_algebra::Vector3;
let pos = Vector3::new(0.0, 0.0, 0.0);
let look_at = Vector3::new(1.0, 1.0, 1.0);
assert_eq!(camera_look_at(pos, look_at), todo!());Source§fn look_at_xz(_pos: Vector3<T>, _look_at: Vector3<T>) -> Self
fn look_at_xz(_pos: Vector3<T>, _look_at: Vector3<T>) -> Self
Generate a rotation for an object at a position look at a point.
only uses the X and Z rotation axes to arrive at this result
Z rotation axis Read more
Source§fn look_at_yz(_pos: Vector3<T>, _look_at: Vector3<T>) -> Self
fn look_at_yz(_pos: Vector3<T>, _look_at: Vector3<T>) -> Self
Generate a rotation for an object at a position look at a point.
only uses the Z and Y rotation axes to arrive at this result
Z rotation axis Read more
Source§fn look_at_lock(
_pos: Vector3<T>,
_look_at: Vector3<T>,
_locked_axis: Vector3<T>,
) -> Self
fn look_at_lock( _pos: Vector3<T>, _look_at: Vector3<T>, _locked_axis: Vector3<T>, ) -> Self
Generate a rotation for an object at a position look at a point.
only uses the Z and Y rotation axes to arrive at this result
Z rotation axis Read more
fn camera_look_at_xz(pos: Vector3<T>, look_at: Vector3<T>) -> Self
fn camera_look_at_yz(pos: Vector3<T>, look_at: Vector3<T>) -> Self
fn camera_look_at_lock( pos: Vector3<T>, look_at: Vector3<T>, locked_axis: Vector3<T>, ) -> Self
const X_AXIS: Vector3<T> = _
const Y_AXIS: Vector3<T> = _
const Z_AXIS: Vector3<T> = _
Source§impl<T> SignOps for Quaternion<T>
impl<T> SignOps for Quaternion<T>
Source§impl<T> Sub<T> for Quaternion<T>
impl<T> Sub<T> for Quaternion<T>
Source§impl<T> Sub for Quaternion<T>
impl<T> Sub for Quaternion<T>
impl<T> Construct<T> for Quaternion<T>where
T: Construct<T>,
impl<T: Copy> Copy for Quaternion<T>
impl<T> ImaginaryConstruct<T> for Quaternion<T>where
T: Construct<T>,
Auto Trait Implementations§
impl<T> Freeze for Quaternion<T>where
T: Freeze,
impl<T> RefUnwindSafe for Quaternion<T>where
T: RefUnwindSafe,
impl<T> Send for Quaternion<T>where
T: Send,
impl<T> Sync for Quaternion<T>where
T: Sync,
impl<T> Unpin for Quaternion<T>where
T: Unpin,
impl<T> UnwindSafe for Quaternion<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more