restore presentation state

This commit is contained in:
Szymon Szczubkowski 2024-02-08 16:18:39 +01:00
parent 90d60a0e48
commit f7991a3a53
4 changed files with 12 additions and 6 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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<Particle> particles;

View File

@ -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);