void Bullet::checkCollision() { QList<QGraphicsItem *> l=scene()->items(); foreach(QGraphicsItem *item, l) { if ( (item->type()==man_type) && item->collidesWithItem(this, Qt::IntersectsItemBoundingRect) ) { Man* deadman = (Man*)item; if (deadman->frame() != 5) return; deadman->done(); emit score(10); setShotCount(shotcount+1); nobullets--; deleteLater(); return; } else if ( (item->type()==helicopter_type) && item->collidesWithItem(this, Qt::IntersectsItemBoundingRect) ) { Helicopter* deadchopper = (Helicopter*) item; deadchopper->done(); emit score(50); setShotCount(shotcount+1); nobullets--; deleteLater(); return; } } //check shot is not out of bounds if ( (y() < 0) || (x() < 0) || (y() > scene()->height()) || ( x() > scene()->width())) { nobullets--; deleteLater(); return; } }
void GameWorld::update(float delta) { scoreTextLabel->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(100, 100)))); scoreLabel->setString(std::to_string(scoreManager->getScore())); pointlocation = this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(110, 130))); scoreLabel->setPosition(pointlocation); heartsprite->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(30, 60)))); healthLabel->setString(std::to_string(player->currentHealth)); healthLabel->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(114, 60)))); //Update the player. player->update(delta); //Update all the npcs. for (Entity* e : *npcManager->getNpcs()) { if (IsType<Crowd>(e)) { Crowd* c = static_cast<Crowd*>(e); c->update(delta); } else if (IsType<Helicopter>(e)) { Helicopter* h = static_cast<Helicopter*>(e); h->update(delta); } else e->update(delta); } //Update all the broken buildings. for (BrokenStructure* b : *structureManager->getStructures()) { b->update(delta); } }
bool onPosto(Helicopter player, Rect posto){ if(player.getGunPosX() > posto.getX() && player.getGunPosX() < (posto.getX() + posto.getWidth()) && player.getGunPosY() > posto.getY() && player.getGunPosY() < (posto.getY() + posto.getHeight()) ){ // on posto return true; } // left posto return false; }
void motion(int x, int y){ static GLdouble previousTime = 0; GLdouble currentTime; GLdouble timeDifference; currentTime = glutGet(GLUT_ELAPSED_TIME); timeDifference = currentTime - previousTime; previousTime = currentTime; if(mouseX < x ) player.rotateGun(timeDifference* 0.1); if(mouseX > x ) player.rotateGun(timeDifference* -0.1); mouseX = x; }
void timerGasBar(int value){ // on posto if(player.getFlying() && !onPosto(player, arena.getPostoAbastecimento())){ player.decGas(); } // refuels if(onPosto(player, arena.getPostoAbastecimento())){ player.setGas(player.getTempoDeVoo()); } glutTimerFunc((1000),timerGasBar,0); glutPostRedisplay(); }
void display(void){ glClear (GL_COLOR_BUFFER_BIT); // arena and helicopter glPushMatrix(); arena.drawArena(ARENAX, ARENAY); glPopMatrix(); if(!checkDefeat(player, ARENAX/2.0,ARENAY/2.0)){ // shots glPushMatrix(); for(int i = 0 ; i < playerShots.size() ; i++) playerShots.at(i).draw(); if(enemyShots.size() > 0){ for(int i = 0 ; i < enemyShots.size() ; i++) enemyShots.at(i).draw(); } glPopMatrix(); glPushMatrix(); player.draw(); glPopMatrix(); glPushMatrix(); enemies.at(0).draw(); enemies.at(1).draw(); enemies.at(2).draw(); glPopMatrix(); } glEnd(); glutSwapBuffers(); }
Bomb::Bomb(const Helicopter &helicopter){ this->xCoordinate = helicopter.getXCoordinate(); this->yCoordinate = helicopter.getYCoordinate(); if(helicopter.getXVelocity() != 0) this->xVelocity = helicopter.getXVelocity(); else this->xVelocity = 0; this->yVelocity = +4; this->hitbox.leftBorder = this->xCoordinate + 52; this->hitbox.rightBorder = this->hitbox.leftBorder + BOMB_WIDTH; this->hitbox.topBorder = this->yCoordinate + 25; this->hitbox.bottomBorder = this->hitbox.topBorder + BOMB_HEIGHT; }
int main(int argc, char* argv[]){ char path[255]; if(argc != 2){ cout << "Running at default path './config/config.xml'..." << endl; strcpy(path, "../config/config.xml"); }else{ strcpy(path, argv[1]); strcat(path, "config.xml"); } srand(time(NULL)); config.readXML(path); arena.readXMLArena((config.getArena().getPath() + config.getArena().getName() + "." + config.getArena().getExtension()).c_str()); player = config.readHelicopterConfig(path); player.setArena(ARENAX, ARENAY); enemies.push_back(config.readEnemyHelicopter(path, ARENAX/100 * 90, ARENAY/100 * 10)); enemies.push_back(config.readEnemyHelicopter(path, ARENAX/100 * 90, ARENAY/100 * 90)); enemies.push_back(config.readEnemyHelicopter(path, ARENAX/100 * 10, ARENAY/100 * 90)); enemies.at(0).setAngle(0); glutInit (&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize (ARENAX,ARENAY); glutInitWindowPosition (0, 0); glutCreateWindow ("Arena"); init (ARENAX, ARENAY); glutDisplayFunc (display); glutMouseFunc (mouse); glutIdleFunc (idle); glutKeyboardFunc (setKeyDown); glutKeyboardUpFunc (setKeyUp); //timers glutTimerFunc((player.getTempoDeVoo() * 1000)/5, timerGasBar, 0); glutTimerFunc(rand() % (int)(5 - 2 + 1),timerEnemyMovement,0); glutTimerFunc(200,timerEnemyShooting,200); glutPassiveMotionFunc(motion); glutMainLoop (); }
void Bullet::checkCollision() { QCanvasItem* item; QCanvasItemList l=collisions(FALSE); for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { item = *it; if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) { Man* deadman = (Man*)item; if (deadman->frame() != 5) return; deadman->done(); emit score(10); setShotCount(shotcount+1); setAnimated(false); nobullets--; delete this; return; } else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) { Helicopter* deadchopper = (Helicopter*) item; deadchopper->done(); emit score(50); setAnimated(false); nobullets--; delete this; return; } } //check shot is not out of bounds if ( (y() < 0) || (x() < 0) || (y() > canvas()->height()) || ( x() > canvas()->width())) { setAnimated(false); nobullets--; delete this; return; } }
// true = victory // false = defeat bool checkDefeat(Helicopter player, float x, float y){ string defeat = "DEFEAT"; if(player.getGas() <= 0){ // if(player.getGas() >10){ glPushMatrix(); glTranslatef(x, y, 0.0); glColor3f(0.0, 0.0, 0.0); glScalef(0.5, 0.5, 0.5); glRotatef(180.0, 1.0, 0.0, 0.0); for(int i = 0; i < 6 ; i++) glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,defeat[i]); glPopMatrix(); return true; } return false; }
bool onArena(Helicopter player, Rect arena, float displacement){ float nextMoveX = player.getNextMoveX(displacement) + player.getCx(); float nextMoveY = player.getNextMoveY(displacement) + player.getCy(); if(nextMoveX + player.getRadius() > arena.getWidth() || nextMoveX - player.getRadius() < 0.0 || nextMoveY + player.getRadius() > arena.getHeight() || nextMoveY - player.getRadius() < 0.0){ // left arena return true; } // on arena return false; }
void RealTimeTest::maxSpead() { Hud *maxSpeadTestingHud = game.getHudsManager()->createHud(HudAlignment::RIGHT); maxSpeadTestingHud->setText("MAX SPEAD TESTING STARTED..."); DelayCommand dc(15); dc.execute(); Helicopter *helicopter = game.getHelicopter(); JoystickMoveForward jmf(helicopter->getJoystick()); RotorNeutral rn(helicopter->getMainRotor()); float oldV = 0; float newV = 0; std::cout << "\nmaxSpead test started:" << std::endl; game.getConfiguration()->activateFriction(); helicopter->reset(); helicopter->setPosistion(osg::Vec3f(0, 0, 600)); jmf.execute(); rn.execute(); do { oldV = newV; dc.execute(); newV = helicopter->getVelocity().x(); } while (oldV < newV); // viscous resistance = v * (6 * WORLD_PI * 0.001 * 4) // if joystick(theta = 15, phi = 0) and throttle(9.8), then // ax = sin15 * 9.8 = 0.2588 * 9.8 = 2.53624 // viscous resistance should be equal 2.53624 // v * (6 * WORLD_PI * 0.001 * 4) = 2.53624 <= now solve for v // v = 2.53624 / (6 * WORLD_PI * 0.001 * 4) // v = 33.6379 Assert(33.6379, helicopter->getVelocity().x(), 0.01); std::cout << "maxSpead test passed" << std::endl; std::cout << "maxSpead test results:" << std::endl; std::cout << "vx = " << helicopter->getVelocity().x() << std::endl; maxSpeadTestingHud->setText("HOVER TESTING PASSED..."); }
void mouse(int button, int state, int x, int y){ if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN){ player.setFlying(); } if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && player.getFlying()){ // playerShots.push_back(Shot(player.getGunPosX(), // player.getGunPosY(), // player.getCurrentAngleGun(), // player.getAngle(), // player.getVelTiro(), // player.getAngleGun())); playerShots.push_back(Shot(player.getGunPosX(), player.getGunPosY(), player.getCurrentAngleGun(), player.getAngle(), player.getVelTiro(), player.getAngleGun())); } }
void update(int value) { // _angle += 1.0f; //if (_angle > 360) { // _angle -= 360; //} weirdAngle += 0.5f; if (weirdAngle > 360) { weirdAngle -= 360; } if(horiOff == 8.0f) { incHor = false; } if(horiOff == -8.0f) { incHor = true; } if(vertiOff == 8.0f) { incVert = false; } if(vertiOff == -8.0f) { incVert = true; } if(incHor) { horiOff += 0.5f; } else { horiOff -= 0.5f; } if(incVert) { vertiOff += 0.5f; } else { vertiOff -= 0.5f; } heli.followFlightPath(); hunter1->followPath(); glutPostRedisplay(); glutTimerFunc(25, update, 0); }
void drawScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); keyboardHandler(); camera(); moveBullets(); drawBullets(); //orthogonalStart(); //glBegin(GL_QUADS); //glVertex2f(300, 300); //glVertex2f(300, 800); //glVertex2f(800, 800); //glVertex2f(800, 300); //glEnd(); //orthogonalEnd(); //GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f}; //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); //glRotatef(-_angle, 1.0f, 1.0f, 0.0f); drawFloor(0.0f); //drawTerrain(); bunker1.draw(); bunker2.draw(); sittingDuck1.draw(); atom1.draw(); atom2.draw(); atom3.draw(); building1.draw(); heli.draw(); hunter1->draw(); // cout << "Player position: " << playerInstance->getX() << " " << playerInstance->getZ() // << " Hunter position: " << hunter1->getX() << " " << hunter1->getZ() << endl; glutSwapBuffers(); }
int main(int argc, char** argv) { playerInstance->setX(800); playerInstance->setZ(1000); playerInstance->setY(0); playerInstance->setHeight(PLAYER_EYE_HEIGHT); int seed = 1268511395; srand(seed); cout << "*Using seed: " << seed << endl; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); //http://www.swiftless.com/tutorials/opengl/fullscreen.html //glutGameModeString( "1920x1080:32@75" ); //the settings for fullscreen mode //glutEnterGameMode(); //set glut to fullscreen using the settings in the line above glutInitWindowSize (1280,800); glutInitWindowPosition (100, 100); glutCreateWindow ("Simple Window"); initRendering(); string name = textureDir; name += "heightmap.bmp"; // _terrain = loadTerrain(name.c_str(), 20); int bunkerTextures[] = {_textureFront, _textureRight, _textureBack, _textureLeft}; // For testing purposes: // /* int * testcoords = playerInstance->getGridCoords(); cout << testcoords[0] << "," << testcoords[1] << endl; mapInstance->mark(testcoords[0],testcoords[1],5); //***/ // write maps mapInstance->writeToFile("map.txt"); bunker1 = Bunker(HORI_SIZE, VERTI_SIZE, 800, 0, 1200, bunkerTextures); bunker2 = Bunker(HORI_SIZE, VERTI_SIZE, 1100, 0, 1200, bunkerTextures); atom1 = Atom(600.0f, PLAYER_EYE_HEIGHT, 1200.0f, 14); //Si atom2 = Atom(650.0f, PLAYER_EYE_HEIGHT, 1200.0f, 8); //Oxygen atom3 = Atom(700.0f, PLAYER_EYE_HEIGHT, 1200.0f, 1); //Hydrogen building1 = Building(1300, 0, 1200, 200, 100, 60, _textureBuilding); // testing purposes: mapInstance->writeToFile("map2.txt"); hunter1 = new Necromancer(800,0.0f,1300.0f); int waypoints[6*4] = { 1000, 6*PLAYER_EYE_HEIGHT, 1000, 3000, 4*PLAYER_EYE_HEIGHT, 3000, 3000, 6*PLAYER_EYE_HEIGHT, 1000, 1000, 4*PLAYER_EYE_HEIGHT, 3000, 1000, 6*PLAYER_EYE_HEIGHT, 1000, 2500, 4*PLAYER_EYE_HEIGHT, 2500 }; int k = 0; for(k = 0; k<12; k++) { cout << waypoints[k] << endl; } int numWaypoints = 6; FlightPath fp = FlightPath(waypoints, numWaypoints, true); heli = Helicopter(200.0f, 4*PLAYER_EYE_HEIGHT, 200.0f); heli.setFlightPath(fp); sittingDuck1 = SittingDuck(800.0f, PLAYER_EYE_HEIGHT, 100.0f, 5); duckList.push_back(sittingDuck1); glutDisplayFunc(drawScene); glutKeyboardFunc(handleKeypress); glutKeyboardUpFunc(handleKeyrelease); glutPassiveMotionFunc(mouseMotion); glutReshapeFunc(handleResize); glutTimerFunc(25, update, 0); glutMainLoop(); return 0; }
void idle(){ static GLdouble previousTime = 0; GLdouble currentTime; GLdouble timeDifference; currentTime = glutGet(GLUT_ELAPSED_TIME); timeDifference = currentTime - previousTime; previousTime = currentTime; // key control if(keys['a'] == 1 || keys['A'] == 1) player.rotate(-player.getVelHelicoptero() * timeDifference); if(keys['d'] == 1 || keys['D'] == 1) player.rotate(player.getVelHelicoptero() * timeDifference); if(keys['w'] == 1 || keys['W'] == 1){ // checks if next position exceeds boudaries if(!onArena(player, arena.getArena(), -player.getVelHelicoptero() * timeDifference)) player.moveY(-player.getVelHelicoptero() * timeDifference); } if(keys['s'] == 1 || keys['S'] == 1){ // checks if next position exceeds boudaries if(!onArena(player, arena.getArena(), player.getVelHelicoptero() * timeDifference)) player.moveY(player.getVelHelicoptero() * timeDifference); } if(keys['+'] == 1) player.moveHelice(0.1 * timeDifference); if(keys['-'] == 1) player.moveHelice(-0.1 * timeDifference); // enemies conditional movement for(int i = 0; i < enemies.size() ; i++){ float rndm = 40 + (rand() % (int)(180 - 40 + 1)); float vel= -enemies.at(i).getVelHelicoptero() * timeDifference; if(onEnemy(enemies, i)){ enemies.at(i).setCollided(true); }else{ enemies.at(i).setCollided(false); } if(!enemies.at(i).getCollided() && !onArena(enemies.at(i), arena.getArena(), vel)){ enemies.at(i).moveY(vel); }else{ enemies.at(i).rotate(rndm); enemies.at(i).moveY(vel); enemies.at(i).setCollided(false); } } glutPostRedisplay(); }
void RealTimeTest::hover() { Hud *hoverTestingHud = game.getHudsManager()->createHud(HudAlignment::RIGHT); hoverTestingHud->setText("HOVER TESTING STARTED..."); DelayCommand dc(2); DelayCommand wait10s(10); dc.execute(); std::cout << "\nhover test started:" << std::endl; game.getConfiguration()->deactivateFriction(); Helicopter *helicopter = game.getHelicopter(); helicopter->reset(); helicopter->setPosistion(osg::Vec3f(0, 0, 0)); helicopter->getMainRotor()->increaseMagnitude(); helicopter->getMainRotor()->increaseMagnitude(); helicopter->getMainRotor()->increaseMagnitude(); wait10s.execute(); // after 10s should be at position 15m // a = 0.3 // x = 0 + 0*10 + 0.5 * 0.3 * (10)^2 = 15 // v = 0 + a * t // v = 0.3 * 10 = 3 Assert(15.0, helicopter->getPosistion().z(), 1.0e-1); Assert(3.0, helicopter->getVelocity().z(), 1.0e-1); Assert(0.3, helicopter->getAcceleration().z(), 1.0e-1); std::cout << "hover test passed" << std::endl; std::cout << "hover test results:" << std::endl; std::cout << "pz = " << helicopter->getPosistion().z() << std::endl; std::cout << "vz = " << helicopter->getVelocity().z() << std::endl; std::cout << "az = " << helicopter->getAcceleration().z() << std::endl; hoverTestingHud->setText("HOVER TESTING PASSED..."); }
void init() { glClearColor(1.0,1.0,1.0,0.0); //sets the clear colour to yellow //glClear(GL_COLOR_BUFFER_BIT) in the display function//will clear the buffer to this colour. // Shaders if(!myShader.load("BasicView", "glslfiles/basicTransformations.vert", "glslfiles/basicTransformations.frag")) { cout << "failed to load shader" << endl; } if (!cubeShader.load("BasicView", "glslfiles/cubeShader.vert", "glslfiles/cubeShader.frag")) { cout << "failed to load shader" << endl; } cubeOne.setDim(15); cubeOne.constructGeometry(&cubeShader); worldCube.setDim(1000); worldCube.constructGeometry(&cubeShader); glEnable(GL_TEXTURE_2D); copter.loadModel(myShader); prop.loadModel(myShader); world.loadModel(myShader); ground.loadModel(myShader); houseOne.loadModel(myShader, "TestModels/dododododhouse2.obj", glm::vec3(50, 44, 50), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 0); houseTwo.loadModel(myShader, "TestModels/pyramidhouse2.obj", glm::vec3(-1250, 44, 1000), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 0); houseThree.loadModel(myShader, "TestModels/pyramidhouse2.obj", glm::vec3(-500, 44, -500), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 0); houseFour.loadModel(myShader, "TestModels/pyramidhouse2.obj", glm::vec3(1200, 44, 1200), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 0); houseFive.loadModel(myShader, "TestModels/dododododhouse2.obj", glm::vec3(50, 44, -1150), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 0); houseSix.loadModel(myShader, "TestModels/dododododhouse2.obj", glm::vec3(-900, 44, -500), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 0); treeOne.loadModel(myShader, "TestModels/tree.obj", glm::vec3(250, 20, 250), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeTwo.loadModel(myShader, "TestModels/tree.obj", glm::vec3(350, 20, 250), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeThree.loadModel(myShader, "TestModels/tree.obj", glm::vec3(300, 20, 250), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeFour.loadModel(myShader, "TestModels/tree.obj", glm::vec3(0, 20, 750), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeFive.loadModel(myShader, "TestModels/tree.obj", glm::vec3(200, 20, 180), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeOne.loadModel(myShader, "TestModels/tree.obj", glm::vec3(-900, 20, 580), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeTwo.loadModel(myShader, "TestModels/tree.obj", glm::vec3(1040, 20, 1050), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeThree.loadModel(myShader, "TestModels/tree.obj", glm::vec3(-1260, 20, -250), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeFour.loadModel(myShader, "TestModels/tree.obj", glm::vec3(1270, 20, 250), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); treeFive.loadModel(myShader, "TestModels/tree.obj", glm::vec3(-230, 20, 250), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); leafOne.loadModel(myShader, "TestModels/leaf.obj", glm::vec3(150, -10, 580), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); leafTwo.loadModel(myShader, "TestModels/leaf.obj", glm::vec3(170, -10, 530), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); leafThree.loadModel(myShader, "TestModels/leaf.obj", glm::vec3(150, -10, 550), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); leafFour.loadModel(myShader, "TestModels/leaf.obj", glm::vec3(150, -10, 510), glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, glm::vec4{ 0.8, 0.8, 0.8, 1.0 }, 50); houses.push_back(houseOne); houses.push_back(houseTwo); houses.push_back(houseThree); houses.push_back(houseFour); houses.push_back(houseFive); houses.push_back(houseSix); trees.push_back(treeOne); trees.push_back(treeTwo); trees.push_back(treeThree); trees.push_back(treeFour); trees.push_back(treeFive); trees.push_back(treeSix); trees.push_back(treeSeven); trees.push_back(treeEight); trees.push_back(treeNine); trees.push_back(treeTen); leafs.push_back(leafOne); leafs.push_back(leafTwo); leafs.push_back(leafThree); leafs.push_back(leafFour); glEnable(GL_DEPTH_TEST); }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glm::mat4 ViewMatrix; glm::vec3 cameraPos; glm::vec3 fpLookat; switch (camNum) { case 1://normal benhind copter rotates with copter cameraPos = glm::vec3(0, -8, 35); cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0)); ViewMatrix = glm::lookAt(cameraPos, copter.position, glm::vec3(0, 1, 0)); break; case 2://birdseye cameraPos = glm::vec3(0,-60,1); cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0)); ViewMatrix = glm::lookAt(cameraPos, copter.position, glm::vec3(0, 1, 0)); break; case 3://first person fpLookat = glm::vec3(0, -5, -60); fpLookat = copter.position - glm::rotate(fpLookat, spinY, glm::vec3(0, 1, 0)); cameraPos = glm::vec3(0, 0, -25); //cameraPos = glm::rotate(cameraPos, -tiltZ, glm::vec3(1, 0, 0)); //cameraPos = glm::rotate(cameraPos, -tiltX, glm::vec3(0, 0, 1)); cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0)); ViewMatrix = glm::lookAt(cameraPos, fpLookat, glm::vec3(0, 1, 0)); break; case 4://side view cameraPos = glm::vec3(50, 0, 1); cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0)); ViewMatrix = glm::lookAt(cameraPos, copter.position, glm::vec3(0, 1, 0)); break; case 5://cinematic cameraPos = glm::vec3(100, 100, 100); ViewMatrix = glm::lookAt(cameraPos, copter.position, glm::vec3(0, 1, 0)); break; default: cameraPos = glm::vec3(0, -8, 35); cameraPos = copter.position - glm::rotate(cameraPos, spinY, glm::vec3(0, 1, 0)); ViewMatrix = glm::lookAt(cameraPos, copter.position, glm::vec3(0, 1, 0)); } glUseProgram(cubeShader.handle()); //All of our geometry will have the same projection matrix. //we only need to set it once, since we are using the same shader. GLuint matLocation = glGetUniformLocation(cubeShader.handle(), "ProjectionMatrix"); glUniformMatrix4fv(matLocation, 1, GL_FALSE, &ProjectionMatrix[0][0]); cubeOne.ModelViewMatrix = glm::translate(ViewMatrix, glm::vec3(0, 20, 0)); glUniformMatrix4fv(glGetUniformLocation(cubeShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &cubeOne.ModelViewMatrix[0][0]); //cubeOne.render(); worldCube.ModelViewMatrix = glm::translate(ViewMatrix, glm::vec3(0, 0, 0)); glUniformMatrix4fv(glGetUniformLocation(cubeShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &worldCube.ModelViewMatrix[0][0]); //worldCube.render(); glUseProgram(0); glUseProgram(myShader.handle()); // use the shader glUniform1f(glGetUniformLocation(myShader.handle(), "displacement"), amount); glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ProjectionMatrix"), 1, GL_FALSE, &ProjectionMatrix[0][0]); //viewMatrix = glm::lookAt(glm::vec3(0, 0, -100), glm::vec3(30, 0, 0), //glm::vec3(0, 1, 0)); glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ViewMatrix"), 1, GL_FALSE, &ViewMatrix[0][0]); //Changing from daylight to night setting //Lighting Properties passed to the shader if (dayNight == 0) { Light_Ambient_And_Diffuse = glm::vec4{ 0.8, 0.8, 0.6, 1.0 }; Light_Specular = glm::vec4{ 0.8, 0.8, 0.8, 1.0 }; } else { Light_Ambient_And_Diffuse = glm::vec4{ 0.2, 0.2, 0.2, 1.0 }; Light_Specular = glm::vec4{ 0.2, 0.2, 0.2, 1.0 }; } glUniform4fv(glGetUniformLocation(myShader.handle(), "LightPos"), 1, &LightPos[0]); glUniform4fv(glGetUniformLocation(myShader.handle(), "light_ambient"), 1, &Light_Ambient_And_Diffuse[0]); glUniform4fv(glGetUniformLocation(myShader.handle(), "light_diffuse"), 1, &Light_Ambient_And_Diffuse[0]); glUniform4fv(glGetUniformLocation(myShader.handle(), "light_specular"), 1, &Light_Specular[0]); //DRAW THE MODEL copter.ModelViewMatrix = glm::translate(ViewMatrix, copter.position); copter.ModelViewMatrix = glm::rotate(copter.ModelViewMatrix, spinY, glm::vec3(0, 1, 0)); //rotate object about y axis copter.ModelViewMatrix = glm::rotate(copter.ModelViewMatrix, tiltX, glm::vec3(0, 0, 1)); //tilts the cube around x copter.ModelViewMatrix = glm::rotate(copter.ModelViewMatrix, tiltZ, glm::vec3(1, 0, 0)); //tilts the cube around z //Pass the uniform for the modelview matrix glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &copter.ModelViewMatrix[0][0]); glm::mat4 normalMatrix; glm::mat4 NormalMatrix = ModelViewMatrix * normalMatrix; glUniformMatrix3fv(glGetUniformLocation(myShader.handle(), "NormalMatrix"), 1, GL_FALSE, &normalMatrix[0][0]); copter.render(); //model.drawElementsUsingVBO(&myShader); //prop.ModelViewMatrix = glm::translate(prop.ModelViewMatrix, glm::vec3(0, 0, 0)); prop.ModelViewMatrix = copter.ModelViewMatrix; prop.render(propSpin); //Drawing the world world.ModelViewMatrix = glm::translate(ViewMatrix, glm::vec3(0, 1790, 0)); glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &world.ModelViewMatrix[0][0]); world.render(); ground.ModelViewMatrix = glm::translate(ViewMatrix, glm::vec3(0, -55, 0)); glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &ground.ModelViewMatrix[0][0]); ground.render(); //for (int i = 0; i < houses.size(); i++) //{ // houses[i].render(ViewMatrix); //} //for (int i = 0; i < trees.size(); i++) //{ // trees[i].render(ViewMatrix); //} houseOne.render(ViewMatrix); houseTwo.render(ViewMatrix); houseThree.render(ViewMatrix); houseFour.render(ViewMatrix); houseFive.render(ViewMatrix); houseSix.render(ViewMatrix); treeOne.render(ViewMatrix); treeTwo.render(ViewMatrix); treeThree.render(ViewMatrix); treeFour.render(ViewMatrix); treeFive.render(ViewMatrix); treeSix.render(ViewMatrix); treeSeven.render(ViewMatrix); treeEight.render(ViewMatrix); treeNine.render(ViewMatrix); treeTen.render(ViewMatrix); leafOne.render(ViewMatrix); leafTwo.render(ViewMatrix); leafThree.render(ViewMatrix); leafFour.render(ViewMatrix); glUseProgram(0); //turn off the current shader }