Core 1.0
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
Camera Class Reference

A simple camera. More...

#include <camera.h>

Public Member Functions

 Camera ()
 Create a default camera.
 
 Camera (const Vector &, const Vector &=Vector::Null, const Vector &=Vector::Z, const double &=1.0, const double &=1.0, const double &=1.0, const double &=100000.0)
 Create a camera given its location and look-at point. More...
 
 Camera (const Vector &, const Vector &, const Vector &, const double &, const double &=1.0, const double &=100000.0)
 Create a camera given its location and look at point. More...
 
void Translate (const Vector &)
 Translates a camera by a given vector. More...
 
void Rotate (const Matrix &)
 Rotates the camera with a rotation matrix. More...
 
Vector At () const
 Returns the look-at point.
 
Vector Eye () const
 Returns the eye point.
 
Vector Up () const
 Returns the up point.
 
Vector View () const
 Returns the viewing direction (not normalized).
 
Frame GetFrame () const
 Get the frame of the camera.
 
double GetNear () const
 Get the near distance.
 
double GetFar () const
 Get the far distance.
 
double GetAngleOfViewH () const
 Returns the horizontal angle of view. More...
 
double GetAngleOfViewV (double, double) const
 Returns the vertical angle of view. More...
 
void Step (const double &)
 Steps forward or backward by a given distance. More...
 
bool InsideFrustum (const Vector &) const
 Check if the point lies in the view frustum. More...
 
bool InsideFrustum (const Box &) const
 Check if the argument box lies in the view frustum. More...
 
void LeftRight (const double &)
 Rotates the camera around the up vector by a given angle. More...
 
void Vertical ()
 Reset the camera so that the up vector should point to the sky.
 
void UpDown (const double &)
 Move camera up and down according to the up vector. More...
 
void SideWay (const double &)
 Moves the camera sideway. More...
 
void BackForth (const double &, bool=false)
 Moves the eye point towards or away from the look at point. More...
 
void LeftRightRound (const double &)
 Rotates the camera relatively to the look-at point. More...
 
void UpDownRound (const double &)
 Rotates the camera relatively to the look-at point. More...
 
void LeftRightFPS (const double &)
 Rotates the camera relatively to the look-at point. More...
 
void UpDownRoundFPS (const double &)
 Rotates the camera relatively to the look-at point. More...
 
void SlideHorizontal (const double &)
 Moves the camera left or right in the horizontal plane. More...
 
void SetAt (const Vector &)
 Sets the camera target vector. More...
 
void SetEye (const Vector &)
 Sets the camera eye point. More...
 
void SetPlanes (const double &, const double &)
 Set the near and far planes. More...
 
void UpDownVertical (const double &)
 Moves the camera vertically. More...
 
void LeftRightHorizontal (const double &)
 Moves the camera left or right, preserving its height. More...
 
QString ToString (int=6) const
 Create a QString form a camera. More...
 
Ray PixelToRay (int, int, int, int) const
 Compute the equation of a ray given a pixel in the camera plane. More...
 
Ray PixelToRay (int, int, int, int, int, int, int) const
 Compute the equation of a ray given a pixel in the camera plane. More...
 
bool VectorToPixel (const Vector &, double &, double &, int, int) const
 Compute coordinates of a point in the camera plane. More...
 

Static Public Member Functions

static Camera View (const Box &)
 Create a default camera focusing on a given box. More...
 

Protected Attributes

Vector eye
 Eye.
 
Vector at
 Look at point.
 
Vector up
 Up vector.
 
Vector view
 View unit vector.
 
double width
 Screen width.
 
double height
 Screen height.
 
double cah
 Camera aperture horizontal.
 
double cav
 Camera aperture vertical.
 
double fl
 Focal length.
 
double nearplane
 Near plane.
 
double farplane
 Far plane.
 

Friends

std::ostream & operator<< (std::ostream &, const Camera &)
 Overloaded. More...
 

Detailed Description

A simple camera.

Constructor & Destructor Documentation

◆ Camera() [1/2]

Camera::Camera ( const Vector eye,
const Vector at = Vector::Null,
const Vector up = Vector::Z,
const double &  width = 1.0,
const double &  height = 1.0,
const double &  near = 1.0,
const double &  far = 100000.0 
)
explicit

Create a camera given its location and look-at point.

If no upward vector is provided, it is defined as z-axis.

The view vector is defined as the vector between the eye point and the look at point. The right vector, which is always computed as a cross product between the view vector and the up vector.

Parameters
eyeEye point.
atLook-at point.
upUp vector.
width,heightWidth and height of virtual screen.
near,farNear and far planes.

◆ Camera() [2/2]

Camera::Camera ( const Vector eye,
const Vector at,
const Vector up,
const double &  field,
const double &  near = 1.0,
const double &  far = 100000.0 
)
explicit

Create a camera given its location and look at point.

Parameters
eyeEye point.
atLook-at point.
upUp vector.
fieldField of view, should be in [0,Math::Pi/2.0].
near,farNear and far planes.

Member Function Documentation

◆ BackForth()

void Camera::BackForth ( const double &  a,
bool  t = false 
)

Moves the eye point towards or away from the look at point.

The look-at point does not change.

Parameters
aDistance.
tBoolean, set to true if look-at point should also be moved in the direction.

◆ GetAngleOfViewH()

double Camera::GetAngleOfViewH ( ) const

Returns the horizontal angle of view.

Angle is in radian.

◆ GetAngleOfViewV()

double Camera::GetAngleOfViewV ( double  w,
double  h 
) const

Returns the vertical angle of view.

Angle is in radian.

Parameters
w,hWidth and height of the screen.

◆ InsideFrustum() [1/2]

bool Camera::InsideFrustum ( const Box box) const

Check if the argument box lies in the view frustum.

Parameters
boxThe box.

◆ InsideFrustum() [2/2]

bool Camera::InsideFrustum ( const Vector p) const

Check if the point lies in the view frustum.

Simply check if the point is on the right side of the camera.

Parameters
pThe point.

◆ LeftRight()

void Camera::LeftRight ( const double &  a)

Rotates the camera around the up vector by a given angle.

Parameters
aRotation angle.

◆ LeftRightFPS()

void Camera::LeftRightFPS ( const double &  a)

Rotates the camera relatively to the look-at point.

Parameters
aDistance.

◆ LeftRightHorizontal()

void Camera::LeftRightHorizontal ( const double &  a)

Moves the camera left or right, preserving its height.

Parameters
aDistance.

◆ LeftRightRound()

void Camera::LeftRightRound ( const double &  a)

Rotates the camera relatively to the look-at point.

Parameters
aDistance.

◆ PixelToRay() [1/2]

Ray Camera::PixelToRay ( int  px,
int  py,
int  w,
int  h 
) const

Compute the equation of a ray given a pixel in the camera plane.

Parameters
px,pyPixel coordinates.
w,hSize of the viewing window.

◆ PixelToRay() [2/2]

Ray Camera::PixelToRay ( int  px,
int  py,
int  w,
int  h,
int  a,
int  xa,
int  ya 
) const

Compute the equation of a ray given a pixel in the camera plane.

See also
Camera::PixelToRay(int, int, int, int) const
Parameters
px,pyPixel coordinates.
w,hSize of the viewing window.
aAnti-aliasing sub-pixels.
xa,yaInteger coordinates of the sub-pixel.

◆ Rotate()

void Camera::Rotate ( const Matrix r)

Rotates the camera with a rotation matrix.

The rotation is centered at the eye, so the eye location is preserved. Other parameters are preserved.

Parameters
rRotation matrix.

◆ SetAt()

void Camera::SetAt ( const Vector a)

Sets the camera target vector.

Parameters
aLook-at point.

◆ SetEye()

void Camera::SetEye ( const Vector p)

Sets the camera eye point.

Parameters
pEye point.

◆ SetPlanes()

void Camera::SetPlanes ( const double &  n,
const double &  f 
)

Set the near and far planes.

Parameters
n,fNear and far planes distance to th eye.

◆ SideWay()

void Camera::SideWay ( const double &  a)

Moves the camera sideway.

Parameters
aDistance.

◆ SlideHorizontal()

void Camera::SlideHorizontal ( const double &  a)

Moves the camera left or right in the horizontal plane.

Parameters
aDistance.

◆ Step()

void Camera::Step ( const double &  r)

Steps forward or backward by a given distance.

Parameters
rStepping distance.

◆ ToString()

QString Camera::ToString ( int  n = 6) const

Create a QString form a camera.

Parameters
nNumber of digits used in the representation of reals.

◆ Translate()

void Camera::Translate ( const Vector t)

Translates a camera by a given vector.

Parameters
tTranslation vector.

◆ UpDown()

void Camera::UpDown ( const double &  a)

Move camera up and down according to the up vector.

Parameters
aRotation angle.

◆ UpDownRound()

void Camera::UpDownRound ( const double &  a)

Rotates the camera relatively to the look-at point.

Parameters
aDistance.

◆ UpDownRoundFPS()

void Camera::UpDownRoundFPS ( const double &  a)

Rotates the camera relatively to the look-at point.

Parameters
aDistance.

◆ UpDownVertical()

void Camera::UpDownVertical ( const double &  a)

Moves the camera vertically.

This function keeps the left vector horizontal.

Parameters
aDistance.

◆ VectorToPixel()

bool Camera::VectorToPixel ( const Vector p,
double &  u,
double &  v,
int  w,
int  h 
) const

Compute coordinates of a point in the camera plane.

Parameters
pPoint.
u,vCoordinates in the screen.
w,hSize of the viewing window.

◆ View()

Camera Camera::View ( const Box box)
static

Create a default camera focusing on a given box.

THe camera is located outside of the box and focuses on the center of the target box.

Parameters
boxThe box.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Camera camera 
)
friend

Overloaded.

Parameters
sStream.
cameraThe camera.