我想在用opengl建立的三维坐标系中显示一串点的轨迹,保持屏幕上有最近的六个点,我这样做没有出现想要出现的点,怎么回事呢?
struct coodinate
{int x;int y;int z;};
coodinate plane[50];
coodinate plane1[50];
FILE *stream;
/* Open file in binary mode: */
if( (stream = fopen( "fread.out", "w+b" )) != NULL )
{
for ( int i = 0; i < 50; i++ )
{ plane[i].x=.05*i;
plane[i].y=.03*i;
plane[i].z=.05*i; }
fwrite( plane, sizeof(coodinate), 50, stream ); //写入五十个坐标点到stream中
fclose(stream);
}
else
printf( "Problem opening the file\n" ); if( (stream = fopen( "fread.out", "r+b" )) != NULL )
{
/* Attempt to read in 50 characters */
fread( plane1, sizeof(coodinate), 50, stream );//从stream中读出50个坐标点到plane1中
fclose( stream );
}
void CLeidaView::OnTimer(UINT nIDEvent)
{
static int j=0;
glBegin(GL_POINTS);
glColor3f(1.0,0.0,0.0);
glVertex3d(plane1[j].x,plane1[j].y,plane1[j].z);
glEnd();
if(j<50)
{j++;}
if(j>6)
{ static k=0;
glBegin(GL_POINTS);
glColor3f(1.0,1.0,0.0);
glVertex3d(plane1[k].x,plane1[k].y,plane1[k].z);
glEnd();
if(k<50)
k++;
}
glFlush();
CView::OnTimer(nIDEvent);
}void CLeidaView::OnInitialUpdate()
{
CView::OnInitialUpdate();
SetTimer(1,25,NULL);
}
struct coodinate
{int x;int y;int z;};
coodinate plane[50];
coodinate plane1[50];
FILE *stream;
/* Open file in binary mode: */
if( (stream = fopen( "fread.out", "w+b" )) != NULL )
{
for ( int i = 0; i < 50; i++ )
{ plane[i].x=.05*i;
plane[i].y=.03*i;
plane[i].z=.05*i; }
fwrite( plane, sizeof(coodinate), 50, stream ); //写入五十个坐标点到stream中
fclose(stream);
}
else
printf( "Problem opening the file\n" ); if( (stream = fopen( "fread.out", "r+b" )) != NULL )
{
/* Attempt to read in 50 characters */
fread( plane1, sizeof(coodinate), 50, stream );//从stream中读出50个坐标点到plane1中
fclose( stream );
}
void CLeidaView::OnTimer(UINT nIDEvent)
{
static int j=0;
glBegin(GL_POINTS);
glColor3f(1.0,0.0,0.0);
glVertex3d(plane1[j].x,plane1[j].y,plane1[j].z);
glEnd();
if(j<50)
{j++;}
if(j>6)
{ static k=0;
glBegin(GL_POINTS);
glColor3f(1.0,1.0,0.0);
glVertex3d(plane1[k].x,plane1[k].y,plane1[k].z);
glEnd();
if(k<50)
k++;
}
glFlush();
CView::OnTimer(nIDEvent);
}void CLeidaView::OnInitialUpdate()
{
CView::OnInitialUpdate();
SetTimer(1,25,NULL);
}
二、有可能是读取文件时的问题。
你的 OnTimer() 绘制方法不对。你还没有明白 OpenGL 的绘制流程。作小程序的时候,可以在一个别人已经做好的小程序的基础上作,可以省很多事情,也不会出现这样那样的参数没有设置正确而导致无法显示的问题。参考 http://alphasun.betajin.com/alphasun/wave/index.htm