2012-09-20 31 views
0

我想绘制一个洛伦兹吸引子,其中颜色在整个吸引子中变化。我已经写了下面的计算吸引点的循环。OpenGL glcolor for循环

float x = 1, y = 1, z = 1; 
    glBegin(GL_LINE_STRIP); 

    int i;  
    for (i=0; i < initialIterations; i++) { 
     glColor3d(0,i/50000,1); 
     // compute a new point using the lorenz attractor equations 
     float dx = sigma*(y-x); 
     float dy = x*(r-z) - y; 
     float dz = x*y - b*z; 

     // save the new point 
     x = x + dx*dt; 
     y = y + dy*dt; 
     z = z + dz*dt;   

     glVertex3f(x/50,y/50,z/50); 
    } 
    glEnd(); 

我使用的glcolor的代码的顶部,以改变颜色作为i的函数。但是,我没有看到我想要的结果,我得到的只有一种纯色。我知道颜色像状态机一样工作,但我需要找到一种方法来改变整个颜色。

+0

您使用的是过时的做法,我建议甚至没有讨论这个代码,因为它甚至没有批准一起工作一个现代的OpenGL环境,从OpenGL 3.0+和可编程管线开始。 – Ken

回答

4

你做的整数除法:i/50000,所以它始终为0。

尝试i/50000.0