Camera

class cee.Camera()

Camera settings (view point and projection) for a View.

Use this class to get a View’s current eye point, view direction and up vector.

Setup the camera by providing the eye, view reference point (center) and up vector to setFromLookAt.

You can also use this class to setup the projection and control the front and back clipping planes.

You can access a View’s camera with the View.camera property.

Accessors

cee.Camera.farPlane()
get farPlane(): number

Returns the far clipping plane

Returns: number

cee.Camera.fieldOfViewYDeg()
get fieldOfViewYDeg(): number

Returns the total field of view in the Y direction in degrees.

Returns undefined if parallel (orthographic) projection

Returns: number

cee.Camera.frontPlaneFrustumHeight()
get frontPlaneFrustumHeight(): number

Get height of the view frustum in the front plane in world coordinates.

Returns: number

cee.Camera.nearPlane()
get nearPlane(): number

Returns the near clipping plane

Returns: number

cee.Camera.projectionType()
get projectionType(): ProjectionType

Returns the current projection type (perspective/ortho)

Returns: ProjectionType

cee.Camera.viewMatrix()
get viewMatrix(): Mat4

Returns the current view matrix

Returns: Mat4

cee.Camera.viewport()
get viewport(): { height: number, width: number, x: number, y: number }

Returns the viewport of the camera

Returns: { height: number, width: number, x: number, y: number }

Methods

cee.Camera.applyCameraConfig()
applyCameraConfig(config: CameraConfig, allowChangeOfProjectionType: boolean): void

Helper that applies a camera config to the camera

Parameters

config: CameraConfig

allowChangeOfProjectionType: boolean

Returns: void

cee.Camera.computeFitViewEyePosition()
computeFitViewEyePosition(boundingBox: BoundingBox, dir: Vec3, up: Vec3, coverageFactor: number?): Vec3

Calculate the camera position required to fit the given bounding box in the view when the camera is orientated with the given direction and up vectors.

Parameters

boundingBox: BoundingBox

dir: Vec3

up: Vec3

coverageFactor: number = 0.9

Returns: Vec3

cee.Camera.disableAutoClip()
disableAutoClip(): void

Disables the auto clipping feature

Returns: void

cee.Camera.enableAutoClipFixedNearDistance()
enableAutoClipFixedNearDistance(fixedNearDistance: number): void

Enables the auto clipping feature and sets a fixed near distance

Parameters

fixedNearDistance: number

Returns: void

cee.Camera.enableAutoClipMinimumNearDistance()
enableAutoClipMinimumNearDistance(minNearDistance: number): void

Enables the auto clipping feature and sets a minimum near distance

Parameters

minNearDistance: number

Returns: void

cee.Camera.fitView()
fitView(boundingBox: BoundingBox, dir: Vec3Like, up: Vec3Like, coverageFactor: number?): void

Sets up the view to contain the passed bounding box, with the camera looking from the given direction (dir) and with the given up vector (up).

The passed boundingBox should be the bounding box of the object/model you would like to fit the view to.

The relativeDistance parameter specifies the distance from the camera to the center of the bounding box.

Note: This only works for perspective projection. For orthographic (parallel) projections, use the fitViewOrtho method.

Parameters

boundingBox: BoundingBox

dir: Vec3Like

up: Vec3Like

coverageFactor: number = 0.9

Returns: void

cee.Camera.fitViewOrtho()
fitViewOrtho(boundingBox: BoundingBox, eyeDist: number, dir: Vec3Like, up: Vec3Like, coverageFactor: number?): void

Sets up the view to contain the passed bounding box, with the camera looking from the given direction ‘dir’, at the give distance ‘eyeDist’ and with the given up vector ‘up’.

We recommend to set the ‘eyeDist’ to boundingBox.radius()*2.0

The passed boundingBox should be the bounding box of the object/model you would like to fit the view to.

Note: This only works for orthographic (parallel) projection. For perspective projections, use the fitView method.

Parameters

boundingBox: BoundingBox

eyeDist: number

dir: Vec3Like

up: Vec3Like

coverageFactor: number = 0.9

Returns: void

cee.Camera.getDirection()
getDirection(): Vec3

Returns camera’s forward direction vector. The returned vector is normalized.

Returns: Vec3

cee.Camera.getPosition()
getPosition(): Vec3

Returns the camera’s position (eye point)

Returns: Vec3

cee.Camera.getUp()
getUp(): Vec3

Returns the camera’s up vector. The returned vector is normalized.

Returns: Vec3

cee.Camera.project()
project(point: Vec3Like): Vec3

Maps world (3d) coordinates to window coordinates

Returns null if the specified point cannot be projected.

The returned window coordinates ‘out’ are in WebGL/OpenGL style coordinates, which means a right handed coordinate system with the origin in the lower left corner of the window.

OpenGL like project.

Parameters

point: Vec3Like

Returns: Vec3

cee.Camera.resetCamera()
resetCamera(): void

Resets the camera to its initial state as it appeared upon creation of its containing view

Returns: void

cee.Camera.setClipPlanesFromBoundingBox()
setClipPlanesFromBoundingBox(boundingBox: BoundingBox, minNearPlaneDistance: number): void

Sets the front and back clipping planes close to the given bounding box

Parameters

boundingBox: BoundingBox

minNearPlaneDistance: number

Returns: void

cee.Camera.setFromLookAt()
setFromLookAt(eye: Vec3Like, center: Vec3Like, up: Vec3Like): void

Sets the view matrix from the standard OpenGL ‘lookat’ (eye, center, vup) specification.

View direction will be (center - eye). Center is not stored in this class.

Parameters

eye: Vec3Like

center: Vec3Like

up: Vec3Like

Returns: void

cee.Camera.setProjectionAsOrtho()
setProjectionAsOrtho(height: number, nearPlane: number, farPlane: number): void

Sets up an orthographic (parallel) projection.

The height parameter is the height of the frustum. A good default is the length of the extent of the current bounding box.

Parameters

height: number

nearPlane: number

farPlane: number

Returns: void

cee.Camera.setProjectionAsPerspective()
setProjectionAsPerspective(fieldOfViewYDeg: number, nearPlane: number, farPlane: number): void

Sets up a perspective projection.

The fieldOfViewYDeg parameter is the total field of view angle (in degrees) in the Y direction. Works similar to gluPerspective().

Parameters

fieldOfViewYDeg: number

nearPlane: number

farPlane: number

Returns: void

cee.Camera.setViewChangeHandler()
setViewChangeHandler(handler: CameraViewChangeHandler, waitForIdle: boolean): void

Sets a handler to be invoked each time the camera view changes

Parameters

handler: CameraViewChangeHandler

The handler to invoke on change

waitForIdle: boolean

If true, the handler will only be invoked after any ongoing mouse operations or camera animations have completed. Note that setting this to false will result in a large number of handler invocations, while setting this to true and then starting a never-ending camera animation will result in no invocations.

Returns: void

cee.Camera.setViewMatrix()
setViewMatrix(viewMatrix: Mat4): void

Sets the view matrix of the camera.

Parameters

viewMatrix: Mat4

Returns: void

cee.Camera.setViewpoint()
setViewpoint(eye: Vec3Like, direction: Vec3Like, up: Vec3Like): void

Sets the viewpoint from the eye point position, direction and up vectors.

Parameters

eye: Vec3Like

direction: Vec3Like

up: Vec3Like

Returns: void

cee.Camera.unproject()
unproject(coord: Vec3Like): Vec3

Maps window coordinates to world (3d) coordinates

Returns null if the specified coordinate cannot be unprojected.

The input (window) coordinates ‘coord’ must be specified in WebGL/OpenGL style coordinates, which means a right handed coordinate system with the origin in the lower left corner of the window.

OpenGL like unproject.

Use Viewer.oglWinPosFromClientCoord to convert client coordinates into WebGL style coordinates

Parameters

coord: Vec3Like

Returns: Vec3

cee.Camera.zoomToBoundingBox()
zoomToBoundingBox(boundingBox: BoundingBox): void

Zoom in/out so the given bounding box will fill the view.

This is done without changing the current camera position. It works for both for PERSPECTIVE and ORTHO projection types.

Note: Works best with ZOOM navigation. Combining zoom (changing FOV) and walk navigation can give distorted views.

Parameters

boundingBox: BoundingBox

Returns: void