我按照指南绘制了2D的Lorenz系统.
我现在想要扩展我的项目并从2D切换到3D.据我所知,我必须用gluPerspective或glFrustum替换gluOrtho2D调用.不幸的是,无论我尝试什么都没用.这是我的初始化代码:
// set the background color
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
/// set the foreground (pen) color
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);*/
// set the foreground (pen) color
glColor4f(1.0f, 1.0f, 1.0f, 0.02f);
// enable blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// enable point smoothing
glEnable(GL_POINT_SMOOTH);
glPointSize(1.0f);
// set up the viewport
glViewport(0, 0, 400, 400);
// set up the projection matrix (the camera)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluOrtho2D(-2.0f, 2.0f, -2.0f, 2.0f);
gluPerspective(45.0f, 1.0f, 0.1f, 100.0f); //Sets the frustum to perspective mode
// set up the modelview matrix (the objects)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Run Code Online (Sandbox Code Playgroud)
在画画的时候我这样做:
glClear(GL_COLOR_BUFFER_BIT);
// draw some points
glBegin(GL_POINTS);
// go through the equations many times, drawing a point for each iteration
for (int i = 0; i < iterations; i++) {
// compute a new point using the strange attractor equations
float xnew=z*sin(a*x)+cos(b*y);
float ynew=x*sin(c*y)+cos(d*z);
float znew=y*sin(e*z)+cos(f*x);
// save the new point
x = xnew;
y = ynew;
z = znew;
// draw the new point
glVertex3f(x, y, z);
}
glEnd();
// swap the buffers
glutSwapBuffers();
Run Code Online (Sandbox Code Playgroud)
问题是我不能在窗口中看到任何东西.一切都是黑色的.我究竟做错了什么?
名称"gluOrtho2D"有点误导.实际上gluOrtho2D
可能是有史以来最无用的功能.定义gluOrtho2D
是
void gluOrtho2D(
GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top )
{
glOrtho(left, right, bottom, top, -1, 1);
}
Run Code Online (Sandbox Code Playgroud)
也就是它唯一用它来调用near和far的glOrtho
默认值.哇,多么复杂和巧妙.</sarcasm>
无论如何,即使它被称为...2D
,也没有任何关于它的二维.投影体积的深度范围仍然[-1 ; 1]
是完全三维的.
最有可能产生的点位于投影体积之外,投影体积的Z值范围[0.1 ; 100]
在你的情况下,但是你的点被限制[-1 ; 1]
在任一轴的范围内(而IIRC则奇怪吸引子的Z范围是完全正的).所以你必须应用一些翻译才能看到一些东西.我建议你选择
并应用Z:-5.5的平移将物体移动到观察体积的中心.
归档时间: |
|
查看次数: |
521 次 |
最近记录: |