Core 1.0
Camera Class Reference

A simple camera. More...

#include <camera.h>

Inheritance diagram for Camera:
CameraAnimatedFrame

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.
 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.
void Translate (const Vector &)
 Translates a camera by a given vector.
void Rotate (const Matrix &)
 Rotates the camera with a rotation matrix.
void CircleAnim (const double &angle, const Vector &start_eye)
 Rotates the camera around the look-at point by a given angle, starting from a given eye position.
Vector At () const
 Returns the look-at point.
Vector Eye () const
 Returns the eye point.
Vector Up () const
 Returns the up vector.
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 GetCameraApertureH () const
 Returns the horizontal camera aperture (film gate width) in inches.
double GetCameraApertureV () const
 Returns the vertical camera aperture (film gate height) in inches.
double GetFocalLength () const
 Returns the focal length in millimetres.
double GetAngleOfViewH () const
 Returns the horizontal angle of view.
double GetAngleOfViewV (double, double) const
 Returns the vertical angle of view.
void Step (const double &)
 Steps forward or backward by a given distance.
bool InsideFrustum (const Vector &) const
 Check if the point lies in the view frustum.
bool InsideFrustum (const Box &) const
 Check if the argument box lies in the view frustum.
void LeftRight (const double &)
 Rotates the camera around the up vector by a given angle.
void Vertical ()
 Reset the camera so that the up vector should point to the sky.
void UpDown (const double &)
 Rotates the view direction up or down around the eye, the look-at point moves while the eye remains fixed.
void SideWay (const double &)
 Moves the camera sideway.
void BackForth (const double &, bool=false)
 Moves the eye point towards or away from the look at point.
void LeftRightRound (const double &)
 Rotates the eye around the vertical axis passing through the look-at point.
void UpDownRound (const double &)
 Rotates the eye up or down around the look-at point.
void LeftRightFPS (const double &)
 Rotates the look-at point around the vertical axis passing through the eye, as in a first person view.
void UpDownRoundFPS (const double &)
 Rotates the look-at point up or down around the eye, as in a first person view.
void SlideHorizontal (const double &)
 Moves the camera left or right in the horizontal plane.
void SetAt (const Vector &)
 Sets the camera target vector.
void SetEye (const Vector &)
 Sets the camera eye point.
void SetPlanes (const double &, const double &)
 Set the near and far planes.
void SetCameraApertureH (const double &)
 Set the horizontal camera aperture.
void SetCameraApertureV (const double &)
 Set the vertical camera aperture.
void SetFocalLength (const double &)
 Set the focal length.
void UpDownVertical (const double &)
 Moves the camera vertically.
void LeftRightHorizontal (const double &)
 Moves the camera left or right, preserving its height.
QString ToString (int=6) const
 Create a QString form a camera.
Ray PixelToRay (int, int, int, int) const
 Compute the equation of a ray given a pixel in the camera plane.
Ray PixelToRay (int, int, int, int, int, int, int) const
 Compute the equation of a ray given a pixel in the camera plane.
bool VectorToPixel (const Vector &, double &, double &, int, int) const
 Compute coordinates of a point in the camera plane.

Static Public Member Functions

static Camera Lerp (const Camera &, const Camera &, const double &)
 Linearly interpolates between two cameras.
static Camera View (const Box &)
 Create a default camera focusing on a given box.

Protected Attributes

Vector eye = -Vector::X
 Eye.
Vector at = Vector::Null
 Look at point.
Vector up = Vector::Z
 Up vector.
Vector view = Vector::X
 View unit vector.
double cah = 0.980
 Camera aperture horizontal.
double cav = 0.735
 Camera aperture vertical.
double fl = 35.0
 Focal length.
double nearplane = 1.0
 Near plane.
double farplane = 100000.0
 Far plane.

Friends

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

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, currently ignored (the camera aperture and the focal length keep their default values).
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.

◆ CircleAnim()

void Camera::CircleAnim ( const double & angle,
const Vector & start_eye )

Rotates the camera around the look-at point by a given angle, starting from a given eye position.

Parameters
angleRotation angle in radians.
start_eyeStarting eye position, used to compute the radius and the initial angle of the circular animation.

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

◆ GetCameraApertureH()

double Camera::GetCameraApertureH ( ) const

Returns the horizontal camera aperture (film gate width) in inches.

This is the horizontal dimension of the film gate as used in Maya/RenderMan conventions. The default value is 0.980 inches (standard 35 mm full aperture). It is converted to millimetres internally when computing the angle of view:

{
return 2.0 * atan(cah * 25.4 * 0.5 / fl);
}
double fl
Focal length.
Definition camera.h:18
double GetAngleOfViewH() const
Returns the horizontal angle of view.
Definition camera.cpp:385
double cah
Camera aperture horizontal.
Definition camera.h:16
Returns
Horizontal aperture in inches.
See also
GetAngleOfViewH(), GetFocalLength()

◆ GetCameraApertureV()

double Camera::GetCameraApertureV ( ) const

Returns the vertical camera aperture (film gate height) in inches.

This is the vertical dimension of the film gate as used in Maya/RenderMan conventions. The default value is 0.735 inches (standard 35 mm full aperture).

Returns
Vertical aperture in inches.
See also
GetCameraApertureH(), GetAngleOfViewV()

◆ GetFocalLength()

double Camera::GetFocalLength ( ) const

Returns the focal length in millimetres.

Standard values range from 14 mm (wide angle) to 200 mm (telephoto). The default is 35 mm. Increasing the focal length narrows the angle of view; see GetAngleOfViewH().

Returns
Focal length in millimetres.
See also
GetAngleOfViewH(), GetCameraApertureH()

◆ InsideFrustum() [1/2]

bool Camera::InsideFrustum ( const Box & box) const

Check if the argument box lies in the view frustum.

Only a conservative test is performed: the bounding sphere of the box is checked against the half-space in front of the eye, the side, near and far planes are not tested.

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 look-at point around the vertical axis passing through the eye, as in a first person view.

Parameters
aRotation angle (radians).

◆ 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 eye around the vertical axis passing through the look-at point.

Parameters
aRotation angle (radians).

◆ Lerp()

Camera Camera::Lerp ( const Camera & cA,
const Camera & cB,
const double & alpha )
static

Linearly interpolates between two cameras.

All intrinsic and extrinsic parameters are interpolated: position, look-at point, up vector, screen dimensions, aperture, focal length, and clip planes. The up vector is re-normalised after blending to keep it unit-length.

Parameters
cAFirst camera.
cBSecond camera.
alphaBlend factor in [0,1]: 0 returns cA, 1 returns cB.

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

◆ SetCameraApertureH()

void Camera::SetCameraApertureH ( const double & c)

Set the horizontal camera aperture.

Parameters
cAperture, in inches.

◆ SetCameraApertureV()

void Camera::SetCameraApertureV ( const double & c)

Set the vertical camera aperture.

Parameters
cAperture, in inches.

◆ SetEye()

void Camera::SetEye ( const Vector & p)

Sets the camera eye point.

Parameters
pEye point.

◆ SetFocalLength()

void Camera::SetFocalLength ( const double & f)

Set the focal length.

Parameters
fFocal length, in millimeters.

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

Rotates the view direction up or down around the eye, the look-at point moves while the eye remains fixed.

Parameters
aRotation angle (radians).

◆ UpDownRound()

void Camera::UpDownRound ( const double & a)

Rotates the eye up or down around the look-at point.

Parameters
aRotation angle (radians).

◆ UpDownRoundFPS()

void Camera::UpDownRoundFPS ( const double & a)

Rotates the look-at point up or down around the eye, as in a first person view.

Parameters
aRotation angle (radians).

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

◆ operator<<

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

Overloaded.

Parameters
sStream.
cameraThe camera.