Angel 3.2
A 2D Game Prototyping Engine
Camera.h
1 
2 // Copyright (C) 2008-2013, Shane Liesegang
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of the copyright holder nor the names of any
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
29 
30 #pragma once
31 
32 #include "../Actors/Actor.h"
33 #include "../Infrastructure/Vector3.h"
34 
35 #define theCamera Camera::GetInstance()
36 
38 
59 class Camera : public Actor
60 {
61 public:
68  static Camera &GetInstance();
69 
70  #if !ANGEL_MOBILE
71 
78  static void ResizeCallback(GLFWwindow* window, int w, int h);
79  #endif
80 
85  void Destroy();
86 
90  virtual void Update(float dt);
91 
96  void Render();
97 
101  void Reset();
102 
112  void LockTo(Actor* locked, bool lockX=true, bool lockY=true, bool lockRotation=false);
113 
119  Actor* GetLockedActor() { return _locked; }
120 
126  const int GetWindowHeight() const;
127 
133  const int GetWindowWidth() const;
134 
145  const double GetViewRadius() const;
146 
152  const Vector2 GetWorldMaxVertex() const;
153 
159  const Vector2 GetWorldMinVertex() const;
160 
170  virtual void SetPosition(float x, float y, float z);
171 
179  virtual void SetPosition(float x, float y);
180 
188  virtual void SetPosition(const Vector3& v3);
189 
196  virtual void SetPosition(const Vector2& v2);
197 
210  void MoveTo(const Vector3& newPosition, float duration, bool smooth=false, String onCompletionMessage="");
211 
219  virtual Vector2 GetPosition() const;
220 
226  virtual float GetZ() const;
227 
235  virtual void SetRotation(float rotation);
236 
243  virtual float GetZForViewRadius(float radius);
244 
250  virtual float GetNearClipDist();
251 
257  virtual float GetFarClipDist();
258 
264  virtual void SetZByViewRadius(float newRadius);
265 
272  virtual void SetNearClipDist(float dist);
273 
280  virtual void SetFarClipDist(float dist);
281 
291  virtual void SetViewCenter(float x, float y, float z);
292 
298  virtual const Vector3& GetViewCenter() const;
299 
306  virtual const String GetClassName() const { return "Camera"; }
307 
308 protected:
309  Camera();
310  static Camera *s_Camera;
311 
312  void Resize(int w, int h);
313 
314 private:
315  int _windowWidth;
316  int _windowHeight;
317  double _aperture;
318  Vector3 _camera3DPosition;
319  Vector3 _view;
320  Vector3 _up;
321 
322  float _zNearClip;
323  float _zFarClip;
324 
325  Actor* _locked;
326  bool _lockX;
327  bool _lockY;
328  bool _lockRotation;
329 
330  Interval<Vector3> _3dPositionInterval;
331  String _3dPositionIntervalMessage;
332 };