--- /dev/null
+#include "animate.h"
+#include "demo.h"
+
+using namespace std;
+using namespace Msp;
+
+Animate::Animate():
+ target(0),
+ anim(0),
+ player(0)
+{ }
+
+Animate::Animate(GL::Placeable &t, const GL::Animation &a, GL::AnimationPlayer &p):
+ target(&t),
+ anim(&a),
+ player(&p)
+{ }
+
+void Animate::validate() const
+{
+ if(!target)
+ throw logic_error("null target");
+ if(!anim)
+ throw logic_error("null animation");
+ if(!player)
+ throw logic_error("null player");
+}
+
+void Animate::start(float, float d)
+{
+ float speed = (d ? (anim->get_duration()/Time::sec)/d : 1.0f);
+ player->play(*target, *anim, speed);
+}
+
+
+Animate::Loader::Loader(Animate &a, Demo &d):
+ DataFile::DerivedObjectLoader<Animate, Action::Loader>(a, d)
+{
+ a.player = &demo.get_animation_player();
+ add("animation", &Loader::animation);
+ add("target", &Loader::target);
+}
+
+void Animate::Loader::animation(const string &n)
+{
+ obj.anim = &demo.get_resources().get<GL::Animation>(n);
+}
+
+void Animate::Loader::target(const string &n)
+{
+ obj.target = &demo.get_thing<GL::Placeable>(n);
+}
--- /dev/null
+#ifndef MSP_DEMOSCENE_ANIMATE_H_
+#define MSP_DEMOSCENE_ANIMATE_H_
+
+#include <msp/gl/animation.h>
+#include <msp/gl/animationplayer.h>
+#include "action.h"
+
+class Animate: public Action
+{
+public:
+ class Loader: public Msp::DataFile::DerivedObjectLoader<Animate, Action::Loader>
+ {
+ public:
+ Loader(Animate &, Demo &);
+
+ private:
+ void animation(const std::string &);
+ void target(const std::string &);
+ };
+
+private:
+ Msp::GL::Placeable *target;
+ const Msp::GL::Animation *anim;
+ Msp::GL::AnimationPlayer *player;
+
+public:
+ Animate();
+ Animate(Msp::GL::Placeable &, const Msp::GL::Animation &, Msp::GL::AnimationPlayer &);
+
+ virtual void validate() const;
+
+ virtual void start(float, float);
+};
+
+#endif
+++ /dev/null
-#include "cameracontrol.h"
-
-using namespace Msp;
-
-void CameraControl::set_camera(const GL::Camera &c)
-{
- camera.set_object_matrix(c.get_object_matrix());
- camera.set_up_direction(c.get_up_direction());
- camera.set_field_of_view(c.get_field_of_view());
- camera.set_depth_clip(c.get_near_clip(), c.get_far_clip());
-}
-
-void CameraControl::animate_camera(const GL::Animation &anim, float speed)
-{
- anim_player.play(camera, anim, speed);
-}
-
-void CameraControl::tick(float, float d)
-{
- anim_player.tick(d*Time::sec);
-}
-
-
-CameraControl::SetCamera::SetCamera(CameraControl &cc, const GL::Camera &c):
- control(cc),
- camera(c)
-{ }
-
-void CameraControl::SetCamera::start(float, float)
-{
- control.set_camera(camera);
-}
-
-
-CameraControl::AnimateCamera::AnimateCamera(CameraControl &cc, const GL::Animation &a):
- control(cc),
- anim(a)
-{ }
-
-void CameraControl::AnimateCamera::start(float, float d)
-{
- control.animate_camera(anim, (d ? (anim.get_duration()/Time::sec)/d : 1.0f));
-}
+++ /dev/null
-#ifndef MSP_DEMOSCENE_CAMERACONTROL_H_
-#define MSP_DEMOSCENE_CAMERACONTROL_H_
-
-#include <msp/gl/animationplayer.h>
-#include <msp/gl/camera.h>
-#include "action.h"
-
-class CameraControl: public Action
-{
-public:
- class SetCamera: public Action
- {
- private:
- CameraControl &control;
- const Msp::GL::Camera &camera;
-
- public:
- SetCamera(CameraControl &, const Msp::GL::Camera &);
-
- virtual void validate() const { }
-
- virtual void start(float, float);
- };
-
- class AnimateCamera: public Action
- {
- private:
- CameraControl &control;
- const Msp::GL::Animation &anim;
-
- public:
- AnimateCamera(CameraControl &, const Msp::GL::Animation &);
-
- virtual void validate() const { }
-
- virtual void start(float, float);
- };
-
-private:
- Msp::GL::Camera camera;
- Msp::GL::AnimationPlayer anim_player;
-
-public:
- void set_camera(const Msp::GL::Camera &);
- void animate_camera(const Msp::GL::Animation &, float);
- Msp::GL::Camera &get_camera() { return camera; }
-
- virtual void validate() const { }
-
- virtual void tick(float, float);
-};
-
-#endif
Demo::Demo(Graphics::Window &window, Graphics::GLContext &gl_ctx, DataFile::Collection &r):
resources(r),
view(window, gl_ctx),
+ anim_action(anim_player),
music_source(0),
streamer(0),
music_io(0),
{
things["window"] = static_cast<GL::View *>(&view);
+ sequencer.add_static_action(anim_action);
sequencer.signal_finished.connect(signal_finished);
}
{
sequencer.seek(pos*sequencer.get_beats_per_minute()/Time::min);
}
+
+
+Demo::AnimationAction::AnimationAction(GL::AnimationPlayer &p):
+ player(p)
+{ }
+
+void Demo::AnimationAction::tick(float, float d)
+{
+ player.tick(d*Time::sec);
+}
#include <msp/al/source.h>
#include <msp/al/streamer.h>
#include <msp/datafile/collection.h>
+#include <msp/gl/animationplayer.h>
#include <msp/gl/windowview.h>
+#include "action.h"
#include "sequencer.h"
class Demo
{
+private:
+ class AnimationAction: public Action
+ {
+ private:
+ Msp::GL::AnimationPlayer &player;
+
+ public:
+ AnimationAction(Msp::GL::AnimationPlayer &);
+
+ virtual void validate() const { }
+
+ virtual void tick(float, float);
+ };
+
public:
sigc::signal<void> signal_finished;
Sequencer sequencer;
Msp::DataFile::Collection &resources;
Msp::GL::WindowView view;
+ Msp::GL::AnimationPlayer anim_player;
+ AnimationAction anim_action;
Msp::AL::Source *music_source;
Msp::AL::Streamer *streamer;
Msp::IO::Seekable *music_io;
public:
virtual ~Demo();
+ Msp::DataFile::Collection &get_resources() const { return resources; }
+ Msp::GL::AnimationPlayer &get_animation_player() { return anim_player; }
+
template<typename T>
T &get_thing(const std::string &);
#include <cmath>
#include <msp/core/algorithm.h>
#include <msp/core/maputils.h>
+#include "animate.h"
#include "fadeoverlay.h"
#include "sequencer.h"
#include "stage.h"
{
set_beats_per_minute(bpm);
+ register_action_type<Animate>("animate");
register_action_type<FadeOverlay::Fade>("fade");
register_action_type<Stage::UseInView>("use_stage");
+ register_action_type<Stage::SetCamera>("set_camera");
}
void Sequencer::set_beats_per_minute(float bpm)
delete pipeline;
}
+void Stage::set_camera(const GL::Camera &c)
+{
+ camera.set_object_matrix(c.get_object_matrix());
+ camera.set_up_direction(c.get_up_direction());
+ camera.set_field_of_view(c.get_field_of_view());
+ camera.set_depth_clip(c.get_near_clip(), c.get_far_clip());
+}
+
Stage::UseInView::UseInView():
view(0),
void Stage::UseInView::start(float, float)
{
- view->set_camera(&stage->camera_control.get_camera());
+ view->set_camera(&stage->camera);
view->set_content(stage->pipeline);
}
+Stage::SetCamera::SetCamera():
+ stage(0),
+ camera(0)
+{ }
+
+Stage::SetCamera::SetCamera(Stage &s, const GL::Camera &c):
+ stage(&s),
+ camera(&c)
+{ }
+
+void Stage::SetCamera::validate() const
+{
+ if(!stage)
+ throw logic_error("null stage");
+ if(!camera)
+ throw logic_error("null camera");
+}
+
+void Stage::SetCamera::start(float, float)
+{
+ stage->set_camera(*camera);
+}
+
+
Stage::UseInView::Loader::Loader(UseInView &u, Demo &d):
DataFile::DerivedObjectLoader<UseInView, Action::Loader>(u, d)
{
{
obj.view = &demo.get_thing<GL::View>(n);
}
+
+
+Stage::SetCamera::Loader::Loader(SetCamera &s, Demo &d):
+ DataFile::DerivedObjectLoader<SetCamera, Action::Loader>(s, d)
+{
+ add("camera", &Loader::camera);
+ add("stage", &Loader::stage);
+}
+
+void Stage::SetCamera::Loader::stage(const string &n)
+{
+ obj.stage = &demo.get_thing<Stage>(n);
+}
+
+void Stage::SetCamera::Loader::camera(const string &n)
+{
+ obj.camera = &demo.get_resources().get<GL::Camera>(n);
+}
#ifndef MSP_DEMOSCENE_STAGE_H_
#define MSP_DEMOSCENE_STAGE_H_
+#include <msp/gl/camera.h>
#include <msp/gl/pipeline.h>
-#include "cameracontrol.h"
#include "action.h"
struct Stage
virtual void start(float, float);
};
+ class SetCamera: public Action
+ {
+ public:
+ class Loader: public Msp::DataFile::DerivedObjectLoader<SetCamera, Action::Loader>
+ {
+ public:
+ Loader(SetCamera &, Demo &);
+
+ private:
+ void camera(const std::string &);
+ void stage(const std::string &);
+ };
+
+ private:
+ Stage *stage;
+ const Msp::GL::Camera *camera;
+
+ public:
+ SetCamera();
+ SetCamera(Stage &, const Msp::GL::Camera &);
+
+ virtual void validate() const;
+
+ virtual void start(float, float);
+ };
+
Msp::GL::Pipeline *pipeline;
- CameraControl camera_control;
+ Msp::GL::Camera camera;
Stage();
~Stage();
+
+ void set_camera(const Msp::GL::Camera &);
};
#endif