The Viewport class represents a viewport of a perspective projection used by a 3D application.
sealed class
|
Viewport
|
extends
|
VersionedBase
|
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 / fovwhere
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.
The aspect ratio of the viewport.
public
property
|
AspectRatio
{
get
}
|
||
type
|
float64
|
||
value
|
|
The new aspect ratio (i.e. width divided by height). |
The base field of view angle.
public
property
|
BaseFieldOfView
{
get
set
}
|
||
type
|
float64
|
||
value
|
|
The
base
field
of
view
angle,
in
degrees.
Set
to
0
to
disable
the
base
field
of
view
handling.
Defaults
to
0 .
|
Remarks:
Depending on Mode, the angle is either measured along the viewports X-axis (Horizontal) or Y-axis (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.
See also:
IsZoomedThe current field of view angle, in degrees.
public
property
|
FieldOfView
{
get
set
}
|
||
type
|
float64
|
||
value
|
|
The current field of view angle, in degrees. |
Remarks:
Depending on Mode, the angle is either measured along the viewports X-axis ( Horizontal) or Y-axis (Vertical).
See also:
InsideReturns the field-of-view along the viewport X-axis.
public
property
|
FieldOfViewX
{
get
}
|
||
type
|
float64
|
||
value
|
|
The horizontal field-of-view, in degrees. |
Returns the field-of-view along the viewport Y-axis.
public
property
|
FieldOfViewY
{
get
}
|
||
type
|
float64
|
||
value
|
|
The vertical field-of-view, in degrees. |
The viewport height.
public
property
|
Height
{
get
}
|
||
type
|
int32
|
||
value
|
|
The viewport height, in pixels. |
See also:
SetSizeIs the viewport currently zoomed in?
public
property
|
IsZoomed
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
the
viewport
is
zoomed
in,
false
if
not. |
See also:
BaseFieldOfViewThe current field of view angle mode.
public
property
|
Mode
{
get
set
}
|
||
type
|
FovMode
|
||
value
|
The field of view mode. Defaults to Vertical. |
Returns the current version of object.
public
property
|
Version
{
get
}
|
||
type
|
int32
|
||
value
|
The current version number. | ||
inherited
|
VersionedBase.Version
|
Remarks:
For each modification, the version is incremented by at least one.
The viewport width.
public
property
|
Width
{
get
}
|
||
type
|
int32
|
||
value
|
|
The viewport width, in pixels. |
See also:
SetSizeCreates a new instance of Viewport.
public
constructor
|
Viewport
(int32 width = 1024,
int32 height = 768,
float64 fieldOfView = 70,
FovMode mode = FovMode.Vertical)
|
||
params
|
width
|
[>0]
|
The
viewport
width,
in
screen
pixels.
Defaults
to
1024 .
|
height
|
[>0]
|
The
viewport
height,
in
screen
pixels.
Defaults
to
768 .
|
|
fieldOfView
|
[0..360]
|
The
field
of
view
angle,
in
degrees.
Defaults
to
70 .
|
|
mode
|
The field of view angle mode. Defaults to Vertical |
Computes a field-of-view angle that avoids fish-eye distortions.
[Pure]
|
||||
public
static
method
|
ComputeFieldOfView
(int32 width,
int32 height,
float64 fov = 50.625,
float64 max = 90,
FovMode mode = FovMode.Vertical)
|
|||
type
|
float64
|
|||
params
|
width
|
[>0]
|
The viewport width. | |
height
|
[>0]
|
The viewport height. | ||
fov
|
[>0]
|
The
desired
field-of-view
angle
(according
to
mode),
in
degrees.
Defaults
to
50.625 .
|
||
max
|
[>0]
|
The
maximum
field-of-view
angle
to
enforce
both
horizontally
and
vertically,
in
degrees.
Defaults
to
90 .
|
||
mode
|
The field-of-view mode. Defaults to Vertical. | |||
returns
|
|
The resulting field-of-view angle, in degrees. |
Checks if the given point or sphere is at least partially inside of the viewport frustum.
[Pure]
|
||||
public
method
|
Inside
(float64 eyeX,
float64 eyeY,
float64 eyeZ,
float64 radius = 0)
|
|||
type
|
bool
|
|||
params
|
eyeX
|
X-component of eye vector (point to camera), in camera space (see remarks). | ||
eyeY
|
Y-component of eye vector (point to camera), in camera space (see remarks). | |||
eyeZ
|
Z-component of eye vector (point to camera), in camera space (see remarks). | |||
radius
|
Radius
of
sphere
or
0
for
a
point.
Defaults
to
0 .
|
|||
returns
|
true
if
the
point
or
sphere
is
at
least
partially
inside
of
the
viewport
frustum,
false
if
it
is
outside
of
it.
|
Remarks:
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).
See also:
FieldOfViewXProjects a given error value from terrain-space to screen-space.
[Pure]
|
||||
public
method
|
Project
(float64 error,
float64 distanceToCamera,
bool useBaseFov = false)
|
|||
type
|
float64
|
|||
params
|
error
|
The terrain-space error value. | ||
distanceToCamera
|
Distance to camera, in terrain-space. | |||
useBaseFov
|
Use
the
given
base
field
of
view
(see
BaseFieldOfView)
instead
of
the
current
field
of
view?
Defaults
to
false .
|
|||
returns
|
The screen-space error value. |
Projects a given error value from terrain-space to screen-space.
[Pure]
|
||||
public
method
|
ProjectSqr
(float64 errorSqr,
float64 distanceToCameraSqr,
bool useBaseFov = false)
|
|||
type
|
float64
|
|||
params
|
errorSqr
|
The squared terrain-space error value. | ||
distanceToCameraSqr
|
Squared distance to camera, in terrain-space. | |||
useBaseFov
|
Use
the
given
base
field
of
view
(see
BaseFieldOfView)
instead
of
the
current
field
of
view?
Defaults
to
false .
|
|||
returns
|
The squared screen-space error value. |
Sets the viewport size.
public
method
|
SetSize
(int32 width,
int32 height)
|
||
params
|
width
|
[>0]
|
The viewport width, in pixels. |
height
|
[>0]
|
The viewport height, in pixels. |
See also:
InsideProjects a given error value from screen-space to terrain-space.
[Pure]
|
||||
public
method
|
Unproject
(float64 error,
float64 distanceToCamera,
bool useBaseFov = false)
|
|||
type
|
float64
|
|||
params
|
error
|
The screen-space error value. | ||
distanceToCamera
|
Distance to camera, in terrain-space. | |||
useBaseFov
|
Use
the
given
base
field
of
view
(see
BaseFieldOfView)
instead
of
the
current
field
of
view?
Defaults
to
false .
|
|||
returns
|
The terrain-space error value. |
Projects a given error value from screen-space to terrain-space.
[Pure]
|
||||
public
method
|
UnprojectSqr
(float64 errorSqr,
float64 distanceToCameraSqr,
bool useBaseFov = false)
|
|||
type
|
float64
|
|||
params
|
errorSqr
|
The squared screen-space error value. | ||
distanceToCameraSqr
|
Squared distance to camera, in terrain-space. | |||
useBaseFov
|
Use
the
given
base
field
of
view
(see
BaseFieldOfView)
instead
of
the
current
field
of
view?
Defaults
to
false .
|
|||
returns
|
The squared terrain-space error value. |