Advertisement
aditya369

LorenzAttractor.h

Nov 28th, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include "OpenGLFramework.h"
  2.  
  3. #ifndef __LORENZ_ATTRACTOR__
  4. #define __LORENZ_ATTRACTOR__
  5.  
  6. using namespace openGLFramework;
  7.  
  8. //All constants go here
  9. #define MAX_PARTICLES   10000
  10.  
  11. class LorenzAttractor {
  12.  
  13.     private:
  14.         unsigned int numPointsDrawn;
  15.         float sx, sy, sz, x0, y0, z0, x1, y1, z1;
  16.         float red, green, blue;
  17.        
  18.         float h, a, b, c;
  19.  
  20.     public:
  21.         LorenzAttractor() : h(0.01), a(10.0), b(28.0), c(8.0/3.0) {
  22.             numPointsDrawn = 0;
  23.             x0 = y0 = z0 = x1 = y1 = z1 = 0;
  24.             red = green = blue = 0.5f;
  25.         }
  26.  
  27.         LorenzAttractor(float xStart, float yStart, float zStart, float colorRed, float colorGreen, float colorBlue): h(0.01), a(10.0), b(28.0), c(8.0/3.0) {
  28.             numPointsDrawn = 0;
  29.             x1 = y1 = z1 = 0;
  30.            
  31.             sx = x0 = xStart;
  32.             sy = y0 = yStart;
  33.             sz = z0 = zStart;
  34.  
  35.             red = colorRed;
  36.             green = colorGreen;
  37.             blue = colorBlue;
  38.         }
  39.  
  40.         void setParams(float h, float a, float b, float c) {
  41.             this->h = h;
  42.             this->a = a;
  43.             this->b = b;
  44.             this->c = c;
  45.         }
  46.  
  47.         void setAttributes(float xStart, float yStart, float zStart, float colorRed, float colorGreen, float colorBlue) {
  48.             sx = x0 = xStart;
  49.             sy = y0 = yStart;
  50.             sz = z0 = zStart;
  51.  
  52.             red = colorRed;
  53.             green = colorGreen;
  54.             blue = colorBlue;
  55.         }
  56.  
  57.         void simulate() {
  58.             unsigned int i = 0;
  59.  
  60.             x0 = sx;
  61.             y0 = sy;
  62.             z0 = sz;
  63.  
  64.             x1 = y1 = z1 = 0.0f;
  65.  
  66.             glPushMatrix();
  67.  
  68.                 glPointSize(1.0f);
  69.  
  70.                 glColor3f(red, green, blue);
  71.  
  72.                 glBegin(GL_LINE_STRIP);
  73.  
  74.                     for (i = 0; i < numPointsDrawn; i++) {
  75.  
  76.                         x1 = x0 + h * a * (y0 - x0);
  77.                         y1 = y0 + h * (x0 * (b - z0) - y0);
  78.                         z1 = z0 + h * (x0 * y0 - c * z0);
  79.  
  80.                         x0 = x1;
  81.                         y0 = y1;
  82.                         z0 = z1;       
  83.  
  84.                         glVertex3f(x0, y0, z0);
  85.                     }
  86.  
  87.                 glEnd();
  88.  
  89.             glPopMatrix();
  90.  
  91.             numPointsDrawn = (numPointsDrawn >= MAX_PARTICLES) ? 0 : numPointsDrawn + 1;
  92.         }
  93. };
  94.  
  95. #endif    //__LORENZ_ATTRACTOR__
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement