smartGL icon indicating copy to clipboard operation
smartGL copied to clipboard

Object3D location vs screen coordinates

Open creek23 opened this issue 7 years ago • 3 comments

Is there a documentation on how to properly map 3D object's location on phone screen?

I'm trying to touch the 3D and move it around my screen. I tried iteration of 1 but the jump wasn't per pixel but by some kind of unit I'm currently not aware of.

I can cheat around for my phone's screen size but what would assure me that my app will work properly to someone else's phone?

~creek23

creek23 avatar Jul 04 '17 20:07 creek23

Hi,

there is no "pixel" position for 3D Objects.

The size of the objects depends on the size of the view. You can compare this to a picture that you resize. On small screens you have a small picture, on big TVs you have a big picture, but the picture is the same.

If on a device the aspect ratio is different (rectangle vs square) it may have some more or less space on the side of your object.

Arnaud.

smart-fun avatar Jul 07 '17 13:07 smart-fun

How do you suggest how I should handle situations like, I touch to screen's X/Y coordinate and have a 3D object move to that location?

~creek23

creek23 avatar Jul 07 '17 13:07 creek23

If you can cheat I would recommend to do it as it is not that simple to go from 2D to 3D. As you can imagine, there are infinite solutions when you click on a X,Y position (the 3D point can be from very near to infinite distance)

When going from 3D to 2D, a projection matrix is used. To do the opposite operation (2D to 3D), you need to invert the process. Here is a good and short explanation of the 2 operations: https://stackoverflow.com/questions/31613832/converting-screen-2d-to-world-3d-coordinates#31617382

to get the matrix for the projection you can use: openGLView->getOpenGLRenderer()->getProjection3DMatrix()

to get the matrix of your Object3D you can use: object.getMatrix()

Probably this is something I could do in the future, but if you have time to experiment, go for it ^^

Arnaud.

smart-fun avatar Jul 07 '17 14:07 smart-fun