Struct veloren_common_net::synced_components::inner::ori::Ori

pub struct Ori(Quaternion<f32>);

Tuple Fields§

§0: Quaternion<f32>

Implementations§

§

impl Ori

pub fn new(quat: Quaternion<f32>) -> Ori

pub fn from_unnormalized_vec<T>(vec: T) -> Option<Ori>
where T: Into<Vec3<f32>>,

Tries to convert into a Dir and then the appropriate rotation

pub fn look_vec(self) -> Vec3<f32>

Look direction as a vector (no pedantic normalization performed)

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

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

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

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
where Quaternion<f32>: Mul<T>,

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
where Quaternion<f32>: Mul<T>,

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

Find the angle between two Oris

NOTE: This finds the angle of the quaternion between the two Oris 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

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

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

Returns a version which has been yawed towards dir as much as possible without pitching or rolling

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 Clone for Ori

§

fn clone(&self) -> Ori

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Component for Ori

§

type Storage = VecStorage<Ori>

Associated storage type for this component.
§

impl Debug for Ori

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Ori

§

fn default() -> Ori

Returns the default orientation (no rotation; default Dir)

§

impl<'de> Deserialize<'de> for Ori

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Ori, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl From<Dir> for Ori

§

fn from(dir: Dir) -> Ori

Converts to this type from the input type.
source§

impl From<Ori> for EcsCompPacket

source§

fn from(other: Ori) -> EcsCompPacket

Converts to this type from the input type.
§

impl From<Ori> for Vec3<f32>

§

fn from(ori: Ori) -> Vec3<f32>

Converts to this type from the input type.
§

impl From<Quaternion<f32>> for Ori

§

fn from(_: Quaternion<f32>) -> Ori

Converts to this type from the input type.
§

impl From<Quaternion<f32>> for Ori

§

fn from(quat: Quaternion<f32>) -> Ori

Converts to this type from the input type.
§

impl From<SerdeOri> for Ori

§

fn from(serde_quat: SerdeOri) -> Ori

Converts to this type from the input type.
§

impl From<Vec3<f32>> for Ori

§

fn from(dir: Vec3<f32>) -> Ori

Converts to this type from the input type.
source§

impl InterpolatableComponent for Ori

§

type InterpData = InterpBuffer<Ori>

§

type ReadData = ()

source§

fn new_data(x: Self) -> Self::InterpData

source§

fn update_component( &self, interp_data: &mut Self::InterpData, time: f64, force_update: bool, )

source§

fn interpolate(self, interp_data: &Self::InterpData, t2: f64, _: &()) -> Self

§

impl PartialEq for Ori

§

fn eq(&self, other: &Ori) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for Ori

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<EcsCompPacket> for Ori

§

type Error = InvalidType

The type returned in the event of a conversion error.
source§

fn try_from(other: EcsCompPacket) -> Result<Ori, Self::Error>

Performs the conversion.
§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<C, M> ConvertSaveload<M> for C

§

type Data = C

(De)Serializable data representation for data type
§

type Error = Infallible

Error may occur during serialization or deserialization of component
§

fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
where F: FnMut(Entity) -> Option<M>,

Convert this data type into serializable form (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>
where F: FnMut(M) -> Option<Entity>,

Convert this data from a deserializable form (Data) using entity to marker mapping function
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<Context> SubContext<Context> for Context

§

fn sub_context(self) -> Context

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> TryDefault for T
where T: Default,

§

fn try_default() -> Result<T, String>

Tries to create the default.
§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Event for T
where T: Send + Sync + 'static,

§

impl<T> Resource for T
where T: Any + Send + Sync,

§

impl<T> Storable for T
where T: Send + Sync + 'static,