Body

Struct Body 

Source
#[non_exhaustive]
pub struct Body { pub flying: bool, pub noclip: bool, pub yaw: FreeCoordinate, pub pitch: FreeCoordinate, /* private fields */ }
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.
§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.

§Panics

Panics if any component of position is NaN or infinite.

Source

pub fn position(&self) -> FreePoint

Returns the body’s current position.

If you are interested in the space it occupies, use Self::collision_box_abs() instead.

Source

pub fn set_position(&mut self, position: FreePoint)

Sets the position of the body, disregarding collision.

Note: This may have effects that normal time stepping does not. In particular, body.set_position(body.position()) is not guaranteed to do nothing.

If position contains any component which is infinite or NaN, this function does nothing. This behavior may change in the future.

Source

pub fn velocity(&self) -> Vector3D<f64, Velocity>

Returns the body’s current velocity.

Source

pub fn add_velocity(&mut self, Δv: Vector3D<f64, Velocity>)

Adds the given value to the body’s velocity.

If Δv contains any component which is infinite or NaN, this function does nothing. This behavior may change in the future.

Source

pub fn set_velocity(&mut self, v: Vector3D<f64, Velocity>)

Replaces the body’s velocity with the given value.

If Δv contains any component which is infinite or NaN, this function does nothing. This behavior may change in the future.

Source

pub fn collision_box_rel(&self) -> Aab

Returns the body’s configured collision box in coordinates relative to Self::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 collision_box_abs(&self) -> Aab

Returns the body’s current collision box in world coordinates.

This is not necessarily equal in size to Self::collision_box_rel().

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_direction(&self) -> FreeVector

Returns the direction the body is facing (when it is part of a character).

Source

pub fn set_look_direction(&mut self, direction: FreeVector)

Changes self.yaw and self.pitch to look in the given direction vector.

If direction has zero length, the resulting direction is unspecified but valid.

Trait Implementations§

Source§

impl Clone for Body

Source§

fn clone(&self) -> Body

Returns a duplicate 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 Body
where Self: Send + Sync + 'static,

Required Components: [PhysicsOutputs], [rg :: Destination].

A component’s Required Components are inserted whenever it is inserted. Note that this will also insert the required components of the required components, recursively, in depth-first order.

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have Component<Mutability = Mutable>, while immutable components will instead have Component<Mutability = Immutable>. Read more
Source§

fn register_required_components( requiree: ComponentId, components: &mut ComponentsRegistrator<'_>, required_components: &mut RequiredComponents, inheritance_depth: u16, recursion_check_stack: &mut Vec<ComponentId>, )

Registers required components.
Source§

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§

fn register_component_hooks(hooks: &mut ComponentHooks)

👎Deprecated since 0.16.0: Use the individual hook methods instead (e.g., Component::on_add, etc.)
Called when registering this component, allowing mutable access to its ComponentHooks.
Source§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add ComponentHook for this Component if one is defined.
Source§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert ComponentHook for this Component if one is defined.
Source§

fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_replace ComponentHook for this Component if one is defined.
Source§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove ComponentHook for this Component if one is defined.
Source§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn ComponentHook for this Component if one is defined.
Source§

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given EntityMapper. This is used to remap entities in contexts like scenes and entity cloning. When deriving Component, this is populated by annotating fields containing entities with #[entities] 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<'de> Deserialize<'de> for Body

Available on crate feature save only.
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 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl Serialize for Body

Available on crate feature save only.
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 Transactional for Body

Source§

type Transaction = BodyTransaction

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

fn transact<'c, F, O>( &mut self, f: F, ) -> Result<O, ExecuteError<Self::Transaction>>
where F: FnOnce(&mut Self::Transaction, &Self) -> Result<O, <Self::Transaction as Merge>::Conflict>, Self::Transaction: Transaction<Target = Self, Context<'c> = (), Output = NoOutput> + Default,

Convenience method for building and then applying a transaction to self, equivalent to the following steps: Read more
Source§

impl StructuralPartialEq for Body

Auto Trait Implementations§

§

impl Freeze for Body

§

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<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut ComponentsRegistrator<'_>, ids: &mut impl FnMut(ComponentId), )

Source§

fn register_required_components( components: &mut ComponentsRegistrator<'_>, required_components: &mut RequiredComponents, )

Registers components that are required by the components in this Bundle.
Source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Gets this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<C> BundleFromComponents for C
where C: Component,

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<C> DynamicBundle for C
where C: Component,

Source§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
Source§

fn get_components( self, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

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.

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
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,

Source§

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>,

Source§

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>,

Source§

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

impl<T> ConditionalSend for T
where T: Send,

Source§

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