Qt 4.8
|
The QQuaternion class represents a quaternion consisting of a vector and scalar. More...
#include <qquaternion.h>
Public Functions | |
QQuaternion | conjugate () const |
Returns the conjugate of this quaternion, which is (-x, -y, -z, scalar). More... | |
bool | isIdentity () const |
Returns true if the x, y, and z components of this quaternion are set to 0. More... | |
bool | isNull () const |
Returns true if the x, y, z, and scalar components of this quaternion are set to 0. More... | |
qreal | length () const |
Returns the length of the quaternion. More... | |
qreal | lengthSquared () const |
Returns the squared length of the quaternion. More... | |
void | normalize () |
Normalizes the currect quaternion in place. More... | |
QQuaternion | normalized () const |
Returns the normalized unit form of this quaternion. More... | |
operator QVariant () const | |
Returns the quaternion as a QVariant. More... | |
QQuaternion & | operator*= (qreal factor) |
Multiplies this quaternion's components by the given factor, and returns a reference to this quaternion. More... | |
QQuaternion & | operator*= (const QQuaternion &quaternion) |
Multiplies this quaternion by quaternion and returns a reference to this quaternion. More... | |
QQuaternion & | operator+= (const QQuaternion &quaternion) |
Adds the given quaternion to this quaternion and returns a reference to this quaternion. More... | |
QQuaternion & | operator-= (const QQuaternion &quaternion) |
Subtracts the given quaternion from this quaternion and returns a reference to this quaternion. More... | |
QQuaternion & | operator/= (qreal divisor) |
Divides this quaternion's components by the given divisor, and returns a reference to this quaternion. More... | |
QQuaternion () | |
Constructs an identity quaternion, i. More... | |
QQuaternion (qreal scalar, qreal xpos, qreal ypos, qreal zpos) | |
Constructs a quaternion with the vector (xpos, ypos, zpos) and scalar. More... | |
QQuaternion (qreal scalar, const QVector3D &vector) | |
Constructs a quaternion vector from the specified vector and scalar. More... | |
QQuaternion (const QVector4D &vector) | |
Constructs a quaternion from the components of vector. More... | |
QVector3D | rotatedVector (const QVector3D &vector) const |
Rotates vector with this quaternion to produce a new vector in 3D space. More... | |
qreal | scalar () const |
Returns the scalar component of this quaternion. More... | |
void | setScalar (qreal scalar) |
Sets the scalar component of this quaternion to scalar. More... | |
void | setVector (const QVector3D &vector) |
Sets the vector component of this quaternion to vector. More... | |
void | setVector (qreal x, qreal y, qreal z) |
Sets the vector component of this quaternion to (x, y, z). More... | |
void | setX (qreal x) |
Sets the x coordinate of this quaternion's vector to the given x coordinate. More... | |
void | setY (qreal y) |
Sets the y coordinate of this quaternion's vector to the given y coordinate. More... | |
void | setZ (qreal z) |
Sets the z coordinate of this quaternion's vector to the given z coordinate. More... | |
QVector4D | toVector4D () const |
Returns this quaternion as a 4D vector. More... | |
QVector3D | vector () const |
Returns the vector component of this quaternion. More... | |
qreal | x () const |
Returns the x coordinate of this quaternion's vector. More... | |
qreal | y () const |
Returns the y coordinate of this quaternion's vector. More... | |
qreal | z () const |
Returns the z coordinate of this quaternion's vector. More... | |
Static Public Functions | |
static QQuaternion | fromAxisAndAngle (const QVector3D &axis, qreal angle) |
Creates a normalized quaternion that corresponds to rotating through angle degrees about the specified 3D axis. More... | |
static QQuaternion | fromAxisAndAngle (qreal x, qreal y, qreal z, qreal angle) |
Creates a normalized quaternion that corresponds to rotating through angle degrees about the 3D axis (x, y, z). More... | |
static QQuaternion | nlerp (const QQuaternion &q1, const QQuaternion &q2, qreal t) |
Interpolates along the shortest linear path between the rotational positions q1 and q2. More... | |
static QQuaternion | slerp (const QQuaternion &q1, const QQuaternion &q2, qreal t) |
Interpolates along the shortest spherical path between the rotational positions q1 and q2. More... | |
Properties | |
qreal | wp |
qreal | xp |
qreal | yp |
qreal | zp |
Friends | |
bool | operator!= (const QQuaternion &q1, const QQuaternion &q2) |
Returns true if q1 is not equal to q2; otherwise returns false. More... | |
const QQuaternion | operator* (qreal factor, const QQuaternion &quaternion) |
const QQuaternion | operator* (const QQuaternion &quaternion, qreal factor) |
const QQuaternion | operator* (const QQuaternion &q1, const QQuaternion &q2) |
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. More... | |
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. More... | |
const QQuaternion | operator- (const QQuaternion &quaternion) |
Returns a QQuaternion object that is formed by changing the sign of all three components of the given quaternion. More... | |
const QQuaternion | operator/ (const QQuaternion &quaternion, qreal divisor) |
Returns the QQuaternion object formed by dividing all components of the given quaternion by the given divisor. More... | |
bool | operator== (const QQuaternion &q1, const QQuaternion &q2) |
Returns true if q1 is equal to q2; otherwise returns false. More... | |
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. More... | |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &stream, const QQuaternion &quaternion) |
Writes the given quaternion to the given stream and returns a reference to the stream. More... | |
QDataStream & | operator>> (QDataStream &stream, QQuaternion &quaternion) |
Reads a quaternion from the given stream into the given quaternion and returns a reference to the stream. More... | |
QDataStream & | operator>> (QDataStream &stream, QEasingCurve &easing) |
Reads an easing curve from the given stream into the given easing curve and returns a reference to the stream. More... | |
The QQuaternion class represents a quaternion consisting of a vector and scalar.
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 59 of file qquaternion.h.
|
inline |
Constructs an identity quaternion, i.
e. with coordinates (1, 0, 0, 0).
Definition at line 141 of file qquaternion.h.
Referenced by conjugate(), fromAxisAndAngle(), normalized(), operator*(), operator+(), operator-(), operator/(), and rotatedVector().
Constructs a quaternion with the vector (xpos, ypos, zpos) and scalar.
Definition at line 143 of file qquaternion.h.
Constructs a quaternion vector from the specified vector and scalar.
Definition at line 279 of file qquaternion.h.
|
inlineexplicit |
Constructs a quaternion from the components of vector.
Definition at line 305 of file qquaternion.h.
|
inline |
Returns the conjugate of this quaternion, which is (-x, -y, -z, scalar).
Definition at line 166 of file qquaternion.h.
Referenced by rotatedVector().
|
static |
Creates a normalized quaternion that corresponds to rotating through angle degrees about the specified 3D axis.
Definition at line 420 of file qquaternion.cpp.
|
static |
Creates a normalized quaternion that corresponds to rotating through angle degrees about the 3D axis (x, y, z).
Definition at line 440 of file qquaternion.cpp.
|
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 151 of file qquaternion.h.
|
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 146 of file qquaternion.h.
qreal QQuaternion::length | ( | ) | const |
Returns the length of the quaternion.
This is also called the "norm".
Definition at line 272 of file qquaternion.cpp.
Referenced by fromAxisAndAngle().
qreal QQuaternion::lengthSquared | ( | ) | const |
Returns the squared length of the quaternion.
Definition at line 282 of file qquaternion.cpp.
|
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.
Definition at line 635 of file qquaternion.cpp.
Referenced by slerp().
void QQuaternion::normalize | ( | ) |
Normalizes the currect quaternion in place.
Nothing happens if this is a null quaternion or the length of the quaternion is very close to 1.
Definition at line 318 of file qquaternion.cpp.
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.
Definition at line 297 of file qquaternion.cpp.
Referenced by fromAxisAndAngle(), and nlerp().
QQuaternion::operator QVariant | ( | ) | const |
Returns the quaternion as a QVariant.
Definition at line 659 of file qquaternion.cpp.
|
inline |
Multiplies this quaternion's components by the given factor, and returns a reference to this quaternion.
Definition at line 189 of file qquaternion.h.
|
inline |
Multiplies this quaternion by quaternion and returns a reference to this quaternion.
Definition at line 214 of file qquaternion.h.
|
inline |
Adds the given quaternion to this quaternion and returns a reference to this quaternion.
Definition at line 171 of file qquaternion.h.
|
inline |
Subtracts the given quaternion from this quaternion and returns a reference to this quaternion.
Definition at line 180 of file qquaternion.h.
|
inline |
Divides this quaternion's components by the given divisor, and returns a reference to this quaternion.
Definition at line 220 of file qquaternion.h.
Rotates vector with this quaternion to produce a new vector in 3D space.
The following code:
is equivalent to the following:
Definition at line 360 of file qquaternion.cpp.
|
inline |
Returns the scalar component of this quaternion.
Definition at line 159 of file qquaternion.h.
Referenced by operator<<(), operator>>(), QMatrix4x4::rotate(), and QDeclarativeQuaternionValueType::setValue().
|
inline |
Sets the scalar component of this quaternion to scalar.
Definition at line 164 of file qquaternion.h.
Referenced by operator>>(), and QDeclarativeQuaternionValueType::setScalar().
|
inline |
Sets the vector component of this quaternion to vector.
Definition at line 282 of file qquaternion.h.
Sets the vector component of this quaternion to (x, y, z).
Definition at line 296 of file qquaternion.h.
|
inline |
Sets the x coordinate of this quaternion's vector to the given x coordinate.
Definition at line 161 of file qquaternion.h.
Referenced by operator>>(), and QDeclarativeQuaternionValueType::setX().
|
inline |
Sets the y coordinate of this quaternion's vector to the given y coordinate.
Definition at line 162 of file qquaternion.h.
Referenced by operator>>(), and QDeclarativeQuaternionValueType::setY().
|
inline |
Sets the z coordinate of this quaternion's vector to the given z coordinate.
Definition at line 163 of file qquaternion.h.
Referenced by operator>>(), and QDeclarativeQuaternionValueType::setZ().
|
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.
Definition at line 583 of file qquaternion.cpp.
Referenced by _q_interpolate(), and fromAxisAndAngle().
|
inline |
|
inline |
Returns the vector component of this quaternion.
Definition at line 289 of file qquaternion.h.
|
inline |
Returns the x coordinate of this quaternion's vector.
Definition at line 156 of file qquaternion.h.
Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::rotate(), and QDeclarativeQuaternionValueType::setValue().
|
inline |
Returns the y coordinate of this quaternion's vector.
Definition at line 157 of file qquaternion.h.
Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::rotate(), and QDeclarativeQuaternionValueType::setValue().
|
inline |
Returns the z coordinate of this quaternion's vector.
Definition at line 158 of file qquaternion.h.
Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::rotate(), and QDeclarativeQuaternionValueType::setValue().
|
friend |
Returns true if q1 is not equal to q2; otherwise returns false.
This operator uses an exact floating-point comparison.
Definition at line 234 of file qquaternion.h.
|
friend |
Returns a copy of the given quaternion, multiplied by the given factor.
Definition at line 249 of file qquaternion.h.
|
friend |
Returns a copy of the given quaternion, multiplied by the given factor.
Definition at line 254 of file qquaternion.h.
|
friend |
Multiplies q1 and q2 using quaternion multiplication. The result corresponds to applying both of the rotations specified by q1 and q2.
Definition at line 198 of file qquaternion.h.
|
friend |
Returns a QQuaternion object that is the sum of the given quaternions, q1 and q2; each component is added separately.
Definition at line 239 of file qquaternion.h.
|
friend |
Returns a QQuaternion object that is formed by subtracting q2 from q1; each component is subtracted separately.
Definition at line 244 of file qquaternion.h.
|
friend |
Returns a QQuaternion object that is formed by changing the sign of all three components of the given quaternion.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Equivalent to {QQuaternion(0,0,0,0)
- quaternion}.
Definition at line 259 of file qquaternion.h.
|
friend |
Returns the QQuaternion object formed by dividing all components of the given quaternion by the given divisor.
Definition at line 264 of file qquaternion.h.
|
related |
Writes the given quaternion to the given stream and returns a reference to the stream.
Definition at line 691 of file qquaternion.cpp.
Referenced by toVector4D().
|
friend |
Returns true if q1 is equal to q2; otherwise returns false.
This operator uses an exact floating-point comparison.
Definition at line 229 of file qquaternion.h.
|
related |
Reads a quaternion from the given stream into the given quaternion and returns a reference to the stream.
Definition at line 711 of file qquaternion.cpp.
|
related |
Reads an easing curve from the given stream into the given easing curve and returns a reference to the stream.
Definition at line 925 of file qeasingcurve.cpp.
Referenced by toVector4D().
|
friend |
Returns true if q1 and q2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.
Definition at line 269 of file qquaternion.h.
Referenced by qFuzzyCompare().
|
private |
Definition at line 136 of file qquaternion.h.
Referenced by conjugate(), isIdentity(), isNull(), length(), lengthSquared(), nlerp(), normalize(), normalized(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator==(), qFuzzyCompare(), scalar(), setScalar(), slerp(), and toVector4D().
|
private |
Definition at line 136 of file qquaternion.h.
Referenced by conjugate(), isIdentity(), isNull(), length(), lengthSquared(), nlerp(), normalize(), normalized(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator==(), qFuzzyCompare(), setVector(), setX(), slerp(), toVector4D(), vector(), and x().
|
private |
Definition at line 136 of file qquaternion.h.
Referenced by conjugate(), isIdentity(), isNull(), length(), lengthSquared(), nlerp(), normalize(), normalized(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator==(), qFuzzyCompare(), setVector(), setY(), slerp(), toVector4D(), vector(), and y().
|
private |
Definition at line 136 of file qquaternion.h.
Referenced by conjugate(), isIdentity(), isNull(), length(), lengthSquared(), nlerp(), normalize(), normalized(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator==(), qFuzzyCompare(), setVector(), setZ(), slerp(), toVector4D(), vector(), and z().