void myGlutDisplay(void) { glClearColor(.9f, .9f, .9f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); camera->SetViewAngle(viewAngle); camera->SetNearPlane(clipNear); camera->SetFarPlane(clipFar); glMatrixMode(GL_PROJECTION); glLoadIdentity(); Matrix projection = camera->GetProjectionMatrix(); glMultMatrixd(projection.unpack()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); Point eyeP(eyeX, eyeY, eyeZ); Vector lookV(lookX, lookY, lookZ); Vector upV(0, 1, 0); camera->Orient(eyeP, lookV, upV); camera->RotateV(camRotV); camera->RotateU(camRotU); camera->RotateW(camRotW); Matrix modelView = camera->GetModelViewMatrix(); glMultMatrixd(modelView.unpack()); //rotate object glRotatef(rotX, 1.0, 0.0, 0.0); glRotatef(rotY, 0.0, 1.0, 0.0); glRotatef(rotZ, 0.0, 0.0, 1.0); //drawing the axes glDisable(GL_LIGHTING); glBegin(GL_LINES); glColor3f(1.0, 0.0, 0.0); glVertex3f(0, 0, 0); glVertex3f(1.0, 0, 0); glColor3f(0.0, 1.0, 0.0); glVertex3f(0, 0, 0); glVertex3f(0.0, 1.0, 0); glColor3f(0.0, 0.0, 1.0); glVertex3f(0, 0, 0); glVertex3f(0, 0, 1.0); glEnd(); //scale object glScalef(scale / 50.0, scale / 50.0, scale / 50.0); shape->setSegments(segmentsX, segmentsY); if (normal) { glColor3f(1.0, 0.0, 0.0); shape->drawNormal(); } glEnable(GL_LIGHTING); if (fill) { glEnable(GL_POLYGON_OFFSET_FILL); glColor3f(0.5, 0.5, 0.5); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); shape->draw(); } if (wireframe) { glDisable(GL_POLYGON_OFFSET_FILL); glColor3f(0.0, 0.0, 0.0); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); shape->draw(); } camera->RotateV(-camRotV); camera->RotateU(-camRotU); camera->RotateW(-camRotW); glutSwapBuffers(); }
void myGlutDisplay(void){ static long frameCount = 1; if(wireframe){ glDisable(GL_POLYGON_OFFSET_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); }else{ glEnable(GL_POLYGON_OFFSET_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } glClearColor(.9f, .9f, .9f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); camera->SetViewAngle(viewAngle); camera->SetNearPlane(clipNear); camera->SetFarPlane(clipFar); glMatrixMode(GL_PROJECTION); glLoadIdentity(); Matrix projection = camera->GetProjectionMatrix(); glMultMatrixd(projection.unpack()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); Point eyeP(eyeX, eyeY, eyeZ); Vector lookV(lookX, lookY, lookZ); Vector upV(0, 1, 0); camera->Orient(eyeP, lookV, upV); camera->RotateV(camRotV); camera->RotateU(camRotU); camera->RotateW(camRotW); Matrix modelView = camera->GetModelViewMatrix(); glMultMatrixd(modelView.unpack()); camera->RotateV(-camRotV); camera->RotateU(-camRotU); camera->RotateW(-camRotW); if(debugMode){ //TODO: fix text display //displayText( 50,50, 255,0,0, "debug" ); draw_grid(); //drawing the axes glDisable(GL_LIGHTING); glLineWidth(4); glBegin(GL_LINES); glColor3f(1.0, 0.0, 0.0); glVertex3f(0, 0, 0); glVertex3f(1.0, 0, 0); glColor3f(0.0, 1.0, 0.0); glVertex3f(0, 0, 0); glVertex3f(0.0, 1.0, 0); glColor3f(0.0, 0.0, 1.0); glVertex3f(0, 0, 0); glVertex3f(0, 0, 1.0); glEnd(); glLineWidth(1); glEnable(GL_LIGHTING); } glColor3f(0,0,0); glutSolidCube(20); static int MAX_FRAMES=500; static int MAX_FRAMES_FireWorks=500; static float speed = 1.15; static float shrink = 0.00005; static float frameTimeStep= 0.003;//replace with chronos lib if lab comps support c++11 static float speed0 = 1.15; static float shrink0 = 0.00015; frameCount++; if(frameCount%MAX_FRAMES_FireWorks==0){ resetFireWork(); speed0 = 1.15; shrink0 = 0.00015; } if(frameCount%MAX_FRAMES==0){ for(int i=0;i<NUM_OF_PARTICALS;i++){ if(particalsVec[i]){ delete particalsVec[i]; } particalsVec[i]=new ParticalRound(); initVector(i); } speed = 1.15; frameCount = 1; } for(int i=0;i<NUM_OF_PARTICALS;i++){ if(particalsVec[i]->getRadius()>0&&particalsVec[i]->getLocation()[1]>0){ particalsVec[i]->draw(); } particalsVec[i]->updateTimeAlive(frameTimeStep); Point p=physics.calculatePosition(particalsVec[i]); particalsVec[i]->setPosition(p); double collisionDist; Vector movementVector=physics.getMovementVector(particalsVec[i]); Point fromPoint=particalsVec[i]->getPosition(); movementVector.normalize(); if(collision(fromPoint,movementVector,collisionDist)){ Vector normal=shape->findIsectNormal(shapeTransformInv*fromPoint,shapeTransformInv*movementVector,collisionDist); movementVector.normalize(); Vector newLaunchVect=-physics.getReflectedRay(movementVector,normal); newLaunchVect.normalize(); particalsVec[i]->setLaunchVector(newLaunchVect); particalsVec[i]->setOrigin(particalsVec[i]->getLocation()); double timeToCollision=particalsVec[i]->getTimeAlive(); particalsVec[i]->resetTime(); particalsVec[i]->setLaunchVelocity(particalsVec[i]->getLuanchVelocity()/(timeToCollision*10)); } if(frameCount>100){ particalsVec[i]->setRadius(particalsVec[i]->getRadius()-shrink); } particalsVec[i]->updateColor(double(frameCount)/double(MAX_FRAMES/2)); } ///////////FIREWORKS////////// if(frameCount < 10){ speed0 -= 0.0025; } if(frameCount < 30){ speed0 -= 0.002; } if(frameCount > 40){ speed0 -= 0.01; } if(speed0 < 1.001) speed0 = 1.001; glPushMatrix(); glTranslatef(fireWorkLocation[0],fireWorkLocation[1],fireWorkLocation[2]); for(int i=0; i<NUM_OF_PARTICALS; i++){ Point o = particals[i]->getOrigin()*speed0; if(frameCount > 60){ o[1] -= 0.005; }else{ ParticalRound pp(o[0], o[1], o[2]); pp.setColor(particals[i]->getColor()); additionalParticals.push_back(pp); } particals[i]->setOrigin(o); particals[i]->setRadius(particals[i]->getRadius()-shrink0); Point c = particals[i]->getColor(); c[0] -= 0.09; c[1] -= 0.09; c[2] -= 0.09; particals[i]->setColor(c); particals[i]->draw(); } for(unsigned int i=0; i<additionalParticals.size(); i++){ additionalParticals[i].setRadius(additionalParticals[i].getRadius()-(shrink0*10)); if(additionalParticals[i].getRadius() > 0){ additionalParticals[i].draw(); } } glPopMatrix(); glColor3f(1,1,0); glPushMatrix(); glMultMatrixd(shapeTransform.unpack()); shape->setSegments(20,20); shape->draw(); glPopMatrix(); glutSwapBuffers(); glutPostRedisplay(); ////////////////////////// }