]> git.tdb.fi Git - libs/game.git/blob - source/game/camera.h
Use the setup generator to create setup structs
[libs/game.git] / source / game / camera.h
1 #ifndef MSP_GAME_CAMERA_H_
2 #define MSP_GAME_CAMERA_H_
3
4 #include <msp/geometry/angle.h>
5 #include <msp/linal/vector.h>
6 #include "component.h"
7 #include "mspgame_api.h"
8 #include "setups.h"
9
10 namespace Msp::Game {
11
12 struct CameraData
13 {
14         Geometry::Angle<float> fov_y;
15         LinAl::Vector<float, 2> size;
16         float height;
17         float near_clip;
18         float far_clip;
19
20         bool is_orthographic() const { return fov_y==Geometry::Angle<float>::zero(); }
21         Geometry::Angle<float> get_fov_horizontal() const { return Geometry::atan(tan(fov_y/2.0f)*get_aspect())*2.0f; }
22         float get_aspect() const { return size.x/size.y; }
23 };
24
25 class MSPGAME_API Camera: public BufferedComponent<CameraData>
26 {
27 public:
28         using Setup = CameraSetup;
29
30 private:
31         const Setup &setup;
32
33 public:
34         Camera(Handle<Entity>, const Setup &);
35
36         void set_field_of_view(Geometry::Angle<float>, float);
37         void set_size(const LinAl::Vector<float, 2> &);
38         bool is_orthographic() const { return read().is_orthographic(); }
39         Geometry::Angle<float> get_fov_vertical() const { return read().fov_y; }
40         Geometry::Angle<float> get_fov_horizontal() const { return read().get_fov_horizontal(); }
41         const LinAl::Vector<float, 2> &get_size() const { return read().size; }
42         float get_aspect() const { return read().get_aspect(); }
43         float get_near_clip() const { return read().near_clip; }
44         float get_far_clip() const { return read().far_clip; }
45         CameraScaling get_scaling() const { return setup.scaling; }
46         const std::string &get_sequence_name() const { return setup.sequence_name; }
47 };
48
49 } // namespace Msp::Game
50
51 #endif