Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89708

QMatrix4x4 operator* with QVector3D is unclear



    • Type: Suggestion
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.2, 6.0.0
    • Fix Version/s: None
    • Component/s: GUI: OpenGL, GUI: Painting
    • Labels:


       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:

      1. 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.
      2. 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. 
      3. 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. 


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            lagocs Laszlo Agocs
            juan.casafranca Juan José Casafranca
            0 Vote for this issue
            6 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes