#include <msp/core/getopt.h>
#include <msp/fs/utils.h>
#include <msp/graphics/simplewindow.h>
+#include <msp/gl/animatedobject.h>
+#include <msp/gl/animation.h>
+#include <msp/gl/animationplayer.h>
#include <msp/gl/blend.h>
#include <msp/gl/camera.h>
#include <msp/gl/framebuffer.h>
#include <msp/gl/tests.h>
#include <msp/input/mouse.h>
#include <msp/io/print.h>
+#include <msp/time/timestamp.h>
+#include <msp/time/utils.h>
using namespace std;
using namespace Msp;
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;
float light_yaw;
float light_pitch;
unsigned dragging;
+ Time::TimeStamp last_tick;
public:
Viewer(int, char **);
mouse(window),
object(0),
mesh(0),
+ animation(0),
+ anim_object(0),
+ anim_player(0),
yaw(0),
pitch(0),
distance(10),
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; i<argc; ++i)
{
- object = new GL::Object;
- DataFile::load(*object, fn);
+ string fn = argv[i];
+ string ext = FS::extpart(fn);
+
+ if(ext==".mesh")
+ {
+ if(mesh || object)
+ throw usage_error("Only one mesh or object may be specified");
+
+ mesh = new GL::Mesh;
+ DataFile::load(*mesh, fn);
+ }
+ else if(ext==".object")
+ {
+ if(mesh || object)
+ throw usage_error("Only one mesh or object may be specified");
+
+ object = new GL::Object;
+ DataFile::load(*object, fn);
+ }
+ else if(ext==".anim")
+ {
+ if(!object)
+ throw usage_error("An object must be provided for animation");
+
+ animation = new GL::Animation;
+ DataFile::load(*animation, argv[2]);
+ anim_object = new GL::AnimatedObject(*object);
+ anim_player = new GL::AnimationPlayer;
+ anim_player->play(*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));
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);
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();