Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QQuaternion Class Reference

The QQuaternion class represents a quaternion consisting of a vector and scalar. More...

#include <qquaternion.h>

+ Collaboration diagram for QQuaternion:

Public Member Functions

 QQuaternion ()
 Constructs an identity quaternion (1, 0, 0, 0), i.e.
 
 QQuaternion (Qt::Initialization)
 
 QQuaternion (float scalar, float xpos, float ypos, float zpos)
 Constructs a quaternion with the vector (xpos, ypos, zpos) and scalar.
 
 QQuaternion (float scalar, const QVector3D &vector)
 Constructs a quaternion vector from the specified vector and scalar.
 
 QQuaternion (const QVector4D &vector)
 Constructs a quaternion from the components of vector.
 
bool isNull () const
 Returns true if the x, y, z, and scalar components of this quaternion are set to 0.0; otherwise returns false.
 
bool isIdentity () const
 Returns true if the x, y, and z components of this quaternion are set to 0.0, and the scalar component is set to 1.0; otherwise returns false.
 
QVector3D vector () const
 Returns the vector component of this quaternion.
 
void setVector (const QVector3D &vector)
 Sets the vector component of this quaternion to vector.
 
void setVector (float x, float y, float z)
 Sets the vector component of this quaternion to (x, y, z).
 
float x () const
 Returns the x coordinate of this quaternion's vector.
 
float y () const
 Returns the y coordinate of this quaternion's vector.
 
float z () const
 Returns the z coordinate of this quaternion's vector.
 
float scalar () const
 Returns the scalar component of this quaternion.
 
void setX (float x)
 Sets the x coordinate of this quaternion's vector to the given x coordinate.
 
void setY (float y)
 Sets the y coordinate of this quaternion's vector to the given y coordinate.
 
void setZ (float z)
 Sets the z coordinate of this quaternion's vector to the given z coordinate.
 
void setScalar (float scalar)
 Sets the scalar component of this quaternion to scalar.
 
float length () const
 Returns the length of the quaternion.
 
float lengthSquared () const
 Returns the squared length of the quaternion.
 
QQuaternion normalized () const
 Returns the normalized unit form of this quaternion.
 
void normalize ()
 Normalizes the current quaternion in place.
 
QQuaternion inverted () const
 
QQuaternion conjugated () const
 
QVector3D rotatedVector (const QVector3D &vector) const
 Rotates vector with this quaternion to produce a new vector in 3D space.
 
QQuaternionoperator+= (const QQuaternion &quaternion)
 Adds the given quaternion to this quaternion and returns a reference to this quaternion.
 
QQuaternionoperator-= (const QQuaternion &quaternion)
 Subtracts the given quaternion from this quaternion and returns a reference to this quaternion.
 
QQuaternionoperator*= (float factor)
 Multiplies this quaternion's components by the given factor, and returns a reference to this quaternion.
 
QQuaternionoperator*= (const QQuaternion &quaternion)
 Multiplies this quaternion by quaternion and returns a reference to this quaternion.
 
QQuaternionoperator/= (float divisor)
 Divides this quaternion's components by the given divisor, and returns a reference to this quaternion.
 
QVector4D toVector4D () const
 Returns this quaternion as a 4D vector.
 
 operator QVariant () const
 Returns the quaternion as a QVariant.
 
void getAxisAndAngle (QVector3D *axis, float *angle) const
 
void getAxisAndAngle (float *x, float *y, float *z, float *angle) const
 
QVector3D toEulerAngles () const
 
void getEulerAngles (float *pitch, float *yaw, float *roll) const
 
QMatrix3x3 toRotationMatrix () const
 
void getAxes (QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const
 

Static Public Member Functions

static constexpr float dotProduct (const QQuaternion &q1, const QQuaternion &q2)
 
static QQuaternion fromAxisAndAngle (const QVector3D &axis, float angle)
 Creates a normalized quaternion that corresponds to rotating through angle degrees about the specified 3D axis.
 
static QQuaternion fromAxisAndAngle (float x, float y, float z, float angle)
 Creates a normalized quaternion that corresponds to rotating through angle degrees about the 3D axis (x, y, z).
 
static QQuaternion fromEulerAngles (const QVector3D &eulerAngles)
 
static QQuaternion fromEulerAngles (float pitch, float yaw, float roll)
 
static QQuaternion fromRotationMatrix (const QMatrix3x3 &rot3x3)
 
static QQuaternion fromAxes (const QVector3D &xAxis, const QVector3D &yAxis, const QVector3D &zAxis)
 
static QQuaternion fromDirection (const QVector3D &direction, const QVector3D &up)
 
static QQuaternion rotationTo (const QVector3D &from, const QVector3D &to)
 
static QQuaternion slerp (const QQuaternion &q1, const QQuaternion &q2, float t)
 Interpolates along the shortest spherical path between the rotational positions q1 and q2.
 
static QQuaternion nlerp (const QQuaternion &q1, const QQuaternion &q2, float t)
 Interpolates along the shortest linear path between the rotational positions q1 and q2.
 

Friends

QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE friend bool operator== (const QQuaternion &q1, const QQuaternion &q2) noexcept
 Returns true if q1 is equal to q2; otherwise returns false.
 
bool operator!= (const QQuaternion &q1, const QQuaternion &q2) noexcept
 Returns true if q1 is not equal to q2; otherwise returns false.
 
QT_WARNING_POP friend const QQuaternion operator+ (const QQuaternion &q1, const QQuaternion &q2)
 Returns a QQuaternion object that is the sum of the given quaternions, q1 and q2; each component is added separately.
 
const QQuaternion operator- (const QQuaternion &q1, const QQuaternion &q2)
 Returns a QQuaternion object that is formed by subtracting q2 from q1; each component is subtracted separately.
 
const QQuaternion operator* (float factor, const QQuaternion &quaternion)
 Returns a copy of the given quaternion, multiplied by the given factor.
 
const QQuaternion operator* (const QQuaternion &quaternion, float factor)
 Returns a copy of the given quaternion, multiplied by the given factor.
 
const QQuaternion operator* (const QQuaternion &q1, const QQuaternion &q2)
 Multiplies q1 and q2 using quaternion multiplication.
 
const QQuaternion operator- (const QQuaternion &quaternion)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QQuaternion object that is formed by changing the sign of all three components of the given quaternion.
 
const QQuaternion operator/ (const QQuaternion &quaternion, float divisor)
 Returns the QQuaternion object formed by dividing all components of the given quaternion by the given divisor.
 
bool qFuzzyCompare (const QQuaternion &q1, const QQuaternion &q2)
 Returns true if q1 and q2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.
 

Related Symbols

(Note that these are not member symbols.)

const QQuaternion operator+ (const QQuaternion &q1, const QQuaternion &q2)
 Returns a QQuaternion object that is the sum of the given quaternions, q1 and q2; each component is added separately.
 
const QQuaternion operator- (const QQuaternion &q1, const QQuaternion &q2)
 Returns a QQuaternion object that is formed by subtracting q2 from q1; each component is subtracted separately.
 
const QQuaternion operator* (float factor, const QQuaternion &quaternion)
 Returns a copy of the given quaternion, multiplied by the given factor.
 
const QQuaternion operator* (const QQuaternion &quaternion, float factor)
 Returns a copy of the given quaternion, multiplied by the given factor.
 
const QQuaternion operator* (const QQuaternion &q1, const QQuaternion &q2)
 Multiplies q1 and q2 using quaternion multiplication.
 
const QQuaternion operator- (const QQuaternion &quaternion)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QQuaternion object that is formed by changing the sign of all three components of the given quaternion.
 
const QQuaternion operator/ (const QQuaternion &quaternion, float divisor)
 Returns the QQuaternion object formed by dividing all components of the given quaternion by the given divisor.
 
QVector3D operator* (const QQuaternion &quaternion, const QVector3D &vec)
 
bool qFuzzyCompare (const QQuaternion &q1, const QQuaternion &q2)
 Returns true if q1 and q2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.
 
QDataStreamoperator<< (QDataStream &stream, const QQuaternion &quaternion)
 Writes the given quaternion to the given stream and returns a reference to the stream.
 
QDataStreamoperator>> (QDataStream &stream, QQuaternion &quaternion)
 Reads a quaternion from the given stream into the given quaternion and returns a reference to the stream.
 

Detailed Description

The QQuaternion class represents a quaternion consisting of a vector and scalar.

Since
4.6

\inmodule QtGui

Quaternions are used to represent rotations in 3D space, and consist of a 3D rotation axis specified by the x, y, and z coordinates, and a scalar representing the rotation angle.

Definition at line 20 of file qquaternion.h.

Constructor & Destructor Documentation

◆ QQuaternion() [1/5]

QQuaternion::QQuaternion ( )
inline

Constructs an identity quaternion (1, 0, 0, 0), i.e.

with the vector (0, 0, 0) and scalar 1.

Definition at line 138 of file qquaternion.h.

Referenced by conjugated(), fromAxisAndAngle(), fromAxisAndAngle(), fromDirection(), fromEulerAngles(), fromRotationMatrix(), inverted(), normalized(), rotatedVector(), and rotationTo().

+ Here is the caller graph for this function:

◆ QQuaternion() [2/5]

QQuaternion::QQuaternion ( Qt::Initialization  )
inlineexplicit
Since
5.5

Constructs a quaternion without initializing the contents.

Definition at line 24 of file qquaternion.h.

◆ QQuaternion() [3/5]

QQuaternion::QQuaternion ( float  scalar,
float  xpos,
float  ypos,
float  zpos 
)
inline

Constructs a quaternion with the vector (xpos, ypos, zpos) and scalar.

Definition at line 140 of file qquaternion.h.

◆ QQuaternion() [4/5]

QQuaternion::QQuaternion ( float  scalar,
const QVector3D vector 
)
inline

Constructs a quaternion vector from the specified vector and scalar.

See also
vector(), scalar()

Definition at line 287 of file qquaternion.h.

◆ QQuaternion() [5/5]

QQuaternion::QQuaternion ( const QVector4D vector)
inlineexplicit

Constructs a quaternion from the components of vector.

Definition at line 337 of file qquaternion.h.

Member Function Documentation

◆ conjugated()

QQuaternion QQuaternion::conjugated ( ) const
inline
Since
5.5

Returns the conjugate of this quaternion, which is (-x, -y, -z, scalar).

Definition at line 184 of file qquaternion.h.

References QQuaternion().

Referenced by QQuickQuaternionValueType::conjugated(), rotatedVector(), and src_gui_math3d_qquaternion::wrapper1().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dotProduct()

constexpr float QQuaternion::dotProduct ( const QQuaternion q1,
const QQuaternion q2 
)
inlinestaticconstexpr
Since
5.5

Returns the dot product of q1 and q2.

See also
length()

Definition at line 166 of file qquaternion.h.

Referenced by QQuickQuaternionValueType::dotProduct(), nlerp(), and slerp().

+ Here is the caller graph for this function:

◆ fromAxes()

QQuaternion QQuaternion::fromAxes ( const QVector3D xAxis,
const QVector3D yAxis,
const QVector3D zAxis 
)
static
Since
5.5

Constructs the quaternion using 3 axes (xAxis, yAxis, zAxis).

Note
The axes are assumed to be orthonormal.
See also
getAxes(), fromRotationMatrix()

Definition at line 660 of file qquaternion.cpp.

References fromRotationMatrix(), Qt::Uninitialized, QVector3D::x(), QVector3D::y(), and QVector3D::z().

Referenced by fromDirection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromAxisAndAngle() [1/2]

QQuaternion QQuaternion::fromAxisAndAngle ( const QVector3D axis,
float  angle 
)
static

Creates a normalized quaternion that corresponds to rotating through angle degrees about the specified 3D axis.

See also
getAxisAndAngle()

Definition at line 348 of file qquaternion.cpp.

References QQuaternion(), QVector3D::normalized(), qDegreesToRadians(), QVector3D::x(), QVector3D::y(), and QVector3D::z().

Referenced by QQuick3DQuaternionUtils::fromAxesAndAngles(), QQuick3DQuaternionUtils::fromAxesAndAngles(), QQuick3DQuaternionUtils::fromAxisAndAngle(), QQuick3DQuaternionUtils::fromAxisAndAngle(), QQuick3DQuaternionUtils::lookAt(), QQuick3DNode::rotate(), and rotationQuaternionForLookAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromAxisAndAngle() [2/2]

QQuaternion QQuaternion::fromAxisAndAngle ( float  x,
float  y,
float  z,
float  angle 
)
static

Creates a normalized quaternion that corresponds to rotating through angle degrees about the 3D axis (x, y, z).

See also
getAxisAndAngle()

Definition at line 402 of file qquaternion.cpp.

References QQuaternion(), length(), qDegreesToRadians(), qFuzzyCompare, qFuzzyIsNull(), and qHypot().

+ Here is the call graph for this function:

◆ fromDirection()

QQuaternion QQuaternion::fromDirection ( const QVector3D direction,
const QVector3D up 
)
static
Since
5.5

Constructs the quaternion using specified forward direction direction and upward direction up. If the upward direction was not specified or the forward and upward vectors are collinear, a new orthonormal upward direction will be generated.

See also
fromAxes(), rotationTo()

Definition at line 686 of file qquaternion.cpp.

References QQuaternion(), QVector3D::crossProduct(), direction, fromAxes(), QVector3D::lengthSquared(), QVector3D::normalize(), qFuzzyIsNull(), and rotationTo().

Referenced by setupCameraForShadowMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromEulerAngles() [1/2]

QQuaternion QQuaternion::fromEulerAngles ( const QVector3D eulerAngles)
inlinestatic
Since
5.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Creates a quaternion that corresponds to a rotation of eulerAngles: eulerAngles.z() degrees around the z axis, eulerAngles.x() degrees around the x axis, and eulerAngles.y() degrees around the y axis (in that order).

See also
toEulerAngles()

Definition at line 321 of file qquaternion.h.

References fromEulerAngles(), QVector3D::x(), QVector3D::y(), and QVector3D::z().

Referenced by calculate(), QPhysicsCommandReset::execute(), fromEulerAngles(), QQuick3DQuaternionUtils::fromEulerAngles(), QQuick3DQuaternionUtils::fromEulerAngles(), RotationData::getQuaternionRotation(), QQuick3DQuaternionAnimation::setFromXRotation(), QQuick3DQuaternionAnimation::setFromYRotation(), QQuick3DQuaternionAnimation::setFromZRotation(), QSSGRenderLayer::setProbeOrientation(), QQuick3DQuaternionAnimation::setToXRotation(), QQuick3DQuaternionAnimation::setToYRotation(), QQuick3DQuaternionAnimation::setToZRotation(), setupCubeReflectionCameras(), and setupCubeShadowCameras().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromEulerAngles() [2/2]

QQuaternion QQuaternion::fromEulerAngles ( float  pitch,
float  yaw,
float  roll 
)
static
Since
5.5

Creates a quaternion that corresponds to a rotation of roll degrees around the z axis, pitch degrees around the x axis, and yaw degrees around the y axis (in that order).

See also
getEulerAngles()

Definition at line 513 of file qquaternion.cpp.

References QQuaternion(), c2, qDegreesToRadians(), s2, and s3.

+ Here is the call graph for this function:

◆ fromRotationMatrix()

QQuaternion QQuaternion::fromRotationMatrix ( const QMatrix3x3 rot3x3)
static
Since
5.5

Creates a quaternion that corresponds to a rotation matrix rot3x3.

Note
If a given rotation matrix is not normalized, the resulting quaternion will contain scaling information.
See also
toRotationMatrix(), fromAxes()

Definition at line 596 of file qquaternion.cpp.

References QQuaternion(), i, j, and scalar().

Referenced by QQuick3DNodePrivate::emitChangesToSceneTransform(), fromAxes(), getPhysXWorldTransform(), QQuick3DInstancing::InstanceTableEntry::getRotation(), QQuick3DNode::rotate(), QQuick3DNode::sceneRotation(), and QQuick3DNode::updateSpatialNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAxes()

void QQuaternion::getAxes ( QVector3D xAxis,
QVector3D yAxis,
QVector3D zAxis 
) const
Since
5.5

Returns the 3 orthonormal axes (xAxis, yAxis, zAxis) defining the quaternion.

See also
fromAxes(), toRotationMatrix()

Definition at line 640 of file qquaternion.cpp.

References Q_ASSERT, and toRotationMatrix().

+ Here is the call graph for this function:

◆ getAxisAndAngle() [1/2]

void QQuaternion::getAxisAndAngle ( float *  x,
float *  y,
float *  z,
float *  angle 
) const
Since
5.5

Extracts a 3D axis (x, y, z) and a rotating angle angle (in degrees) that corresponds to this quaternion.

See also
fromAxisAndAngle()

Definition at line 371 of file qquaternion.cpp.

References length(), Q_ASSERT, qFuzzyCompare, qFuzzyIsNull(), qHypot(), and qRadiansToDegrees().

+ Here is the call graph for this function:

◆ getAxisAndAngle() [2/2]

void QQuaternion::getAxisAndAngle ( QVector3D axis,
float *  angle 
) const
inline
Since
5.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Extracts a 3D axis axis and a rotating angle angle (in degrees) that corresponds to this quaternion.

See also
fromAxisAndAngle()

Definition at line 307 of file qquaternion.h.

References getAxisAndAngle().

Referenced by getAxisAndAngle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getEulerAngles()

void QQuaternion::getEulerAngles ( float *  pitch,
float *  yaw,
float *  roll 
) const
Since
5.5

Calculates roll, pitch, and yaw Euler angles (in degrees) that corresponds to this quaternion.

See also
fromEulerAngles()

Definition at line 452 of file qquaternion.cpp.

References epsilon, length(), M_PI_2, Q_ASSERT, qFuzzyIsNull(), and qRadiansToDegrees().

Referenced by toEulerAngles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inverted()

QQuaternion QQuaternion::inverted ( ) const
inline
Since
5.5

Returns the inverse of this quaternion. If this quaternion is null, then a null quaternion is returned.

See also
isNull(), length()

Definition at line 171 of file qquaternion.h.

References QQuaternion(), and qFuzzyIsNull().

Referenced by calculateParticleRotation(), QQuickQuaternionValueType::inverted(), and QAbstractPhysicsNode::updateFromPhysicsTransform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isIdentity()

bool QQuaternion::isIdentity ( ) const
inline

Returns true if the x, y, and z components of this quaternion are set to 0.0, and the scalar component is set to 1.0; otherwise returns false.

Definition at line 150 of file qquaternion.h.

◆ isNull()

QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE bool QQuaternion::isNull ( ) const
inline

Returns true if the x, y, z, and scalar components of this quaternion are set to 0.0; otherwise returns false.

Definition at line 145 of file qquaternion.h.

◆ length()

float QQuaternion::length ( ) const

Returns the length of the quaternion.

This is also called the "norm".

See also
lengthSquared(), normalized(), dotProduct()

Definition at line 199 of file qquaternion.cpp.

References qHypot().

Referenced by fromAxisAndAngle(), getAxisAndAngle(), getEulerAngles(), normalize(), and normalized().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lengthSquared()

float QQuaternion::lengthSquared ( ) const

Returns the squared length of the quaternion.

Note
Though cheap to compute, this is susceptible to overflow and underflow that length() avoids in many cases.
See also
length(), dotProduct()

Definition at line 212 of file qquaternion.cpp.

◆ nlerp()

QQuaternion QQuaternion::nlerp ( const QQuaternion q1,
const QQuaternion q2,
float  t 
)
static

Interpolates along the shortest linear path between the rotational positions q1 and q2.

The value t should be between 0 and 1, indicating the distance to travel between q1 and q2. The result will be normalized().

If t is less than or equal to 0, then q1 will be returned. If t is greater than or equal to 1, then q2 will be returned.

The nlerp() function is typically faster than slerp() and will give approximate results to spherical interpolation that are good enough for some applications.

See also
slerp()

Definition at line 906 of file qquaternion.cpp.

References dot(), dotProduct(), and normalized().

Referenced by q_quaternionNlerpInterpolator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalize()

void QQuaternion::normalize ( )

Normalizes the current quaternion in place.

Nothing happens if this is a null quaternion or the length of the quaternion is very close to 1.

See also
length(), normalized()

Definition at line 241 of file qquaternion.cpp.

References length(), and qFuzzyIsNull().

+ Here is the call graph for this function:

◆ normalized()

QQuaternion QQuaternion::normalized ( ) const

Returns the normalized unit form of this quaternion.

If this quaternion is null, then a null quaternion is returned. If the length of the quaternion is very close to 1, then the quaternion will be returned as-is. Otherwise the normalized form of the quaternion of length 1 will be returned.

See also
normalize(), length(), dotProduct()

Definition at line 227 of file qquaternion.cpp.

References QQuaternion(), length(), and qFuzzyIsNull().

Referenced by QQuick3DNodePrivate::emitChangesToSceneTransform(), getPhysXWorldTransform(), RotationData::getQuaternionRotation(), QQuick3DInstancing::InstanceTableEntry::getRotation(), nlerp(), QQuickQuaternionValueType::normalized(), RotationData::operator=(), QQuick3DNode::rotate(), and QQuick3DNode::sceneRotation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator QVariant()

QQuaternion::operator QVariant ( ) const

Returns the quaternion as a QVariant.

Definition at line 928 of file qquaternion.cpp.

References QVariant::fromValue().

+ Here is the call graph for this function:

◆ operator*=() [1/2]

QQuaternion & QQuaternion::operator*= ( const QQuaternion quaternion)
inline

Multiplies this quaternion by quaternion and returns a reference to this quaternion.

Definition at line 232 of file qquaternion.h.

◆ operator*=() [2/2]

QQuaternion & QQuaternion::operator*= ( float  factor)
inline

Multiplies this quaternion's components by the given factor, and returns a reference to this quaternion.

See also
operator/=()

Definition at line 207 of file qquaternion.h.

◆ operator+=()

QQuaternion & QQuaternion::operator+= ( const QQuaternion quaternion)
inline

Adds the given quaternion to this quaternion and returns a reference to this quaternion.

See also
operator-=()

Definition at line 189 of file qquaternion.h.

◆ operator-=()

QQuaternion & QQuaternion::operator-= ( const QQuaternion quaternion)
inline

Subtracts the given quaternion from this quaternion and returns a reference to this quaternion.

See also
operator+=()

Definition at line 198 of file qquaternion.h.

◆ operator/=()

QQuaternion & QQuaternion::operator/= ( float  divisor)
inline

Divides this quaternion's components by the given divisor, and returns a reference to this quaternion.

See also
operator*=()

Definition at line 238 of file qquaternion.h.

◆ rotatedVector()

QVector3D QQuaternion::rotatedVector ( const QVector3D vector) const

Rotates vector with this quaternion to produce a new vector in 3D space.

The following code:

QVector3D result = q.rotatedVector(vector);
QVector3D vector() const
Returns the vector component of this quaternion.
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]

is equivalent to the following:

QVector3D result = (q * QQuaternion(0, vector) * q.conjugated()).vector();
QQuaternion()
Constructs an identity quaternion (1, 0, 0, 0), i.e.

Definition at line 281 of file qquaternion.cpp.

References QQuaternion(), conjugated(), and vector().

Referenced by operator*(), and QSpatialSoundPrivate::updateRoomEffects().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rotationTo()

QQuaternion QQuaternion::rotationTo ( const QVector3D from,
const QVector3D to 
)
static
Since
5.5

Returns the shortest arc quaternion to rotate from the direction described by the vector from to the direction described by the vector to.

See also
fromDirection()

Definition at line 712 of file qquaternion.cpp.

References QQuaternion(), QVector3D::crossProduct(), d, QVector3D::dotProduct(), QVector3D::lengthSquared(), QVector3D::normalize(), QVector3D::normalized(), qFuzzyIsNull(), v0, v1, QVector3D::x(), QVector3D::y(), and QVector3D::z().

Referenced by fromDirection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scalar()

float QQuaternion::scalar ( ) const
inline

Returns the scalar component of this quaternion.

See also
setScalar(), x(), y(), z()

Definition at line 159 of file qquaternion.h.

Referenced by fromRotationMatrix(), operator<<(), QMatrix4x4::rotate(), QAudioListener::setRotation(), and QPhysicsUtils::toPhysXType().

+ Here is the caller graph for this function:

◆ setScalar()

void QQuaternion::setScalar ( float  scalar)
inline

Sets the scalar component of this quaternion to scalar.

See also
scalar(), setX(), setY(), setZ()

Definition at line 164 of file qquaternion.h.

Referenced by operator>>().

+ Here is the caller graph for this function:

◆ setVector() [1/2]

void QQuaternion::setVector ( const QVector3D vector)
inline

Sets the vector component of this quaternion to vector.

See also
vector(), setScalar()

Definition at line 290 of file qquaternion.h.

References QVector3D::x(), QVector3D::y(), and QVector3D::z().

+ Here is the call graph for this function:

◆ setVector() [2/2]

void QQuaternion::setVector ( float  x,
float  y,
float  z 
)
inline

Sets the vector component of this quaternion to (x, y, z).

See also
vector(), setScalar()

Definition at line 328 of file qquaternion.h.

◆ setX()

void QQuaternion::setX ( float  x)
inline

Sets the x coordinate of this quaternion's vector to the given x coordinate.

See also
x(), setY(), setZ(), setScalar()

Definition at line 161 of file qquaternion.h.

Referenced by operator>>().

+ Here is the caller graph for this function:

◆ setY()

void QQuaternion::setY ( float  y)
inline

Sets the y coordinate of this quaternion's vector to the given y coordinate.

See also
y(), setX(), setZ(), setScalar()

Definition at line 162 of file qquaternion.h.

Referenced by operator>>().

+ Here is the caller graph for this function:

◆ setZ()

void QQuaternion::setZ ( float  z)
inline

Sets the z coordinate of this quaternion's vector to the given z coordinate.

See also
z(), setX(), setY(), setScalar()

Definition at line 163 of file qquaternion.h.

Referenced by operator>>().

+ Here is the caller graph for this function:

◆ slerp()

QQuaternion QQuaternion::slerp ( const QQuaternion q1,
const QQuaternion q2,
float  t 
)
static

Interpolates along the shortest spherical path between the rotational positions q1 and q2.

The value t should be between 0 and 1, indicating the spherical distance to travel between q1 and q2.

If t is less than or equal to 0, then q1 will be returned. If t is greater than or equal to 1, then q2 will be returned.

See also
nlerp()

Definition at line 857 of file qquaternion.cpp.

References dot(), and dotProduct().

Referenced by _q_interpolate(), and q_quaternionInterpolator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toEulerAngles()

QVector3D QQuaternion::toEulerAngles ( ) const
inline
Since
5.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Calculates roll, pitch, and yaw Euler angles (in degrees) that corresponds to this quaternion.

See also
fromEulerAngles()

Definition at line 314 of file qquaternion.h.

References getEulerAngles().

Referenced by RotationData::getEulerRotation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toRotationMatrix()

QMatrix3x3 QQuaternion::toRotationMatrix ( ) const
Since
5.5

Creates a rotation matrix that corresponds to this quaternion.

Note
If this quaternion is not normalized, the resulting rotation matrix will contain scaling information.
See also
fromRotationMatrix(), getAxes()

Definition at line 553 of file qquaternion.cpp.

References Qt::Uninitialized.

Referenced by calculate(), QQuick3DInstancing::calculateTableEntryFromQuaternion(), QSSGRenderNode::calculateTransformMatrix(), getAxes(), QQuick3DNode::rotate(), QSSGRenderLayer::setProbeOrientation(), and RotationData::toRotationMatrix().

+ Here is the caller graph for this function:

◆ toVector4D()

QVector4D QQuaternion::toVector4D ( ) const
inline

Returns this quaternion as a 4D vector.

Definition at line 340 of file qquaternion.h.

◆ vector()

QVector3D QQuaternion::vector ( ) const
inline

Returns the vector component of this quaternion.

See also
setVector(), scalar()

Definition at line 297 of file qquaternion.h.

Referenced by rotatedVector().

+ Here is the caller graph for this function:

◆ x()

QT_WARNING_POP float QQuaternion::x ( ) const
inline

Returns the x coordinate of this quaternion's vector.

See also
setX(), y(), z(), scalar()

Definition at line 156 of file qquaternion.h.

Referenced by operator<<(), QMatrix4x4::rotate(), QAudioListener::setRotation(), QPhysicsUtils::toPhysXType(), and QAbstractPhysicsNode::updateFromPhysicsTransform().

+ Here is the caller graph for this function:

◆ y()

float QQuaternion::y ( ) const
inline

Returns the y coordinate of this quaternion's vector.

See also
setY(), x(), z(), scalar()

Definition at line 157 of file qquaternion.h.

Referenced by operator<<(), QMatrix4x4::rotate(), QAudioListener::setRotation(), QPhysicsUtils::toPhysXType(), and QAbstractPhysicsNode::updateFromPhysicsTransform().

+ Here is the caller graph for this function:

◆ z()

float QQuaternion::z ( ) const
inline

Returns the z coordinate of this quaternion's vector.

See also
setZ(), x(), y(), scalar()

Definition at line 158 of file qquaternion.h.

Referenced by operator<<(), QMatrix4x4::rotate(), QAudioListener::setRotation(), QPhysicsUtils::toPhysXType(), and QAbstractPhysicsNode::updateFromPhysicsTransform().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator!=

bool QQuaternion::operator!= ( const QQuaternion q1,
const QQuaternion q2 
)
friend

Returns true if q1 is not equal to q2; otherwise returns false.

This operator uses an exact floating-point comparison.

Definition at line 78 of file qquaternion.h.

◆ operator*() [1/7]

const QQuaternion operator* ( const QQuaternion q1,
const QQuaternion q2 
)
related

Multiplies q1 and q2 using quaternion multiplication.

The result corresponds to applying both of the rotations specified by q1 and q2.

See also
QQuaternion::operator*=()

Definition at line 216 of file qquaternion.h.

◆ operator* [2/7]

const QQuaternion operator* ( const QQuaternion q1,
const QQuaternion q2 
)
friend

Multiplies q1 and q2 using quaternion multiplication.

The result corresponds to applying both of the rotations specified by q1 and q2.

See also
QQuaternion::operator*=()

Definition at line 216 of file qquaternion.h.

◆ operator*() [3/7]

QVector3D operator* ( const QQuaternion quaternion,
const QVector3D vec 
)
related
Since
5.5

Rotates a vector vec with a quaternion quaternion to produce a new vector in 3D space.

Definition at line 302 of file qquaternion.h.

References rotatedVector().

+ Here is the call graph for this function:

◆ operator*() [4/7]

const QQuaternion operator* ( const QQuaternion quaternion,
float  factor 
)
related

Returns a copy of the given quaternion, multiplied by the given factor.

See also
QQuaternion::operator*=()

Definition at line 262 of file qquaternion.h.

◆ operator* [5/7]

const QQuaternion operator* ( const QQuaternion quaternion,
float  factor 
)
friend

Returns a copy of the given quaternion, multiplied by the given factor.

See also
QQuaternion::operator*=()

Definition at line 262 of file qquaternion.h.

◆ operator*() [6/7]

const QQuaternion operator* ( float  factor,
const QQuaternion quaternion 
)
related

Returns a copy of the given quaternion, multiplied by the given factor.

See also
QQuaternion::operator*=()

Definition at line 257 of file qquaternion.h.

◆ operator* [7/7]

const QQuaternion operator* ( float  factor,
const QQuaternion quaternion 
)
friend

Returns a copy of the given quaternion, multiplied by the given factor.

See also
QQuaternion::operator*=()

Definition at line 257 of file qquaternion.h.

◆ operator+() [1/2]

const QQuaternion operator+ ( const QQuaternion q1,
const QQuaternion q2 
)
related

Returns a QQuaternion object that is the sum of the given quaternions, q1 and q2; each component is added separately.

See also
QQuaternion::operator+=()

Definition at line 247 of file qquaternion.h.

◆ operator+ [2/2]

const QQuaternion operator+ ( const QQuaternion q1,
const QQuaternion q2 
)
friend

Returns a QQuaternion object that is the sum of the given quaternions, q1 and q2; each component is added separately.

See also
QQuaternion::operator+=()

Definition at line 247 of file qquaternion.h.

◆ operator-() [1/4]

const QQuaternion operator- ( const QQuaternion q1,
const QQuaternion q2 
)
related

Returns a QQuaternion object that is formed by subtracting q2 from q1; each component is subtracted separately.

See also
QQuaternion::operator-=()

Definition at line 252 of file qquaternion.h.

◆ operator- [2/4]

const QQuaternion operator- ( const QQuaternion q1,
const QQuaternion q2 
)
friend

Returns a QQuaternion object that is formed by subtracting q2 from q1; each component is subtracted separately.

See also
QQuaternion::operator-=()

Definition at line 252 of file qquaternion.h.

◆ operator-() [3/4]

const QQuaternion operator- ( const QQuaternion quaternion)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QQuaternion object that is formed by changing the sign of all three components of the given quaternion.

Equivalent to {QQuaternion(0,0,0,0) - quaternion}.

Definition at line 267 of file qquaternion.h.

◆ operator- [4/4]

const QQuaternion operator- ( const QQuaternion quaternion)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QQuaternion object that is formed by changing the sign of all three components of the given quaternion.

Equivalent to {QQuaternion(0,0,0,0) - quaternion}.

Definition at line 267 of file qquaternion.h.

◆ operator/() [1/2]

const QQuaternion operator/ ( const QQuaternion quaternion,
float  divisor 
)
related

Returns the QQuaternion object formed by dividing all components of the given quaternion by the given divisor.

See also
QQuaternion::operator/=()

Definition at line 272 of file qquaternion.h.

◆ operator/ [2/2]

const QQuaternion operator/ ( const QQuaternion quaternion,
float  divisor 
)
friend

Returns the QQuaternion object formed by dividing all components of the given quaternion by the given divisor.

See also
QQuaternion::operator/=()

Definition at line 272 of file qquaternion.h.

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QQuaternion quaternion 
)
related

Writes the given quaternion to the given stream and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 958 of file qquaternion.cpp.

References scalar(), x(), y(), and z().

+ Here is the call graph for this function:

◆ operator==

bool QQuaternion::operator== ( const QQuaternion q1,
const QQuaternion q2 
)
friend

Returns true if q1 is equal to q2; otherwise returns false.

This operator uses an exact floating-point comparison.

Definition at line 74 of file qquaternion.h.

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QQuaternion quaternion 
)
related

Reads a quaternion from the given stream into the given quaternion and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 975 of file qquaternion.cpp.

References setScalar(), setX(), setY(), and setZ().

+ Here is the call graph for this function:

◆ qFuzzyCompare() [1/2]

bool qFuzzyCompare ( const QQuaternion q1,
const QQuaternion q2 
)
related

Returns true if q1 and q2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.

Definition at line 277 of file qquaternion.h.

◆ qFuzzyCompare [2/2]

bool qFuzzyCompare ( const QQuaternion q1,
const QQuaternion q2 
)
friend

Returns true if q1 and q2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.

Definition at line 277 of file qquaternion.h.

Referenced by fromAxisAndAngle(), and getAxisAndAngle().


The documentation for this class was generated from the following files: