diff --git a/Makefile b/Makefile index f88ed22..8bde9d7 100755 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ CXXFLAGS := $(CXXFLAGS) -g -DDEBUG endif -OBJECTS = main.o array.o poly.o model.o light.o vec.o color.o +OBJECTS = main.o poly.o model.o light.o vec.o color.o all: $(OBJECTS) @if [ ! -d $(BINDIR) ]; then \ diff --git a/include/array.h b/include/array.h deleted file mode 100755 index f9a5269..0000000 --- a/include/array.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _ARRAY_H -#define _ARRAY_H -class Array { - private: - int _size; - int _current; - int _stacksize; - void** _data; - public: - Array(); - Array(Array* oa); - void setPos(int np); - int pos(); - int length(); - void reset(); - void* current(); - void* next(); - void push(void* elem); - void* pop(); - void* get(int p); - void set(int p, void* ne); - void clear(); - void operator+=(void *ne); - void*& operator[](int p); - ~Array(); -}; -#endif diff --git a/include/model.h b/include/model.h index fef4ce3..b430152 100755 --- a/include/model.h +++ b/include/model.h @@ -1,7 +1,6 @@ #ifndef _MODEL_H #define _MODDEL_H -#include "array.h" #include "vec.h" #include "poly.h" #include diff --git a/include/poly.h b/include/poly.h index 30ead36..28377a6 100755 --- a/include/poly.h +++ b/include/poly.h @@ -32,5 +32,7 @@ int numPoints(); void vardump(std::string whitespace); void addPoint(Vec* p); + void setColor(Color c); + Color* getColor(); }; #endif diff --git a/sources/array.cpp b/sources/array.cpp deleted file mode 100755 index d3d0f6c..0000000 --- a/sources/array.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include - -#include "array.h" - -Array::Array() { - _size = 0; - _current = 0; - _stacksize = 0; -} - -Array::Array(Array* oa) { - _size = 0; - _current = 0; - _stacksize = 0; - void* telem; - int tc = oa->pos(); - oa->reset(); - - while ( (telem = oa->next()) ) { - push(telem); - } - - oa->setPos(tc); - -} - -void Array::setPos(int np) { - _current = np; -} - -int Array::pos() { - return _current; -} - -int Array::length() { - return _size; -} - -void Array::reset() { - _current = 0; -} - -void* Array::current() { - if ( _current < _size ) { - return _data[_current]; - } else { - return 0; - } -} - -void* Array::next() { - if ( _current < _size ) { - _current++; - return _data[_current-1]; - } else { - return 0; - } -} - -void Array::push(void* elem) { - if ( _size >= _stacksize ) { - _stacksize = _stacksize + 3; - void** tdat = new void*[_stacksize]; - - for ( int i = 0; i < _size; i++ ) { - tdat[i] = _data[i]; - } - - if ( _size > 0 ) { - delete[] _data; - } - _data = tdat; - } - - _data[_size] = elem; - _size++; -} - -void* Array::pop() { - _size--; - if ( _current == _size ) { - _current = _size-1; - } - return _data[_size]; -} - -void* Array::get(int p) { - assert(p>=0); - assert(p<_size); - return _data[p]; -} - -void Array::set(int p, void* ne) { - assert(p>=0); - assert(p<_size); - _data[p] = ne; -} - -void Array::clear() { - _size = 0; - _current = 0; - _stacksize = 0; - delete[] _data; -} - -void Array::operator+=(void* ne) { - push(ne); -} - -void*& Array::operator[](int p) { - assert(p>=0); - assert(p<_size); - return _data[p]; -} - -Array::~Array() { - delete[] _data; -} diff --git a/sources/main.cpp b/sources/main.cpp index c7a1bd8..dd9534a 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -43,7 +43,6 @@ #pragma comment(lib, "sdlmain.lib") #endif -#include "array.h" #include "vec.h" #include "color.h" #include "poly.h" @@ -328,6 +327,10 @@ float deltaz = 0.0f; float deltacolor = 0.0f; + float viewer_xpos = 0.0f; + float viewer_ypos = 0.0f; + float viewer_zpos = -50.0f; + while (!done) { ///////////////////// @@ -345,7 +348,7 @@ // Place the viewer 50 units backward: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -50.0f); + glTranslatef(viewer_xpos, viewer_ypos, viewer_zpos); // Draw a rotating triangle: glRotatef(deltay, 0.0f, 1.0f, 0.0f); // Rotation around the Y axis @@ -428,6 +431,62 @@ deltaz += 2.0f; } + // move viewer + if (keystate[SDLK_w]) { + viewer_zpos -= 0.1f; + } + + if (keystate[SDLK_s]) { + viewer_zpos += 0.1f; + } + + //if (keystate[SDLK_w]) { + //viewer_ypos += 0.1f; + //} + + //if (keystate[SDLK_s]) { + //viewer_ypos -= 0.1f; + //} + + if (keystate[SDLK_a]) { + viewer_xpos -= 0.1f; + } + + if (keystate[SDLK_d]) { + viewer_xpos += 0.1f; + } + + //light rotation + /* if (keystate[SDLK_a]) + lightpos[0]+=lightdelta; + if (keystate[SDLK_d]) + lightpos[0]-=lightdelta; + if (keystate[SDLK_w]) + lightpos[1]+=lightdelta; + if (keystate[SDLK_s]) + lightpos[1]-=lightdelta; + if (keystate[SDLK_q]) + lightpos[2]+=lightdelta; + if (keystate[SDLK_e]) + lightpos[2]-=lightdelta; + */ + if (keystate[SDLK_SPACE]) { + deltacolor += 0.01f; + if (deltacolor > 1.0f) { + deltacolor = 0.0f; + } + } + + + + //////////////// + // Swap buffers: + usleep(2000); // Just don't kill computer resources ;) + SDL_GL_SwapBuffers(); + + // Plain stupid log, just to show values: + //printf("X: %d, Y: %d, but1: %d, but2: %d\n", + //light rotation /* if (keystate[SDLK_a]) lightpos[0]+=lightdelta; diff --git a/sources/poly.cpp b/sources/poly.cpp index 2c84328..19ef35c 100755 --- a/sources/poly.cpp +++ b/sources/poly.cpp @@ -149,3 +149,11 @@ void Poly::addPoint(Vec* p) { initpoints.push_back(p); } + +void Poly::setColor(Color c) { + color = c.clone(); +} + +Color* Poly::getColor() { + return color; +}