Struct veloren_common::comp::ori::Ori
source · pub struct Ori(Quaternion<f32>);
Tuple Fields§
§0: Quaternion<f32>
Implementations§
source§impl Ori
impl Ori
pub fn new(quat: Quaternion<f32>) -> Self
sourcepub fn from_unnormalized_vec<T>(vec: T) -> Option<Self>
pub fn from_unnormalized_vec<T>(vec: T) -> Option<Self>
Tries to convert into a Dir and then the appropriate rotation
sourcepub fn look_vec(self) -> Vec3<f32>
pub fn look_vec(self) -> Vec3<f32>
Look direction as a vector (no pedantic normalization performed)
sourcepub fn to_quat(self) -> Quaternion<f32>
pub fn to_quat(self) -> Quaternion<f32>
Get the internal quaternion representing the rotation from
Dir::default()
to this orientation.
The operation is a cheap copy.
pub fn up(&self) -> Dir
pub fn down(&self) -> Dir
pub fn left(&self) -> Dir
pub fn right(&self) -> Dir
pub fn slerp(ori1: Self, ori2: Self, s: f32) -> Self
pub fn slerped_towards(self, ori: Ori, s: f32) -> Self
sourcepub fn rotated(self, q: Quaternion<f32>) -> Self
pub fn rotated(self, q: Quaternion<f32>) -> Self
Multiply rotation quaternion by q
(the rotations are in local vector space).
use vek::{Quaternion, Vec3};
use veloren_common::{comp::Ori, util::Dir};
let ang = 90_f32.to_radians();
let roll_right = Quaternion::rotation_y(ang);
let pitch_up = Quaternion::rotation_x(ang);
let ori1 = Ori::from(Dir::new(Vec3::unit_x()));
let ori2 = Ori::default().rotated(roll_right).rotated(pitch_up);
assert!((ori1.look_dir().dot(*ori2.look_dir()) - 1.0).abs() <= f32::EPSILON);
sourcepub fn prerotated(self, q: Quaternion<f32>) -> Self
pub fn prerotated(self, q: Quaternion<f32>) -> Self
Premultiply rotation quaternion by q
(the rotations are in global vector space).
use vek::{Quaternion, Vec3};
use veloren_common::{comp::Ori, util::Dir};
let ang = 90_f32.to_radians();
let roll_right = Quaternion::rotation_y(ang);
let pitch_up = Quaternion::rotation_x(ang);
let ori1 = Ori::from(Dir::up());
let ori2 = Ori::default().prerotated(roll_right).prerotated(pitch_up);
assert!((ori1.look_dir().dot(*ori2.look_dir()) - 1.0).abs() <= f32::EPSILON);
sourcepub fn global_to_local<T>(
&self,
global: T,
) -> <Quaternion<f32> as Mul<T>>::Output
pub fn global_to_local<T>( &self, global: T, ) -> <Quaternion<f32> as Mul<T>>::Output
Take global
into this Ori’s local vector space
use vek::Vec3;
use veloren_common::{comp::Ori, util::Dir};
let ang = 90_f32.to_radians();
let (fw, left, up) = (Dir::default(), Dir::left(), Dir::up());
let ori = Ori::default().rolled_left(ang).pitched_up(ang);
approx::assert_relative_eq!(ori.global_to_local(fw).dot(*-up), 1.0);
approx::assert_relative_eq!(ori.global_to_local(left).dot(*fw), 1.0);
let ori = Ori::default().rolled_right(ang).pitched_up(2.0 * ang);
approx::assert_relative_eq!(ori.global_to_local(up).dot(*left), 1.0);
sourcepub fn local_to_global<T>(
&self,
local: T,
) -> <Quaternion<f32> as Mul<T>>::Output
pub fn local_to_global<T>( &self, local: T, ) -> <Quaternion<f32> as Mul<T>>::Output
Take local
into the global vector space
use vek::Vec3;
use veloren_common::{comp::Ori, util::Dir};
let ang = 90_f32.to_radians();
let (fw, left, up) = (Dir::default(), Dir::left(), Dir::up());
let ori = Ori::default().rolled_left(ang).pitched_up(ang);
approx::assert_relative_eq!(ori.local_to_global(fw).dot(*left), 1.0);
approx::assert_relative_eq!(ori.local_to_global(left).dot(*-up), 1.0);
let ori = Ori::default().rolled_right(ang).pitched_up(2.0 * ang);
approx::assert_relative_eq!(ori.local_to_global(up).dot(*left), 1.0);
pub fn to_horizontal(self) -> Self
sourcepub fn angle_between(self, other: Self) -> f32
pub fn angle_between(self, other: Self) -> f32
Find the angle between two Ori
s
NOTE: This finds the angle of the quaternion between the two Ori
s
which can involve rolling and thus can be larger than simply the
angle between vectors at the start and end points.
Returns angle in radians
pub fn dot(self, other: Self) -> f32
pub fn pitched_up(self, angle_radians: f32) -> Self
pub fn pitched_down(self, angle_radians: f32) -> Self
pub fn yawed_left(self, angle_radians: f32) -> Self
pub fn yawed_right(self, angle_radians: f32) -> Self
pub fn rolled_left(self, angle_radians: f32) -> Self
pub fn rolled_right(self, angle_radians: f32) -> Self
sourcepub fn rolled_towards(self, dir: Dir) -> Self
pub fn rolled_towards(self, dir: Dir) -> Self
Returns a version which is rolled such that its up points towards dir
as much as possible without pitching or yawing
sourcepub fn pitched_towards(self, dir: Dir) -> Self
pub fn pitched_towards(self, dir: Dir) -> Self
Returns a version which has been pitched towards dir
as much as
possible without yawing or rolling
sourcepub fn yawed_towards(self, dir: Dir) -> Self
pub fn yawed_towards(self, dir: Dir) -> Self
Returns a version which has been yawed towards dir
as much as possible
without pitching or rolling
sourcepub fn uprighted(self) -> Self
pub fn uprighted(self) -> Self
Returns a version without sideways tilt (roll)
use veloren_common::comp::Ori;
let ang = 45_f32.to_radians();
let zenith = vek::Vec3::unit_z();
let rl = Ori::default().rolled_left(ang);
assert!((rl.up().angle_between(zenith) - ang).abs() <= f32::EPSILON);
assert!(rl.uprighted().up().angle_between(zenith) <= f32::EPSILON);
let pd_rr = Ori::default().pitched_down(ang).rolled_right(ang);
let pd_upr = pd_rr.uprighted();
assert!((pd_upr.up().angle_between(zenith) - ang).abs() <= f32::EPSILON);
let ang1 = pd_upr.rolled_right(ang).up().angle_between(zenith);
let ang2 = pd_rr.up().angle_between(zenith);
assert!((ang1 - ang2).abs() <= f32::EPSILON);
fn is_normalized(&self) -> bool
Trait Implementations§
source§impl<'de> Deserialize<'de> for Ori
impl<'de> Deserialize<'de> for Ori
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<Quaternion<f32>> for Ori
impl From<Quaternion<f32>> for Ori
source§fn from(_: Quaternion<f32>) -> Self
fn from(_: Quaternion<f32>) -> Self
source§impl From<Quaternion<f32>> for Ori
impl From<Quaternion<f32>> for Ori
source§fn from(quat: Quaternion<f32>) -> Self
fn from(quat: Quaternion<f32>) -> Self
impl Copy for Ori
impl StructuralPartialEq for Ori
Auto Trait Implementations§
impl Freeze for Ori
impl RefUnwindSafe for Ori
impl Send for Ori
impl Sync for Ori
impl Unpin for Ori
impl UnwindSafe for Ori
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<C, M> ConvertSaveload<M> for C
impl<C, M> ConvertSaveload<M> for C
§type Error = Infallible
type Error = Infallible
§fn convert_into<F>(
&self,
_: F,
) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
Data
) using
entity to marker mapping function§fn convert_from<F>(
data: <C as ConvertSaveload<M>>::Data,
_: F,
) -> Result<C, <C as ConvertSaveload<M>>::Error>
fn convert_from<F>( data: <C as ConvertSaveload<M>>::Data, _: F, ) -> Result<C, <C as ConvertSaveload<M>>::Error>
Data
) using
entity to marker mapping function§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<Context> SubContext<Context> for Context
impl<Context> SubContext<Context> for Context
fn sub_context(self) -> Context
§impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
§fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
§fn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.