Class BaseCamera

This is the base class for the camera. It is used to create a camera that can be used to view a board.

If there's only one class that you want to use in this library, it is this one. The is the back bone of the board camera system.

With the CameraRig class, you can create a camera system that can be used to achieve the infinite canvas effect.

This class is not observable (you can not register a callback for camera state changes). If you need to observe the camera state, use the DefaultBoardCamera class instead.

Implements

Camera

  • Inverts a point from the world coordinate system to the viewport coordinate system.

    Parameters

    • point: Point

      The point in the world coordinate system.

    Returns Point

    The point in the viewport coordinate system.

Other

  • Parameters

    • viewPortWidth: number = 1000

      The width of the viewport. (The width of the canvas in css pixels)

    • viewPortHeight: number = 1000

      The height of the viewport. (The height of the canvas in css pixels)

    • position: Point = { x: 0, y: 0 }

      The position of the camera in the world coordinate system

    • rotation: number = 0

      The rotation of the camera in the world coordinate system

    • zoomLevel: number = 1

      The zoom level of the camera

    • boundaries: Boundaries = { min: { x: -10000, y: -10000 }, max: { x: 10000, y: 10000 } }

      The boundaries of the camera in the world coordinate system

    • zoomLevelBoundaries: ZoomLevelLimits = { min: 0.1, max: 10 }

      The boundaries of the zoom level of the camera

    • rotationBoundaries: RotationLimits = undefined

      The boundaries of the rotation of the camera

    Returns BaseCamera

  • The order of the transformation is as follows:

    1. Scale (scale the context using the device pixel ratio)
    2. Translation (move the origin of the context to the center of the canvas)
    3. Rotation (rotate the context negatively the rotation of the camera)
    4. Zoom (scale the context using the zoom level of the camera)
    5. Translation (move the origin of the context to the position of the camera in the context coordinate system)

    Parameters

    • devicePixelRatio: number

      The device pixel ratio of the canvas

    • alignCoorindate: boolean

      Whether to align the coordinate system to the camera's position

    Returns { a: number; b: number; c: number; d: number; e: number; f: number }

    The transformation matrix

  • This function is used to set the position of the camera.This function has a guard that checks if the destination point is within the boundaries of the camera. If the destination point is not within the boundaries, the function will return false and the position will not be updated. If the destination point is within the boundaries, the function will return true and the position will be updated.

    Parameters

    • destination: Point

      The destination point of the camera.

    Returns boolean

    Whether the position is set successfully.

  • This function is used to set the zoom level of the camera.This function has a guard that checks if the zoom level is within the boundaries of the camera. If the zoom level is not within the boundaries, the function will return false and the zoom level will not be updated. If the zoom level is within the boundaries, the function will return true and the zoom level will be updated.

    Parameters

    • zoomLevel: number

      The zoom level of the camera.

    Returns boolean

    Whether the zoom level is set successfully.