From 141ebfc5ed84f95edfd0fba0c354336785eb9807 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 21 Dec 2017 13:14:17 +0200 Subject: [PATCH] Add a loader to Camera --- source/camera.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++ source/camera.h | 18 +++++++++++++++ source/resources.cpp | 2 ++ 3 files changed, 74 insertions(+) diff --git a/source/camera.cpp b/source/camera.cpp index 6ae162ae..b3cedbc6 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -149,5 +149,59 @@ void Camera::update_object_matrix() view_matrix = invert(matrix); } + +Camera::Loader::Loader(Camera &c): + DataFile::ObjectLoader(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::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 diff --git a/source/camera.h b/source/camera.h index 1c13e67d..a5802301 100644 --- a/source/camera.h +++ b/source/camera.h @@ -1,6 +1,7 @@ #ifndef MSP_GL_CAMERA_H_ #define MSP_GL_CAMERA_H_ +#include #include "placeable.h" namespace Msp { @@ -8,6 +9,23 @@ namespace GL { class Camera: public Placeable { +public: + class Loader: public DataFile::ObjectLoader + { + 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 fov; float height; diff --git a/source/resources.cpp b/source/resources.cpp index c34139b2..c8e61ef8 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -2,6 +2,7 @@ #include #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().suffix(".anim").keyword("animation"); add_type().suffix(".arma").keyword("armature"); + add_type().keyword("camera"); add_type().keyword("font"); add_type().suffix(".kframe").keyword("keyframe"); add_type().suffix(".lightn").keyword("lighting"); -- 2.45.2