QCameraLens fieldOfView is ... geometrically in Qt :
-
I set my Qt3D views camera as
camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, .01f, cameraFarRestDistance + 2.0f);which sets the fieldOfView as 45° .
By geometric projection theory I can calculate the angle the pixel below the mouse pointer is pointing in relative to the center of the screen as
double x = mouseX + .5 - view->width() / 2.0; double z = mouseY + .5 - view->height() / 2.0; x *= fieldOfViewX / (view->width() - 1.0); z *= fieldOfViewX / (view->width() - 1.0); const double pi = 3.1415926535897931; double hitX = camera->position().x() + tan(x * pi / 180.0) * (camera->position().y() - planeY); double hitZ = camera->position().z() + tan(z * pi / 180.0) * (camera->position().y() - planeY); qDebug() << "expected hit at " << hitX << " " << hitZ;code above for determining the point on a plane whose normal is the y-axis hit by the ray emitting from the camera position in the direction the pixel below the mouse pointer is pointing in.
(Mouse pointer coordinates adjusted to have the screen center pixel be 0, 0.)
Comparing QScreenRayCaster with that theoretical value for the given fieldOfView of 45° the following code however lets plane-hits match up to and including the 3rd decimal digit of the hit-coordinate on the plane:
double x = mouseX - view->width() / 2.0; double z = mouseY - view->height() / 2.0; x *= 63.75 / (view->width() - 1.0); z *= 63.75 / (view->width() - 1.0); const double pi = 3.1415926535897931; double hitX = camera->position().x() + tan(x * pi / 180.0) * (camera->position().y() - planeY); double hitZ = camera->position().z() + tan(z * pi / 180.0) * (camera->position().y() - planeY); qDebug() << "expected hit at " << hitX << " " << hitZ;Note the value at the place of the fieldOfView has "nothing" to do with the value I set to the QCameraLens, even when trying to account for the aspect ratio.
Also the (+ .5) is missing to have a best match.Addendum: the value of 63.75 works for the default window size of 800 x 800 only.
Solution:double distance = camera->position().y() - planeY; double factor1 = camera->fieldOfView() * camera->aspectRatio() * 3.1415926535897931 / (180.0 * (viewWidth - 1.0)); double factor2 = camera->fieldOfView() * 3.1415926535897931 / (180.0 * (viewHeight - 1.0)); returnValue.x = camera->position().x() + tan((mouseX + .5 - viewWidth / 2.0) * factor1) * distance; returnValue.y = camera->position().z() + tan((mouseY + .5 - viewHeight / 2.0) * factor2) * distance;works for all window sizes.
Thus the answer to my question as phrased originally in the title:
QCameraLens fieldOfView obeyed or what is it in Qt geometrically ?
is
"yes and it is the vertical fov"Here 2 images for visual aid in understanding the geometric projection theory, note they also work when the value of the pixel width of the screen is odd:


And I try to calculate the direction of the pixel below the mouse pointer myself due to various issues of QScreenRayCaster:
https://forum.qt.io/topic/140870/qscreenraycaster-does-not-hit-triangles-around-size-1-0f-and-smaller/3
https://forum.qt.io/topic/140902/qscreenraycaster-depth-of-ray-adjustable-appears-limited-to-50-000
https://forum.qt.io/topic/140977/qscreenraycaster-addlayer-has-no-effect