diff --git a/include/glumodel.h b/include/glumodel.h index 205a8b2..e13ae1f 100644 --- a/include/glumodel.h +++ b/include/glumodel.h @@ -31,11 +31,21 @@ void draw(); }; -class KochFractal : public GenericModel { +class Fractal : public GenericModel { public: float iters; float len; + float multiplicity; + float mult_angle; + Fractal(); + void init(float _iters, float _len); +}; + +class KochFractal : public Fractal { + public: KochFractal(); + //TODO: move draw function to Fractal class, it's common for all + //inheriting fractals.... void draw(); void iter(float nbit); }; diff --git a/sources/glumodel.cpp b/sources/glumodel.cpp index 784da2a..ba50b4f 100644 --- a/sources/glumodel.cpp +++ b/sources/glumodel.cpp @@ -51,16 +51,33 @@ } +Fractal::Fractal() { + init(4, 30); +} + +void Fractal::init(float _iters, float _len) { + iters = _iters; + len = _len / (iters*iters*iters); + + //arbitrary values, to be reset + //used to draw several instances of same fractal + multiplicity = 1; + mult_angle = 90; +} + KochFractal::KochFractal() { - iters = 4; - len = 30 / (iters*iters*iters); + Fractal::init(3, 30); + multiplicity = 6; + mult_angle = 60; } void KochFractal::draw() { + //TODO: move draw function to Fractal class, it's common for all + //inheriting fractals.... glPushMatrix(); - for (int i = 0; i < 6; i++) { + for (int i = 0; i < multiplicity; i++) { iter(iters); - glRotatef(60, 1,0,0); + glRotatef(mult_angle, 1,0,0); } glPopMatrix(); } @@ -76,8 +93,6 @@ iter(n); glRotatef(60,1,0,0); iter(n); - //glRotatef(30,1,0,0); - } else { glBegin(GL_LINES); glVertex3f(0,0,0);