b2BodyDef

Struct b2BodyDef 

Source
#[repr(C)]
pub struct b2BodyDef {
Show 18 fields pub type_: b2BodyType, pub position: b2Vec2, pub rotation: b2Rot, pub linearVelocity: b2Vec2, pub angularVelocity: f32, pub linearDamping: f32, pub angularDamping: f32, pub gravityScale: f32, pub sleepThreshold: f32, pub name: *const c_char, pub userData: *mut c_void, pub motionLocks: b2MotionLocks, pub enableSleep: bool, pub isAwake: bool, pub isBullet: bool, pub isEnabled: bool, pub allowFastRotation: bool, pub internalValue: c_int,
}
Expand description

A body definition holds all the data needed to construct a rigid body. You can safely re-use body definitions. Shapes are added to a body after construction. Body definitions are temporary objects used to bundle creation parameters. Must be initialized using b2DefaultBodyDef(). @ingroup body

Fields§

§type_: b2BodyType

The body type: static, kinematic, or dynamic.

§position: b2Vec2

The initial world position of the body. Bodies should be created with the desired position. @note Creating bodies at the origin and then moving them nearly doubles the cost of body creation, especially if the body is moved after shapes have been added.

§rotation: b2Rot

The initial world rotation of the body. Use b2MakeRot() if you have an angle.

§linearVelocity: b2Vec2

The initial linear velocity of the body’s origin. Usually in meters per second.

§angularVelocity: f32

The initial angular velocity of the body. Radians per second.

§linearDamping: f32

Linear damping is used to reduce the linear velocity. The damping parameter can be larger than 1 but the damping effect becomes sensitive to the time step when the damping parameter is large. Generally linear damping is undesirable because it makes objects move slowly as if they are floating.

§angularDamping: f32

Angular damping is used to reduce the angular velocity. The damping parameter can be larger than 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is large. Angular damping can be use slow down rotating bodies.

§gravityScale: f32

Scale the gravity applied to this body. Non-dimensional.

§sleepThreshold: f32

Sleep speed threshold, default is 0.05 meters per second

§name: *const c_char

Optional body name for debugging. Up to 31 characters (excluding null termination)

§userData: *mut c_void

Use this to store application specific body data.

§motionLocks: b2MotionLocks

Motions locks to restrict linear and angular movement. Caution: may lead to softer constraints along the locked direction

§enableSleep: bool

Set this flag to false if this body should never fall asleep.

§isAwake: bool

Is this body initially awake or sleeping?

§isBullet: bool

Treat this body as a high speed object that performs continuous collision detection against dynamic and kinematic bodies, but not other bullet bodies. @warning Bullets should be used sparingly. They are not a solution for general dynamic-versus-dynamic continuous collision. They do not guarantee accurate collision if both bodies are fast moving because the bullet does a continuous check after all non-bullet bodies have moved. You could get unlucky and have the bullet body end a time step very close to a non-bullet body and the non-bullet body then moves over the bullet body. In continuous collision, initial overlap is ignored to avoid freezing bodies in place. I do not recommend using them for game projectiles if precise collision timing is needed. Instead consider using a ray or shape cast. You can use a marching ray or shape cast for projectile that moves over time. If you want a fast moving projectile to collide with a fast moving target, you need to consider the relative movement in your ray or shape cast. This is out of the scope of Box2D. So what are good use cases for bullets? Pinball games or games with dynamic containers that hold other objects. It should be a use case where it doesn’t break the game if there is a collision missed, but the having them captured improves the quality of the game.

§isEnabled: bool

Used to disable a body. A disabled body does not move or collide.

§allowFastRotation: bool

This allows this body to bypass rotational speed limits. Should only be used for circular objects, like wheels.

§internalValue: c_int

Used internally to detect a valid definition. DO NOT SET.

Trait Implementations§

Source§

impl Clone for b2BodyDef

Source§

fn clone(&self) -> b2BodyDef

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for b2BodyDef

Source§

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

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

impl Copy for b2BodyDef

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.