Skip to main content

BodyDesc

Struct BodyDesc 

Source
#[non_exhaustive]
pub struct BodyDesc { pub shape: Shape, pub motion: MotionType, pub mass: f32, pub position: Vec3, pub orientation: Quat, pub linear_velocity: Vec3, pub angular_velocity: Vec3, pub friction: f32, pub restitution: f32, pub linear_damping: f32, pub gravity_scale: f32, pub angular_damping: f32, }
Expand description

Construction parameters for a Body. Body 的构造参数。

Mass is the input and the inertia tensor is derived from the Shape, so the two can never disagree. See docs/physics-spec.md §3. 输入的是质量,惯量张量由 Shape 推导,因此二者永不可能不一致。见 docs/physics-spec.md §3。

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.
§shape: Shape

The Body’s collision shape. Body 的碰撞形状。

§motion: MotionType

How the Body’s motion is produced. Body 的运动如何产生。

§mass: f32

Mass in kilograms. Ignored when motion is not MotionType::Dynamic. 质量(千克)。当 motion 不是 MotionType::Dynamic 时忽略。

§position: Vec3

Initial position. 初始位置。

§orientation: Quat

Initial orientation. Normalized on insertion. 初始朝向。插入时会被归一化。

§linear_velocity: Vec3

Initial linear velocity. 初始线速度。

§angular_velocity: Vec3

Initial angular velocity. 初始角速度。

§friction: f32

Coulomb friction coefficient. 库仑摩擦系数。

§restitution: f32

Bounciness, from 0 (no bounce) upward. 弹性,0 表示不反弹。

§linear_damping: f32

Velocity decay per second applied to linear motion. 每秒施加于线运动的衰减。

§gravity_scale: f32

How much of the World’s gravity reaches this Body. See BodyDesc::with_gravity_scale. World 的重力有多少作用于此 Body。见 BodyDesc::with_gravity_scale。

§angular_damping: f32

Velocity decay per second applied to angular motion. 每秒施加于角运动的衰减。

Implementations§

Source§

impl BodyDesc

Source

pub fn new(shape: Shape, motion: MotionType) -> Self

A Body in the given motion mode, with the given shape. 给定运动模式与形状的 Body。

Source

pub fn dynamic(shape: Shape, mass: f32) -> Self

A Dynamic Body of the given shape and mass. A non-positive or non-finite mass yields a Body nothing can accelerate. 给定形状与质量的 Dynamic Body。非正或非有限的质量得到无法被加速的 Body。

Source

pub fn stationary(shape: Shape) -> Self

A Static Body: it never moves. Static Body:永不移动。

Source

pub fn kinematic(shape: Shape) -> Self

A Kinematic Body, moved by whatever velocity the app sets on it. Kinematic Body,由应用设定的速度驱动。

Source

pub fn with_mass(self, mass: f32) -> Self

Set the mass. 设置质量。

Source

pub fn at(self, position: Vec3) -> Self

Set the initial position. 设置初始位置。

Source

pub fn oriented(self, orientation: Quat) -> Self

Set the initial orientation. 设置初始朝向。

Source

pub fn with_velocity(self, velocity: Vec3) -> Self

Set the initial linear velocity. 设置初始线速度。

Source

pub fn with_angular_velocity(self, angular_velocity: Vec3) -> Self

Set the initial angular velocity. 设置初始角速度。

Source

pub fn with_friction(self, friction: f32) -> Self

Set the friction coefficient. 设置摩擦系数。

Source

pub fn with_restitution(self, restitution: f32) -> Self

Set the restitution. 设置弹性。

Source

pub fn with_gravity_scale(self, scale: f32) -> Self

Scale the World’s gravity for this Body. 按比例缩放作用于此 Body 的 World 重力。

0.0 means gravity never touches it, which is what a caller wants when something else already owns the Body’s motion — a flight model, or anything kinematic-in-spirit that still needs contacts and friction. 1.0 is the default and 2.0 falls twice as fast. 0.0 表示重力永不作用于它,这正是当别的东西已经拥有该 Body 的运动时想要的——例如 飞行模型,或任何在精神上近似运动学、却仍需要接触与摩擦的东西。默认为 1.0,2.0 则以两倍速度下坠。

Negative or non-finite values are clamped to zero. 负值或非有限值被钳制为零。

Source

pub fn with_damping(self, linear: f32, angular: f32) -> Self

Damping applied to linear and angular velocity. 施加于线速度与角速度的阻尼。

Trait Implementations§

Source§

impl Clone for BodyDesc

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 BodyDesc

Source§

impl Debug for BodyDesc

Source§

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

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

impl PartialEq for BodyDesc

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 BodyDesc

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.