Quat - GL Math¶
PHP-GLFW comes with a built-in math library this is a quick reference for the Quat
class.
The Quat
represents a vector with 4 components (w
, x
, y
, z
, ),
which can be and is generally used to represent rotations.
namespace GL\Math
{
class Quat {
public float $w;
public float $x;
public float $y;
public float $z;
}
}
The properties of this class are virtual, meaning in this case they are not real PHP properties. But rather values stored internally that can be accessed like a property. The same values can be read and written using different names:
Is exactly the same as:
Methods¶
__construct
¶
Constructor
fromVec4
¶
Constructs and returns a new quaternion based on the given Vec4 vector.
The quaternion is arragned as (w, x, y, z), while the vector is arranged as (x, y, z, w). This method will swap the x and w components.
- arguments
-
\Vec4
$vector
The vector to construct the quaternion from.
- returns
-
\Quat
The constructed quaternion.
fromMat4
¶
Constructs and returns a new quaternion based on the given Mat4 matrix
- arguments
-
\Mat4
$matrix
The matrix to construct the quaternion from.
- returns
-
\Quat
The constructed quaternion.
inverted
¶
Constructs and return a inverted quaternion based on the given one
- arguments
-
\Quat
$quat
The quaternion to invert.
- returns
-
\Quat
The inverted quaternion.
normalized
¶
Constructs and returns a normalized quaternion based on the given one
- arguments
-
\Quat
$quat
The quaternion to normalize.
- returns
-
\Quat
The normalized quaternion.
mix
¶
Performs a linear interpolation between two quaternions and returns the resulting quaternion.
- arguments
-
\Quat
$left
The left quaternion.\Quat
$right
The right quaternion.float
$t
The interpolation factor.
- returns
-
\Quat
The interpolated quaternion.
slerp
¶
Performs a spherical linear interpolation between two quaternions and returns the resulting quaternion.
- arguments
-
\Quat
$left
The left quaternion.\Quat
$right
The right quaternion.float
$t
The interpolation factor.
- returns
-
\Quat
The interpolated quaternion.
dot
¶
Returns the dot product of two quaternions.
- arguments
-
\Quat
$left
The left quaternion.\Quat
$right
The right quaternion.
- returns
-
float
The dot product.
normalize
¶
The same as normalized()
, but modifies the current quaternion instead of creating a new one.
length
¶
Returns the length of the quaternion
eulerAngles
¶
Returns the quaternion represented as euler angles (in radians)
- returns
-
\Vec3
The euler angles.
rotate
¶
Rotates the quaternion by the given angle (in radians) around the given axis
- arguments
-
float
$angle
The angle to rotate by (in radians)\Vec3
$axis
The axis to rotate around
inverse
¶
Invseres the current quaternion, this is basically the same as inverted()
but
modifies the current quaternion instead of creating a new one.
mat4
¶
Constructs a Mat4 matrix based on the current quaternion
- returns
-
\Mat4
The matrix representation of the quaternion.