From de1e1703104cc7501f6826ada98e1dc11c60eb74 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 5 Aug 2012 15:53:41 +0300 Subject: [PATCH] Add support for viewing animations --- tools/viewer.cpp | 73 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 14 deletions(-) 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(); -- 2.45.2