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: DVec3Centre in local simulation space.
half_extents: DVec3Half-width along each of the box’s own axes, in metres.
rotation: DQuatHow 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
impl BoxCollider
Sourcepub fn new(centre: DVec3, half_extents: DVec3) -> Self
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?
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}Sourcepub const fn with_rotation(self, rotation: DQuat) -> Self
pub const fn with_rotation(self, rotation: DQuat) -> Self
This box turned by rotation about its centre, which must be a unit
quaternion.
Sourcepub fn aabb(&self) -> Aabb
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.