Options
All
  • Public
  • Public/Protected
  • All
Menu

A Viewport represents the drawing area in the viewer.

When a frame is received from the rendering pipeline, it might not be the same dimensions of the viewport because of an interactive frame or because of bandwidth limitations or other performance reasons.

The viewport contains methods to scale an image to the viewport, as well as translate 2D coordinates between the viewport and the frame.

Hierarchy

  • Viewport

Implements

  • Dimensions

Index

Constructors

  • new Viewport(width: number, height: number): Viewport

Properties

center: Point

The center point of the viewport.

height: number
width: number

Accessors

  • get dimensions(): Dimensions

Methods

  • calculateDrawRect(image: FrameImageLike): Rectangle
  • transformNdcPointToViewport(ndc: Point): Point
  • Transforms a normalized device coordinate to a 2D point within the viewport.

    Parameters

    • ndc: Point

      A 2D point in NDC.

    Returns Point

    A 2D point in the coordinate space of the viewport.

  • transformPointToFrame(pt: Point, image: FrameImageLike): Point
  • Transforms a point in viewport coordinate space to a point in a frame's coordinate space.

    Parameters

    • pt: Point

      A point in viewport coordinate space.

    • image: FrameImageLike

      An image of a frame.

    Returns Point

    A point in the coordinate space of the frame.

  • transformPointToRay(pt: Point, image: FrameImageLike, camera: FrameCameraBase): Ray
  • Transforms a point in viewport coordinates to a ray.

    For perspective cameras, the returned ray will have an origin that is at the position of the camera with a direction that is pointing into world space away from the camera.

    For orthographic cameras, the returned ray will have an origin that is at the world point of viewport coordinate with a direction that is pointing into world space away from the camera.

    Parameters

    • pt: Point

      A point in viewport coordinates.

    • image: FrameImageLike

      An image of a frame.

    • camera: FrameCameraBase

      A camera used to determine orientation of the scene.

    Returns Ray

    A ray

  • transformPointToViewport(pt: Point, image: FrameImageLike): Point
  • transformPointToWorldSpace(pt: Point, depthBuffer: DepthBuffer, fallbackNormalizedDepth?: number): Vector3
  • Transforms a point in viewport coordinates to a point in world space coordinates. This method expects a depth buffer in order to compute a value for the Z axis.

    Parameters

    • pt: Point

      A point in viewport coordinates.

    • depthBuffer: DepthBuffer

      A depth buffer for computing the Z axis.

    • Optional fallbackNormalizedDepth: number

      A fallback value if the depth is the max depth value, or cannot be determined.

    Returns Vector3

  • transformScreenPointToNdc(screenPt: Point, image: FrameImageLike): Point
  • Maps a screen point to normalized device coordinates (NDC). A screen point at 0,0 represents the top-left of the viewport.

    Parameters

    • screenPt: Point

      A screen point.

    • image: FrameImageLike

    Returns Point

  • transformVectorToViewport(ndc: Vector3): Point
  • Transforms a normalized device coordinate to a 2D point within the viewport.

    Parameters

    • ndc: Vector3

      A 3D point in NDC.

    Returns Point

    A 2D point in the coordinate space of the viewport.

  • transformWorldToViewport(worldPt: Vector3, projectionViewMatrix: Matrix4): Point
  • Transforms a world point to 2D point in viewport space.

    Parameters

    • worldPt: Vector3

      The world point to transform.

    • projectionViewMatrix: Matrix4

      The projection matrix to transform a 3D point to 2D point.

    Returns Point

    A point in viewport space.

  • fromDimensions(dimensions: Dimensions): Viewport