This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
Extending Editor Functionality
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.Physics Class

Controls the simulation of physics. For more information on principles and implementation of physics in real-time rendering, see the articles Execution Sequence, Physics and Simulation of Physics.

See Also#

  • The Creating a Car with Suspension Joints usage example demonstrating how to set up physics parameters
  • A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/physics/ folder

Physics Class

Properties

float UpdateTime#

The duration of the update phase, during which the objects are prepared for their collision response to be calculated.

float TotalTime#

The total time that both rendering and calculating of the frame took (the duration of the main loop in the application execution sequence).

float SimulationTime#

The duration of all of the simulation phases added together.

float ResponseTime#

The duration value of the response phase, in which collision response is calculated and joints are solved.

int NumJoints#

The number of joints within the physics radius.

int NumIslands#

The number of physical islands within the physics radius that could be calculated separately. The lower this number, the less efficient multi-threading is, if enabled.

int NumContacts#

The number of contacts within the physics radius; it includes contacts between the bodies (their shapes) and body-mesh contacts.

int NumBodies#

The number of bodies present within the physics radius.

float NarrowTime#

The duration of the narrow phase, during which exact collision tests are performed.

float IntegrateTime#

The duration of the integrate phase, in which physics simulation results are applied to bodies.

int Frame#

The current frame of physics update.

float BroadTime#

The duration of the broad phase, during which potentially colliding objects are found.

int NumIterations#

The current number of iterations used to solve contacts and constraints.
set
Updates the number of iterations used to solve contacts and constraints. Note that if this value is too low, the precision of calculations will suffer.
set value - New number of iterations. If a non-positive value is provided, 1 will be used instead.

int NumFrozenFrames#

The current number of frames, during which an object should keep certain angular and linear velocities to become frozen.
set
Updates the number of frames, during which an object should keep certain angular and linear velocities to become frozen.
set value - Number of frames. If a non-positive value is provided, 1 will be used instead.

float Time#

The current time that can be used when shifting between physics update frames.
set
Forces simulation of physics for a given time. It means, until the set time elapses, physics will be calculated each physics tick (frame) that occurs depending on physics frame rate. It allows you to control the starting point for physics simulation.
Source code (C#)
// AppWorldLogic.cs

/* ... */
public override bool Init() {
	// to prevent physics from being automatically calculated with each update, set one of the following:
	Physics.Enabled = true;
	// or
	Physics.Scale = 0.0f;
}

public override bool Update() {
	// add the time elapsed from the last physics update to the next time count cycle:
	Physics.Time += ifps);
}
/* ... */
In the example, ifps is the time between frames of the renderer.
set value - Time to continue updating physics in seconds.

float Scale#

A value used to scale a frame duration.
set
Updates a value that is used to scale a frame duration. The provided value is saturated in the range [0;16].
set value - Scaling factor.

float PenetrationTolerance#

A value indicating how deeply one object can penetrate another.
set
Updates the current penetration tolerance.
set value - New penetration tolerance. If a negative value is provided, 0 will be used instead, however, this value should be greater than 0 for stable simulation.

float PenetrationFactor#

A penalty force factor. 0 means no penalty force in contacts. The maximum value is 1.
set
Updates the current penalty force factor.
set value - New penetration factor. 0 means no penalty force in contacts. The provided value is saturated in the range [0; 1].

float MaxLinearVelocity#

The current maximum possible linear velocity.
set
Updates the maximum possible linear velocity.
set value - New maximum velocity value. If a negative value is provided, 0 will be used instead.

float MaxAngularVelocity#

The current maximum possible angular velocity.
set
Updates the maximum possible angular velocity.
set value - New maximum velocity value. If a negative value is provided, 0 will be used instead.

float LinearDamping#

The current linear damping value.
set
Updates the current linear damping value.
set value - New linear damping. If a negative value is provided, 0 will be used instead.

float IFps#

A physics frame duration.
set
Updates a frame duration. In fact, this function updates the FPS count used to calculate physics.
set value - Frame duration (1/FPS).

vec3 Gravity#

The current gravity value.
set
Updates the current gravity value.
set value - New gravity.

float FrozenLinearVelocity#

The current linear velocity threshold for freezing object simulation. an object stops to be updated if its linear velocity remains lower than this threshold during the number of Frozen frames (together with angular one).
set
Updates the linear velocity threshold for freezing object simulation. If the object linear velocity remains lower than this threshold during the number of Frozen frames (together with angular one), it stops to be updated.
set value - New "freeze" linear velocity. If a negative value is provided, 0 will be used instead.

float FrozenAngularVelocity#

The current angular velocity threshold for freezing object simulation. an object stops to be updated if its angular velocity remains lower than this threshold during the number of Frozen frames (together with linear one).
set
Updates the angular velocity threshold for freezing object simulation. If the object angular velocity remains lower than this threshold during the number of Frozen frames (together with linear one), it stops to be updated.
set value - New "freeze" angular velocity. If a negative value is provided, 0 will be used instead.

float AngularDamping#

The current angular damping value.
set
Updates the current angular damping value.
set value - New angular damping. If a negative value is provided, 0 will be used instead.

float Distance#

A distance after which the physics will not be simulated.
set
Updates a distance after which the physics will not be simulated.
set value - Distance in units.

float Budget#

The physics simulation budget. physics isn't simulated when time is out of the budget.
set
Sets the physics simulation budget. Physics isn't simulated when time is out of the budget.
set value - The budget value in seconds. The default value is 1/20.

string Data#

User string data associated with the world. this string is written directly into the data tag of the *.world file.
set
Sets user data associated with the world. In the *.world file, the data is set in the data tag.
set value - User data. Data can contain an XML formatted string.

bool IsFixed#

A flag indicating if rendering fps is synchronized to physics one. such fps limitation allows to calculate physics each rendered frame (rather then interpolate it when this flag is set to 0). in this mode, there are no twitching of physical objects if they have non-linear velocities. if the rendering fps is lower than the physics one, this flag has no effect.
set
Sets a flag to synchronize rendering FPS to physics one. Such FPS limitation allows to calculate physics each rendered frame (rather then interpolate it when this flag is set to 0). In this mode, there are no twitching of physical objects if they have non-linear velocities. If the rendering FPS is lower than the physics one, this flag has no effect.
set value - 1 to cap rendering FPS to physics one; 0 to interpolate physics if rendering FPS is higher.

bool IsStable#

A value indicating if objects are updated in a definite order or not. the default is 0 (the update order may change).
set
Sets a value indicating if objects are updated in a definite order or not.
set value - 1 to indicate that the objects are updated in a definite order; 0 to indicate that an objects update order may change.

bool IsEnabled#

A value indicating if physics simulation is enabled. the default is 1.
set
Enables or disables physics simulation.
set value - Positive number to enable physics, 0 to disable it.

Members


Body GetBody ( int id ) #

Returns a body with a given ID.

Arguments

  • int id - Body ID.

Return value

Body with a given ID or NULL (0), if there is no body with a given ID.

int IsBody ( int id ) #

Checks if a body with a given ID exists.

Arguments

  • int id - Body ID.

Return value

1 if a body with a given ID exists; otherwise, 0.

Object GetIntersection ( vec3 p0, vec3 p1, int mask, Node[] exclude, PhysicsIntersection intersection ) #

Performs tracing from the p0 point to the p1 point to find a collision object located on that line. If an object is assigned a body, intersection occurs with its shape. If an object has no body, this function detects intersection with surfaces (polygons) of objects with intersection flag set. Intersection is found only for objects with a matching mask if their ID is not found in the exclude list. Intersection is Intersection does not work for disabled objects.

Notice
This function uses world space coordinates.

Arguments

  • vec3 p0 - Line start point coordinates.
  • vec3 p1 - Line end point coordinates.
  • int mask - Physics intersection mask. If 0 is passed, the function will return NULL.
  • Node[] exclude - Array of nodes to be excluded.
  • PhysicsIntersection intersection - PhysicsIntersection class instance containing intersection data.

Return value

The first intersected object, if found; otherwise, 0.

Object GetIntersection ( vec3 p0, vec3 p1, int mask, PhysicsIntersection intersection ) #

Performs tracing from the p0 point to the p1 point to find a collision object located on that line. If an object is assigned a body, intersection occurs with its shape. If an object has no body, this function detects intersection with surfaces (polygons) of objects with intersection flag set. Physics intersection shall only be detected for objects with a matching mask. Intersection does not work for disabled objects.

Notice
This function uses world space coordinates.

Usage Example

The following example shows how you can get the intersection information by using the PhysicsIntersection class. In this example we specify a line from the point of the camera (vec3 p0) to the point of the mouse pointer (vec3 p1). The executing sequence is the following:

  1. Define and initialize two points (p0 and p1) by using the Player.getDirectionFromScreen() function.
  2. Create an instance of the PhysicsIntersection class to get the intersection information.
  3. Check, if there is an intersection with an object with a shape or a collision object. The getIntersection() function returns an intersected object when the object intersects with the traced line.
  4. In this example, when the object intersects with the traced line, all the surfaces of the intersected object change their material parameters. If the object has a shape, its information will be shown in console. The PhysicsIntersection class instance gets the coordinates of the intersection point and the Shape class object. You can get all these fields by using getShape(), getPoint() functions.
Source code (C#)
public override bool Update() {

	// initialize points of the mouse direction
	Vec3 p0, p1;

	// get the current player (camera)
	Player player = Game.Player;
	if (player == null)
		return 0;
	// get width and height of the current application window
	int width = App.getWidth();
	int height = App.getHeight();
	// get the current X and Y coordinates of the mouse pointer
	int mouse_x = App.getMouseX();
	int mouse_y = App.getMouseY();
	// get the mouse direction from the player's position (p0) to the mouse cursor pointer (p1)
	player.getDirectionFromScreen(out p0, out p1, mouse_x, mouse_y, width, height);

	// create the instance of the PhysicsIntersection object to save the information about the intersection
	PhysicsIntersection intersection = new PhysicsIntersection();
	// get an intersection
	Unigine.Object obj = Physics.getIntersection(p0, p1, 1, intersection);

	// if the intersection has been occurred, change the parameter of the object's material    
	if (obj != null)
	{
		for (int i = 0; i < obj.NumSurfaces; i++)
		{
			obj.setMaterialParameterFloat4("albedo_color", new vec4(1.0f, 1.0f, 0.0f, 1.0f), i);
		}

		// if the intersected object has a shape, show the information about the intersection   
		Shape shape = intersection.Shape;
		if (shape != null)
		{
			Log.Message("physics intersection info: point: {0} shape: {1}\n", intersection.Point.GetType(), shape.Type.GetType());
		}
	}

	return true;
}

Arguments

  • vec3 p0 - Line start point coordinates.
  • vec3 p1 - Line end point coordinates.
  • int mask - Physics intersection mask. If 0 is passed, the function will return NULL.
  • PhysicsIntersection intersection - PhysicsIntersection class instance containing intersection data.

Return value

The first intersected object, if found; otherwise, 0.

Object GetIntersection ( vec3 p0, vec3 p1, int mask, PhysicsIntersectionNormal intersection ) #

Performs tracing from the p0 point to the p1 point to find a collision object located on that line. If an object is assigned a body, intersection occurs with its shape. If an object has no body, this function detects intersection with surfaces (polygons) of objects with intersection flag set. Physics intersection shall only be detected for objects with a matching mask. Intersection does not work for disabled objects.

Notice
This function uses world space coordinates.

Arguments

  • vec3 p0 - Line start point coordinates.
  • vec3 p1 - Line end point coordinates.
  • int mask - Physics intersection mask. If 0 is passed, the function will return NULL.
  • PhysicsIntersectionNormal intersection - PhysicsIntersectionNormal class instance containing intersection data.

Return value

The first intersected object, if found; otherwise, 0.

Object GetIntersection ( vec3 p0, vec3 p1, int mask, Node[] exclude, PhysicsIntersectionNormal intersection ) #

Performs tracing from the p0 point to the p1 point to find a collision object located on that line. If an object is assigned a body, intersection occurs with its shape. If an object has no body, this function detects intersection with surfaces (polygons) of objects with intersection flag set. Intersection is found only for objects with a matching mask if their ID is not found in the exclude list. Intersection is Intersection does not work for disabled objects.

Notice
This function uses world space coordinates.

Arguments

  • vec3 p0 - Line start point coordinates.
  • vec3 p1 - Line end point coordinates.
  • int mask - Physics intersection mask. If 0 is passed, the function will return NULL.
  • Node[] exclude - Array of nodes to be excluded.
  • PhysicsIntersectionNormal intersection - PhysicsIntersectionNormal class instance containing intersection data.

Return value

The first intersected object, if found; otherwise, 0.

Joint GetJoint ( int id ) #

Returns a joint with a given ID.

Arguments

  • int id - Joint ID.

Return value

Joint with a given ID or NULL (0), if there is no joint with a given ID.

int IsJoint ( int id ) #

Checks if a joint with a given ID exists.

Arguments

  • int id - Joint ID.

Return value

1 if a joint with a given ID exists; otherwise, 0.

Shape GetShape ( int id ) #

Returns a shape with a given ID.

Arguments

  • int id - Shape ID.

Return value

Shape with a given ID or NULL (0), if there is no shape with a given ID.

int IsShape ( int id ) #

Checks if a shape with a given ID exists.

Arguments

  • int id - Shape ID.

Return value

1 if a shape with a given ID exists; otherwise, 0.

void AddUpdateNode ( Node node ) #

Adds the node for which physical state should be updated. If a node is not added with this function, it won't be updated when out of physics simulation distance.

Arguments

  • Node node - Node to be updated.

void addUpdateNodes ( Node[] nodes ) #

Adds the nodes for which physical state should be updated. If nodes are not added with this function, they won't be updated when out of physics simulation distance.

Arguments

  • Node[] nodes - Nodes to be updated.

int LoadSettings ( string name ) #

Loads the physics settings from a given file.

Arguments

  • string name - Path to an XML file with desired settings.

Return value

Returns 1 if the settings are loaded successfully; otherwise, 0.

int LoadWorld ( Xml xml ) #

Loads physics settings from the Xml.

Arguments

  • Xml xml - Xml node.

Return value

Returns 1 if settings are loaded successfully; otherwise, 0.

int RemoveScene ( int id ) #

Removes the previously saved physics scene.

Arguments

  • int id - ID number of the scene.

Return value

Returns 1 if the scene is removed successfully; otherwise, 0.

int RestoreScene ( int id ) #

Restores the previously saved physics scene from the buffer.

Arguments

  • int id - ID number of the scene.

Return value

Returns 1 if the scene is restored successfully; otherwise, 0.

int RestoreState ( Stream stream ) #

Restores physics settings from the stream.
Warning
This function is deprecated and will be removed in the next release.

Arguments

  • Stream stream - Stream to restore settings from.

Return value

Returns 1 if settings are restored successfully; otherwise, 0.

int SaveScene ( ) #

Saves the current physics scene (physical properties of all objects) into the buffer.

Return value

Scene buffer ID.

int SaveSettings ( string name, int force = 0 ) #

Saves the current physics settings to a given file.

Arguments

  • string name - Path to a target file.
  • int force - Forced saving of physics settings.

Return value

Returns 1 if the settings are saved successfully; otherwise, 0.

int SaveState ( Stream stream ) #

Saves physics settings into the stream.
Warning
This function is deprecated and will be removed in the next release.

Arguments

  • Stream stream - Stream to save settings into.

Return value

Returns 1 if settings are saved successfully; otherwise, 0.

int SaveWorld ( Xml xml, int force = 0 ) #

Saves physics settings into the Xml.

Arguments

  • Xml xml - Xml node.
  • int force - Forced saving of physics settings.

Return value

Returns 1 if settings are saved successfully; otherwise, 0.
Last update: 2020-06-01
Build: ()