Camera.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef DC_H_CAMERA_INCLUDED
34 #define DC_H_CAMERA_INCLUDED
35 
36 #include <Dynacoe/Util/Vector.h>
37 #include <Dynacoe/Backends/Renderer/Renderer.h>
38 #include <Dynacoe/Util/TransformMatrix.h>
39 #include <Dynacoe/Entity.h>
40 // The Camera transformations apply to the 3D context.
41 
42 
43 
44 
45 namespace Dynacoe {
46 
56 class Camera : public Entity {
57  public:
58  Camera();
59 
61  enum class Type {
64  };
65 
66  void BindTransformBuffers(RenderBufferID mview, RenderBufferID proj);
67 
68 
71  void SetType(Type);
72 
75  void Refresh();
76 
80 
81 
82 
88  void SetTarget(const Dynacoe::Vector & pos);
89 
90 
91 
100  Dynacoe::Vector TransformScreenToWorld(const Dynacoe::Vector & point, float distance);
101 
106 
107 
112  void SetRenderResolution(int w, int h);
113 
114 
117  int Width();
118 
121  int Height();
122 
123 
124 
128 
132 
136 
141 
142 
143  void OnStep();
144  private:
145  static Camera * activeRef;
146 
147  void UpdateView();
148  void UpdateProjection();
149  void Activate(Renderer *);
150  void Deactivate();
151 
152  int lastW, lastH;
153 
154  Type type;
155  TransformMatrix projectionMatrix;
156  Framebuffer * fb;
157 
158 
159  RenderBufferID modelView;
160  RenderBufferID projection;
161  void Initialize();
162  void OnUpdateTransform();
163 };
164 }
165 
166 #endif
Basic interactive object.
Definition: Entity.h:62
A transform representated as a row-major matrix.
Definition: TransformMatrix.h:44
Contains a visual state.
Definition: Framebuffer.h:49
bool autoRefresh
Sets whether to call Refresh() automatically.
Definition: Camera.h:79
brief Indicates use for 2D orthographics viewing
int Width()
Returns the width of the Camera's framebuffer.
void OnStep()
Called when Step() is called.
3D and 2D positional vector.
Definition: Vector.h:55
int Height()
Returns the height of the Camera's framebuffer.
Definition: AssetID.h:37
Type
The type of Camera.
Definition: Camera.h:61
Dynacoe::Vector TransformScreenToWorld(const Dynacoe::Vector &point, float distance)
Converts a point representing a pixel on a display to a point in 3D space.
Dynacoe::Vector TransformWorldToScreen(const Dynacoe::Vector &point)
Converts a point in transformed space to a pixel position on the display.
The viewport object.
Definition: Camera.h:56
void SetTarget(const Dynacoe::Vector &pos)
Sets the Camera's target.
void SetType(Type)
Sets the Type of Camera.
Assets are referred to by an AssetID. The AssetID uniquely refers to an Asset stored within memory...
Definition: AssetID.h:42
Framebuffer * GetFramebuffer()
Returns the framebuffer for the camera.
TransformMatrix GetProjectionTransform()
Returns the projection matrix of the Camera.
Indicates use for 3D perspective viewing.
TransformMatrix GetViewTransform()
Returns the viewing matrix of the Camera.
void SetRenderResolution(int w, int h)
Convenience function to set the rendering resultion.
AssetID CopyDisplay()
Returns a copy of the last rendered visual stored to this camera.
void Refresh()
Forces clearing of the results of drawing stored within the Camera.