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

2021-03-25 Thread Alex john
On Mon, Mar 22, 2021 at 10:55 AM Alex john  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()
}
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2021-03-24 Thread Alex john
On Mon, Mar 22, 2021 at 10:55 AM Alex john  wrote:
>
> On Thu, Mar 18, 2021 at 5:22 AM Walter Rawdanik  wrote:
> >
> > You can’t convert 2d coordinates to a 3d position because you are missing 
> > the z coordinate.
>
> I can have a dummy z value as 1 for the calculation. The problem is
> similar  as described here
> https://community.khronos.org/t/getting-2d-to-3d/20050/6 in opengl
> they could fetch the requirted matrix for gluUnProject and get the 3d
> coordinates from 2d. However, in Qt3d, I'm stuck to fetch the required
> matrix i.e modelView etc and pass it correctly to the
> vector3d::uproject and get the corresponding 3d points back. All I
> could do is the following, however I doubt the correctness of it.
>
> // The code is exactly same as wireframe example file TrefoilKnot.qml
>
> 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
> }
>
> In translation, Qt.vector2D(100, 100) is where I give the x,y (window
> coordinates) and expect the unproject api will return the 3d points
> for translation. mainCam.projectionMatrix and
> forwardRenderer.viewportRect are set from BasicCamera and
> Forwardrenderer from main.qml respectively. And I do not know where to
> get modelView. If you let me know the modelView matrix and confirm the
> above changes are right,  I'll be thankful.
>
> Do let me know.

Can anyone let me know about this?
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2021-03-21 Thread Alex john
On Thu, Mar 18, 2021 at 5:22 AM Walter Rawdanik  wrote:
>
> You can’t convert 2d coordinates to a 3d position because you are missing the 
> z coordinate.

I can have a dummy z value as 1 for the calculation. The problem is
similar  as described here
https://community.khronos.org/t/getting-2d-to-3d/20050/6 in opengl
they could fetch the requirted matrix for gluUnProject and get the 3d
coordinates from 2d. However, in Qt3d, I'm stuck to fetch the required
matrix i.e modelView etc and pass it correctly to the
vector3d::uproject and get the corresponding 3d points back. All I
could do is the following, however I doubt the correctness of it.

// The code is exactly same as wireframe example file TrefoilKnot.qml

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
}

In translation, Qt.vector2D(100, 100) is where I give the x,y (window
coordinates) and expect the unproject api will return the 3d points
for translation. mainCam.projectionMatrix and
forwardRenderer.viewportRect are set from BasicCamera and
Forwardrenderer from main.qml respectively. And I do not know where to
get modelView. If you let me know the modelView matrix and confirm the
above changes are right,  I'll be thankful.

Do let me know.
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2021-03-17 Thread Walter Rawdanik
You can’t convert 2d coordinates to a 3d position because you are missing the z 
coordinate. It is similar problem like with picking objects in a 3D scene - you 
can unproject a 2d screen coordinate to a vector/ray in your 3d scene and then 
do a ray casting to see what you hit but that’s about it.
If you just want to render a 3D object at a specific location on a screen you 
can do so via rendering to an offscreen target and then displaying it like a 
regular 2d image but that will look and act like an overlay image rather than 
being composed into your scene.

Sent from my iPad

> On Mar 16, 2021, at 10:52 AM, Alex john  wrote:
> 
> 
> 
> 
> I did the following changes to the wireframe example (Trefoilknot.qml file 
> translation property of transform) but still unable to get the modelView 
> Matrix,  and also not sure whether the following changes to translation are 
> right If anyone can confirm and let me know
> 
> property var mainCam   // got the mainCamera ID from main.qml (wireframe 
> example)
> property var forwardRenderer //forwardRendered id from main.qml (wireframe 
> example)
> 
>  Transform {
> id: trefoilMeshTransform
> translation:Qt.vector3d(Qt.vector2D(4, 4)).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
> }
> /*
>  translation : Qt.vector2D(100, 100) is where I intend to give window 2d 
> coordinates(here its x:100, y:100)and I assume that unproject api will 
> convert the 2d points to 3d and renders the 3d object exactly at 100, 100 
> pixel 2d location
> */
> 
> I got the projectionMatrix from camera, viewPortRect from ForwardRenderer in 
> Rendering settings. I'm completely stuck for this step. If anyone can please 
> confirm the changes and let me know the modelView matrix.
> 
> 
>> On Mon, Mar 15, 2021 at 5:14 PM Alex john  wrote:
>> > Going the other way round (back-projection) can be done by e.g. 
>> > QVector3D::unproject()
>> 
>> Thanks, as I'm referring the the wireframe example I was able to get
>> the camera projection matrix from Camera Qml.  However, I'm unsure how
>> to get the ModelView matrix and the viewport.
>> 
>> As I have loaded my custom obj in wireframe example and using the same
>> geometry and camera settings as its for wireframe, therefore can you
>> please let me know how this can be done at QML side? I did try to find
>> this in the documentation but didn't find the usage.
>> 
>> 
>> 
>> 
>> > On Mon, Mar 15, 2021 at 11:03 AM Alex john  wrote:
>> >>
>> >> Hello ,
>> >>
>> >> Im successessfully able to load the obj file in Scene3D, and by using
>> >> fromEulerAngles I'm able to get the required yaw, pitch and
>> >> roll.However, I'm not able to use the right translation to get the
>> >> object rendered. I get the x,y coordinates in pixels from the other
>> >> module and I need to render the 3d model exactly at that pixel
>> >> location. It turns out that the Transform type has translation and it
>> >> takes the input in 3d coordinates (not sure which unit) if I try to
>> >> assign the x,y coordinates to the 3d coordinates it renders somewhere
>> >> else. Seems like the x,y in the translation is not the pixel 2d
>> >> values, as even with a x=0.3 it deflects more than expected.
>> >>
>> >> Is there a way to assign the x,y 2d pixel values (as we do for
>> >> Rectangle {x: 100, y:100}) to the translation so that it is rendered
>> >> to the right place where it's desired.
>> >> ___
>> >> Interest mailing list
>> >> Interest@qt-project.org
>> >> https://lists.qt-project.org/listinfo/interest
> ___
> Interest mailing list
> Interest@qt-project.org
> https://lists.qt-project.org/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2021-03-16 Thread Alex john
I did the following changes to the wireframe example (Trefoilknot.qml file
translation property of transform) but still unable to get the modelView
Matrix,  and also not sure whether the following changes to translation are
right If anyone can confirm and let me know

property var mainCam   // got the mainCamera ID from main.qml (wireframe
example)
property var forwardRenderer //forwardRendered id from main.qml (wireframe
example)

 Transform {
id: trefoilMeshTransform
*translation:Qt.vector3d(Qt.vector2D(4, 4)).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
}
/*
 *translation* : Qt.vector2D(100, 100) is where I intend to give window 2d
coordinates(here its x:100, y:100)and I assume that unproject api will
convert the 2d points to 3d and renders the 3d object exactly at 100, 100
pixel 2d location
*/

I got the projectionMatrix from camera, viewPortRect from ForwardRenderer
in Rendering settings. I'm completely stuck for this step. If anyone can
please confirm the changes and let me know the modelView matrix.


On Mon, Mar 15, 2021 at 5:14 PM Alex john  wrote:

> > Going the other way round (back-projection) can be done by e.g.
> QVector3D::unproject()
>
> Thanks, as I'm referring the the wireframe example I was able to get
> the camera projection matrix from Camera Qml.  However, I'm unsure how
> to get the ModelView matrix and the viewport.
>
> As I have loaded my custom obj in wireframe example and using the same
> geometry and camera settings as its for wireframe, therefore can you
> please let me know how this can be done at QML side? I did try to find
> this in the documentation but didn't find the usage.
>
>
>
>
> > On Mon, Mar 15, 2021 at 11:03 AM Alex john 
> wrote:
> >>
> >> Hello ,
> >>
> >> Im successessfully able to load the obj file in Scene3D, and by using
> >> fromEulerAngles I'm able to get the required yaw, pitch and
> >> roll.However, I'm not able to use the right translation to get the
> >> object rendered. I get the x,y coordinates in pixels from the other
> >> module and I need to render the 3d model exactly at that pixel
> >> location. It turns out that the Transform type has translation and it
> >> takes the input in 3d coordinates (not sure which unit) if I try to
> >> assign the x,y coordinates to the 3d coordinates it renders somewhere
> >> else. Seems like the x,y in the translation is not the pixel 2d
> >> values, as even with a x=0.3 it deflects more than expected.
> >>
> >> Is there a way to assign the x,y 2d pixel values (as we do for
> >> Rectangle {x: 100, y:100}) to the translation so that it is rendered
> >> to the right place where it's desired.
> >> ___
> >> Interest mailing list
> >> Interest@qt-project.org
> >> https://lists.qt-project.org/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2021-03-15 Thread Alex john
> Going the other way round (back-projection) can be done by e.g. 
> QVector3D::unproject()

Thanks, as I'm referring the the wireframe example I was able to get
the camera projection matrix from Camera Qml.  However, I'm unsure how
to get the ModelView matrix and the viewport.

As I have loaded my custom obj in wireframe example and using the same
geometry and camera settings as its for wireframe, therefore can you
please let me know how this can be done at QML side? I did try to find
this in the documentation but didn't find the usage.




> On Mon, Mar 15, 2021 at 11:03 AM Alex john  wrote:
>>
>> Hello ,
>>
>> Im successessfully able to load the obj file in Scene3D, and by using
>> fromEulerAngles I'm able to get the required yaw, pitch and
>> roll.However, I'm not able to use the right translation to get the
>> object rendered. I get the x,y coordinates in pixels from the other
>> module and I need to render the 3d model exactly at that pixel
>> location. It turns out that the Transform type has translation and it
>> takes the input in 3d coordinates (not sure which unit) if I try to
>> assign the x,y coordinates to the 3d coordinates it renders somewhere
>> else. Seems like the x,y in the translation is not the pixel 2d
>> values, as even with a x=0.3 it deflects more than expected.
>>
>> Is there a way to assign the x,y 2d pixel values (as we do for
>> Rectangle {x: 100, y:100}) to the translation so that it is rendered
>> to the right place where it's desired.
>> ___
>> Interest mailing list
>> Interest@qt-project.org
>> https://lists.qt-project.org/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2021-03-15 Thread Federico Ferri
The 3D coordinates are *world coordinates*, and their units is whatever you
like, e.g. you can have a cube of size 0.1, 1, or 100, and with appropriate
camera settings, it will appear the same onto the window/device.

2D *window coordinates* are another thing.

For going to world coords to window coords points are (left) multiplied by
the view matrix, then by the projection matrix, then coordinates are
scaled/translated to render in the window/viewport (this is not specific to
Qt3D, it's just basic OpenGL).

Going the other way round (back-projection) can be done by e.g.
QVector3D::unproject()

On Mon, Mar 15, 2021 at 11:03 AM Alex john  wrote:

> Hello ,
>
> Im successessfully able to load the obj file in Scene3D, and by using
> fromEulerAngles I'm able to get the required yaw, pitch and
> roll.However, I'm not able to use the right translation to get the
> object rendered. I get the x,y coordinates in pixels from the other
> module and I need to render the 3d model exactly at that pixel
> location. It turns out that the Transform type has translation and it
> takes the input in 3d coordinates (not sure which unit) if I try to
> assign the x,y coordinates to the 3d coordinates it renders somewhere
> else. Seems like the x,y in the translation is not the pixel 2d
> values, as even with a x=0.3 it deflects more than expected.
>
> Is there a way to assign the x,y 2d pixel values (as we do for
> Rectangle {x: 100, y:100}) to the translation so that it is rendered
> to the right place where it's desired.
> ___
> Interest mailing list
> Interest@qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2021-03-15 Thread Alex john
Hello ,

Im successessfully able to load the obj file in Scene3D, and by using
fromEulerAngles I'm able to get the required yaw, pitch and
roll.However, I'm not able to use the right translation to get the
object rendered. I get the x,y coordinates in pixels from the other
module and I need to render the 3d model exactly at that pixel
location. It turns out that the Transform type has translation and it
takes the input in 3d coordinates (not sure which unit) if I try to
assign the x,y coordinates to the 3d coordinates it renders somewhere
else. Seems like the x,y in the translation is not the pixel 2d
values, as even with a x=0.3 it deflects more than expected.

Is there a way to assign the x,y 2d pixel values (as we do for
Rectangle {x: 100, y:100}) to the translation so that it is rendered
to the right place where it's desired.
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest