ianmackenzie/elm-3d-camera/3.1.0

NOTE: the latest version is 4.0.1

Camera3d

A Camera3d is a perspective or orthographic camera in 3D, encapsulating the camera's viewpoint and projection matrix as well as the dimensions of the screen the camera renders to. This module contains functions for:

  • Defining perspective and orthographic cameras
  • Obtaining view and projection matrices for a given camera, which can then be used for WebGL rendering
  • Using cameras to project 3D geometry to 2D screen space
type alias Camera3d units coordinates =
Camera3d units coordinates

Constructors

{ viewpoint : Viewpoint3d units coordinates
, verticalFieldOfView : Angle
}
-> Camera3d units coordinates

Create a perspective camera from a viewpoint and a vertical field of view.

perspectiveCamera =
    Camera3d.perspective
        { viewpoint = cameraViewpoint
        , verticalFieldOfView = Angle.degrees 30
        }
{ viewpoint : Viewpoint3d units coordinates
, viewportHeight : Quantity Float units
}
-> Camera3d units coordinates

Create an orthographic camera from a viewpoint and the height of the orthographic viewport: this is the height in 3D world units of the section of the model to be rendered.

orthographicCamera =
    Camera3d.orthographic
        { viewpoint = cameraViewpoint
        , viewportHeight = Length.meters 5
        }

Properties

viewpoint : Camera3d units coordinates -> Viewpoint3d units coordinates

Get the viewpoint defining the position and orientation of a camera.

Ray casting

ray :
Camera3d units coordinates
-> Rectangle2d screenUnits screenCoordinates
-> Point2d screenUnits screenCoordinates
-> Axis3d units coordinates

Given a camera, a rectangle defining the shape and size of a screen, and a 2D point within that screen, calculate the corresponding 3D ray as an Axis3d. Conceptually, the ray will pass through the given point on the screen and will have direction equal to the viewing direction at that point.

For a perspective camera, the origin of the ray will be constant (always equal to the camera's eye point) and the direction will vary depending on the 2D screen point. For an orthographic camera, the direction of the ray will be constant (the view direction of the camera) but the origin will vary depending on the 2D screen point.