Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.2, 6.0.0
-
None
Description
QVector3D documentation says `"The QVector3D class represents a vector or vertex in 3D space." `
QMatrix4x4 provides an operator* to transform a QVector3D. This has several issues:
- Using * remembers of an algebraic operation, which is incorrect between a 4x4 matrix and a 3x1 vector. This is implement as if the QVeector3D was a QVector4D with a 1 in the w coordinate and doing the mathematical operation.
- By doing that, it fails the purpose of QVector3D being a vector or a vertex, since its always considered a vertex. You can't consider a vector because when transforming it with a QMatrix4x4 its going to be treated as a vertex.
- Thee operator* remembers of the algebraic operation, so one could think that the distributive property applies, but it doesnt.
Consider the following code:
QMatrix4x4 worldMatrix; QVector3D p; worldMatrix * p - worldMatrix * QVector3D(0,0,0);
p here is a vector, so when applying the worldMatrix transformation, I dont wan't the traslation. That is why I need to remove it with the `worldMatrix * QVector3D(0,0,0)`.
One could also consider that the code could be refactored as:
QMatrix4x4 worldMatrix;
QVector3D p;
worldMatrix * p; // in algebra, multiplying by a null vector returns a null vector
which doesn't give the same result.
I would suggest deprecating and removing all the non mathematical operations and use proper algebra for these operations.