HudMessage::HudMessage(float x, float y, float z) : Entity(1) { current_position[0] = x; current_position[1] = y; current_position[2] = z; glGenTextures(2, TextureArray); TGA_Texture(TextureArray, "pausegame.tga", 0); TGA_Texture(TextureArray, "gameover.tga", 1); }
Orange::Orange() : Entity(1) { initial_velocity[0] = 0.2f + (rand() % 100) / 100; initial_velocity[1] = 0; initial_velocity[2] = 0.2f + (rand() % 100) / 100; glGenTextures(1, TextureArray); TGA_Texture(TextureArray, "orange.tga", 0); box = new Box(current_position[0], current_position[2], 3.0); }
HudMessage::HudMessage() : Entity(1) { glGenTextures(2, TextureArray); TGA_Texture(TextureArray, "pausegame.tga", 0); TGA_Texture(TextureArray, "gameover.tga", 1); }
void init() { gameScore = 0; //Texture Object definition glGenTextures(12, textureArray); TGA_Texture(textureArray, "stone.tga", 0); TGA_Texture(textureArray, "checker.tga", 1); TGA_Texture(textureArray, "pause.tga", 2); TGA_Texture(textureArray, "death.tga", 3); TGA_Texture(textureArray, "tree.tga", 4); TGA_Texture(textureArray, "particle.tga", 5); TGA_Texture(textureArray, "lensFlare/Flare1.tga", 6); TGA_Texture(textureArray, "lensFlare/Flare2.tga", 7); TGA_Texture(textureArray, "lensFlare/Flare3.tga", 8); TGA_Texture(textureArray, "lensFlare/Flare4.tga", 9); TGA_Texture(textureArray, "lensFlare/Sun.tga", 10); TGA_Texture(textureArray, "lensFlare/SunLight.tga", 11); srand(time(NULL)); for (int i = 0; i < 10; i++) { Car* life = new Car(); life->setPosition(-5.0f + 0.5f*i, -4.0, 5.0f); _lives.push_back(life); } car.setPosition(0.0f, 0.45f, 2.8f); carX = car.getPosition().getX(); carY = car.getPosition().getY(); carZ = car.getPosition().getZ(); std::vector<Car> cars; cars.push_back(car); orangeArray.push_back(orange1); orangeArray.push_back(orange2); orangeArray.push_back(orange3); for (int i = 0; i < orangeArray.size(); i++) { orangeArray[i].init(); } staticObjects.push_back(&butter1); staticObjects.push_back(&butter2); staticObjects.push_back(&butter1ref); staticObjects.push_back(&butter2ref); for (int i = 0; i < 128; i++) { Cheerio* cheerio = new Cheerio(); cheerioArray.push_back(*cheerio); } float xBot = 2.4f; float yBot = 2.5f; float xTop = -2.4f; float yTop = -3.6f; float xRight = 2.4f; float yRight = -2.1f; float xLeft = -2.4f; float yLeft = -2.1f; for (int i = 0; i < 17; i++) { cheerioArray[i].setPosition(xBot - 0.3f * i, 0.52f, yBot); cheerioArray[i+17].setPosition(xBot - 0.3f * i, 0.52f, yBot + 1.2f); cheerioArray[i+34].setPosition(xTop + 0.3f * i, 0.52f, yTop); cheerioArray[i+51].setPosition(xTop + 0.3f * i, 0.52f, yTop + 1.2f); } for (int i = 0; i < 15; i++) { cheerioArray[i+68].setPosition(xRight, 0.52f, yRight + 0.3f * i); cheerioArray[i+83].setPosition(xRight + 1.2f, 0.52f, yRight + 0.3f * i); cheerioArray[i+98].setPosition(xLeft, 0.52f, yLeft + 0.3f * i); cheerioArray[i+113].setPosition(xLeft - 1.2f, 0.52f, yLeft + 0.3f * i); } butter1.setPosition(3.6f, 0.5f, 3.0f); butter2.setPosition(-3.4f, 0.5f, -4.0f); butter1ref.setPosition(3.6f, 0.5f, 3.0f); butter2ref.setPosition(-3.4f, 0.5f, -4.0f); table.setPosition(-4.5, 0.5f, -4.5f); pauseScreen.setPosition(-2.5, -2.5, 5.0f); deathScreen.setPosition(-2.5, -2.5, 5.0f); HUDbg.setPosition(-5.5, -4.0, 0.0f); broccoli[0].setPosition(1.5f, 0.5f, 1.5f); broccoli[1].setPosition(1.5f, 0.5f, -1.5f); broccoli[2].setPosition(-1.5f, 0.5f, -1.5f); broccoli[3].setPosition(-1.5f, 0.5f, 1.5f); sun.setPosition(5.0f, 2.0f, -5.0f); cup.setPosition(-1.5f, 1.0f, 0.0f); speed = Vector3(0.0f, 0.0f, 0.0f); // set the camera position based on its spherical coordinates camX = r * sin(alpha * 3.14f / 180.0f) * cos(beta * 3.14f / 180.0f); camZ = r * cos(alpha * 3.14f / 180.0f) * cos(beta * 3.14f / 180.0f); camY = r * sin(beta * 3.14f / 180.0f); float amb[]= {0.2f, 0.15f, 0.1f, 1.0f}; float diff[] = {0.8f, 0.6f, 0.4f, 1.0f}; float spec[] = {0.8f, 0.8f, 0.8f, 1.0f}; float emissive[] = {0.0f, 0.0f, 0.0f, 1.0f}; float shininess= 100.0f; int texcount = 0; // create geometry and VAO of the pawn objId=0; memcpy(mesh[objId].mat.ambient, amb,4*sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff,4*sizeof(float)); memcpy(mesh[objId].mat.specular, spec,4*sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive,4*sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); float amb1[] = { 0.1f, 0.1f, 0.1f, 1.0f }; float diff1[] = { 0.4f, 0.4f, 0.4f, 1.0f }; float spec1[] = { 0.5f, 0.5f, 0.5f, 1.0f }; shininess = 50.0f; // create geometry and VAO of the sphere objId=1; memcpy(mesh[objId].mat.ambient, amb1,4*sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff1,4*sizeof(float)); memcpy(mesh[objId].mat.specular, spec1,4*sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive,4*sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); // create geometry and VAO of the cylinder float amb2[] = { 0.2f, 0.2f, 0.2f, 1.0f }; float diff2[] = { 0.8f, 0.8f, 0.8f, 1.0f }; float spec2[] = { 0.9f, 0.9f, 0.9f, 1.0f }; shininess = 50.0f; objId=2; memcpy(mesh[objId].mat.ambient, amb2,4*sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff2,4*sizeof(float)); memcpy(mesh[objId].mat.specular, spec2,4*sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive,4*sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); float amb3[] = { 0.1f, 0.075f, 0.0f, 1.0f }; float diff3[] = { 0.8f, 0.6f, 0.0f, 1.0f }; float spec3[] = { 0.3f, 0.3f, 0.3f, 1.0f }; shininess = 50.0f; // create geometry and VAO of the objId=3; memcpy(mesh[objId].mat.ambient, amb3,4*sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff3,4*sizeof(float)); memcpy(mesh[objId].mat.specular, spec3,4*sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive,4*sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createTorus(0.04f, 0.1f, 6, 10); //BlackWheels objId = 4; float amb4[] = { 0.0f, 0.0f, 0.0f, 1.0f }; float diff4[] = { 0.3f, 0.3f, 0.3f, 1.0f }; float spec4[] = { 0.5f, 0.5f, 0.5f, 1.0f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb4, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff4, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec4, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createTorus(1.0f, 3.0f, 6, 12); //CarBiggerCube objId = 5; float amb5[] = { 0.025f, 0.025f, 0.1f, 1.0f }; float diff5[] = { 0.1f, 0.1f, 0.4f, 1.0f }; float spec5[] = { 0.9f, 0.9f, 0.9f, 1.0f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb5, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff5, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec5, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); //CarSmallerCube objId = 6; float amb6[] = { 0.0f, 0.2f, 0.0f, 1.0f }; float diff6[] = { 0.0f, 0.8f, 0.0f, 1.0f }; float spec6[] = { 0.9f, 0.9f, 0.9f, 1.0f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb6, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff6, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec6, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); car.addMesh(&mesh[4]); car.addMesh(&mesh[5]); car.addMesh(&mesh[6]); for (Car* life : _lives) { life->addMesh(&mesh[4]); life->addMesh(&mesh[5]); life->addMesh(&mesh[6]); } butter1.addMesh(&mesh[5]); butter2.addMesh(&mesh[5]); butter1ref.addMesh(&mesh[5]); butter2ref.addMesh(&mesh[5]); butter1ref.reflect(); butter2ref.reflect(); table.addMesh(&mesh[0]); pauseScreen.addMesh(&mesh[0]); pauseScreen.addTexture(textureArray[2]); pauseScreen.addTexture(textureArray[2]); deathScreen.addMesh(&mesh[0]); deathScreen.addTexture(textureArray[3]); deathScreen.addTexture(textureArray[3]); HUDbg.addMesh(&mesh[2]); road.addMesh(&mesh[1]); road.addMesh(&mesh[2]); road.addTexture(textureArray[0]); road.addTexture(textureArray[1]); for (int i = 0; i < 128; i++) { cheerioArray[i].addMesh(&mesh[3]); } //Orange objId = 7; float amb7[] = { 0.2f, 0.1f, 0.025f, 1.0f }; float diff7[] = { 0.8f, 0.4f, 0.1f, 1.0f }; float spec7[] = { 0.0f, 0.0f, 0.0f, 1.0f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb7, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff7, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec7, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createSphere(1.0, 9); for (int i = 0; i < orangeArray.size(); i++) { orangeArray[i].addMesh(&mesh[7]); } //Quad objId = 8; float amb8[] = { 0.1f, 0.1f, 0.1f, 1.0f }; float diff8[] = { 0.6f, 0.6f, 0.6f, 1.0f }; memcpy(mesh[objId].mat.ambient, amb8, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff8, 4 * sizeof(float)); createCube(); for (int i = 0; i < 4; i++) { broccoli[i].addMesh(&mesh[8]); broccoli[i].addTexture(textureArray[4]); } //Cup objId = 9; float amb9[] = { 0.1f, 0.1f, 0.7f, 0.3f }; float diff9[] = { 0.1f, 0.1f, 0.4f, 0.1f }; float spec9[] = { 0.9f, 0.9f, 0.9f, 0.3f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb9, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff9, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec9, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createTorus(0.9f, 1.0f, 32, 12); objId = 10; memcpy(mesh[objId].mat.ambient, amb9, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff9, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec9, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createSphere(1.0, 9); cup.addMesh(&mesh[9]); cup.addMesh(&mesh[10]); //SUN objId = 11; float amb11[] = { 1.0f, 1.0f, 1.0f, 1.0f }; memcpy(mesh[objId].mat.ambient, amb11, 4 * sizeof(float)); createCube(); sun.addMesh(&mesh[11]); sun.addTexture(textureArray[10]); sun.addTexture(textureArray[10]); // some GL settings glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_MULTISAMPLE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.5f, 0.5f, 0.5f, 1.0f); //lights _directional_light.setPosition(0.0f, 1.0f, 0.0f, 0.0f); //4th parameter == 0 => directional light _directional_light.setEnabled(true); LightSource *l1 = new LightSource(); l1->setPosition(2.5f, 1.0f, 2.5f, 1.0f); l1->setEnabled(true); l1->setLocal(true); _lamps.push_back(l1); LightSource *l2 = new LightSource(); l2->setPosition(2.5f, 1.0f, -2.5f, 1.0f); l2->setEnabled(true); l2->setLocal(true); _lamps.push_back(l2); LightSource *l3 = new LightSource(); l3->setPosition(0.0f, 1.0f, 2.5f, 1.0f); l3->setEnabled(true); l3->setLocal(true); _lamps.push_back(l3); LightSource *l4 = new LightSource(); l4->setPosition(0.0f, 1.0f, -2.5f, 1.0f); l4->setEnabled(true); l4->setLocal(true); _lamps.push_back(l4); LightSource *l5 = new LightSource(); l5->setPosition(-2.5f, 1.0f, 2.5f, 1.0f); l5->setEnabled(true); l5->setLocal(true); _lamps.push_back(l5); LightSource *l6 = new LightSource(); l6->setPosition(-2.5f, 1.0f, -2.5f, 1.0f); l6->setEnabled(true); l6->setLocal(true); _lamps.push_back(l6); LightSource *spot1 = new LightSource(); spot1->setEnabled(true); spot1->setLocal(true); spot1->setSpot(true); float cutOff = 2.0f; spot1->setCutOff(cutOff); spot1->setExponent(0.2f); _spotLights.push_back(spot1); LightSource *spot2 = new LightSource(); spot2->setEnabled(true); spot2->setLocal(true); spot2->setSpot(true); cutOff = 2.0f; spot2->setCutOff(cutOff); spot2->setExponent(0.2f); _spotLights.push_back(spot2); // create cameras PerspectiveCamera* p1 = new PerspectiveCamera(53.13f, 0.1f, 1000.0f); _cameras.push_back(p1); OrtogonalCamera* ortho = new OrtogonalCamera(-5, 5, -5, 5, -100, 100); _cameras.push_back(ortho); PerspectiveCamera* p2 = new PerspectiveCamera(53.13f, 0.1f, 1000.0f); _cameras.push_back(p2); _hudCamera = new OrtogonalCamera(-5, 5, -5, 5, -100, 100); // create geometry and VAO of the quad for particles objId = 11; mesh[objId].mat.texCount = texcount; createQuad(2, 2); //particles.init(); }