From f7991a3a539eafd7f7316f3db957ac4f919f2010 Mon Sep 17 00:00:00 2001 From: Szymon Szczubkowski Date: Thu, 8 Feb 2024 16:18:39 +0100 Subject: [PATCH] restore presentation state --- cw_8/shaders/part.vert | 4 +++- cw_8/src/Particle.cpp | 4 +++- cw_8/src/Particle.h | 2 +- cw_8/src/projekt.hpp | 8 +++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cw_8/shaders/part.vert b/cw_8/shaders/part.vert index e4ffdbc..6944dd8 100644 --- a/cw_8/shaders/part.vert +++ b/cw_8/shaders/part.vert @@ -9,12 +9,14 @@ uniform mat4 transformation; uniform vec3 position; uniform vec4 color; +uniform float engPow; + uniform vec3 cameraUp; uniform vec3 cameraSide; void main() { - float scale = 0.1f; + float scale = 0.05f + engPow/20; TexCoords = texCoords; ParticleColor = color; vec3 worldspacePos = cameraSide*vertex.x + cameraUp*vertex.y; diff --git a/cw_8/src/Particle.cpp b/cw_8/src/Particle.cpp index bc31a1b..76ebafc 100644 --- a/cw_8/src/Particle.cpp +++ b/cw_8/src/Particle.cpp @@ -4,7 +4,7 @@ ParticleGenerator::ParticleGenerator() { this->init(); } -void ParticleGenerator::Draw(glm::mat4 modelMatrix, GLuint programParticle, GLuint texture, glm::vec3 cameraDir, bool isColour) { +void ParticleGenerator::Draw(glm::mat4 modelMatrix, GLuint programParticle, GLuint texture, glm::vec3 cameraDir, bool isColour, float engPow) { glEnable(GL_BLEND); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_ALPHA, GL_ONE); @@ -16,6 +16,8 @@ void ParticleGenerator::Draw(glm::mat4 modelMatrix, GLuint programParticle, GLui glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); + + glUniform1f(glGetUniformLocation(programParticle, "engPow"), engPow); glUniformMatrix4fv(glGetUniformLocation(programParticle, "transformation"), 1, GL_FALSE, (float*)&(modelMatrix)); glUniform3f(glGetUniformLocation(programParticle, "position"), particle.position.x, particle.position.y + (rand() % 10 - 5) / 500.f, particle.position.z + (rand() % 10 - 5) / 500.f); if (isColour) { diff --git a/cw_8/src/Particle.h b/cw_8/src/Particle.h index 176bbc6..c6c1e1e 100644 --- a/cw_8/src/Particle.h +++ b/cw_8/src/Particle.h @@ -15,7 +15,7 @@ struct Particle { class ParticleGenerator { public: - void Draw(glm::mat4 modelMatrix, GLuint programParticle, GLuint texture, glm::vec3 cameraDir, bool isColour); + void Draw(glm::mat4 modelMatrix, GLuint programParticle, GLuint texture, glm::vec3 cameraDir, bool isColour, float engPow); ParticleGenerator(); private: std::vector particles; diff --git a/cw_8/src/projekt.hpp b/cw_8/src/projekt.hpp index 2bfe2f5..b35591a 100644 --- a/cw_8/src/projekt.hpp +++ b/cw_8/src/projekt.hpp @@ -89,6 +89,7 @@ float aspectRatio = 1.f; glm::vec3 cameraPos; glm::vec3 cameraDir; +float lastEnginePower = 0; glm::vec3 spaceshipPos = glm::vec3(-4.0f, 0.0f, 0.0f); glm::vec3 spaceshipDir = glm::vec3(1.0f, 0.0f, 0.0f); @@ -150,8 +151,10 @@ void processInput(GLFWwindow* window) if (currentState.buttons[GLFW_GAMEPAD_BUTTON_A]==GLFW_PRESS) engineIs = 2; } - if(currentState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.01) + if (currentState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.01) { spaceshipPos += cameraSpeed * 2 * spaceshipDir * currentState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER]; + lastEnginePower = currentState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER]; + } if (currentState.axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER] > 0.01) spaceshipPos -= cameraSpeed * 2 * spaceshipDir * currentState.axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER]; if (abs(currentState.axes[GLFW_GAMEPAD_AXIS_LEFT_X]) > 0.01) @@ -407,8 +410,7 @@ void renderScene(GLFWwindow* window) { drawObjectPBR(planetContext, glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(0, 0, -3.f)) * glm::eulerAngleY(-1.5f * time) * glm::scale(glm::vec3(0.1f)), texture::earth_albedo, texture::earth_normal, texture::earth_ao, texture::earth_roughness, texture::earth_metallic); drawObjectPBR(planetContext, glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(0, 0, -3.f)) * glm::eulerAngleY( 2.f * time) * glm::translate(glm::vec3(0.4f, 0, 0.4f)) * glm::eulerAngleY(-0.5f * time) * glm::scale(glm::vec3(0.04f)), texture::moon_albedo, texture::moon_normal, texture::moon_ao, texture::moon_roughness, texture::moon_metallic); - mainEngine->Draw(createPerspectiveMatrix() * createCameraMatrix() * glm::translate(glm::vec3(0.f, -0.22f, 0.0f)) * glm::translate(cameraPos + 0.2 * cameraDir + glm::vec3(0, 1, 0) * 0.05f), programParticle, texture::particle_fire, cameraDir, engineIs == 2); - std::cout << glm::to_string(spaceshipPos) << std::endl; + mainEngine->Draw(createPerspectiveMatrix() * createCameraMatrix() * glm::translate(glm::vec3(0.f, -0.22f, 0.0f)) * glm::translate(cameraPos + 0.2 * cameraDir + glm::vec3(0, 1, 0) * 0.05f), programParticle, texture::particle_fire, cameraDir, engineIs == 2, lastEnginePower); //desired objects end here glUseProgram(0); glfwSwapBuffers(window);