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

Player Class

Warning
UnigineScript is deprecated and will be removed in future releases. Please consider using C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScipt is not guaranteed, as the current level of support assumes only fixing critical issues.
Inherits: Node

This class is used to create cameras that view the world. When you create a new player, it creates a camera and specifies controls, masks, postprocess materials for this camera.

Players' viewing frustum is defined by a near clipping plane, far clipping plane and the field of view. Note that if you set up a custom projection matrix and after that call any of these functions:

your custom matrices will be overwritten.

Players cannot have a parent node; they always use the world coordinates for their transformations. The only exception is PlayerDummy.

Player Masks#

Objects, decals and lights can be selectively displayed in the player viewport. To be displayed, their viewport mask should be matching with the player's viewport mask (one matching bit is enough):

Reflections can also be selectively rendered into the viewport: an object can be rendered without reflection or reflection without an object. For that, the player's reflection viewport mask should match:

That is enough to render reflection from the object without an object itself. If an object needs to be present as well, all these conditions should simply go together with above mentioned ones.

To render an object without reflection, simply either its material viewport mask or object surface viewport mask should not match the player's reflection viewport mask.

Players also can have sound source and sound reverberation masks. As well as for viewports, corresponding masks of the Player object should match with SoundReverb and SoundSource masks.

Perspective and Orthographic Projection#

Depending on your project's requirements you can set your player to use perspective or orthographic projection. This can be done via the setProjection() method.

For example, you can use the following code to set up orthographic projection or perspective projection for your current game player depending on a flag value:

Source code (UnigineScript)
// world.usc

Player player;

/* ... */
		
// ortho flag - change this value to switch projection type
int ortho_flag = 0;

int init(){
	/* ... */
	
	// getting the current player
	player = engine.game.getPlayer();

	// setting up near and far clipping planes and aspect ratio
	float znear = 0.001f;
	float zfar = 10000.0f;
	float aspect = 16.0f / 9.0f;

	if (ortho_flag)
	{
		// setting up orthographic projection
		player.setProjection(ortho(-1.0f, 1.0f, -1.0f, 1.0f, znear, zfar));
	}
	else
	{
		// setting up perspective projection
		player.setProjection(perspective(60.0f, aspect, znear, zfar));
	}

	return 1;
}

Getting Euler Angles for an Active Camera

Sometimes it might be necessary to get current rotation of the active camera as a set of Euler angles. When we talk about axes in UNIGINE we assume that:

  • X axis points to the right giving us a pitch angle.
  • Y axis points forward giving us a roll angle.
  • Z axis points up giving us a yaw (heading) angle.
Object Direction Vectors

To get the Euler angles we should use decomposeRotationZXY() also known as Cardan angles (yaw is independent, then we get pitch and in the end, roll). But, there is one thing to be taken into account - cameras have a different system:

  • X axis points to the right giving us a pitch angle.
  • Y axis points up giving us a yaw (heading) angle.
  • Z axis points backward giving us a -roll angle.
Camera Direction Vectors
To compensate it, we need to rotate our camera -90 degrees around X axis.

Player Class

Members


void setCamera ( ) #

Sets given Camera instance to the Player.

Arguments

    getCamera ( ) #

    Returns the Camera instance of the Player node.

    Return value

    The camera of the player.

    void setControlled ( int controlled ) #

    Disables or enables player controls.

    Arguments

    • int controlled - 1 — enable player controls, 0 — disable (player stops responding to them).

    int isControlled ( ) #

    Returns a value indicating whether player controls are disabled (player does not respond to them) or enabled.

    Return value

    Positive number if player controls are disabled; otherwise, 0.

    void setControls ( Controls controls ) #

    Sets a Controls object that will hold settings of input controls relevant to the player.

    Arguments

    • Controls controls - Controls object used to handle input controls.

    Controls getControls ( ) #

    Returns a Controls object that holds settings of input controls relevant to the player.

    Return value

    Controls object used to handle input controls.

    void setFov ( float fov ) #

    Sets a vertical field of view of the player.

    Notice
    Horizontal FOV cannot be used since it varies depending on the viewport's aspect ratio.

    You can use the following formula to calculate horizontal FOV from the vertical one for the given aspect ratio (width/height): FOV_h = 2 × atan ( (width / height) × tan(FOV_v / 2)).

    Arguments

    • float fov - New vertical field of view in degrees. The provided value will be saturated in the range [0; 180]. The default is 60 degrees.

    float getFov ( ) #

    Returns the current vertical field of view of the player.

    Notice
    Horizontal FOV cannot be used since it varies depending on the viewport's aspect ratio.

    You can use the following formula to calculate horizontal FOV from the vertical one for the given aspect ratio (width/height): FOV_h = 2 × atan ( (width / height) × tan(FOV_v / 2)).

    Return value

    Vertical field of view in degrees. The default is 60 degrees.

    void setObliqueFrustum ( int frustum ) #

    Enables or disables obliqueness of the viewing frustum.
    Notice
    It is recommended to set oblique viewing frustum using this method, as it doesn't affect the projection matrix. To specify the near clipping plane use the setObliqueFrustumPlane() method.

    Arguments

    • int frustum - 1 to enable oblique viewing frustum; 0 to disable it.

    int isObliqueFrustum ( ) #

    Returns a value indicating if the viewing frustum is oblique.

    Return value

    1 if the viewing frustum is oblique; otherwise, 0.

    void setObliqueFrustumPlane ( Vec4 plane ) #

    Sets the oblique near clipping plane of the viewing frustum.
    Notice
    This method does not affect the projection matrix. To enable the oblique frustum use the setObliqueFrustum() method.
    Source code (UnigineScript)
    /* .. */
    
    int update() {
    	// Write here code to be called before updating each render frame: specify all graphics-related functions you want to be called every frame while your application executes.
                float time = engine.game.getTime();
    			
    				// initializing a plane to be set as a near clipping plane
                    Vec4 plane = Vec4(1.0f, 1.0f, 1.0f, 1.0f + sin(time) * 4.0f);
    				
    				// getting a player
                    Player player = engine.game.getPlayer();
                    if (player != NULL)
                    {
    					// enabling oblique frustum
                        player.setObliqueFrustum(1);
    
    					// setting our plane as an oblique near clipping plane
                        player.setObliqueFrustumPlane(plane);
                    }
    				
    	return 1;
    }
    
    /* .. */

    Arguments

    • Vec4 plane - World coordinates of the oblique near clipping plane to set (Nx, Ny, Nz, D), where Nx, Ny, Nz - coordinates of the plane normal, D - distance from the origin to the plane.

    Vec4 getObliqueFrustumPlane ( ) #

    Returns the oblique near clipping plane of the viewing frustum.

    Return value

    World coordinates of the oblique near clipping plane to set (Nx, Ny, Nz, D), where Nx, Ny, Nz - coordinates of the plane normal, D - distance from the origin to the plane.

    void setPostMaterials ( string materials ) #

    Sets post postprocess materials that are applied after all other postprocess (such as HDR, DOF, etc.) are rendered.
    They are used after engine.render.setPostMaterials(), if any.

    Arguments

    • string materials - List of comma-separated postprocess materials names.

    string getPostMaterials ( ) #

    Returns names of the current post postprocess materials that are applied after all other postprocess (such as HDR, DOF, etc.) are rendered.
    They are used after engine.render.getPostMaterials(), if any.

    Return value

    Name of the current post postprocess materials.

    void setProjection ( mat4 projection ) #

    Updates the current projection matrix.
    Notice
    It is not recommended to use this method for setting obliqueness of the near clipping plane of the frustum, as in this case a number of features (such as clouds, shadows, TAA, a number of engine optimizations, etc.) will not function properly. Please, use the setObliqueFrustum() method instead.

    Arguments

    • mat4 projection - New projection matrix.

    mat4 getProjection ( ) #

    Returns the current projection matrix with unit (1.0) aspect ratio.

    Return value

    Current projection matrix.

    void setReflectionViewportMask ( int mask ) #

    Sets a bit mask for rendering reflections into the viewport. Reflections are rendered in the viewport if masks of reflective materials match this one (one bit at least).

    Arguments

    • int mask - Reflection viewport mask (an integer, each bit of which is a mask).

    int getReflectionViewportMask ( ) #

    Returns the current bit mask for rendering reflections into the viewport. Reflections are rendered in the viewport if masks of reflective materials match this one (one bit at least).

    Return value

    Reflection viewport mask (an integer, each bit of which is a mask).

    void setReverbMask ( int mask ) #

    Updates a bit mask that determines what reverberation zones can be heard. For sound to reverberate, at least one bit of this mask should match with a reverb mask of the sound source and a reverb mask of the reverberation zone. (Masks of a sound source and reverberation zone can match with the player's one in different bits, not necessarily one).

    Arguments

    • int mask - Integer, each bit of which is a mask for reverberating sound sources and reverberation zones.

    int getReverbMask ( ) #

    Returns the current bit mask that determines what reverberation zones can be heard. For sound to reverberate, at least one bit of this mask should match with a reverb mask of the sound source and a reverb mask of the reverberation zone. (Masks of a sound source and reverberation zone can match with the player's one in different bits, not necessarily one).

    Return value

    Integer, each bit of which is a mask for reverberating sound sources and reverberation zones.

    void setSourceMask ( int mask ) #

    Updates a bit mask that determines what sound sources can be heard. For a sound source to be heard, its mask should match with this one in at least one bit. Plus, the volume of sound channel in which the sound plays (its number also depends on this mask) should not be equal to 0.

    Arguments

    • int mask - Integer, each bit of which specifies a sound channel.

    int getSourceMask ( ) #

    Returns a bit mask that determines what sound channels can be heard. For a sound source to be heard, its mask should match with this one in at least one bit. Plus, the volume of sound channel in which the sound plays (its number also depends on this mask) should not be equal to 0.

    Return value

    Integer, each bit of which specifies a sound channel.

    void setUp ( vec3 up ) #

    Sets an up direction of the player's viewport (i.e. tilt of the player's viewport).
    Notice
    In case of PlayerActor, its transformation forces it to recalculate its inner state (position, direction, angles and so on), so the up direction of the player's viewport may become "negative forward". And then transformation will be recalculated by using this direction, causing flip of the basis of the player actor. To avoid such flipping, the theta and phi angles should be recalculated by using the current viewing orientation of the player.

    Arguments

    • vec3 up - New upward direction vector. The vector is normalized to 1.

    vec3 getUp ( ) #

    Returns the current up direction of the player's viewport (i.e. tilt of the player's viewport).

    Return value

    Upward direction vector.

    void setVelocity ( vec3 velocity ) #

    Sets a player's velocity.
    Notice
    In case of PlayerActor, this function is valid only when the player is not simulated physically (setPhysical() is set to 0). If it is, moving PlayerActor is done via accessing its body.

    Arguments

    • vec3 velocity - New velocity in units per second.

    vec3 getVelocity ( ) #

    Returns the current velocity of the player.

    Return value

    Velocity in units per second.

    void setViewDirection ( vec3 direction ) #

    Sets given view direction vector to the Player instance.

    Arguments

    • vec3 direction - A view direction vector.

    vec3 getViewDirection ( ) #

    Returns Player's view direction vector.

    Return value

    A view direction vector.

    void setViewportMask ( int mask ) #

    Sets a bit mask for rendering into the viewport. Object surfaces, materials, decals, lights and GUI objects will be rendered into the viewport only if their viewport mask matches the player's one (one matching bit is enough).

    Arguments

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

    int getViewportMask ( ) #

    Returns the current bit mask for rendering into the viewport. Object surfaces, materials, decals, lights and GUI objects will be rendered into the viewport only if their viewport mask matches the player's one (one matching bit is enough).

    Return value

    Integer, each bit of which is a mask.

    void setZFar ( float zfar ) #

    Sets a distance to the far clipping plane of the player's viewing frustum.

    Arguments

    • float zfar - New distance in units. If a negative value is provided, 0 will be used instead.

    float getZFar ( ) #

    Returns the current distance to the far clipping plane of the player's viewing frustum.

    Return value

    Distance in units.

    void setZNear ( float znear ) #

    Sets a distance to the near clipping plane of the player's viewing frustum.

    Arguments

    • float znear - New distance in units. If a negative value is provided, 0 will be used instead.

    float getZNear ( ) #

    Returns the current distance to the near clipping plane of the player's viewing frustum.

    Return value

    Distance in units.

    void flushTransform ( ) #

    Forces to immediately set transformations to the player. This function should be called manually after user input has been updated via updateControls().

    void updateControls ( float ifps ) #

    Gets the current player's parameters (impulse, direction, velocity etc) according to user input. After the input has been updated, flushTransform() should be called manually to apply it to the player.

    Arguments

    • float ifps - Frame duration in seconds.

    void setFovMode ( int mode ) #

    Sets the value indicating the type of FOV that is used for the player:
    • For the standard player, the vertical FOV should be set. In this case, FOV is directly set in degrees.
    • For the physically-based player, the horizontal FOV should be set. In this case, FOV is calculated depending on the film gate and focal length of the player.

    Arguments

    int getFovMode ( ) #

    Sets the value indicating the type of FOV that is used for the player.

    Return value

    0 if the player with the vertical FOV is used; 1 if the physically-based player with the horizontal FOV is used.

    void setFilmGate ( float gate ) #

    Sets a film gate for the physically-based camera with horizontal FOV.

    Arguments

    • float gate - Film gate.

    float getFilmGate ( ) #

    Returns a film gate for the physically-based camera with horizontal FOV.

    Return value

    Film gate.

    void setFocalLength ( float length ) #

    Sets a focal length of the physically-based camera lens.

    Arguments

    • float length - Camera lens focal length.

    float getFocalLength ( ) #

    Returns the focal length of the physically-based camera lens.

    Return value

    Camera lens focal length.

    mat4 getAspectCorrectedProjection ( int width = -1, int height = -1 ) #

    Returns projection matrix after correction for the specified aspect ratio (screen width / screen height). Currently fixed FOV component is taken into account.

    Arguments

    • int width - Screen width.
    • int height - Screen height.

    Return value

    Projection matrix after correction for the specified aspect ratio (screen width / screen height).

    int getFovFixed ( ) #

    Returns a value indicating which FOV component (horizontal or vertical) is currently fixed.

    Return value

    Current fixed FOV component, one of the CAMERA_FOV_FIXED_* values.

    void addScriptableMaterial ( Material material ) #

    Attaches a new scriptable material to the player. To apply a scriptable material globally, use the addScriptableMaterial() method of the Render class. The order of execution for scripts assigned to scriptable materials is defined by material's number in the list of the player.
    Notice
    Scriptable materials applied globally have their expressions executed before the ones that are applied per-player.

    Arguments

    • Material material - Scriptable material to be attached to the player.

    void removeScriptableMaterial ( int num ) #

    Removes the scriptable material with the specified number from the player.

    Arguments

    int getNumScriptableMaterials ( ) #

    Returns the total number of scriptable materials attached to the player.

    Return value

    Total number of scriptable materials attached to the player.

    int findScriptableMaterial ( Material material ) #

    Returns the number of the specified scriptable material for the player. This number is player-specific (valid for this player only) and determines the order in which the assigned expressions are executed.
    Notice
    Scriptable materials applied globally have their expressions executed before the ones that are applied per-player.

    Arguments

    • Material material - Scriptable material for which a number is to be found.

    Return value

    Scriptable material number in the range from 0 to the total number of scriptable materials, or -1 if the specified material was not found.

    void setScriptableMaterial ( int num, Material material ) #

    Replaces the scriptable material with the specified number with the new scriptable material specified. The number of material determines the order in which the expressions assigned to it are executed. This number is player-specific (valid for this player only).
    Notice
    Scriptable materials applied globally have their expressions executed before the ones that are applied per-player.

    Arguments

    • int num - Scriptable material number in the range from 0 to the total number of scriptable materials.
    • Material material - New scriptable material to replace the one with the specified number.

    Material getScriptableMaterial ( int num ) #

    Returns a scriptable material attached to the player by its number.

    Arguments

    Return value

    Scriptable material attached to the player with the specified number.

    void setScriptableMaterialEnabled ( int num, int enabled ) #

    Enables or disables the scriptable material with the specified number. When a material is disabled (inactive), the scripts attached to it are not executed.

    Arguments

    • int num - Scriptable material number in the range from 0 to the total number of scriptable materials.
    • int enabled - 1 to enable the scriptable material with the specified number, 0 to disable it.

    int getScriptableMaterialEnabled ( int num ) #

    Returns a value indicating if the scriptable material with the specified number attached to the player is enabled (active). When a material is disabled (inactive), the scripts attached to it are not executed.

    Arguments

    Return value

    1 if the scriptable material with the specified number is enabled; otherwise, 0.

    void swapScriptableMaterials ( int num_0, int num_1 ) #

    Swaps two scriptable materials with specified numbers. The number of material determines the order in which the expressions assigned to it are executed.
    Notice
    The number is player-specific (valid for this player only).

    Arguments

    void clearScriptableMaterials ( ) #

    Clears all scriptable materials attached to the player.

    void setMainPlayer ( int player ) #

    Sets a player as a main player.

    Arguments

    • int player - Pointer to the player

    int isMainPlayer ( ) #

    Checks if the indicated player is a main player.

    Return value

    1 if the player is a main player; otherwise, 0.
    Last update: 2020-06-16
    Build: ()