1

I have a window size width: 1500 height: 780, I would like to render the 3d object with 2d co-ordinates, giving z=1 as dummy value. Following is the qml code.(If i have to render at x=0,y=0 3d should object should render exactly the same place where the Rectangle in qml renders i.e window coordinates)

Entity {
    id: root

    property real x: 2.0
    property real y: 0.0
    property real z: 0.0
    property real scale: 1
    property var mainCam
    property var forwardRenderer
    property Material material


    components: [ trefoilMeshTransform, mesh, root.material ]

    Transform {
        id: trefoilMeshTransform
         property real userAngle: 900.0
        translation:Qt.vector3d(0,1,1) 
        property real theta: 0.0
        property real phi:0.0
        property real roll: 0.0
        rotation: fromEulerAngles(theta, phi, roll)
        scale: root.scale
    }


    Mesh {
        id: mesh
        source: "assets/obj/cube.obj"
    }
}

The code is exactly the same as wireframe example, including the camera settings. I tried to use the qt3d unproject api in qml but ended up unsuccessfully . Can you please help me with the clue?

genpfault
  • 51,148
  • 11
  • 85
  • 139
AceMyWays
  • 11
  • 1
  • 1
    What is your question? – folibis Mar 24 '21 at 07:08
  • @folibis, I want to render the 3d object using 2d coordinates. In translation , I expect to pass the 2d window coordinates by giving dummy z=1 and the 3d object should render at the specific location. I like to do something like this in translation: qt.vector3d(100,100,1). unproject (modelview, projectionMatrix, viewPort) Here 100, 100 is the 2d window coordinates and z=1 is dummy value. But the above code doesn't run as unproject is inaccessible at qml side Can you please help? Or let me to the right direction – AceMyWays Mar 25 '21 at 08:19
  • 1
    It's pretty unclear what you want to do. Do you want the center of your object to render at the location you are giving? How do you want to specify the distance to the camera? Maybe if you explained **why** you want to render your object this way it would make more sense. – Florian Blume Mar 25 '21 at 12:12

1 Answers1

1

Please read this document about How to convert world to screen coordinates and vice versa this is good for understanding some logics. and also this.

In qt3d I get 3d coordinate by using RayCaster and ScreenRayCaster it gives you the local position and world position and screen x , y see this site from kdab and its example

RenderSettings{
    
    //all components that you need like viewport , InputSettings ,...
    
    ScreenRayCaster {
        id: screenRayCaster
        
        onHitsChanged: printHits("Screen hits", hits)
    }
}

MouseHandler {
    id: mouseHandler
    sourceDevice:  MouseDevice {}
    onReleased: { screenRayCaster.trigger(Qt.point(mouse.x, mouse.y)) }
}

function printHits(desc, hits) {
    console.log(desc, hits.length)
    for (var i=0; i<hits.length; i++) {
        console.log("  " + hits[i].entity.objectName, hits[i].distance,
                    hits[i].worldIntersection.x, hits[i].worldIntersection.y, hits[i].worldIntersection.z)
    }
}
Parisa.H.R
  • 3,303
  • 3
  • 19
  • 38