Skip to main content

BoxCollider

Struct BoxCollider 

Source
pub struct BoxCollider {
    pub centre: DVec3,
    pub half_extents: DVec3,
    pub rotation: DQuat,
}
Expand description

A box collider: a centre, half extents along the box’s own axes, and how those axes are turned from the world’s.

BoxCollider::new makes an unturned box, whose axes are the world’s, and BoxCollider::with_rotation turns one. The query world answers rays, sweeps and overlaps against the turned box itself, not the world-axis box around it — see crate::query::ray_vs_box and its siblings — and its broadphase holds that world-axis box, aabb.

Fields§

§centre: DVec3

Centre in local simulation space.

§half_extents: DVec3

Half-width along each of the box’s own axes, in metres.

§rotation: DQuat

How the box’s axes are turned from the world’s: a unit quaternion, DQuat::IDENTITY for a box whose axes are the world’s.

Implementations§

Source§

impl BoxCollider

Source

pub fn new(centre: DVec3, half_extents: DVec3) -> Self

Create an unturned box collider: its axes are the world’s.

§Panics

Panics in debug builds if any half-extent is negative.

Examples found in repository?
examples/filtered_ray_volley.rs (line 64)
49fn volley_world() -> PhysicsWorld {
50    let mut world = PhysicsWorld::new();
51    for n in 0..CHARACTER_COUNT {
52        let id = world.add_capsule(Capsule::new(crowd_point(1, n, 0.9), 0.3, 0.6));
53        world.set_layers(id, CHARACTERS);
54    }
55    for n in 0..RAGDOLL_COUNT {
56        let body = crowd_point(2, n, 0.2);
57        for part in 0..PARTS_PER_RAGDOLL {
58            let offset = DVec3::new(part as f64 * 0.15, 0.0, (part % 3) as f64 * 0.2);
59            let id = world.add_capsule(Capsule::new(body + offset, 0.08, 0.15));
60            world.set_layers(id, RAGDOLLS);
61        }
62    }
63    for n in 0..ITEM_COUNT {
64        let id = world.add_box(BoxCollider::new(crowd_point(3, n, 0.1), DVec3::splat(0.15)));
65        world.set_layers(id, ITEMS);
66    }
67    for n in 0..WALL_COUNT {
68        let angle = n as f64 / WALL_COUNT as f64 * std::f64::consts::TAU;
69        let centre = DVec3::new(cos(angle), 0.0, sin(angle)) * WALL_RING + DVec3::Y * 3.0;
70        let id = world.add_box(BoxCollider::new(centre, DVec3::new(6.0, 3.0, 6.0)));
71        world.set_layers(id, LEVEL);
72    }
73    world.rebuild();
74    world
75}
Source

pub const fn with_rotation(self, rotation: DQuat) -> Self

This box turned by rotation about its centre, which must be a unit quaternion.

Source

pub fn aabb(&self) -> Aabb

The smallest world-axis box holding this one: the box itself for an unturned collider, and for a turned one its half extents projected onto each world axis (the absolute rotation matrix times the extents, Ericson, Real-Time Collision Detection §4.2.6).

Exactly centre ± half_extents when unturned, an infinite extent included, which the projection would turn into 0 · ∞ = NaN.

Source

pub fn is_turned(&self) -> bool

Whether the box’s axes are not the world’s. An unturned box is answered by the world-axis queries directly, so its answers are the ones it had before boxes could turn, to the bit.

Trait Implementations§

Source§

impl Clone for BoxCollider

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for BoxCollider

Source§

impl Debug for BoxCollider

Source§

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

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

impl PartialEq for BoxCollider

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BoxCollider

Auto Trait Implementations§

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§

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<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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.