Qt 4.8
Public Functions | Static Public Functions | Properties | Friends | Related Functions | List of all members
QQuaternion Class Reference

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...
 
QQuaternionoperator*= (qreal factor)
 Multiplies this quaternion's components by the given factor, and returns a reference to this quaternion. More...
 
QQuaternionoperator*= (const QQuaternion &quaternion)
 Multiplies this quaternion by quaternion and returns a reference to this quaternion. More...
 
QQuaternionoperator+= (const QQuaternion &quaternion)
 Adds the given quaternion to this quaternion and returns a reference to this quaternion. More...
 
QQuaternionoperator-= (const QQuaternion &quaternion)
 Subtracts the given quaternion from this quaternion and returns a reference to this quaternion. More...
 
QQuaternionoperator/= (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.)

QDataStreamoperator<< (QDataStream &stream, const QQuaternion &quaternion)
 Writes the given quaternion to the given stream and returns a reference to the stream. More...
 
QDataStreamoperator>> (QDataStream &stream, QQuaternion &quaternion)
 Reads a quaternion from the given stream into the given quaternion and returns a reference to the stream. More...
 
QDataStreamoperator>> (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...
 

Detailed Description

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

Since
4.6

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.

Constructors and Destructors

◆ QQuaternion() [1/4]

QQuaternion::QQuaternion ( )
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().

141 : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {}

◆ QQuaternion() [2/4]

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

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

Definition at line 143 of file qquaternion.h.

143 : wp(aScalar), xp(xpos), yp(ypos), zp(zpos) {}

◆ QQuaternion() [3/4]

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

Constructs a quaternion vector from the specified vector and scalar.

See also
vector(), scalar()

Definition at line 279 of file qquaternion.h.

280  : wp(aScalar), xp(aVector.x()), yp(aVector.y()), zp(aVector.z()) {}

◆ QQuaternion() [4/4]

QQuaternion::QQuaternion ( const QVector4D vector)
inlineexplicit

Constructs a quaternion from the components of vector.

Definition at line 305 of file qquaternion.h.

306  : wp(aVector.w()), xp(aVector.x()), yp(aVector.y()), zp(aVector.z()) {}

Functions

◆ conjugate()

QQuaternion QQuaternion::conjugate ( ) const
inline

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

Definition at line 166 of file qquaternion.h.

Referenced by rotatedVector().

167 {
168  return QQuaternion(wp, -xp, -yp, -zp);
169 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141

◆ fromAxisAndAngle() [1/2]

QQuaternion QQuaternion::fromAxisAndAngle ( const QVector3D axis,
qreal  angle 
)
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.

421 {
422  // Algorithm from:
423  // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56
424  // We normalize the result just in case the values are close
425  // to zero, as suggested in the above FAQ.
426  qreal a = (angle / 2.0f) * M_PI / 180.0f;
427  qreal s = qSin(a);
428  qreal c = qCos(a);
429  QVector3D ax = axis.normalized();
430  return QQuaternion(c, ax.x() * s, ax.y() * s, ax.z() * s).normalized();
431 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
QQuaternion normalized() const
Returns the normalized unit form of this quaternion.
long ASN1_INTEGER_get ASN1_INTEGER * a
qreal x() const
Returns the x coordinate of this point.
Definition: qvector3d.h:161
#define M_PI
Definition: qmath.h:261
qreal qSin(qreal v)
Definition: qmath.h:93
QVector3D normalized() const
Returns the normalized unit vector form of this vector.
Definition: qvector3d.cpp:247
qreal z() const
Returns the z coordinate of this point.
Definition: qvector3d.h:163
qreal angle(const QPointF &p1, const QPointF &p2)
qreal y() const
Returns the y coordinate of this point.
Definition: qvector3d.h:162
qreal qCos(qreal v)
Definition: qmath.h:109

◆ fromAxisAndAngle() [2/2]

QQuaternion QQuaternion::fromAxisAndAngle ( qreal  x,
qreal  y,
qreal  z,
qreal  angle 
)
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.

441 {
442  qreal length = qSqrt(x * x + y * y + z * z);
443  if (!qFuzzyIsNull(length - 1.0f) && !qFuzzyIsNull(length)) {
444  x /= length;
445  y /= length;
446  z /= length;
447  }
448  qreal a = (angle / 2.0f) * M_PI / 180.0f;
449  qreal s = qSin(a);
450  qreal c = qCos(a);
451  return QQuaternion(c, x * s, y * s, z * s).normalized();
452 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
qreal x() const
Returns the x coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:156
long ASN1_INTEGER_get ASN1_INTEGER * a
#define M_PI
Definition: qmath.h:261
qreal length() const
Returns the length of the quaternion.
qreal qSin(qreal v)
Definition: qmath.h:93
qreal y() const
Returns the y coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:157
qreal angle(const QPointF &p1, const QPointF &p2)
qreal z() const
Returns the z coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:158
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal qCos(qreal v)
Definition: qmath.h:109
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ 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 151 of file qquaternion.h.

152 {
153  return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && wp == 1.0f;
154 }
static bool qIsNull(double d)
Definition: qglobal.h:2061

◆ isNull()

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 146 of file qquaternion.h.

147 {
148  return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && qIsNull(wp);
149 }
static bool qIsNull(double d)
Definition: qglobal.h:2061

◆ length()

qreal QQuaternion::length ( ) const

Returns the length of the quaternion.

This is also called the "norm".

See also
lengthSquared(), normalized()

Definition at line 272 of file qquaternion.cpp.

Referenced by fromAxisAndAngle().

273 {
274  return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp);
275 }
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ lengthSquared()

qreal QQuaternion::lengthSquared ( ) const

Returns the squared length of the quaternion.

See also
length()

Definition at line 282 of file qquaternion.cpp.

283 {
284  return xp * xp + yp * yp + zp * zp + wp * wp;
285 }

◆ nlerp()

QQuaternion QQuaternion::nlerp ( const QQuaternion q1,
const QQuaternion q2,
qreal  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 635 of file qquaternion.cpp.

Referenced by slerp().

636 {
637  // Handle the easy cases first.
638  if (t <= 0.0f)
639  return q1;
640  else if (t >= 1.0f)
641  return q2;
642 
643  // Determine the angle between the two quaternions.
644  QQuaternion q2b;
645  qreal dot;
646  dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp;
647  if (dot >= 0.0f)
648  q2b = q2;
649  else
650  q2b = -q2;
651 
652  // Perform the linear interpolation.
653  return (q1 * (1.0f - t) + q2b * t).normalized();
654 }
double qreal
Definition: qglobal.h:1193
QQuaternion normalized() const
Returns the normalized unit form of this quaternion.
The QQuaternion class represents a quaternion consisting of a vector and scalar.
Definition: qquaternion.h:59
static qreal dot(const QPointF &a, const QPointF &b)

◆ normalize()

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.

See also
length(), normalized()

Definition at line 318 of file qquaternion.cpp.

319 {
320  // Need some extra precision if the length is very small.
321  double len = double(xp) * double(xp) +
322  double(yp) * double(yp) +
323  double(zp) * double(zp) +
324  double(wp) * double(wp);
325  if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
326  return;
327 
328  len = qSqrt(len);
329 
330  xp /= len;
331  yp /= len;
332  zp /= len;
333  wp /= len;
334 }
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ 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
length(), normalize()

Definition at line 297 of file qquaternion.cpp.

Referenced by fromAxisAndAngle(), and nlerp().

298 {
299  // Need some extra precision if the length is very small.
300  double len = double(xp) * double(xp) +
301  double(yp) * double(yp) +
302  double(zp) * double(zp) +
303  double(wp) * double(wp);
304  if (qFuzzyIsNull(len - 1.0f))
305  return *this;
306  else if (!qFuzzyIsNull(len))
307  return *this / qSqrt(len);
308  else
309  return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
310 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ operator QVariant()

QQuaternion::operator QVariant ( ) const

Returns the quaternion as a QVariant.

Definition at line 659 of file qquaternion.cpp.

660 {
661  return QVariant(QVariant::Quaternion, this);
662 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator*=() [1/2]

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

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

See also
operator/=()

Definition at line 189 of file qquaternion.h.

190 {
191  xp *= factor;
192  yp *= factor;
193  zp *= factor;
194  wp *= factor;
195  return *this;
196 }

◆ operator*=() [2/2]

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

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

Definition at line 214 of file qquaternion.h.

215 {
216  *this = *this * quaternion;
217  return *this;
218 }

◆ 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 171 of file qquaternion.h.

172 {
173  xp += quaternion.xp;
174  yp += quaternion.yp;
175  zp += quaternion.zp;
176  wp += quaternion.wp;
177  return *this;
178 }

◆ 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 180 of file qquaternion.h.

181 {
182  xp -= quaternion.xp;
183  yp -= quaternion.yp;
184  zp -= quaternion.zp;
185  wp -= quaternion.wp;
186  return *this;
187 }

◆ operator/=()

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

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

See also
operator*=()

Definition at line 220 of file qquaternion.h.

221 {
222  xp /= divisor;
223  yp /= divisor;
224  zp /= divisor;
225  wp /= divisor;
226  return *this;
227 }

◆ 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);

is equivalent to the following:

QVector3D result = (q * QQuaternion(0, vector) * q.conjugate()).vector();

Definition at line 360 of file qquaternion.cpp.

361 {
362  return (*this * QQuaternion(0, vector) * conjugate()).vector();
363 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141
QQuaternion conjugate() const
Returns the conjugate of this quaternion, which is (-x, -y, -z, scalar).
Definition: qquaternion.h:166

◆ scalar()

qreal 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 operator<<(), operator>>(), QMatrix4x4::rotate(), and QDeclarativeQuaternionValueType::setValue().

159 { return qreal(wp); }
double qreal
Definition: qglobal.h:1193

◆ setScalar()

void QQuaternion::setScalar ( qreal  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>>(), and QDeclarativeQuaternionValueType::setScalar().

164 { wp = aScalar; }

◆ 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 282 of file qquaternion.h.

283 {
284  xp = aVector.x();
285  yp = aVector.y();
286  zp = aVector.z();
287 }

◆ setVector() [2/2]

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

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

See also
vector(), setScalar()

Definition at line 296 of file qquaternion.h.

297 {
298  xp = aX;
299  yp = aY;
300  zp = aZ;
301 }

◆ setX()

void QQuaternion::setX ( qreal  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>>(), and QDeclarativeQuaternionValueType::setX().

161 { xp = aX; }

◆ setY()

void QQuaternion::setY ( qreal  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>>(), and QDeclarativeQuaternionValueType::setY().

162 { yp = aY; }

◆ setZ()

void QQuaternion::setZ ( qreal  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>>(), and QDeclarativeQuaternionValueType::setZ().

163 { zp = aZ; }

◆ slerp()

QQuaternion QQuaternion::slerp ( const QQuaternion q1,
const QQuaternion q2,
qreal  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 583 of file qquaternion.cpp.

Referenced by _q_interpolate(), and fromAxisAndAngle().

584 {
585  // Handle the easy cases first.
586  if (t <= 0.0f)
587  return q1;
588  else if (t >= 1.0f)
589  return q2;
590 
591  // Determine the angle between the two quaternions.
592  QQuaternion q2b;
593  qreal dot;
594  dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp;
595  if (dot >= 0.0f) {
596  q2b = q2;
597  } else {
598  q2b = -q2;
599  dot = -dot;
600  }
601 
602  // Get the scale factors. If they are too small,
603  // then revert to simple linear interpolation.
604  qreal factor1 = 1.0f - t;
605  qreal factor2 = t;
606  if ((1.0f - dot) > 0.0000001) {
607  qreal angle = qreal(qAcos(dot));
608  qreal sinOfAngle = qreal(qSin(angle));
609  if (sinOfAngle > 0.0000001) {
610  factor1 = qreal(qSin((1.0f - t) * angle)) / sinOfAngle;
611  factor2 = qreal(qSin(t * angle)) / sinOfAngle;
612  }
613  }
614 
615  // Construct the result quaternion.
616  return q1 * factor1 + q2b * factor2;
617 }
double qreal
Definition: qglobal.h:1193
qreal qSin(qreal v)
Definition: qmath.h:93
qreal angle(const QPointF &p1, const QPointF &p2)
qreal qAcos(qreal v)
Definition: qmath.h:141
The QQuaternion class represents a quaternion consisting of a vector and scalar.
Definition: qquaternion.h:59
static qreal dot(const QPointF &a, const QPointF &b)

◆ toVector4D()

QVector4D QQuaternion::toVector4D ( ) const
inline

Returns this quaternion as a 4D vector.

Definition at line 308 of file qquaternion.h.

309 {
310  return QVector4D(xp, yp, zp, wp);
311 }
The QVector4D class represents a vector or vertex in 4D space.
Definition: qvector4d.h:60

◆ vector()

QVector3D QQuaternion::vector ( ) const
inline

Returns the vector component of this quaternion.

See also
setVector(), scalar()

Definition at line 289 of file qquaternion.h.

290 {
291  return QVector3D(xp, yp, zp);
292 }
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60

◆ x()

qreal 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*(), operator<<(), operator>>(), QMatrix4x4::rotate(), and QDeclarativeQuaternionValueType::setValue().

156 { return qreal(xp); }
double qreal
Definition: qglobal.h:1193

◆ y()

qreal 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*(), operator<<(), operator>>(), QMatrix4x4::rotate(), and QDeclarativeQuaternionValueType::setValue().

157 { return qreal(yp); }
double qreal
Definition: qglobal.h:1193

◆ z()

qreal 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*(), operator<<(), operator>>(), QMatrix4x4::rotate(), and QDeclarativeQuaternionValueType::setValue().

158 { return qreal(zp); }
double qreal
Definition: qglobal.h:1193

Friends and Related Functions

◆ operator!=

bool 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 234 of file qquaternion.h.

235 {
236  return q1.xp != q2.xp || q1.yp != q2.yp || q1.zp != q2.zp || q1.wp != q2.wp;
237 }

◆ operator* [1/3]

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

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

See also
QQuaternion::operator*=()

Definition at line 249 of file qquaternion.h.

250 {
251  return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor);
252 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141

◆ operator* [2/3]

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

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

See also
QQuaternion::operator*=()

Definition at line 254 of file qquaternion.h.

255 {
256  return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor);
257 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141

◆ operator* [3/3]

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 198 of file qquaternion.h.

199 {
200  qreal ww = (q1.zp + q1.xp) * (q2.xp + q2.yp);
201  qreal yy = (q1.wp - q1.yp) * (q2.wp + q2.zp);
202  qreal zz = (q1.wp + q1.yp) * (q2.wp - q2.zp);
203  qreal xx = ww + yy + zz;
204  qreal qq = 0.5 * (xx + (q1.zp - q1.xp) * (q2.xp - q2.yp));
205 
206  qreal w = qq - ww + (q1.zp - q1.yp) * (q2.yp - q2.zp);
207  qreal x = qq - xx + (q1.xp + q1.wp) * (q2.xp + q2.wp);
208  qreal y = qq - yy + (q1.wp - q1.xp) * (q2.yp + q2.zp);
209  qreal z = qq - zz + (q1.zp + q1.yp) * (q2.wp - q2.xp);
210 
211  return QQuaternion(w, x, y, z);
212 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141
double qreal
Definition: qglobal.h:1193
qreal x() const
Returns the x coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:156
qreal y() const
Returns the y coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:157
qreal z() const
Returns the z coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:158

◆ operator+

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 239 of file qquaternion.h.

240 {
241  return QQuaternion(q1.wp + q2.wp, q1.xp + q2.xp, q1.yp + q2.yp, q1.zp + q2.zp);
242 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141

◆ operator- [1/2]

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 244 of file qquaternion.h.

245 {
246  return QQuaternion(q1.wp - q2.wp, q1.xp - q2.xp, q1.yp - q2.yp, q1.zp - q2.zp);
247 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141

◆ operator- [2/2]

const QQuaternion operator- ( const QQuaternion quaternion)
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.

260 {
261  return QQuaternion(-quaternion.wp, -quaternion.xp, -quaternion.yp, -quaternion.zp);
262 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141

◆ operator/

const QQuaternion operator/ ( const QQuaternion quaternion,
qreal  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 264 of file qquaternion.h.

265 {
266  return QQuaternion(quaternion.wp / divisor, quaternion.xp / divisor, quaternion.yp / divisor, quaternion.zp / divisor);
267 }
QQuaternion()
Constructs an identity quaternion, i.
Definition: qquaternion.h:141

◆ 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 691 of file qquaternion.cpp.

Referenced by toVector4D().

692 {
693  stream << double(quaternion.scalar()) << double(quaternion.x())
694  << double(quaternion.y()) << double(quaternion.z());
695  return stream;
696 }
qreal x() const
Returns the x coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:156
qreal scalar() const
Returns the scalar component of this quaternion.
Definition: qquaternion.h:159
static FILE * stream
qreal y() const
Returns the y coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:157
qreal z() const
Returns the z coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:158

◆ operator==

bool 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 229 of file qquaternion.h.

230 {
231  return q1.xp == q2.xp && q1.yp == q2.yp && q1.zp == q2.zp && q1.wp == q2.wp;
232 }

◆ operator>>() [1/2]

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 711 of file qquaternion.cpp.

712 {
713  double scalar, x, y, z;
714  stream >> scalar;
715  stream >> x;
716  stream >> y;
717  stream >> z;
718  quaternion.setScalar(qreal(scalar));
719  quaternion.setX(qreal(x));
720  quaternion.setY(qreal(y));
721  quaternion.setZ(qreal(z));
722  return stream;
723 }
double qreal
Definition: qglobal.h:1193
qreal x() const
Returns the x coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:156
void setZ(qreal z)
Sets the z coordinate of this quaternion&#39;s vector to the given z coordinate.
Definition: qquaternion.h:163
void setX(qreal x)
Sets the x coordinate of this quaternion&#39;s vector to the given x coordinate.
Definition: qquaternion.h:161
qreal scalar() const
Returns the scalar component of this quaternion.
Definition: qquaternion.h:159
static FILE * stream
void setScalar(qreal scalar)
Sets the scalar component of this quaternion to scalar.
Definition: qquaternion.h:164
qreal y() const
Returns the y coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:157
qreal z() const
Returns the z coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:158
void setY(qreal y)
Sets the y coordinate of this quaternion&#39;s vector to the given y coordinate.
Definition: qquaternion.h:162

◆ operator>>() [2/2]

QDataStream & operator>> ( QDataStream stream,
QEasingCurve easing 
)
related

Reads an easing curve from the given stream into the given easing curve and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 925 of file qeasingcurve.cpp.

Referenced by toVector4D().

926 {
928  quint8 int_type;
929  stream >> int_type;
930  type = static_cast<QEasingCurve::Type>(int_type);
931  easing.setType(type);
932 
933  quint64 ptr_func;
934  stream >> ptr_func;
935  easing.d_ptr->func = QEasingCurve::EasingFunction(quintptr(ptr_func));
936 
937  bool hasConfig;
938  stream >> hasConfig;
939  if (hasConfig) {
941  stream >> config->_p;
942  stream >> config->_a;
943  stream >> config->_o;
944  easing.d_ptr->config = config;
945  }
946  return stream;
947 }
int type
Definition: qmetatype.cpp:239
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
unsigned char quint8
Definition: qglobal.h:934
QEasingCurve::EasingFunction func
static FILE * stream
unsigned __int64 quint64
Definition: qglobal.h:943
QEasingCurvePrivate * d_ptr
Definition: qeasingcurve.h:102
QEasingCurveFunction * config
static QEasingCurveFunction * curveToFunctionObject(QEasingCurve::Type type)
Type
The type of easing curve.
Definition: qeasingcurve.h:60
void setType(Type type)
Sets the type of the easing curve to type.
qreal(* EasingFunction)(qreal progress)
This is a typedef for a pointer to a function with the following signature:
Definition: qeasingcurve.h:96

◆ qFuzzyCompare

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 269 of file qquaternion.h.

Referenced by qFuzzyCompare().

270 {
271  return qFuzzyCompare(q1.xp, q2.xp) &&
272  qFuzzyCompare(q1.yp, q2.yp) &&
273  qFuzzyCompare(q1.zp, q2.zp) &&
274  qFuzzyCompare(q1.wp, q2.wp);
275 }
friend 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 compari...
Definition: qquaternion.h:269

Properties

◆ wp

qreal QQuaternion::wp
private

◆ xp

qreal QQuaternion::xp
private

◆ yp

qreal QQuaternion::yp
private

◆ zp

qreal QQuaternion::zp
private

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