Compare commits

...

4 Commits

4 changed files with 90 additions and 13 deletions

View File

@ -38,6 +38,8 @@ public:
glm::vec3 color = glm::vec3(0.3, 0.3, 0.5);
float roughness = 0.2;
float metallic = 1.0;
float turbo = 1.0f;
float turboMAX = 1.0f;
glm::vec3 spaceshipPos /*= glm::vec3(0.065808f, 1.250000f, -2.189549f)*/;
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
@ -49,6 +51,7 @@ public:
glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f);
glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f);
glm::vec3 cameraPosHUDBar = cameraPos;
glm::mat4 additionalHorRotationMatrix;
glm::mat4 additionalVerRotationMatrix;
@ -221,15 +224,28 @@ public:
if (w == GLFW_PRESS) {
if (shiftState == GLFW_PRESS) {
turbo = glm::max(0.0f, turbo - 0.004f * deltaTime * 60);
if (turbo == 0.0f) {
shiftState = GLFW_RELEASE;
moveSpeed = 0.05f * deltaTime * 60;
setPerticlesParameters(100.f, 0.0001f);
}
else {
moveSpeed *= 2;
setPerticlesParameters(200.f, 0.00005f);
}
}
else {
setPerticlesParameters(100.f, 0.0001f);
turbo = glm::min(turboMAX, turbo + 0.001f * deltaTime * 60);
}
}
else {
setPerticlesParameters(50.f, 0.0002f);
turbo = glm::min(turboMAX, turbo + 0.005f * deltaTime * 60);
}
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
@ -255,6 +271,8 @@ public:
requestShoot(time);
cameraPos = spaceshipPos - calculateCameraDistanceHor(w, shiftState, deltaTime) * spaceshipDir + glm::vec3(0, calculateCameraDistanceVer(deltaTime), 0);
cameraPosHUDBar = spaceshipPos - 1.f * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
cameraDir = spaceshipDir;
glm::vec3 perpendicularVector = 0.04f * glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.0f, 1.0f, 0.0f)));
if (leftParticle != nullptr && rightParticle != nullptr) {
@ -340,4 +358,32 @@ public:
glm::mat4 getModelMatrix() override {
return calculateModelMatrix();
}
glm::mat4 calculateModelMatrixForHUDBar() {
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
glm::mat4 spaceshipCameraRotationMatrix = glm::mat4({
spaceshipSide.x, spaceshipSide.y, spaceshipSide.z, 0,
spaceshipUp.x, spaceshipUp.y, spaceshipUp.z, 0,
-spaceshipDir.x, -spaceshipDir.y, -spaceshipDir.z, 0,
0., 0., 0., 1.
});
return glm::translate(spaceshipPos) * spaceshipCameraRotationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.02f));
}
glm::mat4 createCameraMatrixForHUDBar()
{
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraDir));
glm::mat4 cameraRotrationMatrix = glm::mat4({
cameraSide.x,cameraSide.y,cameraSide.z,0,
cameraUp.x,cameraUp.y,cameraUp.z ,0,
-cameraDir.x,-cameraDir.y,-cameraDir.z,0,
0.,0.,0.,1.,
});
cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix);
glm::mat4 cameraMatrix = cameraRotrationMatrix * glm::translate(-cameraPosHUDBar);
return cameraMatrix;
}
};

View File

@ -16,7 +16,7 @@ void Core::SpriteRenderer::DrawHUDBar(const glm::vec3 color, const glm::mat4 mod
Spaceship* spaceship = Spaceship::getInstance();
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrixForHUDBar();
// Kombinuj macierze transformacji
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;

View File

@ -27,9 +27,17 @@
#include "../ParticleSystem.h"
#include "Camera.h"
#ifndef EX_9_1_HPP
#define EX_9_1_HPP
extern int WIDTH;
extern int HEIGHT;
#endif
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
int WIDTH = 500, HEIGHT = 500;
//int WIDTH = 1920, HEIGHT = 1080;
namespace models {
Core::RenderContext marbleBustContext;
Core::RenderContext spaceshipContext;
@ -95,14 +103,36 @@ void updateDeltaTime(float time) {
if (deltaTime > 0.1) deltaTime = 0.1;
lastTime = time;
}
void renderHUD() {
void renderHUD(GLFWwindow* window) {
glm::mat4 modelMatrixHUD = spaceship->calculateModelMatrixForHUDBar();
glm::mat4 healthBarPosition;
glm::vec3 healthBarScale;
glm::mat4 turboBarPosition;
glm::vec3 turboBarScale;
if (glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) {
healthBarPosition = glm::translate(modelMatrixHUD, glm::vec3(38.0f, -11.0f, 0.0f));
healthBarScale = glm::vec3(22.0f, 2.f, 1.0f);
turboBarScale = healthBarScale;
turboBarPosition = glm::translate(healthBarPosition, glm::vec3(0.0f, 3.5f, 0.0f));
}
else {
healthBarScale = glm::vec3(22.0f, 4.f, 1.0f);
healthBarPosition = glm::translate(modelMatrixHUD, glm::vec3(38.0f, -30.0f, 0.0f));
turboBarScale = healthBarScale;
turboBarPosition = glm::translate(healthBarPosition, glm::vec3(0.0f, 5.0f, 0.0f));
}
glUseProgram(programSpriteBar);
glDisable(GL_DEPTH_TEST);
glm::mat4 spaceshipModelMatrix = spaceship->calculateModelMatrix();
glm::mat4 healthBarPosition = glm::translate(spaceshipModelMatrix, glm::vec3(36.0f, -34.0f, 0.0f));
spriteRenderer->DrawHUDBar(
glm::vec3(0.0824f, 0.5725f, 0.9765f),
glm::scale(turboBarPosition, turboBarScale),
spaceship->turbo / spaceship->turboMAX,
programSpriteBar);
spriteRenderer->DrawHUDBar(
glm::vec3(0.0f, 1.0f, 0.0f),
glm::scale(healthBarPosition, glm::vec3(26.0f, 4.f, 1.0f)),
glm::scale(healthBarPosition, healthBarScale),
spaceship->currentHP / spaceship->maxHP,
programSpriteBar);
glEnable(GL_DEPTH_TEST);
@ -229,7 +259,7 @@ void renderScene(GLFWwindow* window)
spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time);
renderHUD();
renderHUD(window);
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);

View File

@ -8,10 +8,11 @@
#include "ex_9_1.hpp"
int WIDTH = 1920, HEIGHT = 1080;
int main(int argc, char** argv)
{
// inicjalizacja glfw
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
@ -23,7 +24,7 @@ int main(int argc, char** argv)
#endif
// tworzenie okna za pomoca glfw
GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "FirstWindow", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
@ -34,7 +35,7 @@ int main(int argc, char** argv)
// ladowanie OpenGL za pomoca glew
glewInit();
glViewport(0, 0, 500, 500);
glViewport(0, 0, WIDTH, HEIGHT);
init(window);