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

Returns the far clipping plane

cee.Camera.fieldOfViewYDeg

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

Returns undefined if parallel (orthographic) projection

cee.Camera.frontPlaneFrustumHeight

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

cee.Camera.nearPlane

Returns the near clipping plane

cee.Camera.projectionType

Returns the current projection type (perspective/ortho)

cee.Camera.viewMatrix

Returns the current view matrix

Methods

computeFitViewEyePosition

cee.Camera.computeFitViewEyePosition(boundingBox, dir, up, coverageFactor)

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.

Arguments
Return type

cee.Vec3

disableAutoClip

cee.Camera.disableAutoClip()

Disables the auto clipping feature

Return type

void

enableAutoClipFixedNearDistance

cee.Camera.enableAutoClipFixedNearDistance(fixedNearDistance)

Enables the auto clipping feature and sets a fixed near distance

Arguments
  • fixedNearDistance (number) –

Return type

void

enableAutoClipMinimumNearDistance

cee.Camera.enableAutoClipMinimumNearDistance(minNearDistance)

Enables the auto clipping feature and sets a minimum near distance

Arguments
  • minNearDistance (number) –

Return type

void

fitView

cee.Camera.fitView(boundingBox, dir, up, coverageFactor)

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).

Arguments
Return type

void

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.

fitViewOrtho

cee.Camera.fitViewOrtho(boundingBox, eyeDist, dir, up, coverageFactor)

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’.

Arguments
Return type

void

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.

getDirection

cee.Camera.getDirection()

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

Return type

cee.Vec3

getPosition

cee.Camera.getPosition()

Returns the camera’s position (eye point)

Return type

cee.Vec3

getUp

cee.Camera.getUp()

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

Return type

cee.Vec3

project

cee.Camera.project(point)

Maps world (3d) coordinates to window coordinates

Arguments
Return type

{  }

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.

setClipPlanesFromBoundingBox

cee.Camera.setClipPlanesFromBoundingBox(boundingBox, minNearPlaneDistance)

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

Arguments
Return type

void

setFromLookAt

cee.Camera.setFromLookAt(eye, center, up)

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

Arguments
Return type

void

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

setProjectionAsOrtho

cee.Camera.setProjectionAsOrtho(height, nearPlane, farPlane)

Sets up a orthographic (parallel) projection.

Arguments
  • height (number) –

  • nearPlane (number) –

  • farPlane (number) –

Return type

void

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

setProjectionAsPerspective

cee.Camera.setProjectionAsPerspective(fieldOfViewYDeg, nearPlane, farPlane)

Sets up a perspective projection.

Arguments
  • fieldOfViewYDeg (number) –

  • nearPlane (number) –

  • farPlane (number) –

Return type

void

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

setViewChangeHandler

cee.Camera.setViewChangeHandler(handler, waitForIdle)

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

Arguments
  • handler (cee.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.

Return type

void

setViewMatrix

cee.Camera.setViewMatrix(viewMatrix)

Sets the view matrix of the camera.

Arguments
Return type

void

setViewpoint

cee.Camera.setViewpoint(eye, direction, up)

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

Arguments
Return type

void

unproject

cee.Camera.unproject(coord)

Maps window coordinates to world (3d) coordinates

Arguments
Return type

cee.Vec3

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

zoomToBoundingBox

cee.Camera.zoomToBoundingBox(boundingBox)

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

Arguments
Return type

void

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.