Struct all_is_cubes::physics::Body

source ·
#[non_exhaustive]
pub struct Body { pub position: FreePoint, pub velocity: Vector3D<FreeCoordinate, Velocity>, pub collision_box: Aab, pub flying: bool, pub noclip: bool, pub yaw: FreeCoordinate, pub pitch: FreeCoordinate, }
Expand description

An object with a position, velocity, and collision volume. What it collides with is determined externally.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§position: FreePoint

Position.

§velocity: Vector3D<FreeCoordinate, Velocity>

Velocity, in position units per second.

§collision_box: Aab

Collision volume, defined with position as the origin.

§flying: bool

Is this body not subject to gravity?

§noclip: bool

Is this body not subject to collision?

§yaw: FreeCoordinate

Yaw of the camera look direction, in degrees clockwise from looking towards -Z.

The preferred range is 0 inclusive to 360 exclusive.

This does not affect the behavior of the Body itself; it has nothing to do with the direction of the velocity.

§pitch: FreeCoordinate

Pitch of the camera look direction, in degrees downward from looking horixontally.

The preferred range is -90 to 90, inclusive.

This does not affect the behavior of the Body itself; it has nothing to do with the direction of the velocity.

Implementations§

source§

impl Body

source

pub fn new_minimal( position: impl Into<FreePoint>, collision_box: impl Into<Aab> ) -> Self

Constructs a Body requiring only information that can’t be reasonably defaulted.

source

pub fn collision_box_abs(&self) -> Aab

Returns the body’s collision box in world coordinates (collision_box translated by position).

use all_is_cubes::math::Aab;
use all_is_cubes::physics::Body;

let body = Body::new_minimal(
    (0.0, 20.0, 0.0),
    Aab::new(-1.0, 1.0, -2.0, 2.0, -3.0, 3.0)
);
assert_eq!(body.collision_box_abs(), Aab::new(-1.0, 1.0, 18.0, 22.0, -3.0, 3.0));
source

pub fn look_at(&mut self, point: FreePoint)

Changes self.yaw and self.pitch to look directly towards the given point within the same coordinate system as self.position.

Trait Implementations§

source§

impl Clone for Body

source§

fn clone(&self) -> Body

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 Debug for Body

source§

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

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

impl Fmt<StatusText> for Body

Omits collision box on the grounds that it is presumably constant

source§

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

Formats self as specified by fopt into destination fmt. Read more
source§

impl PartialEq for Body

source§

fn eq(&self, other: &Body) -> 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 Transaction<Body> for BodyTransaction

§

type CommitCheck = ()

Type of a value passed from Transaction::check to Transaction::commit. This may be used to pass precalculated values to speed up the commit phase, or even lock guards or similar, but also makes it slightly harder to accidentally call commit without check.
§

type Output = Infallible

The results of a Transaction::commit() or Transaction::execute(). Each commit may produce any number of these messages. Read more
source§

fn check(&self, _body: &Body) -> Result<Self::CommitCheck, PreconditionFailed>

Checks whether the target’s current state meets the preconditions and returns Err if it does not. (TODO: Informative error return type.) Read more
source§

fn commit( &self, body: &mut Body, _: Self::CommitCheck, _outputs: &mut dyn FnMut(Self::Output) ) -> Result<(), CommitError>

Perform the mutations specified by this transaction. The check value should have been created by a prior call to Transaction::commit. Read more
source§

fn execute( &self, target: &mut T, outputs: &mut dyn FnMut(Self::Output) ) -> Result<(), ExecuteError>

Convenience method to execute a transaction in one step. Implementations should not need to override this. Equivalent to: Read more
source§

impl Transactional for Body

§

type Transaction = BodyTransaction

The type of transaction which should be used with Self.
source§

impl StructuralPartialEq for Body

Auto Trait Implementations§

§

impl RefUnwindSafe for Body

§

impl Send for Body

§

impl Sync for Body

§

impl Unpin for Body

§

impl UnwindSafe for Body

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> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

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

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Is for T
where T: ?Sized,

§

type EqTo = T

source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<F, T> Refmt<F> for T
where T: Fmt<F> + ?Sized, F: ?Sized,

source§

fn refmt<'a>(&'a self, fopt: &'a F) -> Wrapper<'a, F, T>

Wrap this value so that when formatted with fmt::Debug or fmt::Display, it uses the given Fmt custom format type instead. Read more
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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
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.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.