diff --git a/include/glumodel.h b/include/glumodel.h index d0cba97..e145743 100644 --- a/include/glumodel.h +++ b/include/glumodel.h @@ -7,19 +7,22 @@ #include class GenericModel : public Thing { - public: - GLUquadricObj* pt; - Vec* pos; - Vec* rot; - Material* mat; - float scale; - bool enabled; - GenericModel(); - GenericModel(Vec _pos, Material _mat); - void init(Vec _pos, Material _mat); - - void setMaterial(Color _amb); - void setMaterial(Color _amb, Color _spec); + public: + GLUquadricObj* pt; + Vec* pos; + Vec* rot; + Material* mat; + float scale; + bool enabled; + GenericModel(); + GenericModel(Vec _pos, Material _mat); + void init(Vec _pos, Material _mat); + + void setMaterial(Color _amb); + void setMaterial(Color _amb, Color _spec); + + void translate(Vec d); + void rotate(Vec r); }; class GluSphere : public GenericModel { diff --git a/sources/glumodel.cpp b/sources/glumodel.cpp index 7db0cd6..3ecaceb 100644 --- a/sources/glumodel.cpp +++ b/sources/glumodel.cpp @@ -21,6 +21,14 @@ enabled = true; } +void GenericModel::translate ( Vec d ) { + pos->add((Vec)d); +} + +void GenericModel::rotate ( Vec r ) { + rot->add((Vec)r); +} + GluSphere::GluSphere() { init(Vec(0,0,0), Material(Color(1,0,1)), 10); } @@ -181,14 +189,24 @@ } void KochFractal::draw() { - //TODO: move draw function to Fractal class, it's common for all - //inheriting fractals.... - glPushMatrix(); - for (int i = 0; i < multiplicity; i++) { - iter(iters); - glRotatef(mult_angle, 1,0,0); - } - glPopMatrix(); + //TODO: move draw function to Fractal class, it's common for all + //inheriting fractals.... + glPushMatrix(); + + /* rotate */ + glRotatef(rot->x(), 1.0f, 0.0f, 0.0f); + glRotatef(rot->y(), 0.0f, 1.0f, 0.0f); + glRotatef(rot->z(), 0.0f, 0.0f, 1.0f); + + /* move it to the desired position */ + glTranslatef(pos->x(), pos->y(), pos->z()); + + for (int i = 0; i < multiplicity; i++) { + iter(iters); + glRotatef(mult_angle, 1,0,0); + } + + glPopMatrix(); } void KochFractal::iter(float nbit) { diff --git a/sources/main.cpp b/sources/main.cpp index e842b42..3ded33c 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -246,8 +246,12 @@ KochFractal* kochfrac = new KochFractal(Vec(0,0,0), 3, 30); + userAnim->addThing((Thing*)kochfrac); + SierpinskiPyramid* myfrac = new SierpinskiPyramid(Vec(0,0,0), 4, 30); + userAnim->addThing((Thing*)myfrac); + //myfrac.setCenter(myCen); //myfrac.setMaterial(Color(1,0,1), Color(1,0,1)); //myfrac.setPosition(myCen); @@ -549,11 +553,11 @@ //draw sphere //mysphere.draw(); - myfrac->draw(); - kochfrac->draw(); + //myfrac->draw(); + //kochfrac->draw(); //draw cube - //cube->draw(); + cube->draw(); //draw imported model //myModel->draw();