diff --git a/include/animation.h b/include/animation.h index 4441f1d..fdbac84 100644 --- a/include/animation.h +++ b/include/animation.h @@ -24,6 +24,8 @@ int mouseY; float speed; int current; + int colorpt; + std::vector colors; std::vector things; int kbdlock; bool showNormals; @@ -35,6 +37,7 @@ UserAnimation(Thing* t); UserAnimation(std::vector ths); void addThing(Thing* t); + void addColor(Color* t); void init(); void tick(); }; diff --git a/include/model.h b/include/model.h index ef4e4ad..46642bf 100755 --- a/include/model.h +++ b/include/model.h @@ -14,6 +14,8 @@ float delta; + bool drawMe; + public: Model(); Model(std::vector & _faces); @@ -31,5 +33,8 @@ void showNormals(); void hideNormals(); Model* clone(); + void setColor(Color* c); + void show(); + void hide(); }; #endif diff --git a/include/thing.h b/include/thing.h index 3e90926..dfeb470 100644 --- a/include/thing.h +++ b/include/thing.h @@ -15,6 +15,8 @@ virtual void setDelta(float d); virtual void showNormals(); virtual void hideNormals(); + virtual void show(); + virtual void hide(); virtual void setPosition(Vec newpos); virtual void setCenter(Vec newcenter); virtual void translate(Vec d); @@ -25,6 +27,7 @@ class View : public Thing { private: Vec* rotation; + Vec* position; public: View(); void rotate(Vec rot); diff --git a/sources/animation.cpp b/sources/animation.cpp index 07eadfd..13d4973 100644 --- a/sources/animation.cpp +++ b/sources/animation.cpp @@ -120,14 +120,14 @@ /* 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)); } + 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)); } + 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)); } + 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)); } @@ -138,7 +138,19 @@ if ( kbd[SDLK_y] ) { things.at(current)->scale(0.9f*speed); } /* cycle color */ - //TODO + if ( kbd[SDLK_PERIOD] || kbd[SDLK_COMMA] ) { + if ( kbd[SDLK_PERIOD] ) { + colorpt--; + } else { + colorpt++; + } + + if ( colors.size() > 0 ) { + colorpt = colorpt % colors.size(); + things.at(current)->setColor(colors.at(colorpt)); + kbdlock = 3; + } + } /* normals */ if ( kbd[SDLK_n] ) { @@ -152,6 +164,19 @@ kbdlock = 3; } + /* show/hide object */ + if ( kbd[SDLK_h] ) { + printf("h\n"); + if ( showMe ) { + things.at(current)->hide(); + } else { + things.at(current)->show(); + } + showMe = !showMe; + + kbdlock = 3; + } + /* delta */ if ( kbd[SDLK_m] ) { if ( delta > 0.0f ) { @@ -177,3 +202,8 @@ things.push_back(t); if ( current < 0 ) { current = 0; } } + +void UserAnimation::addColor(Color* c) { + colors.push_back(c); + if ( colorpt < 0 ) { colorpt = 0; } +} diff --git a/sources/main.cpp b/sources/main.cpp index 8dbc542..b2fcdfd 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -175,7 +175,7 @@ void drawFog(GLuint filter) { GLuint fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR }; // Storage For Three Types Of Fog - GLfloat fogColor[4]= {0.5f, 0.5f, 0.5f, 1.0f}; // Fog Color + GLfloat fogColor[4]= {0.8f, 0.3f, 0.6f, 1.0f}; // Fog Color glFogi(GL_FOG_MODE, fogMode[filter]); // Fog Mode glFogfv(GL_FOG_COLOR, fogColor); // Set Fog Color @@ -232,12 +232,24 @@ userAnim->init(); userAnim->addThing((Thing*)myView); + userAnim->addColor(&black); + userAnim->addColor(&blue); + userAnim->addColor(&red); + userAnim->addColor(&violet); + userAnim->addColor(&yellow); + userAnim->addColor(&white); + userAnim->addColor(&green); + userAnim->addColor(&cyan); + userAnim->addColor(&grey); + std::vector models; std::vector anims; anims.push_back((Animation*)userAnim); + bool wireframe = false; + int fog = 3; /* begin cube */ @@ -379,7 +391,7 @@ // Ok, SDL up with a valid OpenGL context! // Now setup some OpenGL parameter: // Clear background with a darkblue color - glClearColor(0.0f, 0.0f, 0.5f, 1.0f); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // correct clipping glEnable (GL_DEPTH_TEST); @@ -434,6 +446,12 @@ // Do some rendering: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if ( wireframe ) { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } + // Setup a perspective view: glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -445,13 +463,13 @@ glMatrixMode(GL_MODELVIEW); - + //initial viewer position glLoadIdentity(); //move viewer - glTranslatef(viewer_pos.x(), viewer_pos.y(), viewer_pos.z()); + //glTranslatef(viewer_pos.x(), viewer_pos.y(), viewer_pos.z()); //rotate viewer //glRotatef(viewer_rot.z(), 0.0f, 0.0f, 1.0f); @@ -471,7 +489,7 @@ /* draw z- axis */ //glBegin(GL_LINES); black.drawColor(); glVertex3f(0.0f, 0.0f, -1000000.0f); glVertex3f(0.0f, 0.0f, 1000000.0f); glEnd(); - stage->draw(); + //stage->draw(); for ( modelCounter = 0; modelCounter < models.size(); modelCounter++ ) { models.at(modelCounter)->draw(); @@ -526,7 +544,8 @@ done = true; } - // lights + + // lights etc. if (react_keyevent == 0) { react_keyevent = 10; @@ -540,6 +559,10 @@ react_keyevent = 0; } + if ( keystate[SDLK_g] ) { + wireframe = !wireframe; + } + } else { react_keyevent -= 1; } @@ -561,6 +584,7 @@ if ( keystate[SDLK_z] ) { fog++; fog = fog % 4; + printf("fog %d\n", fog); } if ( fog < 3 ) { diff --git a/sources/model.cpp b/sources/model.cpp index 8af3e08..99c8017 100755 --- a/sources/model.cpp +++ b/sources/model.cpp @@ -5,6 +5,7 @@ Model::Model() { rotation = new Vec(0,0,0); position = new Vec(0,0,0); + drawMe = true; } Model::Model(vector & _faces) { @@ -15,6 +16,7 @@ Vec c = calcCenter(); setCenter(c); rotation = new Vec(0,0,0); + drawMe = true; } Model::~Model() { @@ -61,8 +63,10 @@ } void Model::draw() { - for (std::vector::size_type i = 0 ; i < faces.size(); i++ ) { - faces.at(i)->draw(); + if ( drawMe ) { + for (std::vector::size_type i = 0 ; i < faces.size(); i++ ) { + faces.at(i)->draw(); + } } } @@ -120,3 +124,17 @@ return nm; } + +void Model::setColor(Color* c) { + for (std::vector::size_type i = 0 ; i < faces.size(); i++ ) { + faces.at(i)->setColor(c); + } +} + +void Model::show() { + drawMe = true; +} + +void Model::hide() { + drawMe = false; +} diff --git a/sources/thing.cpp b/sources/thing.cpp index 66e68c9..b180bb5 100644 --- a/sources/thing.cpp +++ b/sources/thing.cpp @@ -15,9 +15,12 @@ void Thing::translate(Vec d) { } void Thing::scale(float f) { } void Thing::trace(bool s) { } +void Thing::show() { } +void Thing::hide() { } View::View() { rotation = new Vec(0.0f, 0.0f, 0.0f); + position = new Vec(0.0f, 0.0f, 0.0f); } void View::rotate(Vec rot) { @@ -25,9 +28,15 @@ } void View::setPosition(Vec newpos) { /*TODO*/ } void View::setCenter(Vec newcenter) { /*TODO*/ } -void View::translate(Vec d) { /*TODO*/ } +void View::translate(Vec d) { + /* TODO */ + position->add((Vec)d); +} void View::draw() { glRotatef(rotation->x(), 1.0f, 0.0f, 0.0f); glRotatef(rotation->y(), 0.0f, 1.0f, 0.0f); glRotatef(rotation->z(), 0.0f, 0.0f, 1.0f); + + glTranslatef(position->x(), position->y(), position->z()); + }