A camera's orientation (columns: right, up, back, as a quaternion) and its distance from eye to center (at least a tiny one).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | cam(3,3) |
(columns: eye, center, up) |
||
| real(kind=wp), | intent(out) | :: | q(4) |
orientation quaternion [x, y, z, w] |
||
| real(kind=wp), | intent(out) | :: | d |
distance from eye to center |
pure subroutine camera_orientation(cam, q, d) real(wp), intent(in) :: cam(3,3) !! (columns: eye, center, up) real(wp), intent(out) :: q(4) !! orientation quaternion [x, y, z, w] real(wp), intent(out) :: d !! distance from eye to center real(wp) :: f(3), r(3), m(3,3) f = cam(:, 2) - cam(:, 1) d = norm2(f) if (d > 0.0_wp) then f = f / d else f = [0.0_wp, 1.0_wp, 0.0_wp] end if d = max(d, tiny(1.0_wp) * 1.0e10_wp) r = cross(f, cam(:, 3)) if (norm2(r) < 1.0e-12_wp) r = cross(f, [0.0_wp, 0.0_wp, 1.0_wp]) ! (up along the view: any) if (norm2(r) < 1.0e-12_wp) r = cross(f, [1.0_wp, 0.0_wp, 0.0_wp]) r = r / norm2(r) m(:, 1) = r m(:, 2) = cross(r, f) m(:, 3) = -f q = quat_from_matrix(m) end subroutine camera_orientation