This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and 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
CIGI Client 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.Shape Class

This class creates collision shapes that approximate the finite volume of physical bodies and allow them to collide. Shapes are assigned to a body and are positioned in its local coordinates.

See Also#

Shape Class

Properties

bool IsIdentity#

Returns a value indicating if the shape has a scale equal to 1 and no rotation.

mat4 BodyShapeTransform#

The transformation matrix of the shape (in the coordinates of the body). this matrix describes position and orientation of the shape. this method is identical to getShapeTransform().
set
Sets a transformation matrix for the shape (in the coordinates of the body). This matrix describes position and orientation of the shape. This method is identical to setShapeTransform().
set value - Transformation matrix

Mat4 Transform#

The transformation matrix of the shape (in world coordinates). this matrix describes position and orientation of the shape.
set
Sets a transformation matrix for the shape (in world coordinates). This matrix describes position and orientation of the shape. This method resets shape's linear velocity to 0.
set value - Transformation matrix

vec3 CenterOfMass#

Local coordinates of the center of mass of the shape.

mat3 Inertia#

A matrix that represents inertia tensor describing the resistance of the body to rotation in different directions. it is determined by the distribution of mass throughout the body volume.

float Volume#

The volume of the shape.

vec3 Area#

Areas of shape projections on three axes: x, y, and z.

float Restitution#

The restitution of the shape surface.
set
Sets a restitution of the shape surface.
set value - Restitution of the shape surface. The provided value will be saturated in the range [0; 1].

float Friction#

The friction of the shape surface.
set
Sets a friction of the shape surface.
set value - Friction of the shape surface. If a negative value is provided, 0 will be used instead.

float Density#

The current density of a shape.
set
Sets density of a shape. Changing the density influences the mass, that is computed by multiplying shape volume by density.
set value - Density value. If a negative value is provided, 0 will be used instead.

float Mass#

The mass of the shape.
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.
set
Sets a mass of the shape. Changing the mass influences the density, that is computed by dividing the mass by shape volume.
Notice
If g (Earth's gravity) equals to 9.8 m/s 2, and 1 unit equals to 1 m, a shape with mass value of 1 weighs 1 kg.
set value - Mass of the shape. If a negative value is provided, 0 will be used instead.

int ExclusionMask#

The bit mask that prevents collisions of the shape with other ones. this mask is independent of the collision mask. For shape with matching collision masks not to collide, at least one bit of their exclusion mask should match.
set
Sets an bit mask to prevent collisions of the shape with other ones. This mask is independent of the collision mask. For shapes with matching collision masks not to collide, at least one bit of their exclusion mask should match.
set value - Integer, each bit of which is a mask.

int CollisionMask#

The collision mask of the actor. two objects collide if they both have matching masks.see also details on additional collision exclusion mask.
set
Sets a collision mask for the shape. Two objects collide if they both have matching masks. See also details on additional collision exclusion mask.
set value - Integer, each bit of which is a mask.

int IntersectionMask#

An intersection mask of the shape.
set
Sets an intersection mask for the shape.
set value - Integer, each bit of which is a mask.

string Name#

The name of the shape.
set
Sets the name of the shape.
set value - Name of the shape.

bool IsContinuous#

A value indicating if continuous collision detection for spheres or capsules is enabled. Enabled CCD incurs almost no performance penalty. Disabling CCD allows to avoid physics artifacts, if there are any.
set
Enables or disables continuous collision detection for spheres or capsules. Enabled CDD incurs almost no performance penalty. Disabling CCD allows to avoid physics artifacts, if there are any.
set value - Positive value to enable CCD; 0 to disable.

bool IsEnabledSelf#

A value indicating if the shape is enabled.

bool IsEnabled#

A value indicating if physical interactions with the shape are enabled.
set
Enables or disables physical interactions with the shape.
set value - Positive number to enable physical interactions, 0 to disable them.

Body Body#

The body, to which the shape belongs.
set
Sets a body, to which the shape belongs.
set value - Body, to which the shape belongs.

int Number#

The number of shape instances.

string TypeName#

The name of the shape type.

int Type#

The type of the shape.

int ID#

The unique id of the shape.
set
Sets the unique ID for the shape.
set value - Unique ID.

Members


int GetCollision ( Contact[] contacts, float ifps ) #

Performs collision check for the shape and puts information on all contacts to the output buffer.

Collisions with the surface can be found only if the following conditions are fulfilled:

  1. The surface is enabled.
  2. Per-surface Collision flag is enabled.
  3. The surface has a material assigned.
Notice
The shape must be enabled.

Arguments

  • Contact[] contacts - Output buffer containing information on all detected physical contacts for the shape (if any). Information on each contact can be handled via the Contact class.
  • float ifps - Inverse FPS value.

Return value

1 if collisions are found; otherwise, 0.

int GetCollision ( Object object, Contact[] contacts, float ifps ) #

Performs collision check for the shape and puts information on all contacts and contact object to the output buffer.

Collisions with the surface can be found only if the following conditions are fulfilled:

  1. The surface is enabled.
  2. Per-surface Collision flag is enabled.
  3. The surface has a material assigned.
Notice
The shape must be enabled.

Arguments

  • Object object - Contact object instance.
  • Contact[] contacts - Output buffer containing information on all detected physical contacts for the shape (if any). Information on each contact can be handled via the Contact class.
  • float ifps - Inverse FPS value.

Return value

1 if collisions are found; otherwise, 0.

int GetIntersection ( Vec3 p0, Vec3 p1, PhysicsIntersectionNormal intersection ) #

Performs tracing from the p0 point to the p1 point to find a shape intersected by this line. Intersection is found only for objects with a matching intersection mask.

Notice
World space coordinates are used for this function.

Arguments

  • Vec3 p0 - Start point of the line.
  • Vec3 p1 - End point of the line.
  • PhysicsIntersectionNormal intersection - PhysicsIntersectionNormal class instance containing intersection information

Return value

1 if an intersection was detected; otherwise - 0.

int GetIntersection ( Vec3 p0, Vec3 p1, PhysicsIntersection intersection ) #

Performs tracing from the p0 point to the p1 point to find a shape intersected by this line. Intersection is found only for objects with a matching intersection mask.

Notice
World space coordinates are used for this function.

Usage Example

The following example shows how you can get the intersection information by using the PhysicsIntersection class. In this example the line is an invisible traced line from the point of the camera (vec3 p0) to the point of the mouse pointer (vec3 p1). It is supposed that you have a dynamic mesh with a body and a shape assigned. The executing sequence is the following:

  • Define and initialize two points (p0 and p1) by using the Player.getDirectionFromScreen() function.
  • Create an instance of the PhysicsIntersection class to get the information of the intersection point.
  • Check, if there is a intersection with a shape and save the result in the integer variable.
  • In this example, if there is an intersection of mouse direction with a shape, the PhysicsIntersection class instance gets the intersection point. The result is shown in the console.
Source code (C#)
/* ... */
// initialize points of the mouse direction
Vec3 p0, p1;

// get the current player (camera)
Player player = Game.get().getPlayer();
if (player == null)
	return 0;
// get width and height of the current application window
int width = App.get().getWidth();
int height = App.get().getHeight();
// get the current X and Y coordinates of the mouse pointer
int mouse_x = App.get().getMouseX();
int mouse_y = App.get().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();
// create an integer variable to check the result of intersection
int result = 0;
result = shape.getIntersection(p0, p1, intersection);
// if there was an intersection, show the message in console
if (result != 0)
{
	Log.message("Intersection point: ({0} {1} {2}) \n", intersection.getPoint().x, intersection.getPoint().y, intersection.getPoint().z);
}
/* ... */

Arguments

  • Vec3 p0 - Start point of the line.
  • Vec3 p1 - End point of the line.
  • PhysicsIntersection intersection - PhysicsIntersection class instance containing intersection information.

Return value

1 if an intersection was detected; otherwise - 0.

int GetIntersection ( Vec3 p0, Vec3 p1, Vec3[] ret_point, vec3[] ret_normal ) #

Performs tracing from the p0 point to the p1 point to find a shape intersected by this line. Intersection is found only for objects with a matching intersection mask.

Notice
World space coordinates are used for this function.

Arguments

  • Vec3 p0 - Start point of the line (in world coordinates).
  • Vec3 p1 - End point of the line (in world coordinates).
  • Vec3[] ret_point - Container to which contact point coordinates (if any) shall be put (in world coordinate system).
  • vec3[] ret_normal - Container to which contact point normal coordinates (if any) shall be put (in world coordinate system).

Return value

1 if an intersection was detected; otherwise - 0.

Shape GetShape ( ) #

Returns a Shape instance.

Return value

void SetPosition ( Vec3 position ) #

Sets shape position. This method resets shape's velocity to 0.

Arguments

  • Vec3 position - New shape's position, in world coordinates.

string GetTypeName ( int type ) #

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

Arguments

  • int type - Shape type ID. One of the SHAPE_* values.

Return value

Shape type name.

void SetVelocity ( vec3 velocity, float ifps ) #

Sets a new velocity vector for the shape.

Arguments

  • vec3 velocity - Velocity vector, each component represents shape's velocity along the corresponding axis, in units per second.
  • float ifps - Inverse FPS value.

vec3 GetVelocity ( ) #

Returns the current velocity vector of the shape.

Return value

Current celocity vector, each component represents shape's velocity along the corresponding axis, in units per second.

Shape Clone ( ) #

Clones the shape.

Return value

Copy of the shape.

void RenderVisualizer ( vec4 color ) #

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

Arguments

  • vec4 color - Color, in which the shape will be rendered.

int RestoreState ( 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.
Warning
This function is deprecated and will be removed in the next release.

Arguments

  • Stream stream - Stream with saved node state data.

Return value

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

int SaveState ( Stream stream ) #

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.
Warning
This function is deprecated and will be removed in the next release.

Arguments

  • Stream stream - Stream to save node state data.

Return value

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

void Swap ( Shape shape ) #

Swaps the shapes saving the pointers.

Arguments

  • Shape shape - A shape to swap.

Shape CreateShape ( int type ) #

Creates a new shape of the specified type.

Arguments

  • int type - Body type. One of the SHAPE_* values.

Return value

New created shape instance.

Shape CreateShape ( string type_name ) #

Creates a new shape of the specified type.

Arguments

  • string type_name - Shape type name.

Return value

New created shape instance.
Last update: 2019-11-28
Build: ()