void display(void) { if(boolpause==0){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); robotOrientation(); gluLookAt(deltaX+betaX,deltaY+betaY,deltaZ+betaZ,0.0+deltaX,0.0,0.0+deltaZ, 0.0,1.0,0.0); //Draw ground glBegin(GL_QUADS); glColor4f(0.0f,1.0f,0.0f,0.0f); //Green glVertex3f(-5.0f, 0.0f, -5.0f); glVertex3f(-5.0f, 0.0f, (float)(MaxDistance)+5.0f); glVertex3f((float)(MaxDistance)+5.0f,0.0f,(float)(MaxDistance)+5.0f); glVertex3f((float)(MaxDistance)+5.0f,0.0f,-5.0f); glEnd(); //Draw Robot drawRobot(); //Draw Buildings drawBuildings(GL_RENDER); glutSwapBuffers(); } }
void mouse(int button, int state, int x, int y) { GLuint selectBuf[SIZE]; GLint hits; GLint viewport[4]; if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { glGetIntegerv (GL_VIEWPORT, viewport); glSelectBuffer(SIZE, selectBuf); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3]-y), 5.0,5.0,viewport); gluPerspective(60.0f,(float)Window_Width/(float)Window_Height,1.0f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); robotOrientation(); gluLookAt(deltaX+betaX,deltaY+betaY,deltaZ+betaZ,0.0+deltaX,0.0,0.0+deltaZ, 0.0,1.0,0.0); drawBuildings(GL_SELECT); glMatrixMode(GL_PROJECTION); glPopMatrix(); glFlush(); glMatrixMode(GL_MODELVIEW); hits = glRenderMode(GL_RENDER); processHits(hits, selectBuf); //printf("Left Button Press Detected! X: %i Y: %i \n", x, y); glutPostRedisplay(); } }
void renderScene(void) { mainPlane.manageHealth(); //GLfloat lightpos[] = {-x,-z,-y}; //glTranslatef(lightpos[0], lightpos[1], lightpos[2]); glColor3f(1, 1, 1); //glutSolidSphere(30, 20, 20); //glTranslatef(-lightpos[0], -lightpos[1], -lightpos[2]); //glLightfv(GL_LIGHT0, GL_POSITION, lightpos); if (deltaMove) moveMeFlat(deltaMove); if (deltaAngle) { angle += deltaAngle; orientMe(angle); //rotateMe(angle); } if (rotationAngleDelta) { rotationAngle+=rotationAngleDelta; rotationAngleDelta=0; rotateMe(rotationAngle); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw ground glPushMatrix(); //glLoadIdentity(); //glTranslatef(x, y, z); //glRotatef(rotationAngle+90, 0, 1, 0); explosives.drawExplosions(); //glTranslatef(-x, -y, -z); glPopMatrix(); float minX=200000,maxX=0,minY=20000,maxY=0; glBegin(GL_QUADS); for (int i = 20; i <tiles.size()-20; i++) { for (int j = 20; j <tiles.size()-20; j++) { if(tiles[i][j].xMax>maxX) maxX = tiles[i][j].xMax; if(tiles[i][j].yMax>maxY) maxY = tiles[i][j].yMax; if(tiles[i][j].x<minX) minX = tiles[i][j].x; if(tiles[i][j].y<minY) minY = tiles[i][j].y; if (tiles[i][j].z>-.7) { tiles[i][j].drawTile(); } } } drawWater(maxX*40,maxY*40,minX*40,minY*40); glEnd(); drawTrees(); drawBuildings(); advanceLevel(); drawPlane(); //drawSilos(); drawCarrierGroup(); calculateFPS(); glutSwapBuffers(); //std::cout<<"hello"; indexer++; if (loadBuildings) { loadBuildings = 0; cDetector.buildings = &buildings; } cDetector.detectCollisions(); //glLoadIdentity(); }