]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a loader to Camera
authorMikko Rasa <tdb@tdb.fi>
Thu, 21 Dec 2017 11:14:17 +0000 (13:14 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 21 Dec 2017 11:14:17 +0000 (13:14 +0200)
source/camera.cpp
source/camera.h
source/resources.cpp

index 6ae162aeb77909fca84b20fa8bf9b9ed3389dfef..b3cedbc62ad628813b5eee552302a2151ea586c1 100644 (file)
@@ -149,5 +149,59 @@ void Camera::update_object_matrix()
        view_matrix = invert(matrix);
 }
 
+
+Camera::Loader::Loader(Camera &c):
+       DataFile::ObjectLoader<Camera>(c)
+{
+       add("aspect_ratio", &Loader::aspect_ratio);
+       add("depth_clip", &Loader::depth_clip);
+       add("field_of_view", &Loader::field_of_view);
+       add("look_at", &Loader::look_at);
+       add("look_direction", &Loader::look_direction);
+       add("orthographic", &Loader::orthographic);
+       add("position", &Loader::position);
+       add("up_direction", &Loader::up_direction);
+}
+
+void Camera::Loader::aspect_ratio(float a)
+{
+       obj.set_aspect_ratio(a);
+}
+
+void Camera::Loader::depth_clip(float n, float f)
+{
+       obj.set_depth_clip(n, f);
+}
+
+void Camera::Loader::field_of_view(float a)
+{
+       obj.set_field_of_view(Geometry::Angle<float>::from_degrees(a));
+}
+
+void Camera::Loader::look_at(float x, float y, float z)
+{
+       obj.look_at(Vector3(x, y, z));
+}
+
+void Camera::Loader::look_direction(float x, float y, float z)
+{
+       obj.set_look_direction(Vector3(x, y, z));
+}
+
+void Camera::Loader::orthographic(float w, float h)
+{
+       obj.set_orthographic(w, h);
+}
+
+void Camera::Loader::position(float x, float y, float z)
+{
+       obj.set_position(Vector3(x, y, z));
+}
+
+void Camera::Loader::up_direction(float x, float y, float z)
+{
+       obj.set_up_direction(Vector3(x, y, z));
+}
+
 } // namespace GL
 } // namespace Msp
index 1c13e67d9d6de544a1aa0a73c00e0fcb4e4f0248..a58023017745e37b65179b283c9e1ff3f928f2c2 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GL_CAMERA_H_
 #define MSP_GL_CAMERA_H_
 
+#include <msp/datafile/objectloader.h>
 #include "placeable.h"
 
 namespace Msp {
@@ -8,6 +9,23 @@ namespace GL {
 
 class Camera: public Placeable
 {
+public:
+       class Loader: public DataFile::ObjectLoader<Camera>
+       {
+       public:
+               Loader(Camera &);
+
+       private:
+               void aspect_ratio(float);
+               void depth_clip(float, float);
+               void field_of_view(float);
+               void look_at(float, float, float);
+               void look_direction(float, float, float);
+               void orthographic(float, float);
+               void position(float, float, float);
+               void up_direction(float, float, float);
+       };
+
 private:
        Geometry::Angle<float> fov;
        float height;
index c34139b25e139e1b53e588c732715afc30a7ce62..c8e61ef8286d0b54c5364286d622985b0ed308f8 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/fs/utils.h>
 #include "animation.h"
 #include "armature.h"
+#include "camera.h"
 #include "font.h"
 #include "keyframe.h"
 #include "lighting.h"
@@ -34,6 +35,7 @@ Resources::Resources():
 {
        add_type<Animation>().suffix(".anim").keyword("animation");
        add_type<Armature>().suffix(".arma").keyword("armature");
+       add_type<Camera>().keyword("camera");
        add_type<Font>().keyword("font");
        add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
        add_type<Lighting>().suffix(".lightn").keyword("lighting");