diff --git a/include/model.h b/include/model.h index 2fc9b44..ef4e4ad 100755 --- a/include/model.h +++ b/include/model.h @@ -5,7 +5,7 @@ #include "poly.h" #include -class Model { +class Model : public Thing { private: std::vector faces; diff --git a/include/poly.h b/include/poly.h index e277fa0..0694dd4 100755 --- a/include/poly.h +++ b/include/poly.h @@ -10,7 +10,7 @@ using namespace std; -class Poly : SPoly, Thing { +class Poly : SPoly { private: std::vector initpoints; int size; diff --git a/include/thing.h b/include/thing.h index e0c147b..3e90926 100644 --- a/include/thing.h +++ b/include/thing.h @@ -8,18 +8,18 @@ class Thing { public: - void draw(); - void rotate(Vec rot); - void setColor(Color* c); - void setColor(Color c); - void setDelta(float d); - void showNormals(); - void hideNormals(); - void setPosition(Vec newpos); - void setCenter(Vec newcenter); - void move(Vec d); - void scale(float f); - void trace(bool s); + virtual void draw(); + virtual void rotate(Vec rot); + virtual void setColor(Color* c); + virtual void setColor(Color c); + virtual void setDelta(float d); + virtual void showNormals(); + virtual void hideNormals(); + virtual void setPosition(Vec newpos); + virtual void setCenter(Vec newcenter); + virtual void translate(Vec d); + virtual void scale(float f); + virtual void trace(bool s); }; class View : public Thing { @@ -30,7 +30,7 @@ void rotate(Vec rot); void setPosition(Vec newpos); void setCenter(Vec newcenter); - void move(Vec d); + void translate(Vec d); void draw(); }; diff --git a/sources/animation.cpp b/sources/animation.cpp index a7d13c1..07eadfd 100644 --- a/sources/animation.cpp +++ b/sources/animation.cpp @@ -10,6 +10,8 @@ #define PI 3.14159265f #endif +#define DEBUG + /* class Animation */ Animation::Animation() { @@ -50,6 +52,9 @@ } void UserAnimation::tick() { +#ifdef DEBUG + int oldcurrent = current; +#endif /* get mouse */ int newmouseX; int newmouseY; @@ -60,7 +65,7 @@ if ( newmouseX != mouseX || newmouseY != mouseY ) { Vec v = Vec(speed*0.1f*(newmouseY-mouseY), speed*0.1f*(newmouseX-mouseX), 0.0f); - ((View*)things.at(current))->rotate(v); + things.at(current)->rotate(v); mouseX = newmouseX; mouseY = newmouseY; } @@ -97,6 +102,10 @@ current = -1; } +#ifdef DEBUG + if ( current != oldcurrent ) { printf("Switched to object %d\n", current); } +#endif + /* speed */ if ( kbd[SDLK_LSHIFT] || kbd[SDLK_RSHIFT] ) { speed = 10.0f; @@ -108,56 +117,59 @@ } } - /* move x */ - if ( kbd[SDLK_a] ) { things.at(current)->move(Vec(-1.0f*speed, 0.0f, 0.0f)); } - if ( kbd[SDLK_d] ) { things.at(current)->move(Vec(1.0f*speed, 0.0f, 0.0f)); } - /* move y */ - if ( kbd[SDLK_UP] ) { things.at(current)->move(Vec(0.0f, 1.0f*speed, 0.0f)); } - if ( kbd[SDLK_DOWN] ) { things.at(current)->move(Vec(0.0f, -1.0f*speed, 0.0f)); } - /* move z */ - if ( kbd[SDLK_w] ) { things.at(current)->move(Vec(0.0f, 0.0f, -1.0f*speed)); } - if ( kbd[SDLK_s] ) { things.at(current)->move(Vec(0.0f, 0.0f, 1.0f*speed)); } + /* only do operations if we have a current object */ + if ( current > -1 && current < things.size() ) { + /* move x */ + if ( kbd[SDLK_a] ) { things.at(current)->translate(Vec(-1.0f*speed, 0.0f, 0.0f)); } + if ( kbd[SDLK_d] ) { things.at(current)->translate(Vec(1.0f*speed, 0.0f, 0.0f)); } + /* move y */ + if ( kbd[SDLK_UP] ) { things.at(current)->translate(Vec(0.0f, 1.0f*speed, 0.0f)); } + if ( kbd[SDLK_DOWN] ) { things.at(current)->translate(Vec(0.0f, -1.0f*speed, 0.0f)); } + /* move z */ + if ( kbd[SDLK_w] ) { things.at(current)->translate(Vec(0.0f, 0.0f, -1.0f*speed)); } + if ( kbd[SDLK_s] ) { things.at(current)->translate(Vec(0.0f, 0.0f, 1.0f*speed)); } - /* rotate z */ - if ( kbd[SDLK_q] ) { things.at(current)->rotate(Vec(0.0f, 0.0f, 1.0f*speed)); } - if ( kbd[SDLK_e] ) { things.at(current)->rotate(Vec(0.0f, 0.0f, -1.0f*speed)); } + /* rotate z */ + if ( kbd[SDLK_q] ) { things.at(current)->rotate(Vec(0.0f, 0.0f, 1.0f*speed)); } + if ( kbd[SDLK_e] ) { things.at(current)->rotate(Vec(0.0f, 0.0f, -1.0f*speed)); } - /* scaling */ - if ( kbd[SDLK_x] ) { things.at(current)->scale(1.1f*speed); } - if ( kbd[SDLK_y] ) { things.at(current)->scale(0.9f*speed); } + /* scaling */ + if ( kbd[SDLK_x] ) { things.at(current)->scale(1.1f*speed); } + if ( kbd[SDLK_y] ) { things.at(current)->scale(0.9f*speed); } - /* cycle color */ - //TODO + /* cycle color */ + //TODO - /* normals */ - if ( kbd[SDLK_n] ) { - if ( showNormals ) { - things.at(current)->hideNormals(); - showNormals = false; - } else { - things.at(current)->showNormals(); - showNormals = true; - } - kbdlock = 3; - } - - /* delta */ - if ( kbd[SDLK_m] ) { - if ( delta > 0.0f ) { - if ( delta < PI/8.0f ) { - delta = 0.0f; + /* normals */ + if ( kbd[SDLK_n] ) { + if ( showNormals ) { + things.at(current)->hideNormals(); + showNormals = false; } else { - delta = delta/2.0f; + things.at(current)->showNormals(); + showNormals = true; } - } else { - delta = PI; + kbdlock = 3; } - things.at(current)->setDelta(delta); - kbdlock = 3; - } - /* trace */ - if ( kbd[SDLK_t] ) { things.at(current)->trace(trace); trace = !trace; kbdlock = 3; } + /* delta */ + if ( kbd[SDLK_m] ) { + if ( delta > 0.0f ) { + if ( delta < PI/4.0f ) { + delta = 0.0f; + } else { + delta = delta/2.0f; + } + } else { + delta = PI; + } + things.at(current)->setDelta(delta); + kbdlock = 3; + } + + /* trace */ + if ( kbd[SDLK_t] ) { things.at(current)->trace(trace); trace = !trace; kbdlock = 3; } + } } } diff --git a/sources/main.cpp b/sources/main.cpp index 4de62f1..8dbc542 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -300,6 +300,8 @@ cube->addFace(new Poly(front, white)); cube->setCenter(cen); + + userAnim->addThing((Thing*)cube); //cube->setDelta(PI/2.0); //cube->showNormals(); @@ -320,6 +322,8 @@ myModel->showNormals(); myModel->setDelta(PI/2.0); + userAnim->addThing((Thing*)myModel); + //myModel->vardump(""); /* end import */ diff --git a/sources/thing.cpp b/sources/thing.cpp index dbc3825..66e68c9 100644 --- a/sources/thing.cpp +++ b/sources/thing.cpp @@ -12,7 +12,7 @@ void Thing::hideNormals() { } void Thing::setPosition(Vec newpos) { } void Thing::setCenter(Vec newcenter) { } -void Thing::move(Vec d) { } +void Thing::translate(Vec d) { } void Thing::scale(float f) { } void Thing::trace(bool s) { } @@ -25,7 +25,7 @@ } void View::setPosition(Vec newpos) { /*TODO*/ } void View::setCenter(Vec newcenter) { /*TODO*/ } -void View::move(Vec d) { /*TODO*/ } +void View::translate(Vec d) { /*TODO*/ } void View::draw() { glRotatef(rotation->x(), 1.0f, 0.0f, 0.0f); glRotatef(rotation->y(), 0.0f, 1.0f, 0.0f);