|
|
void addVertexAt(int index, float x, float y) {
int i;
numVerticies++;
verticies = (Point2Df *)realloc(verticies, numVerticies * sizeof(*verticies));
for (i = numVerticies - 2; i >= index; i--) {
verticies[i + 1] = verticies;
}
verticies[index].x = x;
verticies[index].y = y;
}
void mouseClick(int button, int state, int x, int y) {
int viewport[4];
double ProjeMatrix[16];
double ModelMatrix[16];
int flippedy;
int clickedVertex;
int cEdge;
switch(button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN) {
glGetIntegerv(GL_VIEWPORT, viewport);
flippedy = viewport[3] - y ;
int winz;
double wx, wy, wz;
winz = 0;
glGetDoublev( GL_MODELVIEW_MATRIX , ModelMatrix ) ;
glGetDoublev( GL_PROJECTION_MATRIX , ProjeMatrix ) ;
// glGetIntegerv( GL_VIEWPORT, viewport ) ;
gluUnProject(x,
flippedy,
winz,
ModelMatrix,
ProjeMatrix,
viewport,
&wx,
&wy,
&wz);
addVertex(wx + 0.0, wy + 0.0);
// movingVertex = numVerticies - 1;
glutPostRedisplay();
} else if (state == GLUT_UP) {
movingVertex = -1;
glutPostRedisplay();
}
break;
default:
break;
}
}
void drawPolyloop(void) {
int i;
int viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glPushMatrix();
if (verticies != NULL) {
glColor3f(1.0, 0.0, 1.0);
glBegin(GL_LINE_LOOP);
for (i = 0; i < numVerticies; i++) {
glVertex3f(verticies.x, verticies.y, 0.0);
}
glEnd();
}
glPopMatrix();
} |
|