X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=tools%2Fviewer.cpp;fp=tools%2Fviewer.cpp;h=db2b99e1869d22c6a5bb19b642c4697e5c494e66;hp=bc024e1f642eab1fb1814895aeb0cf3ee6654f7a;hb=de1e1703104cc7501f6826ada98e1dc11c60eb74;hpb=4c5ba8f7d3bc755d6256cb6bf75907a1b10fc290 diff --git a/tools/viewer.cpp b/tools/viewer.cpp index bc024e1f..db2b99e1 100644 --- a/tools/viewer.cpp +++ b/tools/viewer.cpp @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -13,6 +16,8 @@ #include #include #include +#include +#include using namespace std; using namespace Msp; @@ -24,6 +29,9 @@ private: Input::Mouse mouse; GL::Object *object; GL::Mesh *mesh; + GL::Animation *animation; + GL::AnimatedObject *anim_object; + GL::AnimationPlayer *anim_player; GL::Light light; GL::Lighting lighting; GL::Camera camera; @@ -33,6 +41,7 @@ private: float light_yaw; float light_pitch; unsigned dragging; + Time::TimeStamp last_tick; public: Viewer(int, char **); @@ -56,6 +65,9 @@ Viewer::Viewer(int argc, char **argv): mouse(window), object(0), mesh(0), + animation(0), + anim_object(0), + anim_player(0), yaw(0), pitch(0), distance(10), @@ -66,21 +78,41 @@ Viewer::Viewer(int argc, char **argv): if(argc<2) throw usage_error("Filename must be provided"); - string fn = argv[1]; - string ext = FS::extpart(fn); - - if(ext==".mesh") - { - mesh = new GL::Mesh; - DataFile::load(*mesh, fn); - } - else if(ext==".object") + for(int i=1; iplay(*anim_object, *animation); + } + else + throw usage_error("Don't know how to view this file"); } - else - throw usage_error("Don't know how to view this file"); window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Viewer::exit), 0)); mouse.signal_button_press.connect(sigc::mem_fun(this, &Viewer::button_press)); @@ -108,6 +140,17 @@ int Viewer::main() void Viewer::tick() { + if(anim_player) + { + Time::TimeStamp t = Time::now(); + Time::TimeDelta dt; + if(last_tick) + dt = t-last_tick; + last_tick = t; + + anim_player->tick(dt); + } + window.tick(); GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT); @@ -117,7 +160,9 @@ void Viewer::tick() GL::Bind bind_lighting(lighting); GL::Bind bind_depth(GL::DepthTest::lequal()); GL::Bind bind_blend(GL::Blend::alpha()); - if(object) + if(anim_object) + anim_object->render(); + else if(object) object->render(); else if(mesh) mesh->draw();