This page has been translated automatically.
Programming
Fundamentials
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Core Library
Containers
Node-Related Classes
Rendering-Related Classes
Physics-Related Classes
Bounds-Related Classes
GUI-Related Classes
Controls-Related Classes
Pathfinding-Related Classes
Utility 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.

Game Class

Unigine game. This interface provides access to Unigine game functions.

To use this class, include the UnigineGame.h file.

Game Class

Members


Ptr<Player> getPlayer ()

Returns the current game player.

Return value

Current game player.

void setScale (float scale)

Sets a value that is used to scale frame duration. It scales up or down the speed of rendering, physics and game logic. This function can be used to create effects of slow/accelerated motion.For example, if the scale equals 2, the rate of simulation of all effects (such as particles) speeds up to two times faster. This function scales both setIFps() and setFTime() functions. The default is 1.

Arguments

  • float scale - Scaling factor. The provided values is clamped within range [0;32].

int getRandomInt (int from, int to)

Arguments

  • int from
  • int to

Return value

float getScale ()

Returns a value used to scale a frame duration.

Return value

Value to scale frame duration.

double getRandomDouble (double from, double to)

Arguments

  • double from
  • double to

Return value

void setSeed (int seed)

Sets the seed for pseudo-random number generator.

Arguments

  • int seed - Number used to initialize a pseudo-random sequence of numbers. Non-negative value should be provided, as unsigned integer is used for it.

void setData (const char * data)

Sets user data associated with the world. In the *.world file, the data is set in the data tag.

Arguments

  • const char * data - New user data.

float getIFps ()

Returns the scaled (see the setScale() function) inverse FPS value.

Return value

Scaled inverse FPS value (1/FPS) in seconds. If the game is paused, 0 is returned.

Ptr<Obstacle> getIntersection (const Math::Vec3 & p0, const Math::Vec3 & p1, float radius, int mask, const Vector< Ptr<Node> > & exclude, Math::Vec3 * intersection)

Arguments

  • const Math::Vec3 & p0
  • const Math::Vec3 & p1
  • float radius
  • int mask
  • const Vector< Ptr<Node> > & exclude
  • Math::Vec3 * intersection

Return value

int getSeed ()

Returns the seed for pseudo-random number generator.

Return value

Number used to initialize a pseudo-random sequence of numbers.

void setFrame (int frame)

Sets the game frame number.

Arguments

  • int frame - Frame number.

void setTime (float time)

Sets a specified time value for the game. The time is counted off starting from the world loading and does not take game pauses into account.

Arguments

  • float time - Time value in seconds.

float getNoise1 (float pos, float size, int frequency)

Arguments

  • float pos
  • float size
  • int frequency

Return value

float getNoise3 (const Math::vec3 & pos, const Math::vec3 & size, int frequency)

Arguments

  • const Math::vec3 & pos
  • const Math::vec3 & size
  • int frequency

Return value

void setIFps (float ifps)

Sets the inverse FPS value. This function sets a fixed FPS that does not depend on the real FPS the hardware is capable of. To remove the FPS limitation, use -1.

Arguments

  • float ifps - Inverse FPS value (1/FPS) in seconds. To remove the FPS limitation, use -1.

float getRandomFloat (float from, float to)

Arguments

  • float from
  • float to

Return value

unsigned int getRandom ()

Returns a pseudo-random number within a given range, supports int, float, vec3, and vec4.

Return value

Random number (type depends on arguments).

void setPlayer (const Ptr<Player> & player)

Sets the current game player.

Arguments

  • const Ptr<Player> & player - Game player.

void setFTime (float ftime)

Sets the maximum rendering frame duration value. If the real rendering FPS is higher than the fixed frame FPS, the engine will wait until the fixed frame time is over. To remove fixed frame duration, use -1.

Arguments

  • float ftime - Frame time in seconds. To remove the FPS limitation, use -1.

void setEnabled (int enabled)

Pauses or resumes the current game.

Arguments

  • int enabled - 1 to resume the game, 0 to pause it.

const char * getData ()

Returns user string data associated with the world. This string is written directly into the data tag of the *.world file.

Return value

User string data.

float getFTime ()

Returns time spent between a previous update and a current one. This function takes time scaling into account.

Return value

Frame time in seconds.

float getTime ()

Returns the current time spent in the game. It is counted off starting from the world loading and does not take game pauses into account.

Return value

Time value in seconds.

int isEnabled ()

Returns a value indicating if the game is paused or not.

Return value

Returns 1 if the game is not paused; otherwise, 0.

Ptr<Obstacle> getIntersection (const Math::Vec3 & p0, const Math::Vec3 & p1, float radius, int mask, const Ptr<GameIntersection> & intersection)

Performs intersection to find if a pathfinding obstacle is located within the cylinder between two points.

Notice
World space coordinates are used for this function.

Usage Example

The following example shows how you can get the intersection point (vec3) of the cylinder between two points with an obstacle. In this example the cylinder is an invisible traced cylinder from the point of the camera (vec3 p0) to the point of the mouse pointer (vec3 p1) with the specific radius. The executing sequence is the following:

  • Define and initialize two points (p0 and p1) by using the getPlayerMouseDirection() function from core/scripts/utils.h.
  • Create an instance of the GameIntersection class to get the intersection point coordinates.
  • Check, if there is a intersection with an obstacle. The engine.game.getIntersection() function returns an intersected obstacle when the obstacle appears in the area of the cylinder.
  • After that GameIntersection instance gets the point of the nearest intersection point and you can get it by using the getPoint() function.
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)
getPlayerMouseDirection(p0,p1);

// create an instance of the GameIntersection class
GameIntersection intersection = new GameIntersection();
 
// try to get the intersection with an obstacle.
// cylinder has radius 0.1f, intersection mask equals to 1
Obstacle obstacle = engine.game.getIntersection(p0,p1,0.1f, 1, intersection);

// check, if the intersection of mouse direction with any obstacle was occurred;
if(obstacle !=NULL)
{
  // show the coordinates of the intersection in console 
  log.message("The intersection with obstacle was here: %s\n", typeinfo(intersection.getPoint()));
}
/* ... */

Arguments

  • const Math::Vec3 & p0 - Start point.
  • const Math::Vec3 & p1 - End point.
  • float radius - Radius of the intersection cylinder.
  • int mask - Obstacle intersection mask. The obstacle is ignored if its mask does not match.
  • const Ptr<GameIntersection> & intersection - GameIntersection class instance to put the result into.

Return value

Intersected obstacle.

float getNoise2 (const Math::vec2 & pos, const Math::vec2 & size, int frequency)

Arguments

  • const Math::vec2 & pos
  • const Math::vec2 & size
  • int frequency

Return value

int getFrame ()

Returns the current game frame number.

Return value

Frame number.
Last update: 2017-07-03
Build: ()