diff --git a/include/glumodel.h b/include/glumodel.h index e2eecba..d0cba97 100644 --- a/include/glumodel.h +++ b/include/glumodel.h @@ -33,21 +33,17 @@ class Fractal : public GenericModel { public: - float iters; + int iters; float len; - float multiplicity; - float mult_angle; Fractal(); - void init(float _iters, float _len); + void init(Vec pos, Material m, int _iters, float _len); }; -class SierpinskiPyramid : public GenericModel { +class SierpinskiPyramid : public Fractal { private: - int iter; - std::vector faces; GLuint list; public: - SierpinskiPyramid(Vec p, float l, int n); + SierpinskiPyramid(Vec p, int iters, float len); void construct(int n); void draw(); void drawPyramid(); @@ -57,7 +53,10 @@ class KochFractal : public Fractal { public: - KochFractal(); + float multiplicity; + float mult_angle; + + KochFractal(Vec pos, int iters, float len); //TODO: move draw function to Fractal class, it's common for all //inheriting fractals.... void draw(); diff --git a/sources/glumodel.cpp b/sources/glumodel.cpp index 2517615..7db0cd6 100644 --- a/sources/glumodel.cpp +++ b/sources/glumodel.cpp @@ -52,35 +52,26 @@ } Fractal::Fractal() { - init(4, 30); + init(Vec(0,0,0), Material(), 4, 30); } -void Fractal::init(float _iters, float _len) { +void Fractal::init(Vec _pos, Material _m, int _iters, float _len) { + GenericModel::init(_pos, _m); 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; + pos = _pos.clone(); + len = _len; } -SierpinskiPyramid::SierpinskiPyramid(Vec _pos, float _len, int _iter) { - iter = _iter; - scale = _len; - pos = _pos.clone(); - rot = new Vec(0,0,0); - - buildList(); +SierpinskiPyramid::SierpinskiPyramid(Vec _pos, int _iters, float _len) { + Fractal::init(_pos, Material(), _iters, _len); + rot = new Vec(0,0,0); + buildList(); } void SierpinskiPyramid::buildList() { - list = glGenLists(1); glNewList(list, GL_COMPILE); - drawPyramid(); - glEndList(); } @@ -162,7 +153,6 @@ } void SierpinskiPyramid::draw() { - glPushMatrix(); /* rotate SierpinskiPyramid */ @@ -174,18 +164,18 @@ glTranslatef(pos->x(), pos->y(), pos->z()); /* scale it to the desired length, width and height */ - glScalef(scale, scale, scale); + glScalef(len, len, len); /* draw it */ - construct(iter); + construct(iters); glPopMatrix(); } SierpinskiPyramid::~SierpinskiPyramid ( ) { } -KochFractal::KochFractal() { - Fractal::init(3, 30); +KochFractal::KochFractal(Vec _pos, int _iters, float _len) { + Fractal::init(_pos, Material(), _iters, _len / (_iters*_iters*_iters)); multiplicity = 6; mult_angle = 60; } diff --git a/sources/main.cpp b/sources/main.cpp index 96c1a2b..e842b42 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -244,8 +244,10 @@ Material(Color(1,1,0)), 50); - //KochFractal myfrac = KochFractal(); - SierpinskiPyramid* myfrac = new SierpinskiPyramid(Vec(0,0,0), 30, 6); + KochFractal* kochfrac = new KochFractal(Vec(0,0,0), 3, 30); + + SierpinskiPyramid* myfrac = new SierpinskiPyramid(Vec(0,0,0), 4, 30); + //myfrac.setCenter(myCen); //myfrac.setMaterial(Color(1,0,1), Color(1,0,1)); //myfrac.setPosition(myCen); @@ -548,6 +550,7 @@ //mysphere.draw(); myfrac->draw(); + kochfrac->draw(); //draw cube //cube->draw();