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
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-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.quat Struct

This class represents a quaternion type. Quaternions represent a rotation. Typically, they are used for smooth interpolation between two angles, and for avoiding the gimbal lock problem that can occur with euler angles.

Quaternions add a fourth element to the [ x, y, z] values that define a vector, resulting in arbitrary 4-D vectors. The following example illustrates how each element of a unit quaternion relates to an axis-angle rotation, where q represents a unit quaternion (x, y, z, w), axis is normalized, and theta is the desired counterclockwise (CCW) rotation around the axis:

  • q.x = sin(theta/2) * axis.x
  • q.y = sin(theta/2) * axis.y
  • q.z = sin(theta/2) * axis.z
  • q.w = cos(theta/2)

Usage Example

The following example creates a quaternion for node rotation: 60 degrees per second along Z axis.

Notice
It's supposed that you have already created node instance to rotate.
Source code (C#)
// AppWorldLogic.cs file

public override int update()
{
	/* ... */

	// get Game instance and delta time value
	Game game = Game.get();
	float delta_time = game.getIFps();

	// create quat for 60 degrees per second rotation along Z axis
	quat rotation_delta = new quat(0.0f, 0.0f, 1.0f, 60 * delta_time);

	// rotate the node
	node.setWorldRotation(node.getWorldRotation() * rotation_delta);

	/* ... */
}

In the example above, the quaternion was initialized by using four values: 3 axis components (x,y,z) and angle (w component of the quaternion). 1 value of the Z axis component shows that the rotation will be performed along Z axis.

See Also

quat Class

Members


quat()

Default constructor. Produces an identity quaternion (0.0, 0.0, 0.0, 1.0).

quat(const quat & q)

Constructor. Initializes the quaternion by copying a given source quaternion.

Arguments

  • const quat & q - Source quaternion.

quat(const vec3 & axis, float angle)

Constructor. Initializes the quaternion using given rotation axis and angle.

Arguments

  • const vec3 & axis - Rotation axis.
  • float angle - Rotation angle, in degrees.

quat(float angle_x, float angle_y, float angle_z)

Constructor. Initializes the quaternion using given angles for each axis.

Arguments

  • float angle_x - Rotation angle along the X axis, in degrees.
  • float angle_y - Rotation angle along the Y axis, in degrees.
  • float angle_z - Rotation angle along the Z axis, in degrees.

quat(const vec3 & col0, const vec3 & col1, const vec3 & col2)

Constructor. Initializes the quaternion using three given matrix columns represented by vec3 vectors.

Arguments

  • const vec3 & col0 - First matrix column.
  • const vec3 & col1 - Second matrix column.
  • const vec3 & col2 - Third matrix column.

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

Constructor. Initializes the quaternion using given float values.

Arguments

  • float x - X component of the quaternion.
  • float y - Y component of the quaternion.
  • float z - Z component of the quaternion.
  • float angle - W component of the quaternion.

explicit quat(const mat4 & m)

Constructor. Initializes the quaternion using a given mat4 source matrix (4x4).

Arguments

  • const mat4 & m - Source matrix (4x4).

explicit quat(const dmat4 & m)

Constructor. Initializes the quaternion using a given dmat4 source matrix (3x4).

Arguments

  • const dmat4 & m - Source matrix (3x4).

explicit quat(const float * q)

Constructor. Initializes the vector using a given pointer to the quaternion.

Arguments

  • const float * q - Pointer to the quaternion.

void set(float x, float y, float z, float angle)

Sets the quaternion by components.

Arguments

  • float x - X component of the quaternion.
  • float y - Y component of the quaternion.
  • float z - Z component of the quaternion.
  • float angle - W component of the quaternion.

Examples

Source code (UnigineScript)
quat(1.0, 2.0, 3.0, 60);
/*
Creates a quaternion (1.0, 2.0, 3.0, 60)
*/

void set(const float * qq)

Sets the quaternion using a given pointer to the source quaternion.

Arguments

  • const float * qq - Pointer to the source quaternion.

void get(float * qq) const

Gets the quaternion: qq[0]=x, qq[1]=y, qq[2]=z, qq[3]=w.

Arguments

  • float * qq - Pointer to the quaternion.

float * get()

Returns a pointer to the quaternion.

Return value

Pointer to the quaternion.

const float * get() const

Returns a constant pointer to the quaternion.

Return value

Constant pointer to the quaternion.

vec3 getBinormal() const

Returns the quaternion binormal vector with respect to orientation.

Return value

Quaternion binormal vector.

vec3 getNormal() const

Returns the quaternion normal vector.

Return value

Quaternion normal vector.

vec3 getTangent() const

Returns the quaternion tangent vector.

Return value

Quaternion tangent vector.

vec4 getTangent4() const

Returns the quaternion tangent vector and binormal orientation as a four-component vec4 vector.

Return value

Four-component vector representing guaternion tangent vector and binormal orientation.

float & operator[](int i)

Performs array access to the quaternion item reference by using given item index.

Arguments

  • int i - Quaternion item index.

Return value

Quaternion item reference.

float operator[](int i) const

Performs array access to the quaternion item by using given item index.

Arguments

  • int i - Quaternion item index.

Return value

Quaternion item.

int IDENTITY

Description

Quaternion representing no rotation (0.0, 0.0, 0.0, 1.0).

int ZERO

Description

Zero quaternion (0.0, 0.0, 0.0, 0.0).
Last update: 2018-08-10
Build: ()