Angel 3.2
A 2D Game Prototyping Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | List of all members
Camera Class Reference

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

#include <Camera.h>

+ Inheritance diagram for Camera:

Public Member Functions

void Destroy ()
 
virtual void Update (float dt)
 
void Render ()
 
void Reset ()
 
void LockTo (Actor *locked, bool lockX=true, bool lockY=true, bool lockRotation=false)
 
ActorGetLockedActor ()
 
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)
 
void MoveTo (const Vector3 &newPosition, float duration, bool smooth=false, String onCompletionMessage="")
 
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
 
- Public Member Functions inherited from Actor
 Actor ()
 
virtual ~Actor ()
 
void SetSize (float x, float y=-1.f)
 
void SetSize (const Vector2 &newSize)
 
const Vector2GetSize () const
 
const BoundingBox GetBoundingBox () const
 
const Vector2GetPosition () const
 
const float GetRotation () const
 
void SetColor (float r, float g, float b, float a=1.0f)
 
void SetColor (const Color &color)
 
const ColorGetColor () const
 
void SetAlpha (float newAlpha)
 
const float GetAlpha () const
 
virtual void SetDrawShape (actorDrawShape drawShape)
 
const actorDrawShapeGetDrawShape () const
 
void UseDisplayList (int listIndex)
 
void MoveTo (const Vector2 &newPosition, float duration, bool smooth=false, String onCompletionMessage="")
 
void RotateTo (float newRotation, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeColorTo (const Color &newColor, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeSizeTo (const Vector2 &newSize, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeSizeTo (float newSize, float duration, bool smooth=false, String onCompletionMessage="")
 
int GetSpriteTexture (int frame=0) const
 
bool SetSprite (const String &filename, int frame=0, GLint clampmode=GL_CLAMP, GLint filtermode=GL_LINEAR, bool optional=false)
 
void ClearSpriteInfo ()
 
void LoadSpriteFrames (const String &firstFilename, GLint clampmode=GL_CLAMP, GLint filtermode=GL_LINEAR)
 
void PlaySpriteAnimation (float delay, spriteAnimationType animType=SAT_Loop, int startFrame=-1, int endFrame=-1, const char *animName=NULL)
 
void SetSpriteFrame (int frame)
 
int GetSpriteFrame () const
 
const bool IsSpriteAnimPlaying () const
 
virtual void AnimCallback (String animName)
 
void SetUVs (const Vector2 &lowleft, const Vector2 &upright)
 
void GetUVs (Vector2 &lowleft, Vector2 &upright) const
 
const bool IsTagged (const String &tag)
 
void Tag (const String &newTag)
 
void Untag (const String &oldTag)
 
const StringSet & GetTags () const
 
const String & SetName (String newName)
 
const String & GetName () const
 
virtual void ReceiveMessage (Message *message)
 
void SetLayer (int layerIndex)
 
void SetLayer (const String &layerName)
 
virtual void LevelUnloaded ()
 
ActorGetSelf ()
 
- Public Member Functions inherited from Renderable
 Renderable ()
 
virtual ~Renderable ()
 
void Destroy ()
 
bool IsDestroyed ()
 
int GetLayer ()
 

Static Public Member Functions

static CameraGetInstance ()
 
static void ResizeCallback (GLFWwindow *window, int w, int h)
 
- Static Public Member Functions inherited from Actor
static Actor *const GetNamed (const String &nameLookup)
 
static ActorCreate (const String &archetype)
 
static void SetScriptCreatedActor (Actor *a)
 

Protected Member Functions

void Resize (int w, int h)
 

Static Protected Attributes

static Cameras_Camera = NULL
 
- Static Protected Attributes inherited from Actor
static const float _squareVertices []
 
static float _circleVertices []
 
static float _circleTextureCoords []
 
static std::map< String, Actor * > _nameList
 
static Actor_scriptCreatedActor = NULL
 

Additional Inherited Members

- Protected Attributes inherited from Actor
Vector2 _size
 
Vector2 _position
 
Color _color
 
float _rotation
 
float _UV [8]
 
actorDrawShape _drawShape
 
int _spriteCurrentFrame
 
int _spriteNumFrames
 
float _spriteFrameDelay
 
float _spriteCurrentFrameDelay
 
int _spriteTextureReferences [MAX_SPRITE_FRAMES]
 
spriteAnimationType _spriteAnimType
 
int _spriteAnimStartFrame
 
int _spriteAnimEndFrame
 
int _spriteAnimDirection
 
int _displayListIndex
 
StringSet _tags
 
String _name
 
String _currentAnimName
 

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 ( GLFWwindow *  window,
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 64 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.

Definition at line 57 of file Camera.cpp.

void Camera::Update ( float  dt)
virtual

Override of actor's Update method to deal with the actor lock

Reimplemented from Actor.

Definition at line 134 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 178 of file Camera.cpp.

void Camera::Reset ( )

Resets the viewport to its default.

Definition at line 70 of file Camera.cpp.

void Camera::LockTo ( Actor locked,
bool  lockX = true,
bool  lockY = true,
bool  lockRotation = false 
)

Locks the camera to a specific Actor so it will track it around.

Parameters
lockedThe actor to track
lockXWhether to track the actor's X position
lockYWhether to track the actor's Y position
lockRotationWhether to track the actor's rotation

Definition at line 81 of file Camera.cpp.

Actor* Camera::GetLockedActor ( )
inline

Get the actor that the camera is currently tracking.

Returns
The tracked actor (NULL if not tracking anything)

Definition at line 119 of file Camera.h.

const int Camera::GetWindowHeight ( ) const

Get the window's current height.

Returns
Height in pixels.

Definition at line 108 of file Camera.cpp.

const int Camera::GetWindowWidth ( ) const

Get the window's current width.

Returns
Width in pixels.

Definition at line 113 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 118 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 124 of file Camera.cpp.

const Vector2 Camera::GetWorldMinVertex ( ) const

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

Returns
The world coordinate (GL units).

Definition at line 129 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 194 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 200 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 214 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 207 of file Camera.cpp.

void Camera::MoveTo ( const Vector3 newPosition,
float  duration,
bool  smooth = false,
String  onCompletionMessage = "" 
)

Interval movement for the camera in three dimensions.

See Also
Actor::MoveTo
Parameters
newPositionThe target position for the movement
durationHow long it should take to get there
smoothWhether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp
onCompletionMessageIf specified, a Message of this type will be sent when the movement is complete, letting you know when it's done. You will have to manually subscribe to this Message, though.

Definition at line 221 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.

Definition at line 227 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 232 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 237 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 243 of file Camera.cpp.

float Camera::GetNearClipDist ( )
virtual

Get the near clip distance.

Returns
The near clip distance.

Definition at line 249 of file Camera.cpp.

float Camera::GetFarClipDist ( )
virtual

Get the far clip distance.

Returns
The far clip distance.

Definition at line 254 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 259 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 265 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 271 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 277 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 283 of file Camera.cpp.

virtual const String Camera::GetClassName ( ) const
inlinevirtual

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

Returns
The string "Camera"

Reimplemented from Actor.

Definition at line 306 of file Camera.h.


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