[Interest] [Qt3d] Rendering 3D object with 2D coordinates

Alex john blackbriar153 at gmail.com
Thu Mar 25 16:33:39 CET 2021


On Mon, Mar 22, 2021 at 10:55 AM Alex john <blackbriar153 at gmail.com> wrote:

>     Transform {
>         id: trefoilMeshTransform
>         translation:Qt.vector3d(Qt.vector2D(100, 100)).unproject(
> modelView ,mainCam.projectionMatrix, forwardRenderer.viewportRect)
>         property real theta: 0.0
>         property real phi:0.0
>         property real roll: 0.0
>         rotation: fromEulerAngles(theta, phi, roll)
>         scale: root.scale
>     }


I used the following function to get the 3d coordinates using the 2d,
by refering to the source code
https://code.woboq.org/qt5/qtbase/src/gui/math3d/qvector3d.cpp.html#_ZNK9QVector3D9unprojectERK10QMatrix4x4S2_RK5QRect
I need to render the 3d cube exactly where the Rectangle{x:100, y:100}
renders however there is lot of offset and I think the calculations is
somewhere going wrong. Can clue ?

function projectPointsto3d(){
        var ptX = 100
        var ptY = 100
        var windowPt = Qt.vector4d(ptX,ptY,1,1)
        var mat = mainCam.projectionMatrix.times(mainCam.viewMatrix)
        var inverse = mat.inverted()

        var normalize =  Qt.vector4d(1,1,1,1)
        windowPt.x = (windowPt.x -
forwardRenderer.viewportRect.x)/forwardRenderer.viewportRect.width
        windowPt.y = (windowPt.y -
forwardRenderer.viewportRect.y)/forwardRenderer.viewportRect.height

        windowPt = windowPt.times(2).minus(normalize)

        var a = inverse.times(windowPt)
        var division = a.w (if i use (1/a.w) teh 3d values will be
very high and I do not see object)
        a = a.times(division)
        return a.toVector3d()
    }


More information about the Interest mailing list