This page has been translated automatically.
Видеоуроки
Interface
Essentials
Advanced
Полезные советы
Программирование на C#
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Физика
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Настройки и предпочтения
Работа с проектами
Настройка параметров узла
Setting Up Materials
Setting Up Properties
Освещение
Landscape Tool
Sandworm (Experimental)
Использование инструментов редактора для конкретных задач
Extending Editor Functionality
Встроенные объекты
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
Программирование
Основы
Настройка среды разработки
Примеры использования
UnigineScript
C++
C#
Унифицированный язык шейдеров UUSL
File Formats
Rebuilding the Engine Tools
GUI
Двойная точность координат
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
Работа с контентом
Оптимизация контента
Материалы
Art Samples
Tutorials
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Unigine::Joint Class

Header: #include <UniginePhysics.h>

This class is used to simulate various types of joints and define common parameters shared by all joints.

See Also#

  • A C++ API sample located in the <UnigineSDK>/source/samples/Api/Physics/JointCallbacks folder
  • A C# API sample located in the <UnigineSDK>/source/csharp/samples/Api/Physics/JointCallbacks folder
  • A UnigineScript API sample <UnigineSDK>/data/samples/physics/callbacks_03

Joint Class

Enums

TYPE#

Type of the joint defining its properties.
NameDescription
JOINT_FIXED = 0Fixed joint.
JOINT_BALL = 1Ball joint.
JOINT_HINGE = 2Hinge joint.
JOINT_PRISMATIC = 3Prismatic joint.
JOINT_CYLINDRICAL = 4Cylindrical joint.
JOINT_SUSPENSION = 5Suspension joint.
JOINT_WHEEL = 6Wheel joint.
JOINT_PARTICLES = 7Particles joint.
JOINT_PATH = 8Path joint.
NUM_JOINTS = 9

Members


Ptr<Joint> createJoint ( int type ) #

Creates a new joint of the specified type.

Arguments

  • int type - Joint type. One of the JOINT_* values.

Return value

New created joint smart pointer.

Ptr<Joint> createJoint ( const char * type_name ) #

Creates a new joint of the specified type.

Arguments

  • const char * type_name - Joint type name.

Return value

New created joint smart pointer.

void setAnchor0 ( const Math::Vec3 & anchor ) #

Sets coordinates of the anchor point in a system of coordinates of the first connected body.

Arguments

  • const Math::Vec3 & anchor - Coordinates of the anchor point in the body coordinate space.

Math::Vec3 getAnchor0 ( ) const#

Returns the coordinates of the anchor point in a system of coordinates of the first connected body.

Return value

Coordinates of the anchor point in the body coordinate space.

void setAnchor1 ( const Math::Vec3 & anchor ) #

Sets coordinates of the anchor point in a system of coordinates of the second connected body.

Arguments

  • const Math::Vec3 & anchor - Coordinates of the anchor point in the body coordinate space.

Math::Vec3 getAnchor1 ( ) const#

Returns the coordinates of the anchor point in a system of coordinates of the second connected body.

Return value

Coordinates of the anchor point in the body coordinate space.

void setAngularRestitution ( float restitution ) #

Sets the current angular restitution (stiffness) of the joint. Angular restitution defines how fast the joint compensates for change of the angle between two bodies. When bodies are turned relative each other, restitution controls the magnitude of force which is applied to both bodies so that their anchor points to become aligned again. For example:
  • 1 means that the joint is to return bodies in place throughout 1 physics tick.
  • 0.2 means that the joint is to return bodies in place throughout 5 physics ticks.
The maximum value of 1 can lead to destabilization of physics (as too great forces are applied).

Arguments

  • float restitution - Angular restitution. The provided value will be clamped in the range [0;1].

float getAngularRestitution ( ) const#

Returns the current angular restitution (stiffness) of the joint. Angular restitution defines how fast the joint compensates for change of the angle between two bodies. When bodies are turned relative each other, restitution controls the magnitude of force which is applied to both bodies so that their anchor points to become aligned again. For example:
  • 1 means that the joint is to return bodies in place throughout 1 physics tick.
  • 0.2 means that the joint is to return bodies in place throughout 5 physics ticks.
The maximum value of 1 can lead to destabilization of physics (as too great forces are applied).

Return value

Angular restitution in the range [0;1].

void setAngularSoftness ( float softness ) #

Sets the angular softness (elasticity) of the joint. When the joint is twisted, angular softness defines whether angular velocities of the bodies are averaged out. For example:
  • 0 means that the joint is rigid. Angular velocities of the first and the second body are independent.
  • 1 means that the joint is elastic (jelly-like). If the first body changes its velocity, velocity of the second body is equalized with it.

Arguments

  • float softness - Angular softness. The provided value will be clamped in the range [0;1].

float getAngularSoftness ( ) const#

Returns the current angular softness (elasticity) of the joint. When the joint is twisted, angular softness defines whether angular velocities of the bodies are averaged out. For example:
  • 0 means that the joint is rigid. Angular velocities of the first and the second body are independent.
  • 1 means that the joint is elastic (jelly-like). If the first body changes its velocity, velocity of the second body is equalized with it.

Return value

Angular softness in the range [0;1].

void setNode0 ( const Ptr<Node> & node0 ) #

Sets the node possessing the first body to be connected to the joint.

Arguments

  • const Ptr<Node> & node0 - Node possessing the first body connected to the joint is assigned. The node must be an object and must have a body assigned.

Ptr<Node> getNode0 ( ) const#

Returns a node possessing the first body connected to the joint.

Return value

Node possessing the first body connected to the joint is assigned (if it exists).

void setNode1 ( const Ptr<Node> & node1 ) #

Sets the node possessing the second body to be connected to the joint.

Arguments

  • const Ptr<Node> & node1 - Node possessing the second body connected to the joint is assigned. The node must be an object and must have a body assigned.

Ptr<Node> getNode1 ( ) const#

Returns a node possessing the second body connected to the joint.

Return value

Node possessing the second body connected to the joint is assigned (if it exists).

void setBody0 ( const Ptr<Body> & body ) #

Sets the first body connected using the joint.

Arguments

  • const Ptr<Body> & body - The first body connected with the joint.

Ptr<Body> getBody0 ( ) const#

Returns the first body connected using the joint.

Return value

The first body connected with the joint.

void setBody1 ( const Ptr<Body> & body ) #

Sets the second body connected using the joint.

Arguments

  • const Ptr<Body> & body - The second body connected with the joint.

Ptr<Body> getBody1 ( ) const#

Returns the second body connected using the joint.

Return value

The second body connected with the joint.

Ptr<BodyRigid> getBodyRigid0 ( ) #

Returns the first connected body as a rigid body.

Return value

The first rigid body connected using the joint or NULL (0), if the body is not rigid.

Ptr<BodyRigid> getBodyRigid1 ( ) #

Returns the second connected body as a rigid body.

Return value

The second rigid body connected using the joint or NULL (0), if the body is not rigid.

void setBroken ( bool broken ) #

Sets a value indicating if the joint is broken or not.

Arguments

  • bool broken - Positive number to break the joint, 0 to make it intact.

bool isBroken ( ) const#

Returns a value indicating if the joint is broken or not.

Return value

Positive number if the joint is broken; otherwise, 0.

void * addBrokenCallback ( Unigine::CallbackBase1< Ptr<Joint> > * func ) #

Adds a callback function to be called when the joint breaks. The signature of the broken callback function must be as follows:
Source code (C++)
void broken_callback_function_name(JointPtr joint);

You can set a callback function as follows:

Source code (C++)
addBrokenCallback(MakeCallback(broken_callback_function_name));
Notice
Physics-based callbacks are executed in parallel with the main tread, so you should not modify nodes inside these functions. If you want to reposition, transform, create or delete nodes captured by your callback function, you can store them in the array and then perform all necessary operations in the update().

Example: Setting a joint broken callback function for a certain class:

Source code (C++)
class SomeClass {

	/*...*/
	
	// joint for which a broken callback function is to be set
	Unigine::JointPtr joint;
	
	/*...*/
};

/*...*/

// callback function
void SomeClass::on_broken(JointPtr joint)
{
	// insert your code handling joint breaking here
}

void SomeClass::registerCallback()
{
	// setting the on_broken() function to handle breaking for the joint
	joint->addBrokenCallback(MakeCallback(this, &SomeClass::on_broken));
}
Notice
Physics-based callbacks are not executed immediately, but before the next updatePhysics() or next update() of the world script.

Arguments

Return value

ID of the last added broken callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool removeBrokenCallback ( void * id ) #

Removes the specified callback from the list of broken callbacks.

Arguments

  • void * id - Broken callback ID obtained when adding it.

Return value

True if the broken callback with the given ID was removed successfully; otherwise false.

void clearBrokenCallbacks ( ) #

Clears all added broken callbacks.

void setCollision ( int c ) #

Sets a value indicating if collisions between the connected bodies are enabled.

Arguments

  • int c - Positive number to enable collisions between the bodies, 0 to disable them.

int getCollision ( ) const#

Returns a value indicating if collisions between the connected bodies are enabled.

Return value

Positive number if collisions between the bodies are enabled; otherwise, 0.

void setEnabled ( bool enable ) #

Enables or disables joint calculations.

Arguments

  • bool enable - Positive number to enable the joint, 0 to disable it.

bool isEnabled ( ) const#

Returns a value indicating if the joint calculations are enabled.

Return value

1 if the joint is enabled; otherwise, 0.

bool isEnabledSelf ( ) const#

Returns a value indicating is the joint is enabled.

Return value

1 if the joint is enabled; otherwise, 0.

void setFrozen ( bool f ) #

Freezes or unfreezes the joint.

Arguments

  • bool f - Positive number to freeze the joint, 0 to unfreeze it.

bool isFrozen ( ) const#

Returns a value indicating if the joint is frozen or not.

Return value

Positive number if the joint is frozen; otherwise, 0.

int setID ( int id ) #

Sets the unique ID for the joint.

Arguments

  • int id - Unique ID.

Return value

1 if the ID is set successfully; otherwise, 0.

int getID ( ) const#

Returns the unique ID of the joint.

Return value

Unique ID.

void setLinearRestitution ( float restitution ) #

Sets the linear restitution (stiffness) of the joint. Linear restitution defines how fast the joint compensates for linear coordinate change between two bodies. When bodies are dragged apart, restitution controls the magnitude of force which is applied to both bodies so that their anchor points to become aligned again. For example:
  • 1 means that the joint is to return bodies in place throughout 1 physics tick.
  • 0.2 means that the joint is to return bodies in place throughout 5 physics ticks.
The maximum value of 1 can lead to destabilization of physics (as too great forces are applied).

Arguments

  • float restitution - Linear restitution. The provided value will be clamped in the range [0;1].

float getLinearRestitution ( ) const#

Returns the current linear restitution (stiffness) of the joint. Linear restitution defines how fast the joint compensates for linear coordinate change between two bodies. When bodies are dragged apart, restitution controls the magnitude of force which is applied to both bodies so that their anchor points to become aligned again. For example:
  • 1 means that the joint is to return bodies in place throughout 1 physics tick.
  • 0.2 means that the joint is to return bodies in place throughout 5 physics ticks.
The maximum value of 1 can lead to destabilization of physics (as too great forces are applied).

Return value

Linear restitution in the range [0;1].

void setLinearSoftness ( float softness ) #

Sets the linear softness (elasticity) of the joint. When the joint is stretched, linear softness defines whether linear velocities of the bodies are averaged out. For example:
  • 0 means that the joint is rigid. Linear velocities of the first and the second body are independent.
  • 1 means that the joint is elastic (jelly-like). If the first body changes its velocity, velocity of the second body is equalized with it.

Arguments

  • float softness - Linear softness. The provided value will be clamped in the range [0;1].

float getLinearSoftness ( ) const#

Returns the current linear softness (elasticity) of the joint. When the joint is stretched, linear softness defines whether linear velocities of the bodies are averaged out. For example:
  • 0 means that the joint is rigid. Velocities of the first and the second body are independent.
  • 1 means that the joint is elastic (jelly-like). If the first body changes its velocity, velocity of the second body is equalized with it.

Return value

Linear softness value in the range [0;1].

void setMaxForce ( float force ) #

Sets the maximum amount of force that can be exerted on the joint. If this limit is exceeded, the joint breaks.

Arguments

  • float force - Maximum amount of force.

float getMaxForce ( ) const#

Returns the maximum amount of force that can be exerted on the joint. If this limit is exceeded, the joint breaks.

Return value

Maximum amount of force.

void setMaxTorque ( float torque ) #

Sets the maximum amount of torque that can be exerted on the joint. If this limit is exceeded, the joint breaks.

Arguments

  • float torque - Maximum amount of torque.

float getMaxTorque ( ) const#

Returns the maximum amount of torque that can be exerted on the joint. If this limit is exceeded, the joint breaks.

Return value

Maximum amount of torque.

void setName ( const char * name ) #

Sets the name of the joint.

Arguments

  • const char * name - Name of the joint.

const char * getName ( ) const#

Returns the name of the joint.

Return value

Name of the joint.

void setNumIterations ( int num_iterations ) #

Sets the number of iterations used to solve joints. Note that if this value is too low, the precision of calculations will suffer.

Arguments

  • int num_iterations - Number of iterations. If a non-positive value is provided, 1 will be used instead.

int getNumIterations ( ) const#

Returns the current number of iterations used to solve joints.

Return value

Number of iterations.

Joint::TYPE getType ( ) const#

Returns the type of the joint.

Return value

One of the JOINT_* pre-defined variables.

const char * getTypeName ( ) const#

Returns the name of the joint type.

Return value

Type name.

const char * getTypeName ( int type ) #

Returns the name of a joint type with a given ID.

Arguments

  • int type - Joint type ID. One of the JOINT_* values.

Return value

Joint type name.

void setWorldAnchor ( const Math::Vec3 & anchor ) #

Sets the anchor point in the world coordinates.

Arguments

  • const Math::Vec3 & anchor - Coordinates of the anchor point in the world space.

Math::Vec3 getWorldAnchor ( ) const#

Returns the anchor point in the world coordinates.

Return value

Coordinates of the anchor point in the world space.

Ptr<Joint> clone ( ) const#

Clones the joint.

Return value

Copy of the joint.

void renderVisualizer ( const Math::vec4 & color ) #

Renders the joint.
Notice
You should enable the engine visualizer by the show_visualizer 1 console command.

Arguments

  • const Math::vec4 & color - Color, in which the joint will be rendered.

int restoreState ( const Ptr<Stream> & stream ) #

Restores the state of a given node from a binary stream.
  • If a node is a parent for other nodes, states of these child nodes need to be restored manually.
  • To save the state into a buffer, file or a message from a socket, make sure the stream is opened. If necessary, you can set a position for writing for buffers and files.

Arguments

  • const Ptr<Stream> & stream - Stream with saved node state data.

Return value

1 if node state is successfully restored; otherwise, 0.

int saveState ( const Ptr<Stream> & stream ) const#

Saves the state of a given node into a binary stream.
  • If a node is a parent for other nodes, states of these child nodes need to be saved manually.
  • To save the state from a buffer, file or a message from a socket, make sure the stream is opened. For buffers and files, you also need to set the proper position for reading.

Arguments

  • const Ptr<Stream> & stream - Stream to save node state data.

Return value

1 if node state is successfully saved; otherwise, 0.

void swap ( const Ptr<Joint> & joint ) #

Swaps the joints saving the pointers.

Arguments

  • const Ptr<Joint> & joint - A joint to swap.
Last update: 17.02.2021
Build: ()