world_to_view Function

private function world_to_view(self) result(m)

The transform from the root frame to the view frame (4x4), from the frames' current positions and attitudes.

Type Bound

View

Arguments

Type IntentOptional Attributes Name
class(View), intent(in) :: self

Return Value real(kind=wp), (4,4)


Calls

proc~~world_to_view~~CallsGraph proc~world_to_view View%world_to_view proc~frame_to_root frame_to_root proc~world_to_view->proc~frame_to_root proc~identity_matrix identity_matrix proc~world_to_view->proc~identity_matrix proc~quat_from_vectors quat_from_vectors proc~world_to_view->proc~quat_from_vectors proc~quat_to_matrix quat_to_matrix proc~world_to_view->proc~quat_to_matrix proc~rigid_inverse rigid_inverse proc~world_to_view->proc~rigid_inverse proc~rotated rotated proc~world_to_view->proc~rotated proc~translation_matrix translation_matrix proc~world_to_view->proc~translation_matrix proc~frame_to_root->proc~rigid_inverse proc~world_matrix ReferenceFrame%world_matrix proc~frame_to_root->proc~world_matrix proc~cross cross proc~quat_from_vectors->proc~cross proc~quat_normalize quat_normalize proc~quat_from_vectors->proc~quat_normalize proc~translation_matrix->proc~identity_matrix proc~world_matrix->proc~world_matrix proc~local_matrix ReferenceFrame%local_matrix proc~world_matrix->proc~local_matrix proc~frame_matrix frame_matrix proc~local_matrix->proc~frame_matrix proc~frame_matrix->proc~quat_to_matrix

Called by

proc~~world_to_view~~CalledByGraph proc~world_to_view View%world_to_view proc~fly fly proc~fly->proc~world_to_view proc~get_camera WindowProxy%get_camera proc~get_camera->proc~world_to_view proc~home View%home proc~home->proc~world_to_view proc~place_camera place_camera proc~place_camera->proc~world_to_view proc~place_camera->proc~fly proc~place_camera->proc~home proc~set_camera WindowProxy%set_camera proc~set_camera->proc~world_to_view proc~track_view track_view proc~track_view->proc~world_to_view proc~frame WindowProxy%frame proc~frame->proc~place_camera proc~frame->proc~track_view proc~dispatch_events dispatch_events proc~frame->proc~dispatch_events proc~view_camera view_camera proc~view_camera->proc~get_camera proc~cursor_ray WindowProxy%cursor_ray proc~cursor_ray->proc~view_camera proc~resize WindowProxy%resize proc~resize->proc~frame proc~run WindowProxy%run proc~run->proc~frame proc~screen_position WindowProxy%screen_position proc~screen_position->proc~view_camera proc~window_pick WindowProxy%window_pick proc~window_pick->proc~view_camera proc~drag_handle drag_handle proc~drag_handle->proc~cursor_ray proc~grab_handle grab_handle proc~grab_handle->proc~cursor_ray proc~hover_handle hover_handle proc~hover_handle->proc~window_pick proc~dispatch_event dispatch_event proc~dispatch_event->proc~drag_handle proc~dispatch_event->proc~grab_handle proc~dispatch_event->proc~hover_handle proc~release_handle release_handle proc~dispatch_event->proc~release_handle proc~release_handle->proc~hover_handle proc~dispatch_events->proc~dispatch_event

Source Code

    function world_to_view(self) result(m)
        class(View), intent(in) :: self
        real(wp) :: m(4,4)
        real(wp) :: f(4,4), rel(3), xy(3), r(3,3), len
        real(wp), parameter :: eps = 1.0e-6_wp
        m = identity_matrix()
        if (.not. associated(self%frame)) return
        f = frame_to_root(self, self%frame)
        if (self%frame_type == ABSOLUTE_FRAME) then
            m = translation_matrix(-f(1:3, 4))
        else
            m = rigid_inverse(f)
        end if
        if (.not. associated(self%lookat)) return
        ! the look-at frame's origin in the view frame, turned onto +y
        f = frame_to_root(self, self%lookat)
        rel = matmul(m(1:3, 1:3), f(1:3, 4)) + m(1:3, 4)
        if (norm2(rel) <= eps) return
        if (self%rotation_type == VIEW_DIRECT) then
            m = rotated(quat_to_matrix(quat_from_vectors(rel, [0.0_wp, 1.0_wp, 0.0_wp])), m)
        else
            xy = [rel(1), rel(2), 0.0_wp]
            len = norm2(xy)
            if (len > eps) m = rotated(quat_to_matrix(quat_from_vectors(xy, [0.0_wp, 1.0_wp, 0.0_wp])), m)
            r = quat_to_matrix(quat_from_vectors([0.0_wp, len, rel(3)], [0.0_wp, 1.0_wp, 0.0_wp]))
            m = rotated(r, m)
        end if
    end function world_to_view