void BudgetStatusView::paintEvent(QPaintEvent *event) { QPainter p(this); p.setPen(QPen(Qt::black, 2)); ServerBudgetGUIObj *temp; bool first = true; int prevBudget, prevTime, budget, time; for(list<ServerBudgetGUIObj*>::iterator budgetIter = _budgetList.begin(); budgetIter != _budgetList.end(); budgetIter++) { temp = *budgetIter; if(first){ prevBudget = temp->currentBudget(); prevTime = 0; first = false; } budget = temp->currentBudget(); time = temp->time(); if(prevBudget < budget){//prevBudget < budget, replenishment event p.drawLine(lineXPosStart + prevTime*tickLength, lineYPos - vertLineHeight*prevBudget, lineXPosStart + time*tickLength , lineYPos- vertLineHeight*prevBudget); p.drawLine(lineXPosStart + time*tickLength, lineYPos - vertLineHeight*prevBudget, lineXPosStart + time*tickLength , lineYPos- vertLineHeight*budget); } else p.drawLine(lineXPosStart + prevTime*tickLength, lineYPos - vertLineHeight*prevBudget, lineXPosStart + time*tickLength , lineYPos- vertLineHeight*budget); prevBudget = budget; prevTime = time; } drawStructure("", nVertLines); }
/* Redraws window contents */ void glutWidget::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clears color and depth bits of framebuffer //Convenience variables float t = (float) ((int) (((float) clock()) * 50.0 / CLOCKS_PER_SEC) % 30) / 30.0; int t2 = ((int) (((float) clock()) * 50.0 / CLOCKS_PER_SEC) % 240) / 30; float t3 = (float) clock() * 5.0 / CLOCKS_PER_SEC; //These are the control points for the bezier curves GLfloat curves[8][4][3] = { { {-8, 0, -8.5}, {-7, 0, -8.5}, {-5, 0, -8.5}, {-4, 0, -8.5} }, { {-4, 0, -8.5}, {-3.5, 0, -8.5}, {-3.5, 0, -8.5}, {-3.5, 0, -8} }, { {-3.5, 0, -8}, {-3.5, 0, -7}, {-3.5, 0, -5}, {-3.5, 0, -4} }, { {-3.5, 0, -4}, {-3.5, 0, -3.5}, {-3.5, 0, -3.5}, {-4, 0, -3.5} }, { {-4, 0, -3.5}, {-5, 0, -3.5}, {-7, 0, -3.5}, {-8, 0, -3.5} }, { {-8, 0, -3.5}, {-8.5, 0, -3.5}, {-8.5, 0, -3.5}, {-8.5, 0, -4} }, { {-8.5, 0, -4}, {-8.5, 0, -5}, {-8.5, 0, -7}, {-8.5, 0, -8} }, { {-8.5, 0, -8}, {-8.5, 0, -8.5}, {-8.5, 0, -8.5}, {-8, 0, -8.5} } }; //Manually evaluate the bezier curves float s = 1 - t; float AB[2] = {curves[t2][0][0]*s + curves[t2][1][0]*t, curves[t2][0][2]*s + curves[t2][1][2]*t}; float BC[2] = {curves[t2][1][0]*s + curves[t2][2][0]*t, curves[t2][1][2]*s + curves[t2][2][2]*t}; float CD[2] = {curves[t2][2][0]*s + curves[t2][3][0]*t, curves[t2][2][2]*s + curves[t2][3][2]*t}; float ABC[2] = {AB[0]*s + BC[0]*t, AB[1]*s + BC[1]*t}; float BCD[2] = {BC[0]*s + CD[0]*t, BC[1]*s + CD[1]*t}; float pos[2] = {ABC[0]*s + BCD[0]*t, ABC[1]*s + BCD[1]*t}; float slope = (ABC[1] - BCD[1]) / (ABC[0] - BCD[0]); float theta = atan(slope); //Rotation/translation matrix float matrix[4][4] = { {cos(theta), 0, -sin(theta), 0}, {0, 1, 0, 0}, {sin(theta), 0, cos(theta), 0}, {pos[0], 0.01, pos[1], 1} }; //Keep the texture pointing in the right direction throughout the loop if((ABC[0] - BCD[0]) < 0) { matrix[0][2] = -(matrix[0][2]); matrix[2][0] = -(matrix[2][0]); } else if((ABC[0] - BCD[0]) > 0) { matrix[0][0] = -(matrix[0][0]); matrix[2][2] = -(matrix[2][2]); } //Draw streets glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, street_texture); glUseProgram(m_program); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0,1); glNormal3f(0,1,0); glVertex3f(-10,0,-10); glTexCoord2f(0,0); glNormal3f(0,1,0); glVertex3f(-10,0,10); glTexCoord2f(1,1); glNormal3f(0,1,0); glVertex3f(10,0,-10); glTexCoord2f(1,0); glNormal3f(0,1,0); glVertex3f(10,0,10); glEnd(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); // //Draw cars for (int i = 0; i < 9; i++) { matrix[3][0] = pos[0] + ((i % 3) * 6); matrix[3][2] = pos[1] + ((i / 3) * 6); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(matrix[0]); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, car_texture); glUseProgram(m_program); drawCar(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glPopMatrix(); if (i+1 == camera) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(matrix[3][0],0.5,matrix[3][2],sin(roty)+matrix[3][0],sin(rotx)+0.2,-cos(roty)+matrix[3][2],0,1,0); //Camera rotation/translation is done here } } // //Draw structures for (int i = 0; i < 9; i++) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef((i % 3) * 6, 0, (i / 3) * 6); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, structure_texture); glUseProgram(m_program); drawStructure(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glPopMatrix(); } // //Draw skybox glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, skybox_texture); glUseProgram(m_program); drawSkybox(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); // //Draw walls glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, wall_texture); glUseProgram(m_program); drawWalls(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); // if (!camera) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(cposx,0.25,cposz,sin(roty)+cposx,sin(rotx)+cposy,-cos(roty)+cposz,0,1,0); //Camera rotation/translation is done here } glutSwapBuffers(); //swaps front and back buffer for double buffering }