# BodyRigid Class

This class is used to simulate rigid bodies that move according to the rigid bodies dynamics.

## BodyRigid Class

This class inherits from Body### Members

## BodyRigid ()

Constructor. Creates a rigid body with default properties.## BodyRigid (Object object)

Constructor. Creates a rigid body with default properties for a given object.### Arguments

*Object*- Object approximated with the new rigid body.**object**

## void addForce (vec3 radius, vec3 force)

Applies a force to the radius vector of the body, specified in the local coordinates. This function calculates the cross product of the radius vector and the force vector. It acts like a lever arm that changes both linear and angular velocities of the body.

Unlike impulses, all forces are accumulated first, then the resulting force is calculated and applied to the body (during the physics simulation stage, when the body *update()* function is called).

### Arguments

*vec3*- Radius vector, traced from the center of mass of the body to the point where the force is applied, in local coordinates.**radius***vec3*- The value of the applied force, in local coordinates.**force**

## void addForce (vec3 force)

Applies a force to the body's center of mass, specified in the local coordinates.

Unlike impulses, all forces are accumulated first, then the resulting force is calculated and applied to the body (during the physics simulation stage, when the body *update()* function is called).

### Arguments

*vec3*- Force to apply, in local coordinates.**force**

## void addImpulse (vec3 radius, vec3 impulse)

Applies an impulse to the radius vector of the body, specified in the local coordinates.

Unlike forces, impulses immediately affect both linear and angular velocities of the body.

### Arguments

*vec3*- Radius vector, traced from the center of mass to the point where the impulse is applied, in local coordinates.**radius***vec3*- Impulse to apply, in local coordinates.**impulse**

## void addTorque (vec3 radius, vec3 torque)

Applies a torque to the radius vector of the body, specified in the local coordinates.

This function calculates the cross product of the radius vector and the force vector.

It acts like a lever arm that changes both angular and linear velocities of the body.

All torque values are accumulated first, then the resulting torque is calculated and applied to the body (during the physics simulation stage, when the body update is called).

### Arguments

*vec3*- Radius vector starting in the body's center of mass, in local coordinates. Its end is the point of torque application.**radius***vec3*- Torque to apply.**torque**

## void addTorque (vec3 torque)

Applies a torque to the body's center of mass, in local coordinates.

All torque values are accumulated first, then the resulting torque is calculated and applied to the body (during the physics simulation stage, when the body *update()* function is called).

### Arguments

*vec3*- Torque to apply, in local coordinates.**torque**

## void addWorldForce (vec3 point, vec3 force)

Applies a force to the given point of the body that is specified in world coordinates. This function calculates the cross product of the radius vector (a vector from the center of mass to the point where force is applied) and the force vector (the magnitude of the force). It acts like a lever arm that changes both linear and angular velocities of the body.

Unlike impulses, all forces are accumulated first, then the resulting force is calculated and applied to the body (during the physics simulation stage, when the body update is called).

### Arguments

*vec3*- Point of the body, in world coordinates.**point***vec3*- Force to apply.**force**

## void addWorldImpulse (vec3 point, vec3 impulse)

Applies an impulse to the given point of the body, that is specified in world coordinates. Unlike forces, impulses immediately affect both linear and angular velocities of the body.### Arguments

*vec3*- Point of the body, in world coordinates.**point***vec3*- Impulse to apply.**impulse**

## void addWorldTorque (vec3 point, vec3 torque)

Applies a torque to the given point of the body, that is specified in world coordinates. This function calculates the cross product of the radius vector (a vector from the center of mass to the point where torque is applied) and the force vector (the magnitude of the torque). It acts like a lever arm that changes both angular and linear velocities of the body.

All torque values are accumulated first, then the resulting torque is calculated and applied to the body (during the physics simulation stage, when the body update is called).

### Arguments

*vec3*- Point of the body, in world coordinates.**point***vec3*- Torque to apply.**torque**

## int createShapes (int depth = 4, float error = 0.01, float threshold = 0.01)

Removes all previously created shapes and creates one or more convex shapes approximating the mesh.### Arguments

*int*- Degree of decomposition of the mesh. If**depth****0**or a negative value is provided, only one shape will be created. If a positive**n**is provided, the mesh will be decomposed**n**times. This is an optional parameter.*float*- Approximation error, which is used to create convex hulls. This is an optional parameter.**error***float*- Threshold, which is used to decide, whether two adjoining convex shapes can be replaced with one larger shape. A pair of shapes is replaced with a larger shape, if their volumes are roughly the same. This value is clamped in the range**threshold****[1 E-6; 1]**. This is an optional parameter.

### Return value

**1**if the convex shapes are created successfully; otherwise

**0**.

## float getAngularDamping ()

Returns the angular damping of the body.### Return value

Angular damping.## vec3 getAngularScale ()

Returns a multiplier for the body's angular velocity per axis. If one of vec3 values is set to**0**, movement along this axis will be restricted. For example, for 2D physics with movement restricted to a X axis, set the body's angular scale to (1,0,0).

### Return value

Angular scale per axis.## vec3 getAngularVelocity ()

Returns the current angular velocity of the body.### Return value

Angular velocity in radians per second.## vec3 getCenterOfMass ()

Returns coordinates of the center of mass of the body.### Return value

Coordinates of the center of mass.## float getFrozenAngularVelocity ()

Returns the current angular velocity threshold for freezing body simulation. If body angular velocity remains lower than this threshold during the number of Frozen frames (together with linear one), it stops to be updated.### Return value

"Freeze" angular velocity.## float getFrozenLinearVelocity ()

Returns the current linear velocity threshold for freezing body simulation. If body linear velocity remains lower than this threshold during the number of Frozen frames (together with angular one), it stops to be updated.### Return value

"Freeze" linear velocity.## float getIMass ()

Returns the inverse mass of the body.### Return value

Inverse mass of the body.## float getLinearDamping ()

Returns the linear damping of the body.### Return value

Linear damping.## vec3 getLinearScale ()

Returns a multiplier for the body's linear velocity per axis. If one of vec3 values is set to**0**, movement along this axis will be restricted. For example, for 2D physics with movement restricted to a X axis, set the body's linear scale to (0,1,1).

### Return value

Linear scale per axis.## vec3 getLinearVelocity ()

Returns the current linear velocity of the body.### Return value

Linear velocity in units per second.## float getMass ()

Returns the body mass.*g*(Earth's gravity) equals to 9.8 m/s

^{2}, and 1 unit equals to 1 m, the mass is measured in kilograms.

### Return value

Mass of the body.## float getMaxAngularVelocity ()

Returns the maximum angular velocity of the body.### Return value

Maximum angular velocity in per second.## float getMaxLinearVelocity ()

Returns the maximum linear velocity of the body.### Return value

Maximum linear velocity in units per second.## vec3 getVelocity (vec3 radius)

Returns the total linear velocity of the point specified in local coordinates.### Arguments

*vec3*- Radius vector starting in the body's center of mass.**radius**

### Return value

Total linear velocity in the given point of the body.## vec3 getWorldCenterOfMass ()

Returns world coordinates of the center of mass of the body.### Return value

World coordinates of the body's center of mass.## vec3 getWorldVelocity (vec3 point)

Returns the total linear velocity of the point specified in world coordinates.### Arguments

*vec3*- Point of the body in world coordinates.**point**

### Return value

Total linear velocity in the given point.## int isFreezable ()

Returns a value indicating if the object is not simulated if both its linear and angular velocities are below "freeze" ones (see setFrozenLinearVelocity and setFrozenAngularVelocity functions).### Return value

Positive number if the body "freezes" when necessary;**0**if its physical state is always updated.

## int isShapeBased ()

Returns a value indicating if mass and inertia of the body are bound to its shape properties or not.### Return value

Positive number if mass and inertia are calculated based on shape properties; otherwise,**0**.

## void setAngularDamping (float damping)

Sets an angular damping of the body.### Arguments

*float*- Angular damping. If a negative value is provided,**damping****0**will be used instead.

## void setAngularScale (vec3 scale)

Sets a multiplier for the body's angular velocity per axis. If one of vec3 values is set to**0**, movement along this axis will be restricted. For example, for 2D physics with movement restricted to a X axis, set the body's angular scale to (1,0,0).

### Arguments

*vec3*- Angular scale per axis, in world coordinates.**scale**

## void setAngularVelocity (vec3 velocity)

Sets an angular velocity of the body.### Arguments

*vec3*- Angular velocity in radians per second, in world coordinates.**velocity**

## void setCenterOfMass (vec3 center)

Sets coordinates of the center of mass of the body.### Arguments

*vec3*- Coordinates of the center of mass, in world coordinates.**center**

## void setFreezable (int frozenable)

Sets a value indicating if the body should not be simulated if both its linear and angular velocities are below "freeze" ones (see setFrozenLinearVelocity and setFrozenAngularVelocity functions).### Arguments

*int*- Positive number to "freeze" the body when necessary;**frozenable****0**for its physical state to be always updated.

## void setFrozenAngularVelocity (float velocity)

Sets angular velocity threshold for freezing body simulation. If body angular velocity remains lower than this threshold during the number of Frozen frames (together with linear one), it stops to be updated.### Arguments

*float*- "Freeze" angular velocity. If the value is lower than the engine.physics.setFrozenAngularVelocity one, it is overridden.**velocity**

## void setFrozenLinearVelocity (float velocity)

Sets linear velocity threshold for freezing body simulation. If body linear velocity remains lower than this threshold during the number of Frozen frames (together with angular one), it stops to be updated.### Arguments

*float*- "Freeze" linear velocity. If the value is lower than the engine.physics.setFrozenLinearVelocity one, it is overridden.**velocity**

## void setInertia (mat4 inertia)

Sets an inertia tensor of the body. The inertia tensor describes the distribution of the mass over the body relative to the body's center of mass.### Arguments

*mat4*- Inertia tensor. (In fact, here the engine will handle**inertia***mat4*as*mat3*.)

## void setLinearDamping (float damping)

Sets a linear damping of the body.### Arguments

*float*- Linear damping. If a negative value is provided,**damping****0**will be used instead.

## void setLinearScale (vec3 scale)

Sets a multiplier for the body's linear velocity per axis. If one of vec3 values is set to**0**, movement along this axis will be restricted. For example, for 2D physics with movement restricted to a X axis, set the body's linear scale to (0,1,1).

### Arguments

*vec3*- Linear scale per axis.**scale**

## void setLinearVelocity (vec3 velocity)

Sets a linear velocity of the body.### Arguments

*vec3*- Linear velocity in units per second, in world coordinates.**velocity**

## void setMass (float mass)

Sets a mass of the body.*g*(Earth's gravity) equals to 9.8 m/s

^{2}, and 1 unit equals to 1 m, the mass is measured in kilograms.

### Arguments

*float*- Mass of the body.**mass**

## void setMaxAngularVelocity (float velocity)

Sets a maximum angular velocity of the body.### Arguments

*float*- Maximum angular velocity in radians per second. If a negative value is provided,**velocity****0**will be used instead.

## void setMaxLinearVelocity (float velocity)

Sets a maximum linear velocity of the body.### Arguments

*float*- Maximum linear velocity in units per second. If a negative value is provided,**velocity****0**will be used instead.

## void setShapeBased (int mode)

Sets a value indicating if mass and inertia of the body are bound to its shape properties or not.### Arguments

*int*- Positive number to bind mass and inertia of the body to its shape properties,**mode****0**to allow arbitrary values.