Adjust hud postion to the new scale

This commit is contained in:
s473577 2024-02-03 21:50:55 +01:00
parent 1f09c40bb5
commit 61170baa47
2 changed files with 20 additions and 25 deletions

View File

@ -85,7 +85,7 @@ private:
void shoot(float time) { void shoot(float time) {
Spaceship* spaceship = Spaceship::getInstance(); Spaceship* spaceship = Spaceship::getInstance();
glm::vec3 bulletDirection = glm::normalize(spaceship->spaceshipPos - glm::vec3(modelMatrix[3])); glm::vec3 bulletDirection = glm::normalize(spaceship->spaceshipPos - glm::vec3(modelMatrix[3]));
//bulletDirection += glm::linearRand(glm::vec3(-0.01f), glm::vec3(0.1f)); // Modyfikacja kierunku o losowy szum
this->bullets.push_back(Bullet::createSimpleBullet(bulletDirection, this->modelMatrix[3], time)); this->bullets.push_back(Bullet::createSimpleBullet(bulletDirection, this->modelMatrix[3], time));
this->lastShootTime = time; this->lastShootTime = time;
} }

View File

@ -98,10 +98,10 @@ void renderHUD() {
glUseProgram(programSpriteBar); glUseProgram(programSpriteBar);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glm::mat4 spaceshipModelMatrix = spaceship->calculateModelMatrix(); glm::mat4 spaceshipModelMatrix = spaceship->calculateModelMatrix();
glm::mat4 healthBarPosition = glm::translate(spaceshipModelMatrix, glm::vec3(12.0f, -9.0f, 0.0f)); glm::mat4 healthBarPosition = glm::translate(spaceshipModelMatrix, glm::vec3(36.0f, -34.0f, 0.0f));
spriteRenderer->DrawHUDBar( spriteRenderer->DrawHUDBar(
glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f),
glm::scale(healthBarPosition, glm::vec3(9.0f, 1.1f, 1.0f)), glm::scale(healthBarPosition, glm::vec3(26.0f, 4.f, 1.0f)),
spaceship->currentHP / spaceship->maxHP, spaceship->currentHP / spaceship->maxHP,
programSpriteBar); programSpriteBar);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -198,44 +198,40 @@ void renderScene(GLFWwindow* window)
texture::spaceshipTexture, texture::spaceshipTexture,
spaceship->roughness, spaceship->metallic, programTex spaceship->roughness, spaceship->metallic, programTex
); );
<<<<<<< HEAD
<<<<<<< HEAD
//Core::SetActiveTexture(texture::earthTexture, "textureSampler", programTex, 0); //Core::SetActiveTexture(texture::earthTexture, "textureSampler", programTex, 0);
drawObjectPBRTexture(models::sphereContext, glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(1.0f)), texture::earthTexture, 0.3, 0.0, programTex); drawObjectPBRTexture(models::sphereContext, glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(1.0f)), texture::earthTexture, 0.3, 0.0, programTex);
//glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * //glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) *
Core::SetActiveTexture(texture::earthTexture, "textureSampler", programTex, 0); Core::SetActiveTexture(texture::earthTexture, "textureSampler", programTex, 0);
drawObjectPBRTexture(models::sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), texture::earthTexture, 0.3, 0.0, programTex); drawObjectPBRTexture(models::sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), texture::earthTexture, 0.3, 0.0, programTex);
glUseProgram(programSprite); //glUseProgram(programSprite);
for (const auto& enemy : enemies) { //for (const auto& enemy : enemies) {
if (enemy->isAlive()) { // if (enemy->isAlive()) {
spriteRenderer->DrawSprite(texture::spriteTexture, enemy->modelMatrix, programSprite); // spriteRenderer->DrawSprite(texture::spriteTexture, enemy->modelMatrix, programSprite);
} // }
} //}
glUseProgram(program); //glUseProgram(program);
for (const auto& enemy : enemies) { //for (const auto& enemy : enemies) {
if (enemy->isAlive()) { // if (enemy->isAlive()) {
enemy->attack(spaceship->spaceshipPos, glfwGetTime()); // enemy->attack(spaceship->spaceshipPos, glfwGetTime());
enemy->renderBullets(glfwGetTime(), program); // enemy->renderBullets(glfwGetTime(), program, gameEntities);
} // }
} //}
glm::vec3 cameraSide = glm::normalize(glm::cross(spaceship->cameraDir, glm::vec3(0.f, 1.f, 0.f))); glm::vec3 cameraSide = glm::normalize(glm::cross(spaceship->cameraDir, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, spaceship->cameraDir)); glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, spaceship->cameraDir));
glm::mat4 viewMatrix = Core::createViewMatrix(spaceship->cameraPos, spaceship->cameraDir, cameraUp); glm::mat4 viewMatrix = Core::createViewMatrix(spaceship->cameraPos, spaceship->cameraDir, cameraUp);
spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time); spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time);
=======
=======
renderHUD(); renderHUD();
>>>>>>> 9586849 (Add collision detection and taking dmg)
renderEnemies(); renderEnemies();
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program); //drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
>>>>>>> 6ccdec5 (Add drawing health bars for enemies)
glUseProgram(0); glUseProgram(0);
glfwSwapBuffers(window); glfwSwapBuffers(window);
@ -319,12 +315,11 @@ void init(GLFWwindow* window)
programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag"); programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag"); programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag"); programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
<<<<<<< HEAD
programTex = gameUtils->shaderLoader->CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag"); programTex = gameUtils->shaderLoader->CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
=======
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag"); programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag");
programSpriteBar = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite_bar.vert", "shaders/shader_sprite_bar.frag"); programSpriteBar = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite_bar.vert", "shaders/shader_sprite_bar.frag");
>>>>>>> 6ccdec5 (Add drawing health bars for enemies)
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag"); programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag");