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$vectorThe vector to construct the quaternion from.
- returns
-
\QuatThe constructed quaternion.
fromMat4¶
Constructs and returns a new quaternion based on the given Mat4 matrix
- arguments
-
\Mat4$matrixThe matrix to construct the quaternion from.
- returns
-
\QuatThe constructed quaternion.
inverted¶
Constructs and return a inverted quaternion based on the given one
- arguments
-
\Quat$quatThe quaternion to invert.
- returns
-
\QuatThe inverted quaternion.
normalized¶
Constructs and returns a normalized quaternion based on the given one
- arguments
-
\Quat$quatThe quaternion to normalize.
- returns
-
\QuatThe normalized quaternion.
mix¶
Performs a linear interpolation between two quaternions and returns the resulting quaternion.
- arguments
-
\Quat$leftThe left quaternion.\Quat$rightThe right quaternion.float$tThe interpolation factor.
- returns
-
\QuatThe interpolated quaternion.
slerp¶
Performs a spherical linear interpolation between two quaternions and returns the resulting quaternion.
- arguments
-
\Quat$leftThe left quaternion.\Quat$rightThe right quaternion.float$tThe interpolation factor.
- returns
-
\QuatThe interpolated quaternion.
dot¶
Returns the dot product of two quaternions.
- arguments
-
\Quat$leftThe left quaternion.\Quat$rightThe right quaternion.
- returns
-
floatThe 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
-
\Vec3The euler angles.
rotate¶
Rotates the quaternion by the given angle (in radians) around the given axis
- arguments
-
float$angleThe angle to rotate by (in radians)\Vec3$axisThe 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
-
\Mat4The matrix representation of the quaternion.