#include <msp/gl/view.h>
+#include "demo.h"
#include "stage.h"
-using namespace Msp;
+using namespace std;
+
+namespace Msp {
+namespace DemoScene {
Stage::Stage():
- pipeline(0)
+ pipeline(0),
+ last_view(0)
{ }
Stage::~Stage()
delete pipeline;
}
+void Stage::add_things(Demo::ThingMap &things, const string &prefix)
+{
+ things[prefix+"camera"] = static_cast<GL::Placeable *>(&camera);
+}
+
+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),
+ stage(0)
+{ }
Stage::UseInView::UseInView(GL::View &v, Stage &s):
- view(v),
- stage(s)
+ view(&v),
+ stage(&s)
{ }
+void Stage::UseInView::validate() const
+{
+ if(!view)
+ throw logic_error("null view");
+ if(!stage)
+ throw logic_error("null stage");
+}
+
void Stage::UseInView::start(float, float)
{
- view.set_camera(&stage.camera_control.get_camera());
- view.set_content(stage.pipeline);
+ if(!stage->pipeline || view!=stage->last_view)
+ {
+ stage->create_pipeline(*view);
+ if(!stage->pipeline)
+ throw logic_error("null pipeline");
+ stage->last_view = view;
+ }
+
+ 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)
+{
+ add("stage", &Loader::stage);
+ add("view", &Loader::view);
+}
+
+void Stage::UseInView::Loader::stage(const string &n)
+{
+ obj.stage = &demo.get_thing<Stage>(n);
+}
+
+void Stage::UseInView::Loader::view(const string &n)
+{
+ 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);
+}
+
+} // namespace DemoScene
+} // namespace Msp