Viewport

Description

sealed class Tinman.Terrain.Visibility.Viewport

Derived from

VersionedBase abstract

The Viewport class represents a viewport of a perspective projection used by a 3D application.

Instances of this class are used to project terrain-space error values and bounding spheres to screen-space. This is done using an isotropic metric, which is derived from the following values:

error' = error * scale / distance
scale  = size / fov

where error is the terrain-space error value, distance is the distance from the terrain vertex to the camera position, size is the viewport size in screen pixels along the field of view, fov is the field of view angle in radians and error' is the resulting screen-space error value.

Public / Constructors

Viewport


public constructor Viewport → (4)

width opt : int32 = 1024

[>0]
The viewport width, in screen pixels.

height opt : int32 = 768

[>0]
The viewport height, in screen pixels.

fieldOfView opt : float64 = 70

[0..360]
The field of view angle, in degrees.

mode opt : FovMode = FovMode.Vertical

The field of view angle mode.

Creates a new instance of Viewport.

Public / Methods

ComputeFieldOfView


[Pure]
public static method ComputeFieldOfView → (5)

width in : int32

[>0]
The viewport width.

height in : int32

[>0]
The viewport height.

fov opt : float64 = 50.625

[>0]
The desired field-of-view angle (according to mode opt), in degrees.

maximum opt : float64 = 90

[>0]
The maximum field-of-view angle to enforce both horizontally and vertically, in degrees.

mode opt : FovMode = FovMode.Vertical

The field-of-view mode.

returns → float64

The resulting field-of-view angle, in degrees.

Computes a field-of-view angle that avoids fish-eye distortions.

Inside


[Pure]
public method Inside → (4)

eyeX in : float64

X-component of eye vector (point to camera), in camera space (see remarks).

eyeY in : float64

Y-component of eye vector (point to camera), in camera space (see remarks).

eyeZ in : float64

Z-component of eye vector (point to camera), in camera space (see remarks).

radius opt : float64 = 0

Radius of sphere or 0 for a point.

returns → bool

true if the point or sphere is at least partially inside of the viewport frustum,
false if it is outside of it.

Checks if the given point or sphere is at least partially inside of the viewport frustum.

The point position must be specified in camera space: The positive Z-axis is the camera direction, the positive Y-axis is the camera upwards direction and the X-axis is the camera side direction (cartesian handedness is not relevant for this method).

Project


[Pure]
public method Project → (3)

error in : float64

The terrain-space error value.

distanceToCamera in : float64

Distance to camera, in terrain-space.

useBaseFov opt : bool = false

Use the given base field of view (see BaseFieldOfView) instead of the current field of view?

returns → float64

The screen-space error value.

Projects a given error value from terrain-space to screen-space.

ProjectSqr


[Pure]
public method ProjectSqr → (3)

errorSqr in : float64

The squared terrain-space error value.

distanceToCameraSqr in : float64

Squared distance to camera, in terrain-space.

useBaseFov opt : bool = false

Use the given base field of view (see BaseFieldOfView) instead of the current field of view?

returns → float64

The squared screen-space error value.

Projects a given error value from terrain-space to screen-space.

SetSize


public method SetSize → (2)

width in : int32

[>0]
The viewport width, in pixels.

height in : int32

[>0]
The viewport height, in pixels.

Sets the viewport size.

See also

Viewport.Inside

Unproject


[Pure]
public method Unproject → (3)

error in : float64

The screen-space error value.

distanceToCamera in : float64

Distance to camera, in terrain-space.

useBaseFov opt : bool = false

Use the given base field of view (see BaseFieldOfView) instead of the current field of view?

returns → float64

The terrain-space error value.

Projects a given error value from screen-space to terrain-space.

UnprojectSqr


[Pure]
public method UnprojectSqr → (3)

errorSqr in : float64

The squared screen-space error value.

distanceToCameraSqr in : float64

Squared distance to camera, in terrain-space.

useBaseFov opt : bool = false

Use the given base field of view (see BaseFieldOfView) instead of the current field of view?

returns → float64

The squared terrain-space error value.

Projects a given error value from screen-space to terrain-space.

Public / Attributes

AspectRatio


public attribute AspectRatio → (get)

value : float64

[>0]
The new aspect ratio (i.e. width divided by height).

The aspect ratio of the viewport.

BaseFieldOfView


public attribute BaseFieldOfView → (get,set)

value : float64

[0..360]
The base field of view angle, in degrees. Set to 0 to disable the base field of view handling.

The base field of view angle.

Depending on Mode, the angle is either measured along the viewports X-axis (FovMode.Horizontal) or Y-axis (FovMode.Vertical).

When the current field of view of the viewport is smaller than the base field of view angle given by this method, the viewport is considered to be zoomed in. In this case, terrain-space error values of vertices that lie inside the viewport (see Inside) are projected using the actual viewport field of view (i.e. the zoomed in one), whereas error values of the other vertices are projected using the base field of view:

+-----------------------------+
|                             |
|           +-----+           |
|           |ooooo|           |
|           |ooooo|           |
|           |ooooo|           |
|           +-----+           |
|                             |
+-----------------------------+

This way, additional detail due to zooming is only generated in the visible area (the 'o's in the above figure, which are inside the viewport quadrilateral). Otherwise, additional detail would be introduced into the whole mesh, which would quickly exhaust the vertex capacity.

Defaults to 0.

FieldOfView


public attribute FieldOfView → (get,set)

value : float64

[0..360]
The current field of view angle, in degrees.

The current field of view angle, in degrees.

Depending on Mode, the angle is either measured along the viewports X-axis ( FovMode.Horizontal) or Y-axis (FovMode.Vertical).

See also

Viewport.Inside

FieldOfViewX


public attribute FieldOfViewX → (get)

value : float64

[0..360]
The horizontal field-of-view, in degrees.

Returns the field-of-view along the viewport X-axis.

FieldOfViewY


public attribute FieldOfViewY → (get)

value : float64

[0..360]
The vertical field-of-view, in degrees.

Returns the field-of-view along the viewport Y-axis.

Height


public attribute Height → (get)

value : int32

[>0]
The viewport height, in pixels.

The viewport height.

See also

Viewport.SetSize

IsZoomed


public attribute IsZoomed → (get)

value : bool

true if the viewport is zoomed in, false if not.

Is the viewport currently zoomed in?

Mode


public attribute Mode → (get,set)

value : FovMode

The field of view mode.

The current field of view angle mode.

Defaults to FovMode.Vertical.

Width


public attribute Width → (get)

value : int32

[>0]
The viewport width, in pixels.

The viewport width.

See also

Viewport.SetSize