Qt 4.8
|
The QVector4D class represents a vector or vertex in 4D space. More...
#include <qvector4d.h>
Public Functions | |
bool | isNull () const |
Returns true if the x, y, z, and w coordinates are set to 0. More... | |
qreal | length () const |
Returns the length of the vector from the origin. More... | |
qreal | lengthSquared () const |
Returns the squared length of the vector from the origin. More... | |
void | normalize () |
Normalizes the currect vector in place. More... | |
QVector4D | normalized () const |
Returns the normalized unit vector form of this vector. More... | |
operator QVariant () const | |
Returns the 4D vector as a QVariant. More... | |
QVector4D & | operator*= (qreal factor) |
Multiplies this vector's coordinates by the given factor, and returns a reference to this vector. More... | |
QVector4D & | operator*= (const QVector4D &vector) |
Multiplies the components of this vector by the corresponding components in vector. More... | |
QVector4D & | operator+= (const QVector4D &vector) |
Adds the given vector to this vector and returns a reference to this vector. More... | |
QVector4D & | operator-= (const QVector4D &vector) |
Subtracts the given vector from this vector and returns a reference to this vector. More... | |
QVector4D & | operator/= (qreal divisor) |
Divides this vector's coordinates by the given divisor, and returns a reference to this vector. More... | |
QVector4D () | |
Constructs a null vector, i. More... | |
QVector4D (qreal xpos, qreal ypos, qreal zpos, qreal wpos) | |
Constructs a vector with coordinates (xpos, ypos, zpos, wpos). More... | |
QVector4D (const QPoint &point) | |
Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0. More... | |
QVector4D (const QPointF &point) | |
Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0. More... | |
QVector4D (const QVector2D &vector) | |
Constructs a 4D vector from the specified 2D vector. More... | |
QVector4D (const QVector2D &vector, qreal zpos, qreal wpos) | |
Constructs a 4D vector from the specified 2D vector. More... | |
QVector4D (const QVector3D &vector) | |
Constructs a 4D vector from the specified 3D vector. More... | |
QVector4D (const QVector3D &vector, qreal wpos) | |
Constructs a 4D vector from the specified 3D vector. More... | |
void | setW (qreal w) |
Sets the w coordinate of this point to the given w coordinate. More... | |
void | setX (qreal x) |
Sets the x coordinate of this point to the given x coordinate. More... | |
void | setY (qreal y) |
Sets the y coordinate of this point to the given y coordinate. More... | |
void | setZ (qreal z) |
Sets the z coordinate of this point to the given z coordinate. More... | |
QPoint | toPoint () const |
Returns the QPoint form of this 4D vector. More... | |
QPointF | toPointF () const |
Returns the QPointF form of this 4D vector. More... | |
QVector2D | toVector2D () const |
Returns the 2D vector form of this 4D vector, dropping the z and w coordinates. More... | |
QVector2D | toVector2DAffine () const |
Returns the 2D vector form of this 4D vector, dividing the x and y coordinates by the w coordinate and dropping the z coordinate. More... | |
QVector3D | toVector3D () const |
Returns the 3D vector form of this 4D vector, dropping the w coordinate. More... | |
QVector3D | toVector3DAffine () const |
Returns the 3D vector form of this 4D vector, dividing the x, y, and z coordinates by the w coordinate. More... | |
qreal | w () const |
Returns the w coordinate of this point. More... | |
qreal | x () const |
Returns the x coordinate of this point. More... | |
qreal | y () const |
Returns the y coordinate of this point. More... | |
qreal | z () const |
Returns the z coordinate of this point. More... | |
Static Public Functions | |
static qreal | dotProduct (const QVector4D &v1, const QVector4D &v2) |
Returns the dot product of v1 and v2. More... | |
Private Functions | |
QVector4D (float xpos, float ypos, float zpos, float wpos, int dummy) | |
Properties | |
float | wp |
float | xp |
float | yp |
float | zp |
Friends | |
bool | operator!= (const QVector4D &v1, const QVector4D &v2) |
Returns true if v1 is not equal to v2; otherwise returns false. More... | |
const QVector4D | operator* (qreal factor, const QVector4D &vector) |
const QVector4D | operator* (const QVector4D &vector, qreal factor) |
const QVector4D | operator* (const QVector4D &v1, const QVector4D &v2) |
QVector4D | operator* (const QVector4D &vector, const QMatrix4x4 &matrix) |
QVector4D | operator* (const QMatrix4x4 &matrix, const QVector4D &vector) |
const QVector4D | operator+ (const QVector4D &v1, const QVector4D &v2) |
Returns a QVector4D object that is the sum of the given vectors, v1 and v2; each component is added separately. More... | |
const QVector4D | operator- (const QVector4D &v1, const QVector4D &v2) |
Returns a QVector4D object that is formed by subtracting v2 from v1; each component is subtracted separately. More... | |
const QVector4D | operator- (const QVector4D &vector) |
Returns a QVector4D object that is formed by changing the sign of all three components of the given vector. More... | |
const QVector4D | operator/ (const QVector4D &vector, qreal divisor) |
Returns the QVector4D object formed by dividing all four components of the given vector by the given divisor. More... | |
bool | operator== (const QVector4D &v1, const QVector4D &v2) |
Returns true if v1 is equal to v2; otherwise returns false. More... | |
bool | qFuzzyCompare (const QVector4D &v1, const QVector4D &v2) |
Returns true if v1 and v2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise. More... | |
class | QVector2D |
class | QVector3D |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &stream, const QVector4D &vector) |
Writes the given vector to the given stream and returns a reference to the stream. More... | |
QDataStream & | operator>> (QDataStream &stream, QVector4D &vector) |
Reads a 4D vector from the given stream into the given vector and returns a reference to the stream. More... | |
The QVector4D class represents a vector or vertex in 4D space.
The QVector4D class can also be used to represent vertices in 4D space. We therefore do not need to provide a separate vertex class.
Note: By design values in the QVector4D instance are stored as float
. This means that on platforms where the qreal
arguments to QVector4D functions are represented by double
values, it is possible to lose precision.
Definition at line 60 of file qvector4d.h.
|
inline |
Constructs a null vector, i.
e. with coordinates (0, 0, 0, 0).
Definition at line 143 of file qvector4d.h.
Referenced by normalized(), operator*(), operator+(), operator-(), and operator/().
Constructs a vector with coordinates (xpos, ypos, zpos, wpos).
Definition at line 145 of file qvector4d.h.
|
inlineexplicit |
Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0.
Definition at line 149 of file qvector4d.h.
|
inlineexplicit |
Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0.
Definition at line 151 of file qvector4d.h.
QVector4D::QVector4D | ( | const QVector2D & | vector | ) |
Constructs a 4D vector from the specified 2D vector.
The z and w coordinates are set to zero.
Definition at line 119 of file qvector4d.cpp.
Constructs a 4D vector from the specified 2D vector.
The z and w coordinates are set to zpos and wpos respectively.
Definition at line 133 of file qvector4d.cpp.
QVector4D::QVector4D | ( | const QVector3D & | vector | ) |
Constructs a 4D vector from the specified 3D vector.
The w coordinate is set to zero.
Definition at line 151 of file qvector4d.cpp.
Constructs a 4D vector from the specified 3D vector.
The w coordinate is set to wpos.
Definition at line 165 of file qvector4d.cpp.
|
inlineprivate |
Definition at line 147 of file qvector4d.h.
|
inline |
Returns true if the x, y, z, and w coordinates are set to 0.
0, otherwise returns false.
Definition at line 153 of file qvector4d.h.
qreal QVector4D::length | ( | ) | const |
Returns the length of the vector from the origin.
Definition at line 278 of file qvector4d.cpp.
qreal QVector4D::lengthSquared | ( | ) | const |
Returns the squared length of the vector from the origin.
This is equivalent to the dot product of the vector with itself.
Definition at line 289 of file qvector4d.cpp.
void QVector4D::normalize | ( | ) |
Normalizes the currect vector in place.
Nothing happens if this vector is a null vector or the length of the vector is very close to 1.
Definition at line 324 of file qvector4d.cpp.
QVector4D QVector4D::normalized | ( | ) | const |
Returns the normalized unit vector form of this vector.
If this vector is null, then a null vector is returned. If the length of the vector is very close to 1, then the vector will be returned as-is. Otherwise the normalized form of the vector of length 1 will be returned.
Definition at line 303 of file qvector4d.cpp.
QVector4D::operator QVariant | ( | ) | const |
Returns the 4D vector as a QVariant.
Definition at line 595 of file qvector4d.cpp.
Multiplies this vector's coordinates by the given factor, and returns a reference to this vector.
Definition at line 186 of file qvector4d.h.
Multiplies the components of this vector by the corresponding components in vector.
Definition at line 195 of file qvector4d.h.
Adds the given vector to this vector and returns a reference to this vector.
Definition at line 168 of file qvector4d.h.
Subtracts the given vector from this vector and returns a reference to this vector.
Definition at line 177 of file qvector4d.h.
Divides this vector's coordinates by the given divisor, and returns a reference to this vector.
Definition at line 204 of file qvector4d.h.
|
inline |
Sets the w coordinate of this point to the given w coordinate.
Definition at line 166 of file qvector4d.h.
Referenced by operator>>(), and QDeclarativeVector4DValueType::setW().
|
inline |
Sets the x coordinate of this point to the given x coordinate.
Definition at line 163 of file qvector4d.h.
Referenced by operator>>(), and QDeclarativeVector4DValueType::setX().
|
inline |
Sets the y coordinate of this point to the given y coordinate.
Definition at line 164 of file qvector4d.h.
Referenced by operator>>(), and QDeclarativeVector4DValueType::setY().
|
inline |
Sets the z coordinate of this point to the given z coordinate.
Definition at line 165 of file qvector4d.h.
Referenced by operator>>(), and QDeclarativeVector4DValueType::setZ().
|
inline |
Returns the QPoint form of this 4D vector.
The z and w coordinates are dropped.
Definition at line 266 of file qvector4d.h.
|
inline |
Returns the QPointF form of this 4D vector.
The z and w coordinates are dropped.
Definition at line 271 of file qvector4d.h.
QVector2D QVector4D::toVector2D | ( | ) | const |
Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.
Definition at line 520 of file qvector4d.cpp.
QVector2D QVector4D::toVector2DAffine | ( | ) | const |
Returns the 2D vector form of this 4D vector, dividing the x and y coordinates by the w coordinate and dropping the z coordinate.
Returns a null vector if w is zero.
Definition at line 532 of file qvector4d.cpp.
QVector3D QVector4D::toVector3D | ( | ) | const |
Returns the 3D vector form of this 4D vector, dropping the w coordinate.
Definition at line 548 of file qvector4d.cpp.
QVector3D QVector4D::toVector3DAffine | ( | ) | const |
Returns the 3D vector form of this 4D vector, dividing the x, y, and z coordinates by the w coordinate.
Returns a null vector if w is zero.
Definition at line 559 of file qvector4d.cpp.
|
inline |
Returns the w coordinate of this point.
Definition at line 161 of file qvector4d.h.
Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::setColumn(), QMatrix4x4::setRow(), and QDeclarativeVector4DValueType::setValue().
|
inline |
Returns the x coordinate of this point.
Definition at line 158 of file qvector4d.h.
Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::setColumn(), QMatrix4x4::setRow(), and QDeclarativeVector4DValueType::setValue().
|
inline |
Returns the y coordinate of this point.
Definition at line 159 of file qvector4d.h.
Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::setColumn(), QMatrix4x4::setRow(), and QDeclarativeVector4DValueType::setValue().
|
inline |
Returns the z coordinate of this point.
Definition at line 160 of file qvector4d.h.
Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::setColumn(), QMatrix4x4::setRow(), and QDeclarativeVector4DValueType::setValue().
Returns true if v1 is not equal to v2; otherwise returns false.
This operator uses an exact floating-point comparison.
Definition at line 218 of file qvector4d.h.
Returns a copy of the given vector, multiplied by the given factor.
Definition at line 233 of file qvector4d.h.
Returns a copy of the given vector, multiplied by the given factor.
Definition at line 238 of file qvector4d.h.
Returns the vector consisting of the multiplication of the components from v1 and v2.
Definition at line 243 of file qvector4d.h.
|
friend |
Definition at line 677 of file qmatrix4x4.h.
|
friend |
Definition at line 699 of file qmatrix4x4.h.
Returns a QVector4D object that is the sum of the given vectors, v1 and v2; each component is added separately.
Definition at line 223 of file qvector4d.h.
Returns a QVector4D object that is formed by subtracting v2 from v1; each component is subtracted separately.
Definition at line 228 of file qvector4d.h.
Returns a QVector4D object that is formed by changing the sign of all three components of the given vector.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Equivalent to {QVector4D(0,0,0,0)
- vector}.
Definition at line 248 of file qvector4d.h.
Returns the QVector4D object formed by dividing all four components of the given vector by the given divisor.
Definition at line 253 of file qvector4d.h.
|
related |
Writes the given vector to the given stream and returns a reference to the stream.
Definition at line 627 of file qvector4d.cpp.
Referenced by toPointF().
Returns true if v1 is equal to v2; otherwise returns false.
This operator uses an exact floating-point comparison.
Definition at line 213 of file qvector4d.h.
|
related |
Reads a 4D vector from the given stream into the given vector and returns a reference to the stream.
Definition at line 647 of file qvector4d.cpp.
Referenced by toPointF().
Returns true if v1 and v2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.
Definition at line 258 of file qvector4d.h.
Referenced by qFuzzyCompare().
Definition at line 133 of file qvector4d.h.
Referenced by toVector2D(), and toVector2DAffine().
Definition at line 134 of file qvector4d.h.
Referenced by toVector3D(), and toVector3DAffine().
|
private |
Definition at line 129 of file qvector4d.h.
Referenced by dotProduct(), isNull(), length(), lengthSquared(), normalize(), normalized(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator==(), qFuzzyCompare(), QVector4D(), setW(), toVector2DAffine(), toVector3DAffine(), and w().
|
private |
Definition at line 129 of file qvector4d.h.
Referenced by dotProduct(), isNull(), length(), lengthSquared(), normalize(), normalized(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator==(), qFuzzyCompare(), QVector2D::QVector2D(), QVector3D::QVector3D(), QVector4D(), setX(), toPoint(), toPointF(), toVector2D(), toVector2DAffine(), toVector3D(), toVector3DAffine(), and x().
|
private |
Definition at line 129 of file qvector4d.h.
Referenced by dotProduct(), isNull(), length(), lengthSquared(), normalize(), normalized(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator==(), qFuzzyCompare(), QVector2D::QVector2D(), QVector3D::QVector3D(), QVector4D(), setY(), toPoint(), toPointF(), toVector2D(), toVector2DAffine(), toVector3D(), toVector3DAffine(), and y().
|
private |
Definition at line 129 of file qvector4d.h.
Referenced by dotProduct(), isNull(), length(), lengthSquared(), normalize(), normalized(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator==(), qFuzzyCompare(), QVector3D::QVector3D(), QVector4D(), setZ(), toVector3D(), toVector3DAffine(), and z().