From 874934e603f0934cb55773cd0e74d0cc236586e4 Mon Sep 17 00:00:00 2001 From: s473577 Date: Fri, 5 Jan 2024 00:10:48 +0100 Subject: [PATCH] Change Spaceship::getInstance to spaceship --- grk/project/src/ex_9_1.hpp | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/grk/project/src/ex_9_1.hpp b/grk/project/src/ex_9_1.hpp index d09a794..efa02f1 100644 --- a/grk/project/src/ex_9_1.hpp +++ b/grk/project/src/ex_9_1.hpp @@ -39,9 +39,6 @@ GLuint programTex; Core::Shader_Loader shaderLoader; -Core::RenderContext shipContext; -Core::RenderContext sphereContext; - std::list suns; Sun sun; GLuint VAO,VBO; @@ -54,6 +51,8 @@ glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6); float lastTime = -1.f; float deltaTime = 0.f; +Spaceship& spaceship = Spaceship::getInstance(); + void updateDeltaTime(float time) { if (lastTime < 0) { lastTime = time; @@ -67,7 +66,7 @@ void updateDeltaTime(float time) { void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) { - glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance().createCameraMatrix(); + glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() *spaceship.createCameraMatrix(); glm::mat4 transformation = viewProjectionMatrix * modelMatrix; glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix); @@ -79,7 +78,7 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z); - glUniform3f(glGetUniformLocation(program, "cameraPos"), Spaceship::getInstance().cameraPos.x, Spaceship::getInstance().cameraPos.y, Spaceship::getInstance().cameraPos.z); + glUniform3f(glGetUniformLocation(program, "cameraPos"),spaceship.cameraPos.x,spaceship.cameraPos.y,spaceship.cameraPos.z); const int NUM_LIGHTS = 23; @@ -94,10 +93,10 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec glUniform3f(glGetUniformLocation(program, "lightPos"), sun.sunPos.x, sun.sunPos.y, sun.sunPos.z); glUniform3f(glGetUniformLocation(program, "lightColor"), sun.sunColor.x, sun.sunColor.y, sun.sunColor.z); - glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), Spaceship::getInstance().spotlightConeDir.x, Spaceship::getInstance().spotlightConeDir.y, Spaceship::getInstance().spotlightConeDir.z); - glUniform3f(glGetUniformLocation(program, "spotlightPos"), Spaceship::getInstance().spotlightPos.x, Spaceship::getInstance().spotlightPos.y, Spaceship::getInstance().spotlightPos.z); - glUniform3f(glGetUniformLocation(program, "spotlightColor"), Spaceship::getInstance().spotlightColor.x, Spaceship::getInstance().spotlightColor.y, Spaceship::getInstance().spotlightColor.z); - glUniform1f(glGetUniformLocation(program, "spotlightPhi"), Spaceship::getInstance().spotlightPhi); + glUniform3f(glGetUniformLocation(program, "spotlightConeDir"),spaceship.spotlightConeDir.x,spaceship.spotlightConeDir.y,spaceship.spotlightConeDir.z); + glUniform3f(glGetUniformLocation(program, "spotlightPos"),spaceship.spotlightPos.x,spaceship.spotlightPos.y,spaceship.spotlightPos.z); + glUniform3f(glGetUniformLocation(program, "spotlightColor"),spaceship.spotlightColor.x,spaceship.spotlightColor.y,spaceship.spotlightColor.z); + glUniform1f(glGetUniformLocation(program, "spotlightPhi"),spaceship.spotlightPhi); Core::DrawContext(context); } @@ -132,19 +131,15 @@ void renderScene(GLFWwindow* window) glUseProgram(program); - drawObjectPBR(sphereContext, 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)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0); + drawObjectPBR(models::sphereContext, 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)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0); - drawObjectPBR(sphereContext, + drawObjectPBR(models::sphereContext, 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)), glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0); drawObjectPBR(models::marbleBustContext, glm::mat4(), glm::vec3(1.f, 1.f, 1.f), 0.5f, 1.0f); - drawObjectPBR(shipContext, - Spaceship::getInstance().calculateModelMatrix(), - glm::vec3(0.3, 0.3, 0.5), - 0.2,1.0 - ); + drawObjectPBR(models::spaceshipContext, spaceship.calculateModelMatrix(), spaceship.color, spaceship.roughness, spaceship.metallic); glUseProgram(0); glfwSwapBuffers(window); @@ -202,13 +197,13 @@ void init(GLFWwindow* window) programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag"); programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag"); - loadModelToContext("./models/sphere.obj", sphereContext); - loadModelToContext("./models/spaceship.obj", shipContext); + //loadModelToContext("./models/sphere.obj", sphereContext); + //loadModelToContext("./models/spaceship.obj", spaceship.context); loadModelToContext("./models/marbleBust.obj", models::marbleBustContext); - loadModelToContext("./models/GameUtils::spaceship.obj", models::spaceshipContext); + loadModelToContext("./models/spaceship.obj", models::spaceshipContext); loadModelToContext("./models/sphere.obj", models::sphereContext); createSuns(); @@ -230,8 +225,8 @@ void processInput(GLFWwindow* window) exposition += 0.05;*/ if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) { - printf("GameUtils::spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", Spaceship::getInstance().spaceshipPos.x, Spaceship::getInstance().spaceshipPos.y, Spaceship::getInstance().spaceshipPos.z); - printf("GameUtils::spaceshipDir = glm::vec3(%ff, %ff, %ff);\n", Spaceship::getInstance().spaceshipDir.x, Spaceship::getInstance().spaceshipDir.y, Spaceship::getInstance().spaceshipDir.z); + printf("GameUtils::spaceshipPos = glm::vec3(%ff, %ff, %ff);\n",spaceship.spaceshipPos.x,spaceship.spaceshipPos.y,spaceship.spaceshipPos.z); + printf("GameUtils::spaceshipDir = glm::vec3(%ff, %ff, %ff);\n",spaceship.spaceshipDir.x,spaceship.spaceshipDir.y,spaceship.spaceshipDir.z); } //cameraDir = glm::normalize(-cameraPos);