Struct veloren_common::comp::ori::Ori

source ·
pub struct Ori(Quaternion<f32>);

Tuple Fields§

§0: Quaternion<f32>

Implementations§

source§

impl Ori

source

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

source

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

Tries to convert into a Dir and then the appropriate rotation

source

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

Look direction as a vector (no pedantic normalization performed)

source

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.

source

pub fn look_dir(&self) -> Dir

Look direction (as a Dir it is pedantically normalized)

source

pub fn up(&self) -> Dir

source

pub fn down(&self) -> Dir

source

pub fn left(&self) -> Dir

source

pub fn right(&self) -> Dir

source

pub fn slerp(ori1: Self, ori2: Self, s: f32) -> Self

source

pub fn slerped_towards(self, ori: Ori, s: f32) -> Self

source

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);
source

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);
source

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);
source

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);
source

pub fn to_horizontal(self) -> Self

source

pub fn angle_between(self, other: Self) -> 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

source

pub fn dot(self, other: Self) -> f32

source

pub fn pitched_up(self, angle_radians: f32) -> Self

source

pub fn pitched_down(self, angle_radians: f32) -> Self

source

pub fn yawed_left(self, angle_radians: f32) -> Self

source

pub fn yawed_right(self, angle_radians: f32) -> Self

source

pub fn rolled_left(self, angle_radians: f32) -> Self

source

pub fn rolled_right(self, angle_radians: f32) -> Self

source

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

source

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

source

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

source

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);
source

fn is_normalized(&self) -> bool

Trait Implementations§

source§

impl Clone for Ori

source§

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

impl Component for Ori

§

type Storage = VecStorage<Ori>

Associated storage type for this component.
source§

impl Debug for Ori

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Ori

source§

fn default() -> Self

Returns the default orientation (no rotation; default Dir)

source§

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

source§

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

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

impl From<Dir> for Ori

source§

fn from(dir: Dir) -> Self

Converts to this type from the input type.
source§

impl From<Ori> for Dir

source§

fn from(ori: Ori) -> Self

Converts to this type from the input type.
source§

impl From<Ori> for Quaternion<f32>

source§

fn from(Ori: Ori) -> Self

Converts to this type from the input type.
source§

impl From<Ori> for Quaternion<f32>

source§

fn from(Ori: Ori) -> Self

Converts to this type from the input type.
source§

impl From<Ori> for SerdeOri

source§

fn from(other: Ori) -> SerdeOri

Converts to this type from the input type.
source§

impl From<Ori> for Vec2<f32>

source§

fn from(ori: Ori) -> Self

Converts to this type from the input type.
source§

impl From<Ori> for Vec2<f32>

source§

fn from(ori: Ori) -> Self

Converts to this type from the input type.
source§

impl From<Ori> for Vec3<f32>

source§

fn from(ori: Ori) -> Self

Converts to this type from the input type.
source§

impl From<Ori> for Vec3<f32>

source§

fn from(ori: Ori) -> Self

Converts to this type from the input type.
source§

impl From<Quaternion<f32>> for Ori

source§

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

Converts to this type from the input type.
source§

impl From<Quaternion<f32>> for Ori

source§

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

Converts to this type from the input type.
source§

impl From<SerdeOri> for Ori

source§

fn from(serde_quat: SerdeOri) -> Self

Converts to this type from the input type.
source§

impl From<Vec3<f32>> for Ori

source§

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

Converts to this type from the input type.
source§

impl PartialEq for Ori

source§

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.
source§

impl Serialize for Ori

source§

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

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

impl Copy for Ori

source§

impl StructuralPartialEq for Ori

Auto Trait Implementations§

§

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
§

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.

§

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

impl<Context> SubContext<Context> for Context

source§

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,