diff --git a/include/animation.h b/include/animation.h index 7848ba5..7213ba9 100644 --- a/include/animation.h +++ b/include/animation.h @@ -53,6 +53,7 @@ bool showMe; float delta; bool trace; + int iterations; public: UserAnimation(); UserAnimation(Thing* t); diff --git a/include/glumodel.h b/include/glumodel.h index 85bcb49..609efb4 100644 --- a/include/glumodel.h +++ b/include/glumodel.h @@ -45,6 +45,8 @@ float len; Fractal(); void init(Vec pos, Material m, int _iters, float _len); + void setIterations(int _iters); + }; class SierpinskiPyramid : public Fractal { @@ -63,12 +65,14 @@ public: float multiplicity; float mult_angle; - + float mylen; KochFractal(Vec pos, int iters, float len); //TODO: move draw function to Fractal class, it's common for all //inheriting fractals.... void draw(); void iter(float nbit); + + void setIterations(int _iters); }; #endif diff --git a/sources/glumodel.cpp b/sources/glumodel.cpp index 3b6f669..bc3a1de 100644 --- a/sources/glumodel.cpp +++ b/sources/glumodel.cpp @@ -3,6 +3,7 @@ #include #include // This file import the OpenGL interface #include // This file offers some OpenGL-related utilities +#include GenericModel::GenericModel() { init(Vec(0,0,0), Material()); @@ -84,6 +85,10 @@ len = _len; } +void Fractal::setIterations(int _iters) { + iters = _iters; +} + SierpinskiPyramid::SierpinskiPyramid(Vec _pos, int _iters, float _len) { Fractal::init(_pos, Material(), _iters, _len); rot = new Vec(0,0,0); @@ -198,11 +203,17 @@ SierpinskiPyramid::~SierpinskiPyramid ( ) { } KochFractal::KochFractal(Vec _pos, int _iters, float _len) { - Fractal::init(_pos, Material(), _iters, _len / (_iters*_iters*_iters)); + Fractal::init(_pos, Material(), _iters, _len); + setIterations(_iters); multiplicity = 6; mult_angle = 60; } +void KochFractal::setIterations(int _iters) { + Fractal::setIterations(_iters) ; + mylen = len / pow(3, iters); +} + void KochFractal::draw() { if ( visible ) { //TODO: move draw function to Fractal class, it's common for all @@ -221,7 +232,6 @@ iter(iters); glRotatef(mult_angle, 1,0,0); } - glPopMatrix(); } } @@ -240,8 +250,8 @@ } else { glBegin(GL_LINES); glVertex3f(0,0,0); - glVertex3f(0,len,0); + glVertex3f(0,mylen,0); glEnd(); - glTranslatef(0,len,0); + glTranslatef(0,mylen,0); } } diff --git a/sources/main.cpp b/sources/main.cpp index c19cbf1..a79a943 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -243,19 +243,12 @@ 50); KochFractal* kochfrac = new KochFractal(Vec(0,0,0), 3, 30); - userAnim->addThing((Thing*)kochfrac); - SierpinskiPyramid* myfrac = new SierpinskiPyramid(Vec(0,0,0), 4, 30); + SierpinskiPyramid* myfrac = new SierpinskiPyramid(Vec(-7,10,-7), 4, 15); userAnim->addThing((Thing*)myfrac); - //myfrac.setCenter(myCen); - //myfrac.setMaterial(Color(1,0,1), Color(1,0,1)); - //myfrac.setPosition(myCen); - //myfrac.showNormals(); - //myfrac.setDelta(PI/2.0); - /* begin cube */ Vec* ulh = new Vec(0 ,0 ,0 ); Vec* ulv = new Vec(0 ,0 ,10); @@ -391,7 +384,7 @@ glEnable(GL_LIGHTING); glFrontFace(GL_CCW); - GLfloat global_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; + GLfloat global_ambient[] = { 0.3f, 0.3f, 0.3f, 1.0f }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); //light info @@ -408,7 +401,7 @@ Light light1(GL_LIGHT1, Vec (20, 20, 20), Material(Color(0.5,0.5,0.5), - Color(1,1,1))); + Color(0,0,0))); userAnim->addThing((Thing*)(&light0)); userAnim->addThing((Thing*)(&light1)); @@ -543,7 +536,7 @@ // glEnd(); //draw sphere - //mysphere.draw(); + mysphere.draw(); myfrac->draw(); kochfrac->draw(); @@ -552,7 +545,7 @@ //cube->draw(); //draw imported model - //myModel->draw(); + myModel->draw();