This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
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
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Art Samples
Tutorials
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 bool Update()
{
	/* ... */

	// get delta time value

	float delta_time = Game.IFps;

	// 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.WorldRotate(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 ( quat q ) #

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

Arguments

  • quat q - Source quaternion.

quat ( vec3 axis, float angle ) #

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

Arguments

  • 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 ( vec3 col0, vec3 col1, vec3 col2 ) #

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

Arguments

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

quat ( ) #

Constructor. Initializes the quaternion.

quat ( mat4 m ) #

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

Arguments

  • mat4 m - Source matrix (4x4).

quat ( dmat4 m ) #

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

Arguments

  • dmat4 m - Source matrix (3x4).

quat ( float[] q ) #

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

Arguments

  • float[] q - Pointer to the quaternion.

quat Normalize ( ) #

Returns normalized quaternion.

Return value

Normalized quaternion.

quat NormalizeValid ( ) #

Normalizes a quaternion, makes its magnitude equal to 1. When normalized, a quaternion keeps the same direction but its length is equal to 1. Check for the zero quaternion is performed: if the argument is a zero quaternion, then a zero quaternion is returned.

Return value

Normalized quaternion.

quat NormalizeFast ( ) #

Returns normalized quaternion, calculated using the fast inverse square root algorithm.

Return value

Normalized quaternion.

quat NormalizeValidFast ( ) #

Returns normalized quaternion, calculated using the fast inverse square root algorithm. Check for the zero quaternion is performed: if the argument is a zero quaternion, then a zero quaternion is returned.

Return value

Normalized quaternion.

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 ) #

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

Arguments

  • int i - Quaternion item index.

Return value

Quaternion item.
Last update: 2021-04-29
Build: ()