CopperSpice API  1.9.2
QQuaternion Class Reference

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

Public Methods

 QQuaternion ()
 
 QQuaternion (const QVector4D &vector)
 
 QQuaternion (qreal scalar, const QVector3D &vector)
 
 QQuaternion (qreal scalar, qreal xpos, qreal ypos, qreal zpos)
 
QQuaternion conjugate () const
 
bool isIdentity () const
 
bool isNull () const
 
qreal length () const
 
qreal lengthSquared () const
 
void normalize ()
 
QQuaternion normalized () const
 
 operator QVariant () const
 
QQuaternion & operator*= (const QQuaternion &quaternion)
 
QQuaternion & operator*= (qreal factor)
 
QQuaternion & operator+= (const QQuaternion &quaternion)
 
QQuaternion & operator-= (const QQuaternion &quaternion)
 
QQuaternion & operator/= (qreal divisor)
 
QVector3D rotatedVector (const QVector3D &vector) const
 
qreal scalar () const
 
void setScalar (qreal scalar)
 
void setVector (const QVector3D &vector)
 
void setVector (qreal x, qreal y, qreal z)
 
void setX (qreal x)
 
void setY (qreal y)
 
void setZ (qreal z)
 
QVector4D toVector4D () const
 
QVector3D vector () const
 
qreal x () const
 
qreal y () const
 
qreal z () const
 

Static Public Methods

static QQuaternion fromAxisAndAngle (const QVector3D &axis, qreal angle)
 
static QQuaternion fromAxisAndAngle (qreal x, qreal y, qreal z, qreal angle)
 
static QQuaternion nlerp (const QQuaternion &q1, const QQuaternion &q2, qreal t)
 
static QQuaternion slerp (const QQuaternion &q1, const QQuaternion &q2, qreal t)
 

Friends

bool operator!= (const QQuaternion &q1, const QQuaternion &q2)
 
const QQuaternion operator* (const QQuaternion &q1, const QQuaternion &q2)
 
const QQuaternion operator* (const QQuaternion &quaternion, qreal factor)
 
const QQuaternion operator* (qreal factor, const QQuaternion &quaternion)
 
const QQuaternion operator+ (const QQuaternion &q1, const QQuaternion &q2)
 
const QQuaternion operator- (const QQuaternion &q1, const QQuaternion &q2)
 
const QQuaternion operator- (const QQuaternion &quaternion)
 
const QQuaternion operator/ (const QQuaternion &quaternion, qreal divisor)
 
bool operator== (const QQuaternion &q1, const QQuaternion &q2)
 
bool qFuzzyCompare (const QQuaternion &q1, const QQuaternion &q2)
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &stream, const QQuaternion &quaternion)
 
QDataStreamoperator>> (QDataStream &stream, QEasingCurve &easing)
 
QDataStreamoperator>> (QDataStream &stream, QQuaternion &quaternion)
 

Detailed Description

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.

See also
vector(), scalar()

Constructor & Destructor Documentation

QQuaternion::QQuaternion ( )
inline

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

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

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

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

Constructs a quaternion vector from the specified vector and scalar.

See also
vector(), scalar()
QQuaternion::QQuaternion ( const QVector4D vector)
inlineexplicit

Constructs a quaternion from the components of vector.

Method Documentation

QQuaternion QQuaternion::conjugate ( ) const
inline

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

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.

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).

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.

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.

qreal QQuaternion::length ( ) const

Returns the length of the quaternion. This is also called the "norm".

See also
lengthSquared(), normalized()
qreal QQuaternion::lengthSquared ( ) const

Returns the squared length of the quaternion.

See also
length()
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()
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()
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()
QQuaternion::operator QVariant ( ) const

Returns the quaternion as a QVariant.

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

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

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/=()
QQuaternion & QQuaternion::operator+= ( const QQuaternion &  quaternion)
inline

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

See also
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+=()
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*=()
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();
qreal QQuaternion::scalar ( ) const
inline

Returns the scalar component of this quaternion.

See also
setScalar(), x(), y(), z()
void QQuaternion::setScalar ( qreal  scalar)
inline

Sets the scalar component of this quaternion to scalar.

See also
scalar(), setX(), setY(), setZ()
void QQuaternion::setVector ( const QVector3D vector)
inline

Sets the vector component of this quaternion to vector.

See also
vector(), setScalar()
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()
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()
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()
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()
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()
QVector4D QQuaternion::toVector4D ( ) const
inline

Returns this quaternion as a 4D vector.

QVector3D QQuaternion::vector ( ) const
inline

Returns the vector component of this quaternion.

See also
setVector(), scalar()
qreal QQuaternion::x ( ) const
inline

Returns the x coordinate of this quaternion's vector.

See also
setX(), y(), z(), scalar()
qreal QQuaternion::y ( ) const
inline

Returns the y coordinate of this quaternion's vector.

See also
setY(), x(), z(), scalar()
qreal QQuaternion::z ( ) const
inline

Returns the z coordinate of this quaternion's vector.

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

Friends And Related Function Documentation

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.

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*=()
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*=()
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*=()
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+=()
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-=()
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.

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

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/=()
QDataStream & operator<< ( QDataStream stream,
const QQuaternion &  quaternion 
)
related

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

Refer to Serializing Data Types for additional information.

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.

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

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

Refer to Serializing Data Types for additional information.

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

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

Refer to Serializing Data Types for additional information.

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.