This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm (Experimental)
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine::BodyRigid Class

Header: #include <UniginePhysics.h>
Inherits: Body

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

BodyRigid Class

Members


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.

void setAngularDamping ( 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.

float getAngularDamping ( ) const#

Returns the angular damping of the body.

Return value

Angular damping.

void setAngularScale ( 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::vec3 getAngularScale ( ) const#

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.

void setAngularVelocity ( 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::vec3 getAngularVelocity ( ) const#

Returns the current angular velocity of the body.

Return value

Angular velocity in radians per second.

void setCenterOfMass ( 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::vec3 getCenterOfMass ( ) const#

Returns coordinates of the center of mass of the body.

Return value

Coordinates of the center of mass.

void setFreezable ( bool 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

  • bool freezable - Positive number to "freeze" the body when necessary; 0 for its physical state to be always updated.

bool isFreezable ( ) const#

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.

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 velocity - "Freeze" angular velocity. If the value is lower than the setFrozenAngularVelocity of the Physics class, it is overridden.

float getFrozenAngularVelocity ( ) const#

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.

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 velocity - "Freeze" linear velocity. If the value is lower than the setFrozenLinearVelocity of the Physics class, it is overridden.

float getFrozenLinearVelocity ( ) const#

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 ( ) const#

Returns the inverse mass of the body.

Return value

Inverse mass of the body.

void setInertia ( 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::mat3 getInertia ( ) const#

Returns the inertia tensor of the body.

Return value

Inertia tensor.

Math::mat3 getIWorldInertia ( ) const#

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

Return value

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

void setLinearDamping ( 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.

float getLinearDamping ( ) const#

Returns the linear damping of the body.

Return value

Linear damping.

void setLinearScale ( 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::vec3 getLinearScale ( ) const#

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.

void setLinearVelocity ( 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::vec3 getLinearVelocity ( ) const#

Returns the current linear velocity of the body.

Return value

Linear velocity in units per second.

void setMass ( 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.

float getMass ( ) const#

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.

void setMaxAngularVelocity ( float velocity ) #

Sets a maximum angular velocity of the body.
Notice
This method sets the maximum angular velocity only when the updatePhysics() for the BodyRigid is called.

Arguments

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

float getMaxAngularVelocity ( ) const#

Returns the maximum angular velocity of the body.

Return value

Maximum angular velocity, per second.

void setMaxLinearVelocity ( float velocity ) #

Sets a maximum linear velocity of the body.
Notice
This method sets the maximum linear velocity only when the updatePhysics() for the BodyRigid is called.

Arguments

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

float getMaxLinearVelocity ( ) const#

Returns the maximum linear velocity of the body.

Return value

Maximum linear velocity in units per second.

void setShapeBased ( bool based ) #

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

Arguments

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

bool isShapeBased ( ) const#

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.

Math::vec3 getVelocity ( const Math::vec3 & radius ) const#

Returns the total linear velocity of the point determined by a given radius vector, specified in the 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::Vec3 getWorldCenterOfMass ( ) const#

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

Return value

World coordinates of the body's center of mass.

Math::vec3 getWorldVelocity ( const Math::Vec3 & point ) const#

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.

void addForce ( const Math::vec3 & force ) #

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 updatePhysics() function in the world script. Do not apply forces in the update() function, because you will get unstable result that varies each rendering frame.
  • 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 force will be applied, check if a body is not frozen by isFrozen() and unfreeze it by setFrozen(0) if needed.

Arguments

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

void addForce ( const Math::vec3 & radius, const Math::vec3 & force ) #

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 updatePhysics() function in the world script. Do not apply forces in the update() function, because you will get unstable result that varies each rendering frame.
  • 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 force will be applied, check if a body is not frozen by isFrozen() and unfreeze it by setFrozen(0) if needed.

Arguments

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

void addImpulse ( const Math::vec3 & radius, const Math::vec3 & impulse ) #

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 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 setFrozen(0) if needed.

Arguments

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

void addLinearImpulse ( const Math::vec3 & impulse ) #

Applies an impulse similar to the addImpulse() method, but affects only the linear velocity.

Notice
If a body is frozen, it can't be immediately unfrozen. If the object's velocities are above minimum, it needs the 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 setFrozen(0) if needed.

Arguments

  • const Math::vec3 & impulse - Impulse to be applied, in world coordinates.

void addAngularImpulse ( const Math::vec3 & impulse ) #

Applies an impulse similar to the addImpulse() method, but affects only the angular velocity.

Notice
If a body is frozen, it can't be immediately unfrozen. If the object's velocities are above minimum, it needs the 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 setFrozen(0) if needed.

Arguments

  • const Math::vec3 & impulse - Impulse to be applied, in world coordinates.

void addTorque ( const Math::vec3 & torque ) #

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 updatePhysics() 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 world coordinates.

void addTorque ( const Math::vec3 & radius, const Math::vec3 & torque ) #

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 updatePhysics() function in the world script. Do not apply torques in the update() function, because you will get unstable result that varies each rendering frame.
  • 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 force will be applied, check if a body is not frozen by isFrozen() and unfreeze it by setFrozen(0) if needed.

Arguments

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

void addWorldForce ( 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 updatePhysics() function in the world script. Do not apply forces in the update() function, because you will get unstable result that varies each rendering frame.
  • 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 force will be applied, check if a body is not frozen by isFrozen() and unfreeze it by setFrozen(0) if needed.

Arguments

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

void addWorldImpulse ( 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 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 setFrozen(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.

void addWorldTorque ( 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 updatePhysics() function in the world script. Do not apply torques in the update() function, because you will get unstable result that varies each rendering frame.
  • 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 force will be applied, check if a body is not frozen by isFrozen() and unfreeze it by setFrozen(0) if needed.

Arguments

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

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 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.

void setHighPriorityContacts ( bool contacts ) #

Sets a value indicating if the body has the priority of handling detected contacts it participates in. A contact can be handled by any of the bodies that participate in it. To which body a contact is assigned is random. If the contact is assigned to and handled by the body it is called an internal one, otherwise it is called external (handled by another body). Iterating through internal contacts is much faster than through external ones, so this method can be used if you want a certain body to handle most of the contacts it participates in (i.e., have them as internal) to gain some performance.
Notice
A contact between two bodies with high priority shall be handled by one of them determined at random.

Arguments

  • bool contacts - true to set high priority of handling detected contacts for the body; otherwise false.

bool isHighPriorityContacts ( ) const#

Returns a value indicating if the body has the priority of handling detected contacts it participates in. A contact can be handled by any of the bodies that participate in it. To which body a contact is assigned is random. If the contact is assigned to and handled by the body it is called an internal one, otherwise it is called external (handled by another body). Iterating through internal contacts is much faster than through external ones, so this method can be used if you want a certain body to handle most of the contacts it participates in (i.e., have them as internal) to gain some performance.
Notice
A contact between two bodies with high priority shall be handled by one of them determined at random.

Return value

true if the body has the priority of handling detected contacts it participates in; otherwise false.
Last update: 2021-02-17
Build: ()