import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

The mass properties of a rigid-body is composed of three parts:
- The **mass** which determines the resistance of the rigid-body wrt. linear movements. A high mass implies that
  larger forces are needed to make the rigid-body translate.
- The **angular inertia** determines the resistance of the rigid-body wrt. the angular movements. A high angular
  inertia implies that larger torques are needed to make the rigid-body rotate.
- The **center-of-mass** determines relative to what points torques are applied to the rigid-body.

:::note
Zero is a special value for masses and angular inertia. A mass equal to zero is interpreted as an infinite mass.
An angular inertia equal to zero is interpreted as an infinite angular inertia. Therefore, a rigid-body with a
mass equal to zero will not be affected by any force, and a rigid-body with an angular inertia equal to zero will
not be affected by any torque.
:::

Computing the mass and angular-inertia can often be difficult because they depend on the geometric shape of the
object being simulated. This is why they are automatically computed by Rapier when a [collider](./colliders.mdx#mass-properties) is
attached to the rigid-body: the collider add its own mass and angular-inertia contribution (computed based on the
collider's shape and density) to the rigid-body it is attached to:

<rapier>

```rust
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Mass1' />
```

</rapier>

<bevy>

```rust
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Mass1' />
```

</bevy>
<js>

```js
<load path='/2d/javascript/src/snippets/rigid_bodies.ts' marker='Mass1' />
```

</js>

Alternatively, it is possible to set the mass properties of a rigid-body when it is created. Keep in mind that
this won't prevent the colliders' contributions to be added to these values. So make sure to set the attached
colliders' densities to zero if you want your explicit values to be the final mass-properties values.

<rapier>

<Tabs
groupId="dim"
defaultValue="2D"
values={[
{label: 'Example 2D', value: '2D'},
{label: 'Example 3D', value: '3D'},
]}>
<TabItem value="2D">

```rust
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Mass2' />
```
```rust
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Mass3' />
```

  </TabItem>
  <TabItem value="3D">

```rust
<load path='/3d/rust/examples/rs_rigid_bodies3.rs' marker='Mass2' />
```
```rust
<load path='/3d/rust/examples/rs_rigid_bodies3.rs' marker='Mass3' />
```

  </TabItem>
</Tabs>

</rapier>
<bevy>

```rust
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Mass2' />
```
```rust
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Mass3' />
```

</bevy>
<js>

<Tabs
groupId="dim"
defaultValue="2D"
values={[
{label: 'Example 2D', value: '2D'},
{label: 'Example 3D', value: '3D'},
]}>
<TabItem value="2D">

```js
<load path='/2d/javascript/src/snippets/rigid_bodies.ts' marker='Mass2' />
```

  </TabItem>
  <TabItem value="3D">

```js
<load path='/3d/javascript/src/snippets/rigid_bodies.ts' marker='Mass2' />
```

  </TabItem>
</Tabs>

</js>
