Angel
A 2D Game Prototyping Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes
Camera Class Reference

The class that handles displaying the appropriate viewport. More...

#include <Camera.h>

+ Inheritance diagram for Camera:

List of all members.

Public Member Functions

void Destroy ()
void Render ()
void Reset ()
const int GetWindowHeight () const
const int GetWindowWidth () const
const double GetViewRadius () const
const Vector2 GetWorldMaxVertex () const
const Vector2 GetWorldMinVertex () const
virtual void SetPosition (float x, float y, float z)
virtual void SetPosition (float x, float y)
virtual void SetPosition (const Vector3 &v3)
virtual void SetPosition (const Vector2 &v2)
virtual Vector2 GetPosition () const
virtual float GetZ () const
virtual void SetRotation (float rotation)
virtual float GetZForViewRadius (float radius)
virtual float GetNearClipDist ()
virtual float GetFarClipDist ()
virtual void SetZByViewRadius (float newRadius)
virtual void SetNearClipDist (float dist)
virtual void SetFarClipDist (float dist)
virtual void SetViewCenter (float x, float y, float z)
virtual const Vector3GetViewCenter () const
virtual const String GetClassName () const

Static Public Member Functions

static CameraGetInstance ()
static void ResizeCallback (int w, int h)

Protected Member Functions

void Resize (int w, int h)

Static Protected Attributes

static Cameras_Camera = NULL

Detailed Description

The Camera class is how you control what your players see at any time. It uses the singleton pattern; you can't actually declare a new instance of a Camera. To access the Camera in your world, use "theCamera" to retrieve the singleton object. "theCamera" is defined in both C++ and Lua.

If you're not familiar with the singleton pattern, this paper is a good starting point. (Don't be afraid that it's written by Microsoft.)

http://msdn.microsoft.com/en-us/library/ms954629.aspx

Camera is an Actor so that you can apply motion to it the same way you would any other Actor in your world.

By default the camera is positioned 10 units away from the origin, looking down the Z-axis (0.0, 0.0, 10.0). The visible world stretches from (-13.3, -10) to (13.3, 10).

Whenever the Camera updates its position or the viewport, it broadcasts a "CameraChange" Message that you can subscribe to if you need notifications.

Definition at line 59 of file Camera.h.


Member Function Documentation

Camera & Camera::GetInstance ( ) [static]

Used to access the singleton instance of this class. As a shortcut, you can just use "theCamera".

Returns:
The singleton

Definition at line 47 of file Camera.cpp.

void Camera::ResizeCallback ( int  w,
int  h 
) [static]

The callback used by GLFW to alert us when the user changes the size of the window. You shouldn't need to mess with this.

Parameters:
wNew width in pixels
hNew height in pixels

Definition at line 63 of file Camera.cpp.

void Camera::Destroy ( )

Deletes and NULLs out the singleton -- should only get called at World destruction when the program is exiting.

Reimplemented from Renderable.

Definition at line 57 of file Camera.cpp.

void Camera::Render ( ) [virtual]

Makes sure the view matrix is properly set up on every frame. Called by the world before rendering anything else.

Reimplemented from Actor.

Definition at line 126 of file Camera.cpp.

void Camera::Reset ( )

Resets the viewport to its default.

Definition at line 68 of file Camera.cpp.

const int Camera::GetWindowHeight ( ) const

Get the window's current height.

Returns:
Height in pixels.

Definition at line 100 of file Camera.cpp.

const int Camera::GetWindowWidth ( ) const

Get the window's current width.

Returns:
Width in pixels.

Definition at line 105 of file Camera.cpp.

const double Camera::GetViewRadius ( ) const

If you were to draw a circle inscribed in the viewport, this function will let you know the size of its radius. This is useful for determining how much of the world is currently being displayed.

Note that if you have a non-square viewport, the circle is bounded by the smaller dimension.

Returns:
The radius size in GL units.

Definition at line 110 of file Camera.cpp.

const Vector2 Camera::GetWorldMaxVertex ( ) const

Get the world coordinate of the top-right point of the window.

Returns:
The world coordinate (GL units).

Definition at line 116 of file Camera.cpp.

const Vector2 Camera::GetWorldMinVertex ( ) const

Get the world coordinate of the bottom-left point of the window.

Returns:
The world cooredinate (GL units).

Definition at line 121 of file Camera.cpp.

void Camera::SetPosition ( float  x,
float  y,
float  z 
) [virtual]

Set the position of the camera. Note that the camera is the only Actor that can take a Z coordinate for its position -- you can zoom in and out.

Parameters:
xThe new X position for the camera
yThe new Y position for the camera
zThe new Z position for the camera

Definition at line 146 of file Camera.cpp.

void Camera::SetPosition ( float  x,
float  y 
) [virtual]

Set the position of the camera. Using this two-dimensional function, the position on the Z-axis stays fixed.

Parameters:
xThe new X position for the camera
yThe new Y position for the camera

Reimplemented from Actor.

Definition at line 152 of file Camera.cpp.

void Camera::SetPosition ( const Vector3 v3) [virtual]

Set the position of the camera. Note that the camera is the only Actor that can take a Z coordinate for its position -- you can zoom in and out.

Parameters:
v3The new position for the camera.

Definition at line 166 of file Camera.cpp.

void Camera::SetPosition ( const Vector2 v2) [virtual]

Set the position of the camera. Using this two-dimensional function, the position on the Z-axis stays fixed.

Parameters:
v2The new position for the Camera

Reimplemented from Actor.

Definition at line 159 of file Camera.cpp.

Vector2 Camera::GetPosition ( ) const [virtual]

Gets the position of the Camera. Only returns the X and Y position so as to fit with the other GetPosition functions in the engine. To get the Z coordinate, see below.

Returns:
The (X, Y) position of the camera.

Reimplemented from Actor.

Definition at line 173 of file Camera.cpp.

float Camera::GetZ ( ) const [virtual]

Get the position of the camera on the Z-axis.

Returns:
The camera's Z coordinate.

Definition at line 178 of file Camera.cpp.

void Camera::SetRotation ( float  rotation) [virtual]

Set the rotation of the camera. Only rotates about the Z-axis, since we prefer the 2-dimensional.

Parameters:
v2The new rotation for the Camera. As with Actors, positive rotations are counter-clockwise.

Reimplemented from Actor.

Definition at line 183 of file Camera.cpp.

float Camera::GetZForViewRadius ( float  radius) [virtual]

Get the Z value necessary to achieve the requested view radius.

Parameters:
radiusThe desired view radius.
Returns:
The Z value.

Definition at line 189 of file Camera.cpp.

float Camera::GetNearClipDist ( ) [virtual]

Get the near clip distance.

Returns:
The near clip distance.

Definition at line 195 of file Camera.cpp.

float Camera::GetFarClipDist ( ) [virtual]

Get the far clip distance.

Returns:
The far clip distance.

Definition at line 200 of file Camera.cpp.

void Camera::SetZByViewRadius ( float  newRadius) [virtual]

Set the Z value necessary to achieve the requested view radius.

Parameters:
newRadiusThe desired view radius.

Definition at line 205 of file Camera.cpp.

void Camera::SetNearClipDist ( float  dist) [virtual]

Set the near clip distance. Note this will cause a Resize() to properly update the clipping planes

Parameters:
distThe near clip distance.

Definition at line 211 of file Camera.cpp.

void Camera::SetFarClipDist ( float  dist) [virtual]

Set the far clip distance. Note this will cause a Resize() to properly update the clipping planes

Parameters:
distThe far clip distance.

Definition at line 217 of file Camera.cpp.

void Camera::SetViewCenter ( float  x,
float  y,
float  z 
) [virtual]

Set the point towards which the camera should aim. Since Angel is a predominantly 2D world, be very careful setting this too far off of perpendicular.

Parameters:
xThe X coordinate at which the Camera will aim.
yThe Y coordinate at which the Camera will aim.
zThe Z coordinate at which the Camera will aim.

Definition at line 223 of file Camera.cpp.

const Vector3 & Camera::GetViewCenter ( ) const [virtual]

Get the current look-at target of the camera.

Returns:
The point where the Camera is currently looking.

Definition at line 229 of file Camera.cpp.

virtual const String Camera::GetClassName ( ) const [inline, virtual]

Used by the SetName function to create a basename for this class. Overridden from Actor::GetClassName.

Returns:
The string "Camera"

Definition at line 267 of file Camera.h.


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