Options
All
  • Public
  • Public/Protected
  • All
Menu

A camera that uses an perspective projection. Also known as a 'pinhole' camera.

Note that the Camera API is a low-level API. For simple map navigation use cases, it's recommended to use the higher-level API. The MapNavigator API works in both 2D and 3D, on all map references. If you use the low-level Camera API, keep in mind that the same camera manipulation implementation might not work for other types of camera's (OrthographicCamera vs PerspectiveCamera) or other (types of) map references (projected vs. geocentric).

A camera transforms points from the 'world' reference (often the map's reference) to the view (pixel coordinates).

Besides the position, orientation and viewport properties that it inherits from Camera, the perspective camera defines its projection using the following properties:

  • The fovY: the angle, in degrees, that determines the vertical 'field-of-view' angle of the camera. The horizontal field-of-view angle is derived from the vertical field-of-view and the camera's aspect ratio. You can convert between horizontal (fovX) and vertical (fovY) field-of-view angles. See fovY for a code snippet showing how to do this.

Note that camera's in LuciadRIA are immutable. You can manipulate the map's camera by using copyAndSet or by converting from/to a LookFrom or LookAt.

Currently, the PerspectiveCamera can only be used in combination with geocentric (3D) map references (aka '2D' views). For now, you can not use this camera if the map has a projected (grid) or 2D cartesian reference.

To manipulate a perspective camera in a geocentric reference, consider using lookAt or lookFrom. This allows you to reason about the camera in terms of yaw (angle from north direction), pitch (angle wrt. horizon) and roll. You could also just manipulate the camera's eye position and forward/up directions directly, if that's a better fit for your use case.

Map navigation constraints configured on MapNavigator are not enforced when this camera is updated on the map. Constraints are only respected when using the MapNavigator.

// low-level manipulation of perspective camera: put camera looking over Europe, faced towards the north
map.camera = map.camera.copyAndSet({
  eye: {x: 6214861.581912037, y: 710226.7751339739, z: 4927634.769711619]},
  forward: {x: 0.9588725076044676, y: -0.12713997961061635, z:-0.25376946180526144},
  up: {x: -0.2469197372006221, y: -0.06727846255744102, z: 0.9666976010400992}
});

Hierarchy

Overview

Constructors

constructor

  • Creates a new PerspectiveCamera

    Parameters

    • eye: Vector3

      the 3D position that the camera is looking from, in world coordinates.

    • forward: Vector3

      The 3D direction the camera is looking in, in world coordinates. The combination of the forward and up vector determines the orientation of the camera.

    • up: Vector3

      The 3D direction that indicates the 'up' direction of the camera, in world coordinates. The combination of the forward and up vector determines the orientation of the camera, in world space.

    • near: number

      The distance from the eye to the near clipping plane. Points that fall outside of the near/far interval, are clipped. Note that the near plane distance can be negative.

    • far: number

      The distance from the eye to the far clipping plane. Points that fall outside of the near/far interval, are clipped.

    • width: number

      The width, in pixels, of the camera's viewport.

    • height: number

      The height, in pixels, of the camera's viewport.

    • fovY: number

      The angle, in degrees, that determines the vertical 'field-of-view' angle of the camera.

    • worldReference: CoordinateReference

      The reference in which eye, forward, up, near, far are defined (as well as the world units referred to in scaleX and scaleY).

    Returns PerspectiveCamera

Accessors

aspectRatio

  • get aspectRatio(): number

eye

  • The 3D position that the camera is looking from, in world coordinates.

    Returns Vector3

eyePoint

  • The 3D position that the camera is looking from, in world coordinates. This one is a shape instead of a Vector3, so it can easily be transformed to other references.

    Returns Point

far

  • get far(): number
  • The world distance from the eye to the far clipping plane. Points that fall outside of the near/far interval, are clipped.

    Returns number

forward

  • The 3D direction the camera is looking in, in world coordinates. The combination of the forward and up vector determines the orientation of the camera. in world space.

    Returns Vector3

fovY

  • get fovY(): number
  • The angle, in degrees, that determines the vertical 'field-of-view' angle of the camera. The horizontal field-of-view angle is derived from the vertical field-of-view and the camera's aspect ratio. You can convert between horizontal (fovX) and vertical (fovY) field-of-view angles using the following formulas:

    var DEG2RAD = Math.PI / 180;
    var RAD2DEG = 180 / Math.PI;
    var camerafovX = 2 * Math.atan(Math.tan(camera.fovY * DEG2RAD / 2) * camera.aspectRatio) * RAD2DEG;
    var newFovX = 60;
    var newfovY = 2 * Math.atan(Math.tan(newFovX * DEG2RAD / 2) / camera.aspectRatio) * RAD2DEG;

    Returns number

height

  • get height(): number
  • The height, in pixels, of the camera's viewport.

    Returns number

near

  • get near(): number
  • The world distance from the eye to the near clipping plane. Points that fall outside of the near/far interval, are clipped. Note that the near plane distance can be negative.

    Returns number

up

  • The 3D direction that indicates the 'up' direction of the camera, in world coordinates. The combination of the forward and up vector determines the orientation of the camera, in world space.

    Returns Vector3

width

  • get width(): number
  • The width, in pixels, of the camera's viewport.

    Returns number

worldReference

Methods

asLookAt

  • Returns a LookAt that matches the position and orientation of this camera

    Note you can only use this function if this camera's worldReference is a geocentric reference.

    Parameters

    • distance: number

      a distance (in the world reference's unit) between the camera's position and the LookAt's ref. For geocentric (3D) references, the world unit is usually 1 meter.

    Returns LookAt

    a LookAt object that matches position and orientation of this camera.

asLookFrom

  • Returns a LookFrom that matches the position and orientation of this camera

    Note you can only use this function if this camera's worldReference is a geocentric reference.

    // keep looking from the same point, but pitch the view up 10 degrees
    var lookFrom = map.camera.asLookFrom();
    lookFrom.pitch += 10;
    map.camera = map.camera.lookFrom(lookFrom);

    Returns LookFrom

    a LookFrom object that matches position and orientation of this camera.

copy

copyAndSet

  • Copies this camera, and overrides parameters on the copy.

    // use a horizontal field-of-view on the map, instead of a vertical field-of-view
    var DEG2RAD = Math.PI / 180;
    var RAD2DEG = 180 / Math.PI;
    var newFovX = 90;
    var newfovY = 2 * Math.atan(Math.tan(newFovX * DEG2RAD / 2) / camera.aspectRatio) * RAD2DEG;
    map.camera = this.map.camera.copyAndSet({fovY: newFovY});

    Parameters

    • options: PerspectiveCameraOptions

      Camera parameters to override while copying. The returned copy will have the values of this Camera's parameters, except for the parameters defined in the options argument.

    Returns PerspectiveCamera

    A copy of the current camera, with the parameters defined in the options overridden.

equals

  • (other: any): boolean
  • Checks if two cameras are equal.

    Parameters

    • other: any

      The other object to check equality for

    Returns boolean

    True if other is a PerspectiveCamera instance with the same state as this one.

lookAt

  • Returns a camera that matches the position and orientation of the specified LookAt

    If lookAt.ref is a Point, then that point will be transformed to worldReference (if necessary).

    Note you can only use this function if this camera's worldReference is a geocentric reference.

    map.camera = map.camera.lookAt({
      ref: createPoint(getReference("CRS:84"), [52, 2, 0]),
      distance: 50e3,
      yaw: 180,
      pitch: -35,
      roll: 0
    });

    Parameters

    • lookAt: LookAt

      The returned camera will match this LookFrom's position and orientation.

    Returns PerspectiveCamera

    a camera that matches the position and orientation of the LookAt that was passed in.

lookFrom

  • Returns a camera that matches the position and orientation of the specified LookFrom

    If lookFrom.eye is a Point, then that point will be transformed to worldReference (if necessary).

    Note you can only use this function if this camera's worldReference is a geocentric reference.

    To perform a lookFrom with navigation constraints enforced you can use MapNavigator#lookFrom. This call will respect navigations constraints and additionally it can do the operation animated.

    map.camera = map.camera.lookFrom({
      eye: createPoint(getReference("CRS:84"), [0, 0, 20e3]),
      yaw: 180,
      pitch: -35,
      roll: 0
    });

    Parameters

    • lookFrom: LookFrom

      The returned camera will match this LookFrom's position and orientation.

    Returns PerspectiveCamera

    a camera that matches the position and orientation of the LookFrom that was passed in.

toView

  • Transforms a Vector3 from world to view

    Parameters

    • worldVec: Vector3

      The world point to transform to view space (pixels).

    • Optional vectorSFCT: Vector3

      An optional 'out' parameter. If this is defined, it's x,y and z properties will be assigned to the result of the transformation. If it's not defined, a new Vector3 with the result is constructed and returned. Use this out parameter if you need to transform many points at once, and want to avoid creating many objects.

    Returns Vector3

    The transformed point, in view space (pixels)

toViewPoint

  • Transforms a Point from world to view

    Parameters

    • point: Point

      The point to transform to view space (pixels). If this point is not defined in this camera's worldReference, it will first be transformed to the worldReference.

    • Optional outPointSFCT: Point

      An optional 'out' parameter. If this is defined, that point will be moved to the result of the transformation. If it's not defined, a new Point with the result is constructed and returned. Use this out parameter if you need to transform many points at once, and want to avoid creating many Point instances.

    Returns Point

    The transformed point, in view space (pixels).

toWorld

  • Transforms a Vector3 to world.

    Parameters

    • viewVec: Vector3

      The view point (pixels) to transform to world space.

    • Optional vectorSFCT: Vector3

      An optional 'out' parameter. If this is defined, it's x,y and z properties will be assigned to the result of the transformation. If it's not defined, a new Vector3 with the result is constructed and returned. Use this out parameter if you need to transform many points at once, and want to avoid creating many objects.

    Returns Vector3

    The transformed point, in world space.

toWorldPoint

  • Transforms a Point to world.

    Parameters

    • viewPoint: Point

      The point to transform to view space (pixels). A 'view' point has 'null' as its reference.

    • Optional outPointSFCT: Point

      An optional 'out' parameter. If this is defined, that point will be moved to the result of the transformation. If it is defined, and has a reference other than worldReference, it will be transformed to that reference. If it's not defined, a new Point with the result is constructed and returned. Use this out parameter if you need to transform many points at once, and want to avoid creating many Point instances.

    Returns Point

    The transformed point, in view space (pixels).

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method