c++qtqt3dqtwidgets

QT - Draw a point at a user specified location in a 3D surface


I was going through the Surface example here

When the user clicks anywhere it draws a point

image surface

what i'd like to know is how to do this programatically,like, if a user gives 3 coordinates x, y, and z. How do I go about plotting such point?


Solution

  • you can add a custom item like so:

      QImage color = QImage(2, 2, QImage::Format_RGB32);
            color.fill(Qt::cyan);
    
            QVector3D positionOne = QVector3D(2.0f, 2.0f, 0.0f);
            QCustom3DItem* item = new QCustom3DItem(":/items/monkey.obj", positionOne,
                QVector3D(0.0f, 0.0f, 0.0f),
                QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 0.0f, 45.0f),
                color);
            item->setScaling(QVector3D(0.1f, 0.1f, 0.1f));
            m_graph->addCustomItem(item);
    

    Note that the .obj file must be a mesh file, you can generate one with blender for example, just don't forget to triangulate the mesh before you export the .obj file.

    enter image description here