This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Migration
Migrating to UNIGINE 2.0
C++ API Migration
Migrating from UNIGINE 2.0 to UNIGINE 2.1
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.

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

Members


Shape clone ()

Clones the shape.

Return value

Copy of the shape.

vec3 getArea ()

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

Return value

A triple of projection areas.

Body getBody ()

Returns the body, to which the shape belongs.

Return value

Body, to which the shape belongs.

vec3 getCenterOfMass ()

Returns local coordinates of the center of mass of the shape.

Return value

Coordinates of the center of mass.

int getCollisionMask ()

Returns the collision mask of the actor. Two objects collide if they both have matching masks.See also details on additional collision exclusion mask.

Return value

Integer, each bit of which is a mask.

float getDensity ()

Returns the current density of a shape.

Return value

Density value.

int getExclusionMask ()

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

Return value

Integer, each bit of which is a mask.

float getFriction ()

Returns the friction of the shape surface.

Return value

Friction of the shape surface.

int getID ()

Returns the unique ID of the shape.

Return value

Unique ID.

int getIntersectionMask ()

Returns an intersection mask of the joint.

Return value

Integer, each bit of which is a mask.

int getIntersection (vec3 p0, vec3 p1, int mask = 0, variable v)

Performs tracing from the p0 point to the p1 point to find a shape located on that line. Intersection is found only for objects with a matching mask.

Notice
World space coordinates are used for this function.

Depending on the variable passed as an argument, the result can be presented as the PhysicsIntersection or PhysicsIntersectionNormal node.

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 shape in your world. The executing sequence is the following:

  • Define and initialize two points (p0 and p1) by using the Unigine::getPlayerMouseDirection() function from core/scripts/utils.h.
  • 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 int variable.
  • In this example, if there is an intersection of mouse direction with a specific shape called "shape", the PhysicsIntersection class instance gets the and intersection point and show the result in console.
Source code (UnigineScript)
#include <core/scripts/utils.h>
/* ... */
// define two vec3 coordinates
vec3 p0,p1;
// get the mouse direction from camera (p0) to cursor pointer (p1)
Unigine::getPlayerMouseDirection(p0,p1);		

// create the instance of the PhysicsIntersection object to save the information about the intersection
PhysicsIntersection intersection = new PhysicsIntersection();
// create an int varaible to check the result of intersection
int result;
result = shape2.getIntersection(p0, p1, intersection);
// if there was an intersection, show the message in console
if(result != 0)
{
	log.message("intersection point: %s \n", typeinfo(intersection.getPoint()) );
}
/* ... */

Arguments

  • vec3 p0 - Start point of the line.
  • vec3 p1 - End point of the line.
  • int mask - Intersection mask.
  • variable v - Variable defining which type of intersection object will be returned:

Return value

Reference to the first intersected shape, if found; otherwise - 0.

float getMass ()

Returns the mass of the shape.
Notice
If g (Earth's gravity) equals to 9.8 m/s2, and 1 unit equals to 1 m, the mass is measured in kilograms.

Return value

Mass of the shape.

string getName ()

Returns the name of the shape.

Return value

Name of the shape.

float getRestitution ()

Returns the restitution of the shape surface.

Return value

Restitution of the shape surface.

string getTypeName ()

Returns the name of the shape type.

Return value

Type name.

int getType ()

Returns the type of the shape.

Return value

One of the SHAPE_* pre-defined variables.

float getVolume ()

Returns the volume of the shape.

Return value

Volume of the shape in cubic units.

int isContinuous ()

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

Return value

1 if CCD is enabled; otherwise, 0.

int isEnabledSelf ()

Returns a value indicating if the shape is enabled.

Return value

1 if the shape is enabled; otherwise, 0.

int isEnabled ()

Returns a value indicating if physical interactions with the shape are enabled.

Return value

1 if physical interactions with the shape are enabled; otherwise, 0.

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.

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.

Arguments

  • Stream stream - Stream to save node state data.

Return value

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

void setBody (Body body)

Sets a body, to which the shape belongs.

Arguments

  • Body body - Body, to which the shape belongs.

void setCollisionMask (int mask)

Sets a collision mask for the shape. Two objects collide if they both have matching masks. See also details on additional collision exclusion mask.

Arguments

  • int mask - Integer, each bit of which is a mask.

void setContinuous (int continuous)

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.

Arguments

  • int continuous - Positive value to enable CCD; 0 to disable.

void setDensity (float density)

Sets density of a shape. Changing the density influences the mass, that is computed by multiplying shape volume by density.

Arguments

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

void setEnabled (int mode)

Enables or disables physical interactions with the shape.

Arguments

  • int mode - Positive number to enable physical interactions, 0 to disable them.

void setExclusionMask (int mask)

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.

Arguments

  • int mask - Integer, each bit of which is a mask.

void setFriction (float friction)

Sets a friction of the shape surface.

Arguments

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

int setID (int id)

Sets the unique ID for the shape.

Arguments

  • int id - Unique ID.

Return value

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

void setIntersectionMask (int mask)

Sets an intersection mask for the shape.

Arguments

  • int mask - Integer, each bit of which is a mask.

void setMass (float mass)

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/s2, and 1 unit equals to 1 m, a shape with mass value of 1 weighs 1 kg.

Arguments

  • float mass - Mass of the shape. If a negative value is provided, 0 will be used instead.

void setName (string name)

Sets the name of the shape.

Arguments

  • string name - Name of the shape.

void setRestitution (float restitution)

Sets a restitution of the shape surface.

Arguments

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

void swap (Shape shape)

Swaps the shapes saving the pointers.

Arguments

  • Shape shape - A shape to swap.

int SHAPE_BOX

Description

Box.

int SHAPE_CAPSULE

Description

Capsule.

int SHAPE_CONVEX

Description

Convex hull.

int SHAPE_CYLINDER

Description

Cylinder.

int SHAPE_SPHERE

Description

Sphere.
Last update: 2017-07-03
Build: ()