Skip to main content

Shape

Enum Shape 

Source
#[non_exhaustive]
pub enum Shape { Box { half_extents: Vec3, }, Sphere { radius: f32, }, }
Expand description

A convex collision shape. 凸碰撞形状。

Cylinder, cone, and convex hull are planned but not implemented yet; see docs/physics-spec.md §4. 圆柱、圆锥与凸包已规划但尚未实现;见 docs/physics-spec.md §4。

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Box

An axis-aligned box described by its half extents. 由半长描述的轴对齐盒。

Fields

§half_extents: Vec3

Half the box’s size on each local axis. 盒在局部各轴上尺寸的一半。

§

Sphere

A sphere described by its radius. 由半径描述的球。

Fields

§radius: f32

The sphere’s radius. 球的半径。

Implementations§

Source§

impl Shape

Source

pub fn cuboid(half_extents: Vec3) -> Self

An axis-aligned box with the given half extents. 给定半长的轴对齐盒。

Half extents are clamped to be non-negative, so a negative input yields a degenerate (zero-volume) box rather than an inverted one. 半长被钳制为非负,因此负输入得到退化的(零体积)盒,而不是内外翻转的盒。

Source

pub fn sphere(radius: f32) -> Self

A sphere with the given radius, clamped to be non-negative. 给定半径的球;半径被钳制为非负。

Source

pub fn volume(&self) -> f32

The shape’s volume, used to sanity-check mass input. 形状的体积,用于校验质量输入。

Source

pub fn local_inertia(&self, mass: f32) -> Vec3

The local inertia tensor’s diagonal for a given total mass. 给定总质量时,局部惯量张量的对角元。

Source

pub fn mass_properties(&self, mass: f32) -> MassProperties

Inverse mass properties for a given total mass. 给定总质量时的逆质量属性。

A non-finite or non-positive mass yields MassProperties::IMMOVABLE. A component of the inertia tensor that is zero (a degenerate shape) yields a zero inverse on that axis, so the Body simply never resists that rotation instead of producing inf. 非有限或非正的 mass 返回 MassProperties::IMMOVABLE。惯量张量的某个分量为零 (退化形状)时,该轴的逆值为零,于是 Body 只是不抵抗该轴旋转,而不会产生 inf。

Source

pub fn aabb(&self, position: Vec3, orientation: Quat) -> Aabb

The world-space bounding box of this shape placed at position with orientation. 该形状以 position 与 orientation 摆放时的世界空间包围盒。

Trait Implementations§

Source§

impl Clone for Shape

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 Shape

Source§

impl Debug for Shape

Source§

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

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

impl PartialEq for Shape

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 Shape

Auto Trait Implementations§

§

impl Freeze for Shape

§

impl RefUnwindSafe for Shape

§

impl Send for Shape

§

impl Sync for Shape

§

impl Unpin for Shape

§

impl UnsafeUnpin for Shape

§

impl UnwindSafe for Shape

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.