diff --git a/cw 6/src/main_6_1.cpp b/cw 6/src/main_6_1.cpp index b5e74bd..ac20f9b 100644 --- a/cw 6/src/main_6_1.cpp +++ b/cw 6/src/main_6_1.cpp @@ -40,7 +40,6 @@ static int showCaustics = 1, causticMotion = 1; static int useMipmaps = 1; static int currentCaustic = 0; static int causticIncrement = 1; -static int NUMBER_OF_BUBBLES = 500; static float lightAngle = 0.0, lightHeight = 20; static GLfloat angle = -150; /* in degrees */ @@ -48,11 +47,11 @@ static GLfloat angle2 = 30; /* in degrees */ -CONST int fish1Number = 100; +CONST int fish1Number = 150; float fishRotation1[fish1Number]; glm::vec3 fishLocation[fish1Number]; -CONST int fish2Number = 100; +CONST int fish2Number = 150; float fishRotation2[fish2Number]; glm::vec3 fishLocation2[fish2Number]; @@ -112,14 +111,16 @@ int WIN_WIDTH = 1280; int WIN_HEIGHT = 720; float sea_bottom_y_pos = -3.f; -const int amount_of_marine_plants = 150; +const int amount_of_marine_plants = 300; glm::vec3 marinePlantsLocation[amount_of_marine_plants]; -glm::vec3 planetLocation[100]; -glm::vec3 bubbleLocation[500]; -glm::vec3 bubbleOriginalLocation[500]; -bool bubbleZdir[500] ; -bool bubbleXdir[500] ; +glm::vec3 planetLocation[amount_of_marine_plants]; + +CONST int bubbleQuantity = 150; +glm::vec3 bubbleLocation[bubbleQuantity]; +glm::vec3 bubbleOriginalLocation[bubbleQuantity]; +bool bubbleZdir[bubbleQuantity]; +bool bubbleXdir[bubbleQuantity]; float mouseXPosition; float mouseYPosition; @@ -144,6 +145,8 @@ float vehicleAngleSpeed = 0.0f; float vehicleVerticalSpeed = 0.0f; bool directionChanged = false; +bool freecam = false; + glm::vec3 starLocation; bool starIsPlaced = false; @@ -173,7 +176,8 @@ void keyboard(unsigned char key, int x, int y) //case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(1, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break; //case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(1, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break; - case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(vehicleAngle, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break; + case 'h': if (freecam == true) { freecam = false; } + else { freecam = true; }; break; //delta_x = 0; delta_y = 0; cameraPos = glm::vec3(0, 0, 5); rotation = glm::quat(1, 0, 0, 0); dy = 0; dx = 0; mouseXPositionLast = mouseXPosition; mouseYPositionLast = mouseYPosition; //glutWarpPointer(WIN_WIDTH / 2, WIN_HEIGHT/ 2); @@ -232,32 +236,47 @@ void changeVehicleSpeed() { } +//glutWarpPointer(WIN_WIDTH / 2, WIN_HEIGHT/ 2); + +float Xrotation = 0; +float Yrotation = 0; void mouse(int x, int y) { + + mouseXPosition = x - WIN_WIDTH / 2; + mouseYPosition = y - WIN_HEIGHT / 2; + + Xrotation += mouseXPosition; + Yrotation += mouseYPosition; + if (mouseXPositionLast >= 0) { delta_x = x - mouseXPositionLast; delta_y = y - mouseYPositionLast; } mouseXPositionLast = x; mouseYPositionLast = y; + + glutWarpPointer(WIN_WIDTH / 2, WIN_HEIGHT / 2); } -bool freecam = false; + glm::mat4 createCameraMatrix() { //trzymanie freecama do usuni�cia freecam = false; //delta_x = delta_x + vehicleAngle; - glm::quat rot_x = glm::angleAxis(delta_y, glm::vec3(1, 0, 0)); - glm::quat rot_y = glm::angleAxis(delta_x, glm::vec3(0, 1, 0)); + glm::quat rot_x = glm::angleAxis(Yrotation, glm::vec3(1, 0, 0)); + glm::quat rot_y = glm::angleAxis(Xrotation, glm::vec3(0, 1, 0)); dy += delta_y; dx += delta_x; delta_x = 0; delta_y = 0; + + rotation_x = glm::normalize(rot_x * rotation_x); rotation_y = glm::normalize(rot_y * rotation_y); @@ -495,6 +514,8 @@ void checkIfStarIsNearby() { } } +float coinRotation = 0.0f; + void gameManager() { checkIfStarIsNearby(); @@ -502,22 +523,25 @@ void gameManager() { if (!starIsPlaced) { starLocation.x = (((float)rand() / (float)(RAND_MAX)) * 10) - 6; - starLocation.y = (((float)rand() / (float)(RAND_MAX)) * 10) - 6; + starLocation.y = (((float)rand() / (float)(RAND_MAX)) * 10); starLocation.z = (((float)rand() / (float)(RAND_MAX)) * 10) - 6; starIsPlaced = true; printf("starplaced"); } - glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, -0.2, -0.05)); + glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0.0)); glm::vec3 shipScale = glm::vec3(1., 1., 1.); shipInitialTransformation = glm::scale(shipInitialTransformation, shipScale); shipInitialTransformation = shipInitialTransformation * glm::translate(glm::vec3(0, 0, 0)) * glm::scale(glm::vec3(0.1f)); - glm::mat4 shipModelMatrix = glm::translate(starLocation /* + vehicleDir */) * glm::rotate(-vehicleAngle + 30, glm::vec3(0, 1, 0)) * shipInitialTransformation; + glm::mat4 shipModelMatrix = glm::translate(starLocation /* + vehicleDir */) * glm::rotate(coinRotation, glm::vec3(0, 1, 0)) * shipInitialTransformation; + coinRotation += 0.02; drawObjectTexture(coinContext, shipModelMatrix, coinTexture); } +float fishXTranslation = 0.0f; + void drawScene() { glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, -0.2, -0.05)); @@ -543,7 +567,7 @@ void drawScene() for (int i = 0; i < fish1Number; i++) { float time = glutGet(GLUT_ELAPSED_TIME) / 1000.f; - glm::mat4 modelMatrix = glm::translate(fishLocation[i]) * glm::rotate(glm::radians(fishRotation1[i]), glm::vec3(0.f, 1.f, 0.f)) * glm::translate(glm::vec3(time, 0, 0)); + glm::mat4 modelMatrix = glm::translate(fishLocation[i]) * glm::rotate(glm::radians(fishRotation1[i]), glm::vec3(0.f, 1.f, 0.f)) * glm::translate(glm::vec3(fishXTranslation, 0, 0)); // Scaling models glm::vec3 scale = glm::vec3(0.002, 0.002, 0.002); modelMatrix = glm::scale(modelMatrix, scale); @@ -554,7 +578,7 @@ void drawScene() for (int i = 0; i < fish2Number; i++) { float time = glutGet(GLUT_ELAPSED_TIME) / 2000.f; - glm::mat4 modelMatrix = glm::translate(fishLocation2[i]) * glm::rotate(glm::radians(fishRotation2[i]), glm::vec3(0.f, 1.f, 0.f)) * glm::translate(glm::vec3(time, 0, 0)) * glm::rotate(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)); + glm::mat4 modelMatrix = glm::translate(fishLocation2[i]) * glm::rotate(glm::radians(fishRotation2[i]), glm::vec3(0.f, 1.f, 0.f)) * glm::translate(glm::vec3(fishXTranslation, 0, 0)) * glm::rotate(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)); // Scaling models glm::vec3 scale = glm::vec3(0.1, 0.1, 0.1); modelMatrix = glm::scale(modelMatrix, scale); @@ -562,6 +586,12 @@ void drawScene() drawObjectTexture(fish2Context, modelMatrix, textureFish02); } + fishXTranslation += 0.03; + + if (fishXTranslation > 40) { + fishXTranslation = -40; + } + int i = 0; while (i < amount_of_marine_plants) { @@ -573,7 +603,7 @@ void drawScene() modelMatrix = glm::scale(modelInitialMatrix, scale); drawObjectTexture(smallCoralContext, modelMatrix, smallCoralTexture); i++; - if (i == amount_of_marine_plants) { break;} + if (i == amount_of_marine_plants) { break; } // Model 2 modelInitialMatrix = glm::translate(glm::vec3(marinePlantsLocation[i][0], sea_bottom_y_pos - .7f, marinePlantsLocation[i][2])) * glm::rotate(glm::radians(-45.f), glm::vec3(0.f, 0.f, 1.f)) * glm::rotate(glm::radians(-15.f), glm::vec3(1.f, 0.f, 0.f)); @@ -647,7 +677,7 @@ void drawScene() } void bubbleMovement(int i) { - + float bubbleWobblingDivider = 100; int x = floor(bubbleLocation[i].x); @@ -661,31 +691,32 @@ void bubbleMovement(int i) { //printf(xDir ? "true\n" : "false\n"); //printf(zDir ? "true\n" : "false\n"); - if (bubbleLocation[i].x > bubbleOriginalLocation[i].x + bubbleWobbling * bubbleWobblingDivider ) { - + if (bubbleLocation[i].x > bubbleOriginalLocation[i].x + bubbleWobbling * bubbleWobblingDivider) { + bubbleXdir[i] = false; //printf("herex1\n"); } - if (bubbleLocation[i].x < bubbleOriginalLocation[i].x - bubbleWobbling * bubbleWobblingDivider){ + if (bubbleLocation[i].x < bubbleOriginalLocation[i].x - bubbleWobbling * bubbleWobblingDivider) { bubbleXdir[i] = true; //printf("herex2\n"); } if (bubbleLocation[i].z > bubbleOriginalLocation[i].z + bubbleWobbling * bubbleWobblingDivider) { - bubbleZdir[i] = false; + bubbleZdir[i] = false; } if (bubbleLocation[i].z < bubbleOriginalLocation[i].z - bubbleWobbling * bubbleWobblingDivider) { - bubbleZdir[i] = true; + bubbleZdir[i] = true; } - + if (bubbleXdir[i]) { bubbleLocation[i].x += bubbleWobbling; - } else { + } + else { bubbleLocation[i].x -= bubbleWobbling; } - if (bubbleZdir[i] ) { + if (bubbleZdir[i]) { bubbleLocation[i].z += bubbleWobbling; } else { @@ -702,7 +733,7 @@ void bubbleMovement(int i) { void bubbleManager() { - for (int i = 0; i < NUMBER_OF_BUBBLES; i++) + for (int i = 0; i < bubbleQuantity; i++) { bubbleMovement(i); @@ -812,74 +843,7 @@ void renderScene() } } -/** -void renderScene() -{ - // Aktualizacja macierzy widoku i rzutowania - cameraMatrix = createCameraMatrix(); - perspectiveMatrix = Core::createPerspectiveMatrix(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glClearColor(0.0f, 0.1f, 0.3f, 1.0f); - - glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0)); - // Scaling models - glm::vec3 shipScale = glm::vec3(0.01, 0.01, 0.01); - shipInitialTransformation = glm::scale(shipInitialTransformation, shipScale); - - shipInitialTransformation = shipInitialTransformation * glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.5f)); - glm::mat4 shipModelMatrix = glm::translate(vehiclePos + vehicleDir) * glm::rotate(-vehicleAngle, glm::vec3(0, 1, 0)) * shipInitialTransformation; - drawObjectColor(shipContext, shipModelMatrix, glm::vec3(0.6f)); - - - glm::mat4 modelMatrix = glm::translate(glm::vec3(0, 0, 0)); - // Scaling models - glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001); - modelMatrix = glm::scale(modelMatrix, scale); - - drawObjectTexture(fishContext, modelMatrix, textureFish01); - - for (int i = 0; i < 10; i++) - { - - glm::mat4 modelMatrix = glm::translate(planetLocation[i]); - // Scaling models - glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001); - modelMatrix = glm::scale(modelMatrix, scale); - - drawObjectTexture(fishContext, modelMatrix, textureFish01); - } - - drawPlaneTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture); - - glUseProgram(skyboxTexture); - glUniform1i(glGetUniformLocation(skyboxTexture, "skybox"), 0); - glm::mat4 transformation = perspectiveMatrix * glm::mat4(glm::mat3(cameraMatrix)); - glUniformMatrix4fv(glGetUniformLocation(skyboxTexture, "projectionView"), 1, GL_FALSE, (float*)&transformation); - //Przypisanie VAO i rysowanie skyboxa - glBindVertexArray(skyboxVAO); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture); - glDrawArrays(GL_TRIANGLES, 0, 36); - glBindVertexArray(0); - - //Pr�ba mg�y - glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // We'll Clear To The Color Of The Fog ( Modified ) - float color[] = { 0.5f, 0.5f, 0.5f, 1.0f }; - glFogi(GL_FOG_MODE, GL_EXP2); // Fog Mode - glFogfv(GL_FOG_COLOR, color); // Set Fog Color - glFogf(GL_FOG_DENSITY, 0.35f); // How Dense Will The Fog Be - glHint(GL_FOG_HINT, GL_DONT_CARE); // Fog Hint Value - glFogf(GL_FOG_START, 1.0f); // Fog Start Depth - glFogf(GL_FOG_END, 5.0f); // Fog End Depth - glEnable(GL_FOG); - - glDepthFunc(GL_LESS); - - - - glutSwapBuffers(); -}**/ void loadModelToContext(std::string path, Core::RenderContext& context) { @@ -906,13 +870,13 @@ void init() for (int i = 0; i < amount_of_marine_plants; i++) { - marinePlantsLocation[i] = glm::ballRand(35.0); + marinePlantsLocation[i] = glm::ballRand(20.0); } - for (int i = 0; i < NUMBER_OF_BUBBLES; i++) + for (int i = 0; i < bubbleQuantity; i++) { // srand(time(NULL)); - float MAX_NUM = 100.0; + float MAX_NUM = 20.0; bubbleLocation[i].x = (((float)rand() / (float)(RAND_MAX)) * MAX_NUM) - MAX_NUM / 2; bubbleLocation[i].y = (((float)rand() / (float)(RAND_MAX)) * 10) - 5; @@ -975,11 +939,11 @@ void init() for (int i = 0; i < fish1Number; i++) { - fishLocation[i] = glm::ballRand(59.0); + fishLocation[i] = glm::ballRand(20.0); } for (int i = 0; i < fish2Number; i++) { - fishLocation2[i] = glm::ballRand(59.0); + fishLocation2[i] = glm::ballRand(20.0); } for (int i = 0; i < fish1Number; i++) {