quaternion
Quaternion, used to represent rotations.
Derives from: numarray_stack<float,4> (vec4)
Fields and methods
Members of the struct quaternion. Most of what you do with a CGP type goes through the free functions listed below.
Inherited from vec4 (18 members)
Fields
T x | First coordinate of the vector. |
T y | Second coordinate of the vector. |
T z | Third coordinate of the vector. |
T w | Fourth coordinate of the vector. |
Methods
| Number of components N, fixed at compile time. src | |
| Sets the N components to the given value and returns the vector. src | |
| Returns the element at index, bound-checked unless CGP_NO_DEBUG is defined. src | |
| Returns a const reference to the element at the given index, with bound checking unless CGP_NO_DEBUG is defined. src | |
| Returns a const reference to the element at the given index; bound-checked for sizes 2, 3 and 4 (vec2, vec3, vec4) unless CGP_NO_DEBUG is defined, but not checked for the other sizes N. src | |
| Returns a const iterator to the first element (a plain pointer for sizes 2, 3 and 4). src | |
| Returns a const iterator one past the last element (a plain pointer for sizes 2, 3 and 4). src | |
| Returns a const iterator to the first element (a plain pointer for sizes 2, 3 and 4). src | |
| Returns a const iterator one past the last element (a plain pointer for sizes 2, 3 and 4). src | |
| Returns a const reference to the element at the given index, without bound checking. src | |
| Returns a copy of the first three coordinates (x, y, z) as a vec3. src | |
| Returns a copy of the coordinates (x, y) as a 2D vector (for vec3 and vec4). src | |
| Returns a copy of the coordinates (y, z) as a 2D vector (for vec3 and vec4). src | |
| Returns a copy of the coordinates (x, z) as a 2D vector (for vec3 and vec4). src |
Functions taking a quaternion
Construct 1
Documented on another page
tensor_productOuter product a * transpose(b), as a 4x4 matrix.onmat4
Transform 3
quaternion conjugate(quaternion const& q)Quaternion conjugate (= inverse for a unit quaternion).
Convert 3
Documented on another page
type_strx22 overloadsonvec4
Access 2
Documented on another page
check_index_boundsRaises an error if the index is outside [0, 3]; no-op when CGP_NO_DEBUG is defined.onvec4getComponent idx with the index checked at compile time (static_assert).onvec4
Other 1
Documented on another page
opengl_uniformSend a vec4 uniform to the shader; warns if the uniform is not found and expected is true.onopengl_shader_structure
Functions returning a quaternion
None.
Operators
Show the 17 operators (+, -, *, ==, ...)
operator*
3 overloadsquaternion operator*(quaternion const& a, quaternion const& b)sourceQuaternion (Hamilton) product, with the scalar part stored in w.
quaternion operator*(quaternion const& a, float b)sourceQuaternion with each component multiplied by a scalar.
quaternion operator*(float a, quaternion const& b)sourceQuaternion with each component multiplied by a scalar.
quaternion& operator*=(quaternion& a, quaternion const& b)In-place quaternion (Hamilton) product a = a * b.
quaternion operator+(quaternion const& a, quaternion const& b)Component-wise sum of two quaternions.
quaternion& operator+=(quaternion& a, quaternion const& b)In-place component-wise sum of two quaternions.
quaternion operator-(quaternion const& a, quaternion const& b)Component-wise difference of two quaternions.
quaternion& operator-=(quaternion& a, quaternion const& b)In-place component-wise difference of two quaternions.
operator/
3 overloadsquaternion operator/(quaternion const& a, quaternion const& b)sourceQuaternion division a * inverse(b).
quaternion operator/(quaternion const& a, float b)sourceQuaternion with each component divided by a scalar.
quaternion operator/(float a, quaternion const& b)sourceScalar times the inverse quaternion, a * inverse(b).
quaternion& operator/=(quaternion& a, quaternion const& b)In-place quaternion division a = a * inverse(b).
std::istream& operator>>(std::istream& stream, quaternion& data)Read the four components x y z w of a quaternion from a stream.
Documented on another page
operator*Apply the affine transform to a homogeneous vector, the translation being weighted by w: a direction (w=0) is not translated.onaffineoperator*Apply the rigid transform to a homogeneous vector, the translation being weighted by w.onaffine_rtoperator*Apply the transform to a homogeneous vector, the translation being weighted by w.onaffine_rtsoperator*Homogeneous vector whose xyz part is rotated, w being kept.onrotation_transform