]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/camera.h
Use the setup generator to create setup structs
[libs/game.git] / source / game / camera.h
index 1e8efdd5e85527b536e6d9d87bbcca1f8afedf59..e981afcd3b2e85dfaf4d34d8d5f6ce65413e27b8 100644 (file)
@@ -4,52 +4,44 @@
 #include <msp/geometry/angle.h>
 #include <msp/linal/vector.h>
 #include "component.h"
+#include "mspgame_api.h"
+#include "setups.h"
 
 namespace Msp::Game {
 
-enum class CameraScaling
+struct CameraData
 {
-       ORIGINAL_SIZE,
-       SCALE_TO_FIT,
-       SCALE_TO_COVER,
-       STRETCH_TO_FIT
-};
+       Geometry::Angle<float> fov_y;
+       LinAl::Vector<float, 2> size;
+       float height;
+       float near_clip;
+       float far_clip;
 
-struct CameraSetup
-{
-       Geometry::Angle<float> field_of_view_y = Geometry::Angle<float>::from_degrees(60);
-       LinAl::Vector<float, 2> size = { 16.0f/9.0f, 1.0f };
-       float near_clip = 0.1f;
-       float far_clip = 100.0f;
-       CameraScaling scaling = CameraScaling::SCALE_TO_FIT;
-       std::string sequence_name;
+       bool is_orthographic() const { return fov_y==Geometry::Angle<float>::zero(); }
+       Geometry::Angle<float> get_fov_horizontal() const { return Geometry::atan(tan(fov_y/2.0f)*get_aspect())*2.0f; }
+       float get_aspect() const { return size.x/size.y; }
 };
 
-class Camera: public Component
+class MSPGAME_API Camera: public BufferedComponent<CameraData>
 {
 public:
        using Setup = CameraSetup;
 
 private:
        const Setup &setup;
-       Geometry::Angle<float> fov_y;
-       LinAl::Vector<float, 2> size;
-       float height;
-       float near_clip;
-       float far_clip;
 
 public:
        Camera(Handle<Entity>, const Setup &);
 
        void set_field_of_view(Geometry::Angle<float>, float);
        void set_size(const LinAl::Vector<float, 2> &);
-       bool is_orthographic() const { return fov_y==Geometry::Angle<float>::zero(); }
-       Geometry::Angle<float> get_fov_vertical() const { return fov_y; }
-       Geometry::Angle<float> get_fov_horizontal() const { return Geometry::atan(tan(fov_y/2.0f)*get_aspect())*2.0f; }
-       const LinAl::Vector<float, 2> &get_size() const { return size; }
-       float get_aspect() const { return size.x/size.y; }
-       float get_near_clip() const { return near_clip; }
-       float get_far_clip() const { return far_clip; }
+       bool is_orthographic() const { return read().is_orthographic(); }
+       Geometry::Angle<float> get_fov_vertical() const { return read().fov_y; }
+       Geometry::Angle<float> get_fov_horizontal() const { return read().get_fov_horizontal(); }
+       const LinAl::Vector<float, 2> &get_size() const { return read().size; }
+       float get_aspect() const { return read().get_aspect(); }
+       float get_near_clip() const { return read().near_clip; }
+       float get_far_clip() const { return read().far_clip; }
        CameraScaling get_scaling() const { return setup.scaling; }
        const std::string &get_sequence_name() const { return setup.sequence_name; }
 };