AGL  0
3D graphics library
Camera Class Reference

Camera class for the scene. More...

Public Member Functions

 Camera (const glm::vec3 &pos=glm::vec3(3, 4, 5), const glm::vec3 &lookAt=glm::vec3(0), const glm::vec3 &up=glm::vec3(0, 1, 0))
 Creates a camera. More...
 
void setView (const glm::mat4 &mat)
 Set the view matrix. More...
 
void rotate (float rad=0, const glm::vec3 &axis=glm::vec3(0), bool around=true)
 Rotate the camera. More...
 
void rotate (const glm::quat &rot=glm::quat(1, 0, 0, 0), bool around=true)
 Rotate the camera with the quaternion. More...
 
void rotateX (float rad=0, bool around=true, bool safe=true)
 Rotate around the x-axis. More...
 
void rotateY (float rad=0, bool around=true)
 Rotate around the y-axis. More...
 
void rotateZ (float rad=0, bool around=true)
 Rotate around the z-axis. More...
 
void translate (const glm::vec3 &d=glm::vec3(0))
 Translate (move, shift) the camera. More...
 
void translate (float dx=0, float dy=0, float dz=0)
 Translate (move, shift) the camera. More...
 
Camera setters

These methods are used to set the parameters of the camera, and the view matrix. They modify the internal view matrix.

void setPos (const glm::vec3 &pos=glm::vec3(3, 4, 5))
 Sets the position of the camera. More...
 
void setPos (float x=3, float y=4, float z=5)
 Sets the position of the camera. More...
 
void lookAt (const glm::vec3 &target=glm::vec3(0))
 Set the point the camera will look at. More...
 
void lookAt (float x=0, float y=0, float z=0)
 Set the point the camera will look at. More...
 
void setUp (const glm::vec3 &up=glm::vec3(0, 1, 0))
 Set the up-vector. More...
 
void setUp (float x=0, float y=1, float z=0)
 Set the up-vector. More...
 
View transformations

These methods applies transformations directly to the view matrix. It is advised that you do not use these methods. These methods do not modify either of _pos, _lookAt or _up. All of these are left handed, ie. these are applied on the current transformed matrix.

void viewTranslate (const glm::vec3 &d=glm::vec3(0))
 Translate the view matrix. More...
 
void viewTranslate (float dx=0, float dy=0, float dz=0)
 Translate the view matrix. More...
 
void viewRotate (float rad=0, const glm::vec3 &axis=glm::vec3(0))
 Rotate the view matrix. More...
 
void viewScale (const glm::vec3 &s=glm::vec3(1))
 Scale the view matrix. More...
 
void viewScale (float sx=1, float sy=1, float sz=1)
 Scale the view matrix. More...
 
void viewTransform (const glm::mat4 &m)
 Transform the view matrix. More...
 

Public Attributes

glm::mat4 view
 The view matrix. More...
 
glm::vec3 _pos
 The position of the camera. More...
 
glm::vec3 _lookAt
 The point the camera looks at. More...
 
glm::vec3 _up
 The up vector for the camera. More...
 

Detailed Description

Camera class for the scene.

Camera controls the positioning of the camera for the scene. It controls the rotation of the camera, up-vectors, positioning, etc. This class handles the V part of the MVP matrix.

Constructor & Destructor Documentation

◆ Camera()

Camera ( const glm::vec3 &  pos = glm::vec3(3, 4, 5),
const glm::vec3 &  lookAt = glm::vec3(0),
const glm::vec3 &  up = glm::vec3(0, 1, 0) 
)

Creates a camera.

Parameters
posThe position of the camera.
lookAtThe point the camera looks at.
upThe up vector for the camera.

Member Function Documentation

◆ lookAt() [1/2]

void lookAt ( const glm::vec3 &  target = glm::vec3(0))

Set the point the camera will look at.

Parameters
targetThe point as a vector.

This point will be the center of the scene.

◆ lookAt() [2/2]

void lookAt ( float  x = 0,
float  y = 0,
float  z = 0 
)

Set the point the camera will look at.

Parameters
xThe x position.
yThe y position.
zThe z position.

◆ rotate() [1/2]

void rotate ( float  rad = 0,
const glm::vec3 &  axis = glm::vec3(0),
bool  around = true 
)

Rotate the camera.

Parameters
radAngle to rotate by, in radians.
axisAxis of rotation.
aroundRotate around center?

Rotates the camera by rad radians around the axis. If around is true, the camera rotates while keeping the _lookAt at center, ie. the _pos changes; the camera rotates around the scene. If around is false, the camera rotates while keeping the _pos at center, ie. the _lookAt changes; the camera itself rotates.

◆ rotate() [2/2]

void rotate ( const glm::quat &  rot = glm::quat(1, 0, 0, 0),
bool  around = true 
)

Rotate the camera with the quaternion.

Parameters
rotQuaternion for rotation.
aroundSee rotate.

◆ rotateX()

void rotateX ( float  rad = 0,
bool  around = true,
bool  safe = true 
)

Rotate around the x-axis.

Parameters
radAngle to rotate by, in radians.
aroundSee rotate.
safeRotations beyond 90 degree along the x-axis might cause the render to flip abruptly. Setting this to true tries to prevent that. However, it isn't guaranteed that this will work.

◆ rotateY()

void rotateY ( float  rad = 0,
bool  around = true 
)

Rotate around the y-axis.

Parameters
radAngle to rotate by, in radians.
aroundSee rotate.

◆ rotateZ()

void rotateZ ( float  rad = 0,
bool  around = true 
)

Rotate around the z-axis.

Parameters
radAngle to rotate by, in radians.
aroundSee rotate.

◆ setPos() [1/2]

void setPos ( const glm::vec3 &  pos = glm::vec3(3, 4, 5))

Sets the position of the camera.

Parameters
posThe position as a vector.

◆ setPos() [2/2]

void setPos ( float  x = 3,
float  y = 4,
float  z = 5 
)

Sets the position of the camera.

Parameters
xThe x position.
yThe y position.
zThe z position.

◆ setUp() [1/2]

void setUp ( const glm::vec3 &  up = glm::vec3(0, 1, 0))

Set the up-vector.

Parameters
upThe up vector.

◆ setUp() [2/2]

void setUp ( float  x = 0,
float  y = 1,
float  z = 0 
)

Set the up-vector.

Parameters
xThe x component of the vector.
yThe y component of the vector.
zThe z component of the vector.

◆ setView()

void setView ( const glm::mat4 &  mat)

Set the view matrix.

Parameters
matThe view matrix.

This method can be used to set the view matrix manually, but it'll set _pos, _lookAt and _up to nan. Extracting these information from the matrix is not supported currently.

◆ translate() [1/2]

void translate ( const glm::vec3 &  d = glm::vec3(0))

Translate (move, shift) the camera.

Parameters
dVector to translate by.

◆ translate() [2/2]

void translate ( float  dx = 0,
float  dy = 0,
float  dz = 0 
)

Translate (move, shift) the camera.

Parameters
dxAmount to translate along the x-axis.
dyAmount to translate along the y-axis.
dzAmount to translate along the z-axis.

◆ viewRotate()

void viewRotate ( float  rad = 0,
const glm::vec3 &  axis = glm::vec3(0) 
)

Rotate the view matrix.

Parameters
radAngle to rotate by, in radians.
axisAxis of rotation.

◆ viewScale() [1/2]

void viewScale ( const glm::vec3 &  s = glm::vec3(1))

Scale the view matrix.

Parameters
sVector to scale by.

◆ viewScale() [2/2]

void viewScale ( float  sx = 1,
float  sy = 1,
float  sz = 1 
)

Scale the view matrix.

Parameters
sxAmount to scale along the x-axis.
syAmount to scale along the y-axis.
szAmount to scale along the z-axis.

◆ viewTransform()

void viewTransform ( const glm::mat4 &  m)

Transform the view matrix.

Parameters
mMatrix to transform by.

◆ viewTranslate() [1/2]

void viewTranslate ( const glm::vec3 &  d = glm::vec3(0))

Translate the view matrix.

Parameters
dVector to translate by.

◆ viewTranslate() [2/2]

void viewTranslate ( float  dx = 0,
float  dy = 0,
float  dz = 0 
)

Translate the view matrix.

Parameters
dxAmount to translate along the x-axis.
dyAmount to translate along the y-axis.
dzAmount to translate along the z-axis.

Member Data Documentation

◆ _lookAt

glm::vec3 _lookAt

The point the camera looks at.

◆ _pos

glm::vec3 _pos

The position of the camera.

◆ _up

glm::vec3 _up

The up vector for the camera.

◆ view

glm::mat4 view

The view matrix.


The documentation for this class was generated from the following files: