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:
Cameras have some commmon properties regardless of how they are constructed:
viewpoint defines the position and orientation of the camera in 3D space.nearClipDistance and farClipDistance specify the standard near and far
clipping planes used when rendering.screenWidth and screenHeight specify the dimensions in pixels of the
screen that will be rendered to (the dimensions of an actual WebGl element,
for example). This is used to determine aspect ratio when constructing the
camera's projection matrix, but also by functions such as Camera3d.point2d
which convert from 3D world space to 2D screen space for a given camera.Create a perspective camera with the common camera properties plus vertical
field of view given in radians. The horizontal field of view will be chosen to
match the aspect ratio of the screen given by screenWidth and screenHeight.
perspectiveCamera =
Camera3d.perspective
{ viewpoint = cameraViewpoint
, verticalFieldOfView = degrees 30
, nearClipDistance = 0.1
, farClipDistance = 1000
, screenWidth = 1024
, screenHeight = 768
}Create an orthographic camera with the common camera properties plus the
height of the orthographic viewport: this is the height in 3D world units of the
section of the model to be rendered. (The width will be chosen to match the
aspect ratio of the screen given by screenWidth and screenHeight.)
orthographicCamera =
Camera3d.orthographic
{ viewpoint = cameraViewpoint
, viewportHeight = 5
, nearClipDistance = 0.1
, farClipDistance = 1000
, screenWidth = 1024
, screenHeight = 768
}Get the viewpoint defining the position and orientation of a camera.
Get the width of the screen rendered to by a camera.
Get the height of the screen rendered to by a camera.
Get the view matrix of a camera;
Camera3d.viewMatrix camerais shorthand for
Viewpoint3d.viewMatrix (Camera3d.viewpoint camera)Construct a WebGL model-view matrix given a camera and a Frame3d that
defines the position and orientation of an object;
Camera3d.modelViewMatrix modelFrame camerais shorthand for
Viewpoint3d.modelViewMatrix
modelFrame
(Camera3d.viewpoint camera)Get the projection matrix of a camera. Multiplying by this matrix converts from eye coordinates to WebGL normalized device coordinates.
Get the full model-view-projection matrix given a camera and a Frame3d
that defines the position and orientation of an object;
Camera3d.modelViewProjectionMatrix modelFrame camerais equivalent to
Matrix4.mul (Camera3d.projectionMatrix camera)
(Camera3d.modelViewMatrix modelFrame camera)