Camera

struct glen::Camera

Abstract camera node. Provides camera basic funcrionality.

Subclassed by FreeCamera, OrthoCamera, TargetCamera

Public Functions

Camera()

Constructs a camera By default cameras have a resolution of 800x600 pixels, a near and far clipping plane 0.1 and 1000 units respectively.

void update() = 0

Update the camera position. Accept input from the user to move the camera around.

const glm::uvec2 &dimensions() const

Return

the dimensions of the camera.

const GLfloat &clip_near() const

Return

the near clipping plane of the camera. Anything further away than this from the camera won’t be rendered.

const GLfloat &clip_far() const

Return

the far clipping plane of the camera. Anything closer than this won’t be rendered.

const glm::vec3 position() const

Return

the x, y, z coordinates in local space (relative to camera node).

const glm::mat4 transform() const

Return

the transform matrix in local space (relative to camera node).

const glm::mat4 object_to_cam() const

Return

the transformation matrix to go from object space to camera space.

const glm::mat4 object_to_projection() const

Return

the transformation matrix from object to camera to projection. The projection matrix is the matrix required to transform the scene into a perspective view.

const glm::mat4 cam_to_projection() const = 0

Return

the transformation matrix from the camera to projection. The projection matrix is the matrix required to transform the scene into a perspective view.

const glm::mat4 transform_to_cam(const glm::mat4 &transform) const = 0

Return

the transformation matrix from input transform to the camera transform.

const glm::mat4 transform_to_projection(const glm::mat4 &transform) const

Return

the transformation matrix from input matrix to projection.

void set_dimensions(glm::uvec2 dimensions)

Sets the dimensions of the camera Please note, this is mainly used for determining the aspect ratio of the camera view. Set the actual resolution in Window to affect the view.

Parameters
  • Dimensions: The width and height of the camera’s perspective.

void set_clip_near(GLfloat distance)

Sets the far clipping plane. Anything beyond this won’t be rendered. Ideally set the near and far clipping planes just enough to encompass everything required in the scene and no more. If the difference is too large, you will start to see artefacts.

Parameters
  • distance: Clipping plane distance

void set_clip_far(GLfloat distance)

Sets the near clipping plane. Anything closer to this won’t be rendered. Ideally set the near and far clipping planes just enough to encompass everything required in the scene and no more. If the difference is too large, you will start to see artefacts.

Parameters
  • distance: Clipping plane difference

void set_position(const glm::vec3 &position)

Set the local position of the camera (relative to the camera node).

Parameters
  • position: The new position in x, y, z vector coordinates.

void add_to_position(const glm::vec3 &position)

Take input position vector and add it to the camera’s current position. Useful for implementing extra camera movement.

Parameters
  • position: The offset position in x, y, z vector coordinates.

void register_transform(glm::mat4 *transform)

Used for connecting to a CameraNode. Allows for some useful transform matrices to be calculated.

Parameters
  • transform: The transform matrix to register.

Free Camera

struct glen::FreeCamera : public Camera

Free camera. Not targeted. Orientation is based on parents transforms only

Public Functions

FreeCamera()
void update()

Update the camera position. Accept input from the user to move the camera around. Use W, A, S, D, to move forward, backwars, left, right respectively. Use Q and E to move up and down.

const glm::mat4 transform_to_cam(const glm::mat4 &transform) const override

Return

the transformation matrix from input matrix to projection.

const glm::mat4 cam_to_projection() const override

Return

the transformation matrix from the camera to projection. The projection matrix is the matrix required to transform the scene into a perspective view.

void set_angle_of_view(GLfloat angle)

Set angle of view in the y (up/down) direction

Orthographic Camera

struct glen::OrthoCamera : public Camera

Orthographic camera. No perspective.

Public Functions

OrthoCamera()

Constructor

OrthoCamera(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top)

Constructor /param left coordinate of left vertical clipping plane /param right coordinate of right vertical clipping plane /param bottom coordinate of bottom horizontal clipping plane /param top coordinate of top horizontal clipping plane

void update()

Update the camera position. At the moment this does nothing and movement is entirely dependent on CameraNode movement.

const glm::mat4 transform_to_cam(const glm::mat4 &transform) const override

Return

the transformation matrix from input matrix to projection.

const glm::mat4 cam_to_projection() const override

Return

the transformation matrix from the camera to projection. The projection matrix is the matrix required to transform the scene into a perspective view.

void set_sides(const GLfloat left, const GLfloat right, const GLfloat bottom, const GLfloat top)

Set vertical and horizontal clipping planes /param left coordinate of left vertical clipping plane /param right coordinate of right vertical clipping plane /param bottom coordinate of bottom horizontal clipping plane /param top coordinate of top horizontal clipping plane

void set_left(const GLfloat left)

/param left coordinate of left vertical clipping plane

void set_right(const GLfloat right)

/param right coordinate of right vertical clipping plane

void set_bottom(const GLfloat bottom)

/param bottom coordinate of bottom horizontal clipping plane

void set_top(const GLfloat top)

/param top coordinate of top horizontal clipping plane

Target Camera

struct glen::TargetCamera : public Camera

Public Functions

TargetCamera()

Constructor

void update() override

Update the camera position. Accept input from the user to move the camera around. Use left, middle and right button to rotate around target, move camera + target and zoom respectively Pressing F or Z will cause the camera to ‘look at’ the focus target.

const glm::mat4 transform_to_cam(const glm::mat4 &transform) const override

Reposition camera with matrix.

Return

The new local transformation matrix

Parameters
  • transform: The input transformation matrix

const glm::mat4 cam_to_projection() const override

Return

The camera’s perspective transfrom matrix

void set_view_direction(glm::vec3 direction)

Set the direction the camera is pointing.

Parameters
  • direction: The direction vector

void set_cam_right(glm::vec3 direction)

Set the right direction of the camera An alternative to using set_view_direction

Parameters
  • direction: The direction vector

void set_angle_of_view(GLfloat angle)

Set the angle of view in the y (up/down) direction.

Parameters
  • angle: The angle in radians

void set_focus_target(const glm::vec3 &target)

The point that the camera is looking at. When the F is pressed, this is where the camera will focus.

Parameters
  • target: The target to ‘look at’.