From 6ad07de5ddaef83d6c27adb9780ff0701a88273d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ciesi=C3=B3=C5=82ka?= Date: Thu, 26 Jan 2023 23:18:34 +0100 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20'src'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ex_9_1.hpp | 90 +++++++++++++++++++++++++++++++++++++++----------- src/main.cpp | 4 ++- 2 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/ex_9_1.hpp b/src/ex_9_1.hpp index 8217a80..8347470 100644 --- a/src/ex_9_1.hpp +++ b/src/ex_9_1.hpp @@ -19,12 +19,13 @@ const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024; -int WIDTH = 500, HEIGHT = 500; +int WIDTH = 900, HEIGHT = 900; namespace models { Core::RenderContext spaceshipContext; Core::RenderContext sphereContext; + Core::RenderContext windowFrame; Core::RenderContext bookShelf; Core::RenderContext window; Core::RenderContext potPlant; @@ -37,7 +38,7 @@ namespace models { } namespace textures { GLuint sunTexture; - GLuint windowUkTexture; + GLuint windowFrameTexture; GLuint bookShelfTexture; GLuint potPlantTexture; GLuint officeChariTexture; @@ -60,6 +61,21 @@ GLuint programSkybox; bool flashOff = false; +double prevTime = 0.0; +double currTime = 0.0; +double timeDiff; +unsigned int counter = 0; + +glm::vec3 position = glm::vec3(0, 0, 5); +float horizontalAngle = 3.14f; +float verticalAngle = 0.0f; +float speed = 0.1f; +float sensitivity = 100.0f; +double xpos, ypos; +glm::vec3 Position; +glm::vec3 Orientation = glm::vec3(0.0f, 0.0f, -1.0f); +glm::vec3 Up = glm::vec3(0.0f, 1.0f, 0.0f); + Core::Shader_Loader shaderLoader; Core::RenderContext shipContext; @@ -197,12 +213,12 @@ void renderShadowapSun() { glm::mat4 lightVP = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0)); - //drawObjectDepth(sphereContext, - // lightVP, - // glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f))); - //drawObjectDepth(sphereContext, - // lightVP, - // glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f))); + drawObjectDepth(sphereContext, + lightVP, + glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f))); + drawObjectDepth(sphereContext, + lightVP, + glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f))); //drawObjectDepth(models::bedContext, // lightVP, // glm::mat4()); @@ -263,11 +279,11 @@ void renderScene(GLFWwindow* window) drawObjectPBR(models::window, glm::mat4(), - textures::windowUkTexture, + textures::windowFrameTexture, 0.2, 0.1 ); - drawObjectPBR(models::potPlant, glm::mat4() * glm::scale(glm::vec3(0.2f)) * glm::translate(glm::vec3(-5.0f, 3.0f, -6.0f)), + drawObjectPBR(models::potPlant, glm::mat4() * glm::scale(glm::vec3(0.2f)) * glm::translate(glm::vec3(-5.0f, 55.0f, -6.0f)), textures::potPlantTexture, 1.0f, 0.2f @@ -287,7 +303,7 @@ void renderScene(GLFWwindow* window) 0.4f, 0.0f ); - drawObjectPBR(models::desk, glm::mat4() * glm::translate(glm::vec3(-3.0, 0.0, -3.0f)), + drawObjectPBR(models::desk, glm::mat4(), textures::deskTexture, 0.4f, 0.0f @@ -302,6 +318,10 @@ void renderScene(GLFWwindow* window) 0.3f, 0.0f ); + drawObjectPBR(models::windowFrame, glm::mat4(), + textures::windowFrameTexture, + 0.2f, + 0.0f); drawObjectPBR(models::bookShelf, glm::mat4() * glm::scale(glm::vec3(0.01)), textures::bookShelfTexture, 0.4f, @@ -392,26 +412,19 @@ void init(GLFWwindow* window) loadModelToContext("./models/spaceship.obj", models::spaceshipContext); loadModelToContext("./models/sphere.obj", models::sphereContext); + loadModelToContext("./models2/Frame/Frame.obj", models::windowFrame); loadModelToContext("./models2/bookshelf/shelf.obj", models::bookShelf); loadModelToContext("./models2/potplant/Pot.obj", models::potPlant); loadModelToContext("./models2/lamp/Lamp_LOVMANAD_OBJ.obj", models::lamp); loadModelToContext("./models2/door/source/door.obj", models::door); - loadModelToContext("./models2/bed/untitled.obj", models::bed); - loadModelToContext("./models2/ceiling_lamp/ceilinglamp.obj", models::ceilingLamp); - loadModelToContext("./models2/desk/Desk0.5.obj", models::desk); - //loadModelToContext("./models2/chair/Office_chair.obj", models::officeChair); - //loadModelToContext("./models2/window/WindowUK.obj", models::window); - textures::flashlightTexture = Core::LoadTexture("./models/FlashlightTexture.png"); textures::sunTexture = Core::LoadTexture("./models/sun.jpeg"); + textures::windowFrameTexture = Core::LoadTexture("./models2/Frame/frame.png"); textures::bookShelfTexture = Core::LoadTexture("./models2/bookshelf/SHELF_TEXTURE.bmp"); textures::potPlantTexture = Core::LoadTexture("./models2/potplant/b3.bmp"); textures::lampTexture = Core::LoadTexture("./models2/lamp/_Base_color.png"); textures::doorTexture = Core::LoadTexture("./models2/door/textures/Door_albedo.bmp"); - textures::bedTexture = Core::LoadTexture("./models2/bed/bed.png"); - textures::ceilingLampTexture = Core::LoadTexture("./models2/ceiling_lamp/ceilingLamp.png"); - textures::deskTexture = Core::LoadTexture("./models2/desk/defsk.png"); } void shutdown(GLFWwindow* window) @@ -449,6 +462,29 @@ void processInput(GLFWwindow* window) flashOff = false; if (glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS) flashOff = true; + if (glfwGetKey(window, GLFW_KEY_6) == GLFW_RELEASE) + { + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + glfwGetCursorPos(window, &xpos, &ypos); + + float rotX = sensitivity * (float)(xpos - (WIDTH / 2)) / HEIGHT; + float rotY = sensitivity * (float)(ypos - (HEIGHT / 2)) / WIDTH; + + glm::vec3 newOrientation = glm::rotate(spaceshipDir, glm::radians(-rotY), glm::normalize(glm::cross(spaceshipDir, spaceshipUp))); + + + // Decides whether or not the next vertical Orientation is legal or not + if (abs(glm::angle(newOrientation, spaceshipUp) - glm::radians(90.0f)) <= glm::radians(85.0f)) + { + spaceshipDir = newOrientation; + } + + // Rotates the Orientation left and right + spaceshipDir = glm::rotate(spaceshipDir, glm::radians(-rotX), spaceshipUp); + + glfwSetCursorPos(window, WIDTH/2, HEIGHT/2); + } + cameraPos = spaceshipPos - 0.6 * spaceshipDir + glm::vec3(0, 1, 0) * 0.26f; @@ -472,6 +508,20 @@ void processInput(GLFWwindow* window) void renderLoop(GLFWwindow* window) { while (!glfwWindowShouldClose(window)) { + currTime = glfwGetTime(); + timeDiff = currTime - prevTime; + counter++; + + if (timeDiff >= 1.0 / 30.0) + { + std::string FPS = std::to_string((1.0 / timeDiff) * counter); + std::string newTitle = "Super Gra - " + FPS + " FPS"; + glfwSetWindowTitle(window, newTitle.c_str()); + + prevTime = currTime; + counter = 0; + } + processInput(window); renderScene(window); diff --git a/src/main.cpp b/src/main.cpp index 4e939cd..ec792f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,13 +17,15 @@ int main(int argc, char** argv) glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + //glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #endif // tworzenie okna za pomoca glfw - GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(900, 900, "FirstWindow", NULL, NULL); + glfwSetWindowPos(window, 500, 30); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl;