The camera of a pick: eye, center and up (root frame), a perspective
projection (fovy, degrees, and aspect) or an orthographic one
(ortho: left, right, bottom, top), a viewport of width x height
framebuffer pixels, the cursor (x, y: -1 to 1, y up) and the tolerance
(framebuffer pixels).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | eye(3) |
the camera (root frame) |
||
| real(kind=wp), | intent(in) | :: | center(3) |
the camera (root frame) |
||
| real(kind=wp), | intent(in) | :: | up(3) |
the camera (root frame) |
||
| logical, | intent(in) | :: | perspective |
(true: perspective; false: orthographic) |
||
| real(kind=wp), | intent(in) | :: | fovy |
vertical field of view (degrees; perspective) |
||
| real(kind=wp), | intent(in) | :: | aspect |
width / height (perspective) |
||
| real(kind=wp), | intent(in) | :: | ortho(4) |
left, right, bottom, top (orthographic) |
||
| integer, | intent(in) | :: | width |
the viewport (framebuffer pixels) |
||
| integer, | intent(in) | :: | height |
the viewport (framebuffer pixels) |
||
| real(kind=wp), | intent(in) | :: | x |
the cursor (-1 to 1, y up) |
||
| real(kind=wp), | intent(in) | :: | y |
the cursor (-1 to 1, y up) |
||
| real(kind=wp), | intent(in) | :: | tolerance |
(framebuffer pixels) |
pure function pick_camera(eye, center, up, perspective, fovy, aspect, ortho, width, height, x, y, tolerance) & result(cam) real(wp), intent(in) :: eye(3), center(3), up(3) !! the camera (root frame) real(wp), intent(in) :: fovy !! vertical field of view (degrees; perspective) real(wp), intent(in) :: aspect !! width / height (perspective) real(wp), intent(in) :: ortho(4) !! left, right, bottom, top (orthographic) real(wp), intent(in) :: x, y !! the cursor (-1 to 1, y up) real(wp), intent(in) :: tolerance !! (framebuffer pixels) logical, intent(in) :: perspective !! (true: perspective; false: orthographic) integer, intent(in) :: width, height !! the viewport (framebuffer pixels) type(PickCamera) :: cam real(wp) :: f(3), r(3), d f = center - eye d = norm2(f) if (d > 0.0_wp) f = f / d r = cross(f, up) if (norm2(r) > 0.0_wp) r = r / norm2(r) cam%eye = eye cam%forward = f cam%right = r cam%up = cross(r, f) cam%perspective = perspective cam%tan_y = tan(0.5_wp * fovy * pi / 180.0_wp) cam%aspect = aspect cam%ortho = ortho cam%half_w = 0.5_wp * max(1, width) cam%half_h = 0.5_wp * max(1, height) cam%x = x cam%y = y cam%tolerance = tolerance cam%near = 1.0e-6_wp * max(d, tiny(1.0_wp)) ! (as the renderer's near plane) end function pick_camera