Getting Started
Migrating to UNIGINE 2.0
C++ API Migration
UnigineScript
The Language
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

Type Conversion Functions

See Also

Variable dmat4 (double x, double y, double z)

Casts values to the dmat4 type, returning a translation matrix.

Arguments

  • double x - X component of the translation vector.
  • double y - Y component of the translation vector.
  • double z - Z component of the translation vector.

Return value

Translation matrix.

Variable dmat4 (variable v)

Casts a value to the dmat4 type. The last of the matrix is always (0,0,0,1).

Arguments

  • variable v - Target value. Can be of the following types:
    • int (all elements of the matrix except for last row will be equal to the argument)
    • long
    • float
    • double
    • vec3 (see translate() function)
    • dvec3 (see translate() function)
    • mat4
    • dmat4
    • quat
      Notice
      If the quat is the mesh compressed tangent vector, you should normalize it before converting into the mat4. See the example for more details.
    • string — it should contain 16 floating point values separated with whitespace characters, for example:
      Source code (UnigineScript)
      dmat4 a = dmat4(string("1 0 0 9 0 1 0 9 0 0 1 9 0 0 0 9"));
      dmat4 b = dmat4(string("1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 875765"));
      /*	a and b will be identical matrices in the result:
      1 0 0 0
      0 1 0 0
      0 0 1 0
      0 0 0 1
      */
      

Return value

Converted value.

Variable dmat4 (variable v1, variable v2)

Casts values to the dmat4 type, returning a rotation matrix. The casted values can be of the following types:
  • Rotation axis and rotation angle: vec3 or dvec3 as the first argument and float as a second one.
  • Rotation and position: quat as the first argument and dvec3 as a second one.

Arguments

  • variable v1 - Rotation axis (vec3, dvec3) or rotation (quat).
  • variable v2 - Rotation angle in degrees (float) if the first argument is vec3 or dvec3 or position (dvec3) if the first argument is quat.

Return value

Rotation matrix.

Variable dmat4 (variable v0, variable v1, variable v2, variable v3)

Casts values to the dmat4 type. If the type of the received arguments is float, the function will return a rotation matrix.

Arguments

  • variable v0 - Argument of one of the following types:
    • dvec3 - The first column vector that will be used in calculation of the first column of the matrix.
    • float - X component of the rotation axis.
  • variable v1 - Argument of one of the following types:
    • dvec3 - The second column vector that will be used in calculation of the second column of the matrix.
    • float - Y component of the rotation axis.
  • variable v2 - Argument of one of the following types:
    • dvec3 - The third column vector that will be used in calculation of the third column of the matrix.
    • float - Z component of the rotation axis.
  • variable v3 - Argument of one of the following types:
    • dvec3 - The fourth column vector that will be used in calculation of the fourth column of the matrix.
    • float - Rotation angle in degrees.

Return value

  • Converted value if the type of arguments is dvec3.
  • Rotation matrix, if the type of arguments is float.

Examples

For example, if you pass column vectors to the dmat4(), you will get the following result:

Source code (UnigineScript)
dmat4 mat = dmat4(dvec3_one,dvec3_one * 5.0f,dvec3_one * 10.0f,dvec3_one * 15.0f);
 
log.message("%s\n",string(mat.m00m01m02m03));
log.message("%s\n",string(mat.m10m11m12m13));
log.message("%s\n",string(mat.m20m21m22m23));
log.message("%s\n",string(mat.m30m01m32m33));
						
Output
1 5 10 15
1 5 10 15
1 5 10 15
0 5  0  1
						

Variable double (variable v)

Casts a value to the double type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int
    • long
    • float
    • double
    • string - its first non-whitespace characters should form a double precision floating point number. Additional characters after it will be ignored. inf and -inf are also convertible. For example:
      Source code (UnigineScript)
      double a = double(string("-0.05"));         // a = -0.05
      double b = double(string("0.87354f 1.0f")); // b = 0.87354
      double c = double(string("inf"));           // c = 1E+9f
      

Return value

Converted value.

Variable dvec3 (double x, double y, double z)

Casts values to the dvec3 type.

Arguments

  • double x - X component of the vector.
  • double y - Y component of the vector.
  • double z - Z component of the vector.

Return value

Converted value.

Variable dvec3 (variable v)

Casts values to the dvec3 type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int (all components will be equal to the argument)
    • long
    • float
    • double
    • vec3
    • vec4 (w component of the vector will be omitted)
    • dvec3
    • dvec4 (w component of the vector will be omitted)
    • ivec3
    • string - it should contain 3 double precision floating point numbers separated with whitespace characters, for example:
      Source code (UnigineScript)
      dvec3 a = dvec3(string("8.5 8.5 -0.847657946"));      // a = 8.5 8.5 -0.847657946
      dvec3 b = dvec3(string("10.5f character 1 75476.5")); // b = 10.5 0.0 1.0
      

Return value

Converted value.

Variable dvec4 (double x, double y, double z, double w)

Casts values to the dvec4 type.

Arguments

  • double x - X component of the vector.
  • double y - Y component of the vector.
  • double z - Z component of the vector.
  • double w - W component of the vector.

Return value

Converted value.

Variable dvec4 (variable v)

Casts values to the dvec4 type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int (all components of the vector will be equal to the argument)
    • long
    • float
    • double
    • vec3 (w component of the vector will be equal to 1)
    • vec4
    • dvec3 (w component of the vector will be equal to 1)
    • dvec4
    • ivec4
    • string — it should contain 4 double precision floating point numbers separated with whitespace characters, for example:
      Source code (UnigineScript)
      dvec4 a = dvec4(string("0.5 0.5 -0.5 74567576.0"));      // a = 0.5 0.5 -0.5 74567576.0
      dvec4 b = dvec4(string("10.5f character 1 2 85646.02")); // b = 10.5 0.0 1.0 2.0
      

Return value

Converted value.

Variable dvec4 (variable Variable, double w)

Casts values to the dvec4 type.

Arguments

  • variable Variable - Vector with the first three components (either vec3 or dvec3).
  • double w - W component of the vector.

Return value

Converted value.

variable float (variable v)

Casts a value to the float type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int
    • long
    • float
    • double
    • string — its first non-whitespace characters should form a floating point number. Additional characters after it will be ignored. inf and -inf are also convertible. For example:
      Source code (UnigineScript)
      float a = float(string("0.5"));     // a = 0.5
      float b = float(string("10.5 45")); // b = 10.5
      float c = float(string("inf"));     // c = 1E+9f
      

Return value

Converted value.

variable int (variable v)

Casts a value to the int type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int
    • long
    • float
    • double
    • string — its first non-whitespace characters should form an integer number. Additional characters after it will be ignored. For example:
      Source code (UnigineScript)
      int a = int(string("3"));    // a = 3
      int b = int(string("0.4"));  // b = 0
      int c = int(string("3 42")); // c = 3
      

Return value

Converted value.

variable ivec3 (int x, int y, int z)

Casts values to the ivec3 type.

Arguments

  • int x - X component of the vector.
  • int y - Y component of the vector.
  • int z - Z component of the vector.

Return value

Converted value.

Variable ivec3 (variable v)

Casts a value to the ivec3 type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int (all components will be equal to the argument)
    • long
    • float
    • double
    • vec3
    • dvec3
    • ivec3
    • string - it should contain 3 integer numbers separated with whitespace characters, for example:
      Source code (UnigineScript)
      ivec3 a = ivec3(string("1 -1 42"));               // a = 1 -1 42
      ivec3 b = ivec3(string("10.5f character 1 768")); // b = 10 0 1
      

Return value

Converted value.

Variable ivec4 (int x, int y, int z, int w)

Casts values to the ivec4 type.

Arguments

  • int x - X component of the vector.
  • int y - Y component of the vector.
  • int z - Z component of the vector.
  • int w - W component of the vector.

Return value

Converted value.

Variable ivec4 (variable v)

Casts a value to the ivec4 type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int (all components of the vector will be equal to the argument)
    • long
    • float
    • double
    • vec4
    • dvec4
    • ivec4
    • string — it should contain 4 integer numbers separated with whitespace characters, for example:
      Source code (UnigineScript)
      ivec4 a = ivec4(string("1 1 1 -1"));                // a = 1 1 1 -1
      ivec4 b = ivec4(string("10.5f character 1 2 658")); // b = 10 0 1 2
      

Return value

Converted value.

Variable long (variable v)

Casts a value to the long type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int
    • long
    • float
    • double
    • string - its first non-whitespace characters should form a floating point number. Additional characters after it will be ignored. For example:
      Source code (UnigineScript)
      long a = long(string("8757656")); // a = 8757656
      long b = long(string("34.5"));    // b = 34
      long c = long(string("3 42"));    // c = 3
      

Return value

Converted value.

variable mat4 (float x, float y, float z)

Casts values to the mat4 type, returning a translation matrix.

Arguments

  • float x - X component of the translation vector.
  • float y - Y component of the translation vector.
  • float z - Z component of the translation vector.

Return value

Translation matrix.

Examples

Source code (UnigineScript)
mat4 a;
a = mat4(1,2,3);
/*	translation matrix:
1 0 0 1
0 1 0 2
0 0 1 3
0 0 0 1
*/

variable mat4 (variable v)

Casts a value to the mat4 type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int (all elements of the matrix will be equal to the argument)
    • long
    • float
    • double
    • vec3 (see translate() function)
    • dvec3 (see translate() function)
    • mat4
    • dmat4
    • quat
      Notice
      If the quat is the mesh compressed tangent vector, you should normalize it before converting into the mat4. See the example for more details.
    • string — it should contain 16 floating point values separated with whitespace characters, for example:
      Source code (UnigineScript)
      mat4 a = mat4(string("1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"));
      mat4 b = mat4(string("1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 875765"));
      /*	a and b will be identical matrices in the result:
      1 0 0 0
      0 1 0 0
      0 0 1 0
      0 0 0 1
      */
      

Return value

Converted value.

Variable mat4 (variable v1, variable v2)

Casts values to the mat4 type, returning a rotation matrix. The casted values can be of the following types:
  • Roation axis and rotation angle: vec3 or dvec3 as the first argument and float as a second one.
  • Roatation and position: quat as the first argument and vec3 or dvec3 as a second one.

Arguments

  • variable v1 - Rotation axis (vec3, dvec3) or rotation (quat).
  • variable v2 - Rotation angle in degrees (float) if the first argument is vec3 or dvec3 or position (vec3 or dvec3) if the first argument is quat.

Return value

Rotation matrix.

Examples

Source code (UnigineScript)
mat4 a;
a = mat4(vec3(1,0,0),45);
/*	rotation matrix:
1 0 0 1
0 0.7 -0.7 0
0 0.7 0.7 0
0 0 0 1
*/

Variable mat4 (variable v0, variable v1, variable v2, variable v3)

Casts values to the mat4 type. If the type of the received arguments is float, the function will return a rotation matrix.

Arguments

  • variable v0 - Argument of one of the following types:
    • vec4 - The first column vector that will be used in calculation of the first column of the matrix.
    • float - X component of the rotation axis.
  • variable v1 - Argument of one of the following types:
    • vec4 - The second column vector that will be used in calculation of the second column of the matrix.
    • float - Y component of the rotation axis.
  • variable v2 - Argument of one of the following types:
    • vec4 - The third column vector that will be used in calculation of the third column of the matrix.
    • float - Z component of the rotation axis.
  • variable v3 - Argument of one of the following types:
    • vec4 - The fourth column vector that will be used in calculation of the fourth column of the matrix.
    • float - Rotation angle in degrees.

Return value

  • Converted value if the type of arguments is vec4.
  • Rotation matrix, if the type of arguments is float.

Examples

For example, if you pass column vectors to the mat4(), you will get the following result:

Source code (UnigineScript)
mat4 mat = mat4(vec4_one,vec4_one * 5.0f,vec4_one * 10.0f,vec4_one * 15.0f);
 
log.message("%s\n",string(mat.m00m01m02m03));
log.message("%s\n",string(mat.m10m11m12m13));
log.message("%s\n",string(mat.m20m21m22m23));
log.message("%s\n\n",string(mat.m30m01m32m33));
						
Output
1 5 10 15
1 5 10 15
1 5 10 15
1 5 10 15
						

variable quat (float x, float y, float z, float angle)

Casts values to the quat type, returning a rotation description.

Arguments

  • float x - X component of the rotation axis.
  • float y - Y component of the rotation axis.
  • float z - Z component of the rotation axis.
  • float angle - Rotation angle in degrees.

Return value

Converted value representing a rotation.

variable quat (variable v)

Casts a value to the quat type.

Arguments

  • variable v - Target value. Can be of the following types:
    • vec4
    • mat4
    • dmat4
    • quat
    • string — it should contain 4 floating point numbers separated with whitespace characters, for example:
      Source code (UnigineScript)
      quat a = quat(string("0.0 0.0 0.0 1.0"));     // a = 0.0 0.0 0.0 1.0
      quat b = quat(string("2.5 character 2 2 564")); // a = 2.5 0.0 2.0 2.0
      

Return value

Converted value.

Variable quat (variable axis, float angle)

Casts values to the quat type, returning a rotation description.

Arguments

  • variable axis - Rotation axis (vec3 or dvec3).
  • float angle - Rotation angle in degrees.

Return value

Converted value representing a rotation.

Variable quat (variable v0, variable v1, variable v2)

Casts values to the quat type, returning a rotation description.

If the type of received arguments is vec3, the matrix constructed from this vectors will be converted into the quaternion.

Notice
Each column vector (vec3) corresponds to the column of this matrix.

Arguments

  • variable v0 - Argument of one of the following types:
    • vec3 - The first column vector.
    • float - Roll component of the rotation.
  • variable v1 - Argument of one of the following types:
    • vec3 - The second column vector.
    • float - Pitch component of the rotation.
  • variable v2 - Argument of one of the following types:
    • vec3 - The third column vector.
    • float - Yaw component of the rotation.

Return value

Converted value representing a rotation.

variable string (variable v)

Casts a value to the string type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int
    • long
    • float
    • double
    • vec3
    • vec4
    • dvec3
    • dvec4
    • mat4 (will be written in the column-major order)
    • dmat4 (will be written in the column-major order)
    • quat
    • string

Return value

String representation of the target value.

Examples

Source code (UnigineScript)
string c = string(vec3(1,2,3));   // c = "1 2 3"
string d = string(vec4(1,2,3,4)); // d = "1 2 3 4"
string e = string(quat(1,2,3,4)); // e = "0.00932728 0.0186546 0.0279819 0.999391"
string f = string(mat4(1,2,3));   // f = "1 0 0 0 0 1 0 0 0 0 1 0 1 2 3 1"
// the last row of dmat4 is not stored and is always equal to "0 0 0 1"
string g = string(dmat4("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16")); // g = "1 2 3 0 5 6 7 0 9 10 11 0 13 14 15 1"

Variable string (variable v, int arg)

Casts a given value to the string type.
  • If the type of the argument to be converted is int or long, you should also specify the base radix value. By default, it is 10.
  • In case of any other type, you should pass the number of decimal places displayed.

Arguments

  • variable v - Value to be casted. It can be one of the following types:
    • int
    • long
    • float
    • double
    • vec3
    • vec4
    • dvec3
    • dvec4
    • ivec3
    • ivec4
    • quat
    • string
  • int arg - Argument that receives one of the following values:
    • The base radix value. By default, it is 10.
    • Number of decimal places displayed.

Return value

String representation of the given value.

Examples

The following example demonstrates conversion of the int value with the different base radix values:

Source code (UnigineScript)
log.message("Decimal notation: %s\n",string(10));
log.message("Binary notation: %s\n",string(10,2));
log.message("Octal notation: %s\n",string(10,8));
log.message("Hexadecimal notation: %s\n",string(10,16));
						
Output
Decimal notation: 10
Binary notation: 1010
Octal notation: 12
Hexadecimal notation: a
						

variable vec3 (float x, float y, float z)

Casts values to the vec3 type.

Arguments

  • float x - X component of the vector.
  • float y - Y component of the vector.
  • float z - Z component of the vector.

Return value

Converted value.

variable vec3 (variable v)

Casts a value to the vec3 type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int (all components will be equal to the argument)
    • long
    • float
    • double
    • vec3
    • vec4 (w component of the vector will be omitted)
    • dvec3
    • dvec4 (w component of the vector will be omitted)
    • ivec3
    • string - it should contain 3 floating point numbers separated with whitespace characters, for example:
      Source code (UnigineScript)
      vec3 a = vec3(string("1.5 1.5 -0.676"));         // a = 1.5 1.5 -0.676
      vec3 b = vec3(string("10.5f character 1 78.7")); // b = 10.5 0.0 1.0
      

Return value

Converted value.

variable vec4 (float x, float y, float z, float w)

Casts values to the vec4 type.

Arguments

  • float x - X component of the vector.
  • float y - Y component of the vector.
  • float z - Z component of the vector.
  • float w - W component of the vector.

Return value

Converted value.

variable vec4 (variable v)

Casts a value to the vec4 type.

Arguments

  • variable v - Target value. Can be of the following types:
    • int (all components of the vector will be equal to the argument)
    • long
    • float
    • double
    • vec3 (w component of the vector will be equal to 1)
    • vec4
    • dvec3 (w component of the vector will be equal to 1)
    • dvec4
    • ivec4
    • quat
    • string — it should contain 4 floating point numbers separated with whitespace characters, for example:
      Source code (UnigineScript)
      vec4 a = vec4(string("0.5 -0.5 7456.0"));            // a = 0.5 0.5 -0.5 7456.0
      vec4 b = vec4(string("10.5f character 1 2 856.02")); // b = 10.5 0.0 1.0 2.0
      

Return value

Converted value.

Variable vec4 (variable Variable, float w)

Casts values to the vec4 type.

Arguments

  • variable Variable - Vector with the first three components (either vec3 or dvec3).
  • float w - W component of the vector.

Return value

Converted value.
Last update: 2017-07-03