vkf_view Module

Camera views: where the camera looks from, as OpenFrames' View.

A view follows a frame: the camera's trackball (eye, center, up, which the mouse moves) is kept in the view frame's coordinates, so the camera moves with the frame. The view frame is * RELATIVE_FRAME (the default): the viewed frame itself (a body-fixed view); * ABSOLUTE_FRAME: the root frame's axes, at the viewed frame's origin (an inertial view that follows the frame as it moves). A view between frames (set_view_between_frames) looks from one frame at another: the view frame is turned so that its +y axis (the trackball's initial viewing direction) points at the second frame, in one direct rotation (VIEW_DIRECT) or first in azimuth, then elevation (VIEW_AZEL, the default, which keeps z up).

The default camera (reset_view) looks along +y at the frame's bound from the distance at which it fills the field of view (or from default_view_distance, or from set_default_view_parameters). Views are not owned by windows: a view, and the frames it refers to, must stay alive while used.

The camera (OpenFrames' trackball get/setTransformation): a window's get_camera / set_camera for the view it shows (and smooth transitions, see vkf_window), or set_camera for a view's camera when it is next shown. camera_between interpolates between two cameras (each eye, center, up): the center along a straight line, the distance geometrically, the orientation by the shortest rotation.


Uses

  • module~~vkf_view~~UsesGraph module~vkf_view vkf_view module~vkf_frames vkf_frames module~vkf_view->module~vkf_frames module~vkf_math vkf_math module~vkf_view->module~vkf_math module~vkf_frames->module~vkf_math iso_c_binding iso_c_binding module~vkf_frames->iso_c_binding module~vkf_follower vkf_follower module~vkf_frames->module~vkf_follower module~vkf_geometry vkf_geometry module~vkf_frames->module~vkf_geometry module~vkf_layer vkf_layer module~vkf_frames->module~vkf_layer module~vkf_pick vkf_pick module~vkf_frames->module~vkf_pick module~vkf_text vkf_text module~vkf_frames->module~vkf_text module~vkf_trajectory vkf_trajectory module~vkf_frames->module~vkf_trajectory iso_fortran_env iso_fortran_env module~vkf_math->iso_fortran_env module~vkf_follower->module~vkf_math module~vkf_follower->module~vkf_trajectory module~vkf_geometry->module~vkf_math module~vkf_geometry->iso_c_binding module~vkf_geometry->module~vkf_layer module~vkf_layer->iso_c_binding module~vkf_pick->module~vkf_math module~vkf_text->module~vkf_math module~vkf_text->iso_c_binding module~vkf_text->module~vkf_layer module~vkf_files vkf_files module~vkf_text->module~vkf_files module~vkf_trajectory->module~vkf_math module~vkf_trajectory->iso_c_binding module~vkf_trajectory->iso_fortran_env

Used by

  • module~~vkf_view~~UsedByGraph module~vkf_view vkf_view module~vkf_window vkf_window module~vkf_window->module~vkf_view module~vkframes vkframes module~vkframes->module~vkf_view module~vkframes->module~vkf_window

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: ABSOLUTE_FRAME = 0

the base frame of the trackball (OpenFrames' ViewFrameType) the root frame's axes, at the viewed frame's origin

integer, public, parameter :: ORTHOGRAPHIC = 0

projections (OpenFrames' ProjectionType) orthographic projection

integer, public, parameter :: PERSPECTIVE = 1

perspective projection

integer, public, parameter :: RELATIVE_FRAME = 1

the viewed frame itself

integer, public, parameter :: VIEW_AZEL = 1

azimuth, then elevation (keeps z up)

integer, public, parameter :: VIEW_DIRECT = 0

how a view between frames turns toward the look-at frame (OpenFrames' ViewRotationType) one direct rotation


Interfaces

public interface View

The View constructor: View(...) makes one (see new_view for its arguments).

  • private function new_view(root, frame, lookat, frame_type, rotation_type) result(v)

    A view of frame (in the tree of root), with base frame_type (default RELATIVE_FRAME); with lookat, a view from frame at lookat, turned by rotation_type (default VIEW_AZEL). Without frames, the view looks at the root frame's origin. The frames must stay alive while the view is used.

    Arguments

    Type IntentOptional Attributes Name
    class(ReferenceFrame), intent(in), optional, target :: root

    the tree's root, viewed and looked-at frames

    class(ReferenceFrame), intent(in), optional, target :: frame

    the tree's root, viewed and looked-at frames

    class(ReferenceFrame), intent(in), optional, target :: lookat

    the tree's root, viewed and looked-at frames

    integer, intent(in), optional :: frame_type

    ABSOLUTE_FRAME or RELATIVE_FRAME

    integer, intent(in), optional :: rotation_type

    VIEW_DIRECT or VIEW_AZEL

    Return Value type(View)


Derived Types

type, public ::  View

A view (see the module documentation).

Components

Type Visibility Attributes Name Initial
logical, private :: camera_pending = .false.

true if pending is to be applied when shown

real(kind=wp), private :: center(3) = 0.0_wp

kept center

real(kind=wp), private :: default_center(3) = 0.0_wp

camera center after a reset (view-frame coordinates)

real(kind=wp), private :: default_distance = 0.0_wp

radius framed on reset (<= 0: the frame's bound)

real(kind=wp), private :: default_eye(3) = 0.0_wp

camera eye after a reset (view-frame coordinates)

real(kind=wp), private :: default_up(3) = 0.0_wp

camera up after a reset (zero: no default camera)

real(kind=wp), private :: eye(3) = 0.0_wp

kept eye

real(kind=wp), private :: fovy = 45.0_wp

vertical field of view (degrees)

class(ReferenceFrame), private, pointer :: frame => null()

the viewed frame (not owned)

integer, private :: frame_type = RELATIVE_FRAME

ABSOLUTE_FRAME or RELATIVE_FRAME

logical, private :: has_state = .false.

true if eye, center, up are kept

class(ReferenceFrame), private, pointer :: lookat => null()

the frame looked at (view between frames; not owned)

real(kind=wp), private :: ortho(4) = [-1.0_wp, 1.0_wp, -1.0_wp, 1.0_wp]

left, right, bottom, top

real(kind=wp), private :: pending(3,3) = 0.0_wp

a camera set (eye, center, up), for when it is shown

integer, private :: projection = PERSPECTIVE

ORTHOGRAPHIC or PERSPECTIVE

logical, private :: reset_pending = .true.

true if the camera is to be reset when shown

class(ReferenceFrame), private, pointer :: root => null()

the root of the frames' tree (not owned)

integer, private :: rotation_type = VIEW_AZEL

VIEW_DIRECT or VIEW_AZEL

real(kind=wp), private :: up(3) = 0.0_wp

kept up direction

Constructor

The View constructor: View(...) makes one (see new_view for its arguments).

private function new_view (root, frame, lookat, frame_type, rotation_type)

A view of frame (in the tree of root), with base frame_type (default RELATIVE_FRAME); with lookat, a view from frame at lookat, turned by rotation_type (default VIEW_AZEL). Without frames, the view looks at the root frame's origin. The frames must stay alive while the view is used.

Type-Bound Procedures

procedure, public :: clear_default_view_parameters
procedure, public :: default_view_distance
procedure, public :: default_view_parameters
procedure, public :: field_of_view
procedure, public :: home
procedure, public :: is_valid
procedure, public :: lookat_frame
procedure, public :: orthographic_bounds
procedure, public :: projection_type
procedure, public :: reset_view
procedure, public :: save_state
procedure, public :: saved_state
procedure, public :: set_camera => view_set_camera
procedure, public :: set_default_view_distance
procedure, public :: set_default_view_parameters
procedure, public :: set_orthographic
procedure, public :: set_perspective
procedure, public :: set_view_between_frames
procedure, public :: set_view_frame
procedure, public :: take_camera
procedure, public :: take_reset
procedure, public :: view_frame
procedure, public :: view_frame_type
procedure, public :: view_root
procedure, public :: view_rotation_type
procedure, public :: world_to_view

Functions

public pure function camera_between(s, from, to) result(cam)

The camera a fraction s (0 to 1) of the way from camera from to camera to (columns: eye, center, up; in one frame's coordinates): the center moved along a straight line, the distance to it changed by the same factor at each step (so far-to-near flights don't rush the near part), and the orientation turned by the shortest rotation.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: s

fraction of the way (0: from, 1: to)

real(kind=wp), intent(in) :: from(3,3)

(columns: eye, center, up)

real(kind=wp), intent(in) :: to(3,3)

(columns: eye, center, up)

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

private pure function default_view_distance(self)

The radius framed when the view is reset (<= 0: the viewed frame's bound).

Arguments

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

Return Value real(kind=wp)

private pure function field_of_view(self) result(fovy)

The vertical field of view (degrees) of the perspective projection.

Arguments

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

Return Value real(kind=wp)

private function frame_to_root(self, f) result(m)

The transform from f to the view's root frame (the tree root if none).

Arguments

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

a frame of the view's tree

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

private function is_valid(self)

True if the view has a frame to view.

Arguments

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

Return Value logical

private function lookat_frame(self) result(f)

The frame looked at, for a view between frames (null if none).

Arguments

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

Return Value class(ReferenceFrame), pointer

private function new_view(root, frame, lookat, frame_type, rotation_type) result(v)

A view of frame (in the tree of root), with base frame_type (default RELATIVE_FRAME); with lookat, a view from frame at lookat, turned by rotation_type (default VIEW_AZEL). Without frames, the view looks at the root frame's origin. The frames must stay alive while the view is used.

Arguments

Type IntentOptional Attributes Name
class(ReferenceFrame), intent(in), optional, target :: root

the tree's root, viewed and looked-at frames

class(ReferenceFrame), intent(in), optional, target :: frame

the tree's root, viewed and looked-at frames

class(ReferenceFrame), intent(in), optional, target :: lookat

the tree's root, viewed and looked-at frames

integer, intent(in), optional :: frame_type

ABSOLUTE_FRAME or RELATIVE_FRAME

integer, intent(in), optional :: rotation_type

VIEW_DIRECT or VIEW_AZEL

Return Value type(View)

private pure function orthographic_bounds(self) result(bounds)

The bounds [left, right, bottom, top] of the orthographic projection.

Arguments

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

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

private pure function projection_type(self)

The projection: ORTHOGRAPHIC or PERSPECTIVE.

Arguments

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

Return Value integer

private pure function rotated(r, m) result(rm)

rotate(r) * m, for a rotation r (3x3).

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: r(3,3)

rotation (3x3); transform (4x4)

real(kind=wp), intent(in) :: m(4,4)

rotation (3x3); transform (4x4)

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

private function saved_state(self, eye, center, up)

The kept trackball state; false if there is none.

Arguments

Type IntentOptional Attributes Name
class(View), intent(in) :: self
real(kind=wp), intent(out) :: eye(3)

the kept trackball state (view-frame coordinates)

real(kind=wp), intent(out) :: center(3)

the kept trackball state (view-frame coordinates)

real(kind=wp), intent(out) :: up(3)

the kept trackball state (view-frame coordinates)

Return Value logical

private function take_camera(self, cam)

True (once) if a camera was set (set_camera), and that camera.

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
real(kind=wp), intent(out) :: cam(3,3)

(columns: eye, center, up (view-frame coordinates))

Return Value logical

private function take_reset(self)

True (once) if a reset is pending.

Arguments

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

Return Value logical

public pure function transform_camera(m, cam) result(out)

A camera (columns: eye, center, up) in the coordinates a rigid transform m (4x4) takes it to: the points moved, the up direction turned.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: m(4,4)

rigid transform

real(kind=wp), intent(in) :: cam(3,3)

(columns: eye, center, up)

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

private function view_frame(self) result(f)

The viewed frame (null if none).

Arguments

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

Return Value class(ReferenceFrame), pointer

private pure function view_frame_type(self)

The base of the trackball: ABSOLUTE_FRAME or RELATIVE_FRAME.

Arguments

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

Return Value integer

private function view_root(self) result(f)

The root of the viewed frames' tree (null if none).

Arguments

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

Return Value class(ReferenceFrame), pointer

private pure function view_rotation_type(self)

How a view between frames turns: VIEW_DIRECT or VIEW_AZEL.

Arguments

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

Return Value integer

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.

Arguments

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

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


Subroutines

private pure subroutine camera_orientation(cam, q, d)

A camera's orientation (columns: right, up, back, as a quaternion) and its distance from eye to center (at least a tiny one).

Arguments

Type IntentOptional 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

private subroutine clear_default_view_parameters(self)

Forget the camera set by set_default_view_parameters (back to the default view distance).

Arguments

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

private pure subroutine default_view_parameters(self, eye, center, up)

The camera after a reset (view-frame coordinates; all zero if none is set).

Arguments

Type IntentOptional Attributes Name
class(View), intent(in) :: self
real(kind=wp), intent(out) :: eye(3)

the camera (view-frame coordinates; zero if not set)

real(kind=wp), intent(out) :: center(3)

the camera (view-frame coordinates; zero if not set)

real(kind=wp), intent(out) :: up(3)

the camera (view-frame coordinates; zero if not set)

private subroutine home(self, aspect, eye, center, up)

The default camera (eye, center, up in view-frame coordinates) for a viewport of aspect ratio aspect (width / height): OpenFrames' resetView.

Arguments

Type IntentOptional Attributes Name
class(View), intent(in) :: self
real(kind=wp), intent(in) :: aspect

viewport width / height

real(kind=wp), intent(out) :: eye(3)

the default camera (view-frame coordinates)

real(kind=wp), intent(out) :: center(3)

the default camera (view-frame coordinates)

real(kind=wp), intent(out) :: up(3)

the default camera (view-frame coordinates)

private subroutine reset_view(self)

Put the camera back at the default position (applied at the next frame in which the view is shown).

Arguments

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

private subroutine save_state(self, eye, center, up)

Keep the trackball state while another view is shown.

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
real(kind=wp), intent(in) :: eye(3)

the trackball state (view-frame coordinates)

real(kind=wp), intent(in) :: center(3)

the trackball state (view-frame coordinates)

real(kind=wp), intent(in) :: up(3)

the trackball state (view-frame coordinates)

private subroutine set_default_view_distance(self, distance)

The radius to frame when the view is reset (<= 0: the viewed frame's bound, the default), as OpenFrames' default view distance.

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
real(kind=wp), intent(in) :: distance

radius (<= 0: the frame's bound)

private subroutine set_default_view_parameters(self, eye, center, up)

The camera after a reset, in view-frame coordinates (overrides the default view distance).

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
real(kind=wp), intent(in) :: eye(3)

the camera (view-frame coordinates)

real(kind=wp), intent(in) :: center(3)

the camera (view-frame coordinates)

real(kind=wp), intent(in) :: up(3)

the camera (view-frame coordinates)

private subroutine set_orthographic(self, left, right, bottom, top)

An orthographic projection with the given bounds (in view units).

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
real(kind=wp), intent(in) :: left

bounds (view units)

real(kind=wp), intent(in) :: right

bounds (view units)

real(kind=wp), intent(in) :: bottom

bounds (view units)

real(kind=wp), intent(in) :: top

bounds (view units)

private subroutine set_perspective(self, fovy)

A perspective projection with vertical field of view fovy (degrees; default 45).

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
real(kind=wp), intent(in) :: fovy

vertical field of view (degrees)

private subroutine set_view_between_frames(self, root, frame, lookat, frame_type, rotation_type)

Look from frame at lookat (both in the tree of root).

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
class(ReferenceFrame), intent(in), target :: root

the tree's root, viewed and looked-at frames

class(ReferenceFrame), intent(in), target :: frame

the tree's root, viewed and looked-at frames

class(ReferenceFrame), intent(in), target :: lookat

the tree's root, viewed and looked-at frames

integer, intent(in), optional :: frame_type

ABSOLUTE_FRAME or RELATIVE_FRAME (default)

integer, intent(in), optional :: rotation_type

VIEW_DIRECT or VIEW_AZEL (default)

private subroutine set_view_frame(self, root, frame, frame_type)

View frame (in the tree of root) with base frame_type (default RELATIVE_FRAME).

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
class(ReferenceFrame), intent(in), target :: root

the tree's root; the viewed frame (not owned)

class(ReferenceFrame), intent(in), target :: frame

the tree's root; the viewed frame (not owned)

integer, intent(in), optional :: frame_type

ABSOLUTE_FRAME or RELATIVE_FRAME

private subroutine view_set_camera(self, eye, center, up)

The camera (view-frame coordinates) to show the next time the view is drawn (at once if it is shown: the window's set_camera can also fly there). It replaces a pending reset.

Arguments

Type IntentOptional Attributes Name
class(View), intent(inout) :: self
real(kind=wp), intent(in) :: eye(3)

the camera (view-frame coordinates)

real(kind=wp), intent(in) :: center(3)

the camera (view-frame coordinates)

real(kind=wp), intent(in) :: up(3)

the camera (view-frame coordinates)