Results 1 to 2 of 2

Thread: Qt3D: Most efficient way to position a plane mesh entity in space

  1. #1
    Join Date
    Nov 2006
    Dresden, Germany
    Thanked 10 Times in 9 Posts
    Qt products
    MacOS X Unix/X11 Windows

    Question Qt3D: Most efficient way to position a plane mesh entity in space

    Hi there,

    I'm wondering whether you'd have a suggestion on how to create and position a plane in 3D space using the Qt3DExtra types.

    Specifically, I have defined the target rectangular plane through points in space (p_i, i=0,1,2).

    I first create a plane using Qt3DExtras::QPlaneMesh providing the width w and height h of the given plane (width and height from vectors p_2-p_0 and p_1 - p_0). The plane mesh is created in the x-z plane (positive y-axis being the normal vector), and centered around w/2 and h/2. The points t_i of the newly created plane in world coordinates corresponding the my points p_i are (-w/2, 0, -h/2), (w/2,0,-h/2), and (-w/2, 0, h/2).

    Now I want to rotate and translate the plane entity to be positioned at my world coordinates p_i. My current approach involves creating a transformation matrix for world coordinates with QQuaternions and manually transforming the plane offset (w/2, h/2) (to move the lower left point of the matrix to the origin) into the mapped coordinates and add it to the local coordinate system origin p_0.

    This feels kind of complicated so here's my question: can you come up with a smoother/fancy or just faster solution?

    Thanks a ton,

  2. #2
    Join Date
    Nov 2006
    Dresden, Germany
    Thanked 10 Times in 9 Posts
    Qt products
    MacOS X Unix/X11 Windows

    Smile Re: Qt3D: Most efficient way to position a plane mesh entity in space

    Hi all,

    for your reference, here's my current solution to the problem. Can anyone do it better (shorter/faster/nicer and I mean not by removing the comments :-) ?

    Qt Code:
    1. Qt3DCore::QEntity * createTransformedPlane(Qt3DCore::QEntity * parent, QVector3D p0, QVector3D p1, QVector3D p3) {
    3. // vectors that span the plane
    4. QVector3D v1 = p1-p0;
    5. QVector3D v2 = p3-p0;
    7. // create standard mesh in xz plane
    8. Qt3DExtras::QPlaneMesh *planeMesh = new Qt3DExtras::QPlaneMesh();
    9. float wx = v1.length();
    10. float wz = v2.length();
    11. planeMesh->setWidth(wx);
    12. planeMesh->setHeight(wz);
    14. // Plane entity
    15. Qt3DCore::QEntity * planeEntity = new Qt3DCore::QEntity(parent);
    16. // add the mesh to the entity
    17. planeEntity->addComponent(planeMesh);
    20. // transformation
    22. // compute normal vector
    23. QVector3D n1 = QVector3D::crossProduct(v1,v2);
    25. // determine rotation matrix to align normal vector of plane with normal vector of generated plane (i.e. y-axis)
    26. QVector3D n2(0,1,0);
    28. QQuaternion rot = QQuaternion::rotationTo(n2, n1);
    30. // now we transform the w1 vector (corresponding to the v1 vector) into the target plane
    31. QVector3D w1(-1,0,0);
    32. // Mind: PlaneMesh is generated in x-z plane, with bottom-left point at q0=(w/2, 0, -h/2)
    33. // If numbered counter clock-wise, the next point is at q1=(-w/2, 0, -h/2) and the normalized vector w1 between q0 and q1
    34. // is w1=(-1,0,0)
    36. QVector3D w1Rotated = rot.rotatedVector(w1);
    38. // now we need to compute the rotation matrix to align the w1 vector with the v1 vector
    39. QQuaternion rot2 = QQuaternion::rotationTo(w1Rotated, v1);
    41. // combine both rotations (mind the matrix multiplication order!)
    42. QQuaternion planeRotation = rot2*rot;
    44. // anchor point of generated mesh
    45. QVector3D q0(wx/2, 0, -wz/2);
    46. // Point q0 after rotation
    47. QVector3D q0rot = planeRotation.rotatedVector(q0);
    49. //translation to target anchor point
    50. QVector3D transVec = p0 - q0rot;
    52. // create transformation
    53. Qt3DCore::QTransform *transform = new Qt3DCore::QTransform();
    54. transform->setTranslation(transVec);
    55. transform->setRotation(planeRotation);
    57. // and set it as component
    58. planeEntity->addComponent(transform);
    60. return planeEntity;
    61. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Multiple plane in QGraphicsView
    By jaisankar in forum Qt Programming
    Replies: 4
    Last Post: 14th February 2018, 10:00
  2. QXmlStreamReader and entity label
    By Suppaman in forum Qt Programming
    Replies: 2
    Last Post: 3rd September 2013, 06:42
  3. HttpHeader Request only part of an entity
    By nhs_0702 in forum Qt Programming
    Replies: 21
    Last Post: 25th April 2010, 09:35
  4. How to orientate the plane's positioan on the map
    By lengshuang in forum Qt Programming
    Replies: 0
    Last Post: 10th April 2009, 01:14
  5. Special character's HTML entity to string
    By Hiba in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2009, 14:05


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.