# Unigine::BodyRigid Class

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

## static BodyRigidPtr create()

Constructor. Creates a rigid body with default properties.

## static BodyRigidPtr create(const Ptr<Object> & object)

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

### Arguments

• const Ptr<Object> & object - Object approximated with the new rigid body.

## Ptr<BodyRigid>cast(const Ptr<Body> & body)

### Arguments

• const Ptr<Body> & body

## voidsetAngularDamping(float damping)

Sets an angular damping of the body.

### Arguments

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

## floatgetAngularDamping()

Returns the angular damping of the body.

Angular damping.

## voidsetAngularScale(const Math::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

• const Math::vec3 & scale - Angular scale per axis, in world coordinates.

## Math::vec3getAngularScale()

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.

## voidsetAngularVelocity(const Math::vec3 & velocity)

Sets an angular velocity of the body.

### Arguments

• const Math::vec3 & velocity - Angular velocity in radians per second, in world coordinates.

## Math::vec3getAngularVelocity()

Returns the current angular velocity of the body.

### Return value

Angular velocity in radians per second.

## voidsetCenterOfMass(const Math::vec3 & center)

Sets coordinates of the center of mass of the body.

### Arguments

• const Math::vec3 & center - Coordinates of the center of mass, in world coordinates.

## Math::vec3getCenterOfMass()

Returns coordinates of the center of mass of the body.

### Return value

Coordinates of the center of mass.

## voidsetFreezable(int freezable)

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 freezable - Positive number to "freeze" the body when necessary; 0 for its physical state to be always updated.

## intisFreezable()

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.

## voidsetFrozenAngularVelocity(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.

## floatgetFrozenAngularVelocity()

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.

## voidsetFrozenLinearVelocity(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.

## floatgetFrozenLinearVelocity()

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.

## floatgetIMass()

Returns the inverse mass of the body.

### Return value

Inverse mass of the body.

## voidsetInertia(const Math::mat3 & 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

• const Math::mat3 & inertia - Inertia tensor.

## Math::mat3getInertia()

Returns the inertia tensor of the body.

### Return value

Inertia sensor of the body.

## Math::mat3getIWorldInertia()

Returns the inverse inertia tensor of the body, in the world coordinates.

### Return value

Inverse inertia tensor of the body, in the world coordinates.

## voidsetLinearDamping(float damping)

Sets a linear damping of the body.

### Arguments

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

## floatgetLinearDamping()

Returns the linear damping of the body.

Linear damping.

## voidsetLinearScale(const Math::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

• const Math::vec3 & scale - Linear scale per axis.

## Math::vec3getLinearScale()

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.

## voidsetLinearVelocity(const Math::vec3 & velocity)

Sets a linear velocity of the body.

### Arguments

• const Math::vec3 & velocity - Linear velocity in units per second, in world coordinates.

## Math::vec3getLinearVelocity()

Returns the current linear velocity of the body.

### Return value

Linear velocity in units per second.

## voidsetMass(float mass)

Sets a mass of the body.
Notice
If 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 - Mass of the body.

## floatgetMass()

Returns the body mass.
Notice
If 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.

## voidsetMaxAngularVelocity(float velocity)

Sets a maximum angular velocity of the body.

### Arguments

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

## floatgetMaxAngularVelocity()

Returns the maximum angular velocity of the body.

### Return value

Maximum angular velocity, per second.

## voidsetMaxLinearVelocity(float velocity)

Sets a maximum linear velocity of the body.

### Arguments

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

## floatgetMaxLinearVelocity()

Returns the maximum linear velocity of the body.

### Return value

Maximum linear velocity in units per second.

## voidsetShapeBased(int based)

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

### Arguments

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

## intisShapeBased()

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.

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

### Arguments

• const Math::vec3 & radius - Radius vector starting in the body's center of mass.

### Return value

Total linear velocity in the given point of the body.

## Math::Vec3getWorldCenterOfMass()

Returns world coordinates of the center of mass of the body.

### Return value

World coordinates of the body's center of mass.

## Math::vec3getWorldVelocity(const Math::Vec3 & point)

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

### Arguments

• const Math::Vec3 & point - Point of the body in world coordinates.

### Return value

Total linear velocity in the given point.

Applies a force to the center of mass 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).

Notice
You can call this function only from flush() function in the world script. Do not apply forces in the update() function, because you will get unstable result that varies each rendering frame.

### Arguments

• const Math::vec3 & force - Force to be applied, in local coordinates.

Applies a force to a point determined by a given radius vector, 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).

Notice
You can call this function only from flush() function in the world script. Do not apply forces in the update() function, because you will get unstable result that varies each rendering frame.

### Arguments

• const Math::vec3 & radius - Radius vector, traced from the center of mass of the body to the point where the force is applied, in local coordinates.
• const Math::vec3 & force - Force to be applied, in local coordinates.

Applies an impulse to a point determined by a given radius vector, specified in the local coordinates.

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

Notice
If a body is frozen, it can't be immediately unfrozen. If the object's velocities are above minimum, it needs the engine.physics.getNumFrozenFrames() flush frames to be specified to unfreeze. To make sure that impulse will be applied, check if a body is not frozen by isFrozen() and unfreeze it by setFrosen(0) if needed.

### Arguments

• const Math::vec3 & radius - Radius vector, traced from the center of mass to the point where the impulse is applied, in local coordinates.
• const Math::vec3 & impulse - Impulse to be applied, in local coordinates.

Applies a torque with a pivot point at the center of mass of the body, specified in the 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 is called).

Notice
You can call this function only from flush() function in the world script. Do not apply forces in the update() function, because you will get unstable result that varies each rendering frame.

### Arguments

• const Math::vec3 & torque - Torque to be applied, in local coordinates.

Applies a torque with a pivot point, determined by a given radius vector, 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).

Notice
You can call this function only from flush() function in the world script. Do not apply forces in the update() function, because you will get unstable result that varies each rendering frame.

### Arguments

• const Math::vec3 & radius - Radius vector starting at the body's center of mass, in local coordinates. Its end is the pivot point for the torque to be applied.
• const Math::vec3 & torque - Torque to be applied, in local coordinates.

## voidaddWorldForce(const Math::Vec3 & point, const Math::vec3 & force)

Applies a force to a 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. 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).

Notice
You can call this function only from within flush() in the world script. Do not apply forces in the update(); otherwise, you will get unstable result that varies each rendering frame.

### Arguments

• const Math::Vec3 & point - Point of the body, in world coordinates.
• const Math::vec3 & force - Force to be applied, in world coordinates.

## voidaddWorldImpulse(const Math::Vec3 & point, const Math::vec3 & impulse)

Applies an impulse to a given point of the body, that is specified in world coordinates. Unlike forces, impulses immediately affect both linear and angular velocities of the body.
Notice
If a body is frozen, it can't be immediately unfrozen. If the object's velocities are above minimum, it needs the engine.physics.getNumFrozenFrames() flush frames to be specified to unfreeze. To make sure that impulse will be applied, check if a body is not frozen by isFrozen() and unfreeze it by setFrosen(0) if needed.

### Arguments

• const Math::Vec3 & point - Point of the body, in world coordinates.
• const Math::vec3 & impulse - Impulse to be applied, in world coordinates.

## voidaddWorldTorque(const Math::Vec3 & point, const Math::vec3 & torque)

Applies a torque with a pivot point at a 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 pivot point) and the torque 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).

Notice
You can call this function only from within flush() in the world script. Do not apply torques in the update(); otherwise, you will get unstable result that varies each rendering frame.

### Arguments

• const Math::Vec3 & point - Point of the body, in world coordinates.
• const Math::vec3 & torque - Torque to be applied, in world coordinates.

## intcreateShapes(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 depth - Degree of decomposition of the mesh. If 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 error - Approximation error, which is used to create convex hulls. This is an optional parameter.
• float threshold - 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 [1 E-6; 1]. This is an optional parameter.

### Return value

1 if the convex shapes are created successfully; otherwise 0.
Last update: 2017-07-03