Struct veloren_common_net::synced_components::inner::Ori
pub struct Ori(Quaternion<f32>);
Tuple Fields§
§0: Quaternion<f32>
Implementations§
§impl Ori
impl Ori
pub fn new(quat: Quaternion<f32>) -> Ori
pub fn from_unnormalized_vec<T>(vec: T) -> Option<Ori>
pub fn from_unnormalized_vec<T>(vec: T) -> Option<Ori>
Tries to convert into a Dir and then the appropriate rotation
pub 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 look_dir(&self) -> Dir
pub fn look_dir(&self) -> Dir
Look direction (as a Dir it is pedantically normalized)
pub fn up(&self) -> Dir
pub fn down(&self) -> Dir
pub fn left(&self) -> Dir
pub fn right(&self) -> Dir
pub fn slerp(ori1: Ori, ori2: Ori, s: f32) -> Ori
pub fn slerped_towards(self, ori: Ori, s: f32) -> Ori
pub fn rotated(self, q: Quaternion<f32>) -> Ori
pub fn rotated(self, q: Quaternion<f32>) -> Ori
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);
pub fn prerotated(self, q: Quaternion<f32>) -> Ori
pub fn prerotated(self, q: Quaternion<f32>) -> Ori
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);
pub 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);
pub 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) -> Ori
pub fn angle_between(self, other: Ori) -> f32
pub fn angle_between(self, other: Ori) -> 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: Ori) -> f32
pub fn pitched_up(self, angle_radians: f32) -> Ori
pub fn pitched_down(self, angle_radians: f32) -> Ori
pub fn yawed_left(self, angle_radians: f32) -> Ori
pub fn yawed_right(self, angle_radians: f32) -> Ori
pub fn rolled_left(self, angle_radians: f32) -> Ori
pub fn rolled_right(self, angle_radians: f32) -> Ori
pub fn rolled_towards(self, dir: Dir) -> Ori
pub fn rolled_towards(self, dir: Dir) -> Ori
Returns a version which is rolled such that its up points towards dir
as much as possible without pitching or yawing
pub fn pitched_towards(self, dir: Dir) -> Ori
pub fn pitched_towards(self, dir: Dir) -> Ori
Returns a version which has been pitched towards dir
as much as
possible without yawing or rolling
pub fn yawed_towards(self, dir: Dir) -> Ori
pub fn yawed_towards(self, dir: Dir) -> Ori
Returns a version which has been yawed towards dir
as much as possible
without pitching or rolling
pub fn uprighted(self) -> Ori
pub fn uprighted(self) -> Ori
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);
Trait Implementations§
§impl<'de> Deserialize<'de> for Ori
impl<'de> Deserialize<'de> for Ori
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Ori, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Ori, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl From<Ori> for EcsCompPacket
impl From<Ori> for EcsCompPacket
source§fn from(other: Ori) -> EcsCompPacket
fn from(other: Ori) -> EcsCompPacket
§impl From<Quaternion<f32>> for Ori
impl From<Quaternion<f32>> for Ori
§fn from(_: Quaternion<f32>) -> Ori
fn from(_: Quaternion<f32>) -> Ori
§impl From<Quaternion<f32>> for Ori
impl From<Quaternion<f32>> for Ori
§fn from(quat: Quaternion<f32>) -> Ori
fn from(quat: Quaternion<f32>) -> Ori
source§impl InterpolatableComponent for Ori
impl InterpolatableComponent for Ori
type InterpData = InterpBuffer<Ori>
type ReadData = ()
fn new_data(x: Self) -> Self::InterpData
fn update_component( &self, interp_data: &mut Self::InterpData, time: f64, force_update: bool, )
fn interpolate(self, interp_data: &Self::InterpData, t2: f64, _: &()) -> Self
§impl Serialize for Ori
impl Serialize for Ori
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl TryFrom<EcsCompPacket> for Ori
impl TryFrom<EcsCompPacket> for Ori
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
§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.