CUGL 2.3
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::PerspectiveCamera Class Reference

#include <CUPerspectiveCamera.h>

Inheritance diagram for cugl::PerspectiveCamera:
cugl::Camera

Public Member Functions

 PerspectiveCamera ()
 
 ~PerspectiveCamera ()
 
void dispose () override
 
bool init (const Size size, float fieldOfView=DEFAULT_CAMERA_FOV)
 
bool init (float width, float height, float fieldOfView=DEFAULT_CAMERA_FOV)
 
bool init (const Rect rect, float fieldOfView=DEFAULT_CAMERA_FOV)
 
bool init (const Vec2 origin, const Size size, float fieldOfView=DEFAULT_CAMERA_FOV)
 
bool init (float x, float y, float width, float height, float fieldOfView=DEFAULT_CAMERA_FOV)
 
void set (const Size size, float fieldOfView=DEFAULT_CAMERA_FOV)
 
void set (float width, float height, float fieldOfView=DEFAULT_CAMERA_FOV)
 
void set (const Rect rect, float fieldOfView=DEFAULT_CAMERA_FOV)
 
void set (const Vec2 origin, const Size size, float fieldOfView=DEFAULT_CAMERA_FOV)
 
void set (float x, float y, float width, float height, float fieldOfView=DEFAULT_CAMERA_FOV)
 
void update () override
 
float getFieldOfView () const
 
void setFieldOfView (float fov)
 
- Public Member Functions inherited from cugl::Camera
 Camera ()
 
 ~Camera ()
 
virtual void dispose ()
 
const Vec3 getPosition () const
 
void setPosition (const Vec3 pos)
 
const Vec3 getDirection () const
 
void setDirection (const Vec3 vec)
 
const Vec3 getUp () const
 
void setUp (const Vec3 vec)
 
float getNear () const
 
void setNear (float value)
 
float getFar () const
 
void setFar (float value)
 
const Rect getViewport () const
 
const Mat4getProjection () const
 
const Mat4getView () const
 
const Mat4getCombined () const
 
const Mat4getInverseProjectView () const
 
virtual void update ()=0
 
void lookAt (const Vec3 target)
 
void lookAt (const Vec3 target, const Vec3 up)
 
void lookAt (float x, float y, float z)
 
void normalizeUp ()
 
void rotate (const Quaternion &quat)
 
void rotate (const Vec3 axis, float angle)
 
void rotateX (float angle)
 
void rotateY (float angle)
 
void rotateZ (float angle)
 
void rotate (float angle)
 
void rotate (const Mat4 &transform)
 
void rotateAround (const Vec3 point, const Vec3 axis, float angle)
 
void translate (const Vec3 vec)
 
void translate (const Vec2 vec)
 
void translate (float tx, float ty, float tz)
 
void translate (float tx, float ty)
 
void transform (const Mat4 &transform)
 
Vec3 unproject (const Vec3 windowCoords) const
 
Vec3 unproject (const Vec3 windowCoords, const Rect viewport) const
 
Vec3 screenToWorldCoords (const Vec2 screenCoords) const
 
Vec3 project (const Vec3 worldCoords) const
 
Vec3 project (const Vec3 worldCoords, const Rect viewport) const
 
Vec2 worldToScreenCoords (const Vec3 worldCoords) const
 
Ray getPickRay (const Vec3 windowCoords) const
 
Ray getPickRay (const Vec3 windowCoords, const Rect viewport) const
 
Ray getPickRayFromScreen (const Vec2 screenCoords) const
 
Vec2 windowToScreenCoords (const Vec3 windowCoords) const
 
Vec2 windowToScreenCoords (const Vec3 windowCoords, const Rect viewport) const
 
Vec3 screenToWindowCoords (const Vec2 screenCoords) const
 
Vec3 screenToWindowCoords (const Vec2 screenCoords, const Rect viewport) const
 

Static Public Member Functions

static std::shared_ptr< PerspectiveCameraalloc (const Size size, float fieldOfView=DEFAULT_CAMERA_FOV)
 
static std::shared_ptr< PerspectiveCameraalloc (float width, float height, float fieldOfView=DEFAULT_CAMERA_FOV)
 
static std::shared_ptr< PerspectiveCameraalloc (const Rect rect, float fieldOfView=DEFAULT_CAMERA_FOV)
 
static std::shared_ptr< PerspectiveCameraalloc (const Vec2 origin, const Size size, float fieldOfView=DEFAULT_CAMERA_FOV)
 
static std::shared_ptr< PerspectiveCameraalloc (float x, float y, float width, float height, float fieldOfView=DEFAULT_CAMERA_FOV)
 

Protected Attributes

float _fieldOfView = 67
 
bool _initialized
 
- Protected Attributes inherited from cugl::Camera
Vec3 _position
 
Vec3 _direction
 
Vec3 _upwards
 
Mat4 _projection
 
Mat4 _modelview
 
Mat4 _combined
 
Mat4 _inverse
 
float _near
 
float _far
 
Rect _viewport
 

Detailed Description

This is a class for a camera with a perspective projection.

This camera is used for 3d rendering.

Constructor & Destructor Documentation

◆ PerspectiveCamera()

cugl::PerspectiveCamera::PerspectiveCamera ( )
inline

Creates a degenerate camera.

All of the matrices are the identity and the viewport is empty.

◆ ~PerspectiveCamera()

cugl::PerspectiveCamera::~PerspectiveCamera ( )
inline

Deletes this camera, disposing all resources.

Member Function Documentation

◆ alloc() [1/5]

static std::shared_ptr< PerspectiveCamera > cugl::PerspectiveCamera::alloc ( const Rect  rect,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inlinestatic

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
rectThe viewport bounding box
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ alloc() [2/5]

static std::shared_ptr< PerspectiveCamera > cugl::PerspectiveCamera::alloc ( const Size  size,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inlinestatic

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

The viewport origin is assumed to be (0,0).

Parameters
sizeThe viewport size
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ alloc() [3/5]

static std::shared_ptr< PerspectiveCamera > cugl::PerspectiveCamera::alloc ( const Vec2  origin,
const Size  size,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inlinestatic

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
originThe viewport offset
sizeThe viewport size
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ alloc() [4/5]

static std::shared_ptr< PerspectiveCamera > cugl::PerspectiveCamera::alloc ( float  width,
float  height,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inlinestatic

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

The viewport origin is assumed to be (0,0).

Parameters
widthThe viewport width
heightThe viewport height
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ alloc() [5/5]

static std::shared_ptr< PerspectiveCamera > cugl::PerspectiveCamera::alloc ( float  x,
float  y,
float  width,
float  height,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inlinestatic

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
xThe viewport x offset
yThe viewport y offset
widthThe viewport width
heightThe viewport height
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ dispose()

void cugl::PerspectiveCamera::dispose ( )
overridevirtual

Returns this camera to the denegerate one, with all matrices the identity.

Reimplemented from cugl::Camera.

◆ getFieldOfView()

float cugl::PerspectiveCamera::getFieldOfView ( ) const
inline

Returns the field of view for the given camera.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Returns
the field of view for the given camera.

◆ init() [1/5]

bool cugl::PerspectiveCamera::init ( const Rect  rect,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inline

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
rectThe viewport bounding box
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ init() [2/5]

bool cugl::PerspectiveCamera::init ( const Size  size,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inline

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

The viewport origin is assumed to be (0,0).

Parameters
sizeThe viewport size
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ init() [3/5]

bool cugl::PerspectiveCamera::init ( const Vec2  origin,
const Size  size,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inline

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
originThe viewport offset
sizeThe viewport size
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ init() [4/5]

bool cugl::PerspectiveCamera::init ( float  width,
float  height,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inline

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

The viewport origin is assumed to be (0,0).

Parameters
widthThe viewport width
heightThe viewport height
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ init() [5/5]

bool cugl::PerspectiveCamera::init ( float  x,
float  y,
float  width,
float  height,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)

Initializes a new PerspectiveCamera for the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
xThe viewport x offset
yThe viewport y offset
widthThe viewport width
heightThe viewport height
fieldOfViewThe field of view of the height, in degrees
Returns
true if initialization was successful.

◆ set() [1/5]

void cugl::PerspectiveCamera::set ( const Rect  rect,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inline

Sets this PerspectiveCamera to have the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
rectThe viewport bounding box
fieldOfViewThe field of view of the height, in degrees

◆ set() [2/5]

void cugl::PerspectiveCamera::set ( const Size  size,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inline

Sets this PerspectiveCamera to have the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

The viewport origin is assumed to be (0,0).

Parameters
sizeThe viewport size
fieldOfViewThe field of view of the height, in degrees

◆ set() [3/5]

void cugl::PerspectiveCamera::set ( const Vec2  origin,
const Size  size,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inline

Sets this PerspectiveCamera to have the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
originThe viewport offset
sizeThe viewport size
fieldOfViewThe field of view of the height, in degrees

◆ set() [4/5]

void cugl::PerspectiveCamera::set ( float  width,
float  height,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)
inline

Sets this PerspectiveCamera to have the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

The viewport origin is assumed to be (0,0).

Parameters
widthThe viewport width
heightThe viewport height
fieldOfViewThe field of view of the height, in degrees

◆ set() [5/5]

void cugl::PerspectiveCamera::set ( float  x,
float  y,
float  width,
float  height,
float  fieldOfView = DEFAULT_CAMERA_FOV 
)

Sets this PerspectiveCamera to have the given viewport and field of view.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Offseting the viewport origin has no affect on the position attribute. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
xThe viewport x offset
yThe viewport y offset
widthThe viewport width
heightThe viewport height
fieldOfViewThe field of view of the height, in degrees

◆ setFieldOfView()

void cugl::PerspectiveCamera::setFieldOfView ( float  fov)

Sets the field of view for the given camera.

The field of view given is for the height, and is measured in degrees. The field of view for the width will be calculated according to the aspect ratio. Furthermore, the aspect ratio is derived from the viewport size.

Changing this value will have no effect on the underlying matrices until you call the update() method.

Parameters
fovthe field of view for the given camera.

◆ update()

void cugl::PerspectiveCamera::update ( )
overridevirtual

Recalculates the projection and view matrix of this camera.

Use this after you've manipulated any of the attributes of the camera.

Implements cugl::Camera.

Member Data Documentation

◆ _fieldOfView

float cugl::PerspectiveCamera::_fieldOfView = 67
protected

The field of view of the height, in degrees

◆ _initialized

bool cugl::PerspectiveCamera::_initialized
protected

Whether or not the camera has been initialized


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