我现在一直在分配一个作业,似乎无法弄明白。
分配点是在左键单击时使图形上的点连接。当你右键点击你做一个点,但它没有连接到最后一个点(它是独奏,在它自己)。当您再次单击左侧按钮时,它应该连接到您创建的最后一个点。我点击了工作但是连接不好。该计划如下..
glBegin(GL_LINES);
for (int i=0 ; i<= numberPoints;i++)
for(int j =0; j<=numberEdges; j++)
{
glVertex2fv(points[edges[i][0]]);
glVertex2fv(points[edges[i][1]]);
}
glEnd();
//这是分数
glBegin(GL_POINTS);
for( int i = 0 ; i<numberPoints; i++)
{
glVertex2fv( points[i]);
}
glEnd();
// This is the left click
switch(button)
{
case GLUT_LEFT_BUTTON:
if(state==GLUT_DOWN)
{
points[numberPoints][0] = plotX;
points[numberPoints][1] = plotY;
previousPointSubscript = numberPoints;
edges[numberEdges][0] = previousPointSubscript;
edges[numberEdges][1] = numberPoints;
numberEdges++;
numberPoints++;
glutPostRedisplay();
glFlush();
}
break;
case GLUT_RIGHT_BUTTON:
if(state==GLUT_DOWN)
{
points[numberPoints][0] = plotX;
points[numberPoints][1] = plotY;
numberPoints++;
}
glutPostRedisplay();
glFlush();
break;
}
答案 0 :(得分:0)
我终于明白了!好吧,我做的是拿GL_LINE,只有一个for循环变量i。然后在左键单击我翻转边缘0和边缘1等于周围。因此,边0是numberPoints,边1是previousPointsSubscript。然后我取了previousPointsSubscript = numberPoints行并把它放在两个边之后。这给了我连接每个点的线条。
if(numberPoints>1)
{
glBegin(GL_LINES);
for (int i=0 ; i<numberEdges;i++)
{
glVertex2fv(points[edges[i][0]]);
glVertex2fv(points[edges[i][1]]);
}
}
glEnd();
case GLUT_LEFT_BUTTON:
if(state==GLUT_DOWN)
{
points[numberPoints][0] = plotX;
points[numberPoints][1] = plotY;
edges[numberEdges][0] = numberPoints;
edges[numberEdges][1] = previousPointSubscript;
previousPointSubscript = numberPoints;
numberEdges++;
numberPoints++;
glutPostRedisplay();
glFlush();
}
就那个右键我已经让它自己绘制点所以我所要做的就是在点下面添加previousPointSubscript = numberPoints;
,当点击左键时会连接线。如果你有问题打我。