Compare commits
No commits in common. "master" and "61170baa47da595e26d9b7e497a70470474baeaa" have entirely different histories.
master
...
61170baa47
43
README.md
@ -1,43 +0,0 @@
|
||||
# Nazwa Projektu
|
||||
Projekt z grafiki komputerowej - Interstellar Odyssey
|
||||
|
||||
|
||||
## Opis
|
||||
Interaktywny symulator loty kosmicznego 3D. Celem naszej gry jest zwiedzanie rożnych układów słonecznych.
|
||||
Pokonywanie jak największej ilości wrogów i utrzymywanie się przy życiu za pomocą dostępnych itemków do zebrania.
|
||||
|
||||
|
||||
## Funkcje i możliwości
|
||||
-Physically Based Rendering z mapą normalnych :
|
||||
![normal_map](images/normal_map.png)
|
||||
|
||||
-Sprite Rendering razem z techniką bilboardingu:
|
||||
![sprite_rendering](images/sprite.png)
|
||||
|
||||
- Particle Generator:
|
||||
![Turbo](images/turbo.png)
|
||||
|
||||
- Skybox/Tworzenie wielu galaktyk:
|
||||
![galaktyki](images/galaktyki.png)
|
||||
|
||||
- Strzelanie
|
||||
![strzelanie](images/strzelanie.png)
|
||||
|
||||
- Pas asteroid
|
||||
![pas_asteroid](images/asteroidy.png)
|
||||
|
||||
- Otrzymywanie i zadawanie obrażeń
|
||||
![sprite_dmg](images/sprite_dmg.png)
|
||||
|
||||
- Możliwości uzupełnienia turbo i życia przez zbieranie itemków
|
||||
![hp](images/hp.png)
|
||||
|
||||
oraz dynamiczne poruszanie się statku podczas skrętów, lotów w górę i w dół oraz na ukos
|
||||
|
||||
|
||||
## Skład zespołu
|
||||
Sprite Rendering
|
||||
- Mateusz Kantorski
|
||||
- Paweł Felcyn
|
||||
- Wojciech Goralewski
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
bool checkCollisionWithGameEntities(std::vector<GameEntity*>& gameEntities, glm::mat4 bulletModelMatrix, float attackerDmg) {
|
||||
for (const auto& entity : gameEntities) {
|
||||
glm::mat4 entityModelMatrix = entity->getModelMatrix();
|
||||
|
||||
// Sprawdź kolizję AABB między pociskiem a obiektem z wektora gameEntities
|
||||
if (checkAABBCollision(bulletModelMatrix, entityModelMatrix)) {
|
||||
entity->applyDamage(attackerDmg);
|
||||
return true;
|
||||
@ -70,7 +72,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
bool checkAABBCollision(const glm::mat4& obj1ModelMatrix, const glm::mat4& obj2ModelMatrix) {
|
||||
|
||||
// Pobierz rozmiary obiektów z ich macierzy modelu
|
||||
glm::vec3 obj1Min = glm::vec3(obj1ModelMatrix * glm::vec4(-0.5f, -0.5f, -0.5f, 1.0f));
|
||||
glm::vec3 obj1Max = glm::vec3(obj1ModelMatrix * glm::vec4(0.5f, 0.5f, 0.5f, 1.0f));
|
||||
|
||||
|
@ -12,20 +12,15 @@ private:
|
||||
std::list<Bullet*> bullets;
|
||||
float lastShootTime = 0.f;
|
||||
float shootInterval = 0.3f;
|
||||
float initAggroRange;
|
||||
|
||||
public:
|
||||
glm::mat4 modelMatrix;
|
||||
float aggroRange;
|
||||
glm::mat4 initialModelMatrix;
|
||||
|
||||
|
||||
Enemy(float currHp,float initialHp, glm::mat4 initialModelMatrix, float initialDmg, float initialAggroRange)
|
||||
:
|
||||
aggroRange(initialAggroRange),
|
||||
modelMatrix(initialModelMatrix),
|
||||
initialModelMatrix(initialModelMatrix),
|
||||
initAggroRange(initialAggroRange),
|
||||
GameEntity(currHp, initialHp, initialDmg)
|
||||
{}
|
||||
|
||||
@ -75,16 +70,7 @@ public:
|
||||
{
|
||||
return modelMatrix;
|
||||
}
|
||||
void respawn() override {
|
||||
this->currentHP = this->maxHP;
|
||||
this->modelMatrix = this->initialModelMatrix;
|
||||
this->aggroRange = this->initAggroRange;
|
||||
this->dmg = this->initDMG;
|
||||
return;
|
||||
}
|
||||
void heal() override {
|
||||
this->currentHP = this->currentHP + 5.0f;
|
||||
}
|
||||
|
||||
private:
|
||||
void requestShoot(float time) {
|
||||
if (canShoot(time)) {
|
||||
@ -98,8 +84,7 @@ private:
|
||||
|
||||
void shoot(float time) {
|
||||
Spaceship* spaceship = Spaceship::getInstance();
|
||||
//glm::vec3 bulletDirection = glm::normalize(spaceship->spaceshipPos - glm::vec3(modelMatrix[3]));
|
||||
glm::vec3 bulletDirection = glm::normalize(glm::vec3(spaceship->getModelMatrix()[3]) - 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->lastShootTime = time;
|
||||
|
@ -7,27 +7,17 @@ public:
|
||||
float currentHP;
|
||||
float dmg;
|
||||
float maxHP;
|
||||
float initDMG;
|
||||
|
||||
GameEntity(float currentHP, float maxHP, float initialDmg)
|
||||
: currentHP(currentHP), maxHP(maxHP), dmg(initialDmg), initDMG(initialDmg)
|
||||
: currentHP(currentHP), maxHP(maxHP), dmg(initialDmg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
virtual void applyDamage(float attackerDmg) {
|
||||
currentHP = currentHP - attackerDmg;
|
||||
};
|
||||
virtual glm::vec3 getPosition() const = 0;
|
||||
virtual glm::mat4 getModelMatrix() = 0;
|
||||
virtual bool isAlive() {
|
||||
if (this->currentHP <= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
virtual void respawn() = 0;
|
||||
virtual void heal() = 0;
|
||||
};
|
||||
|
||||
|
@ -1,55 +0,0 @@
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include "src/Render_Utils.h"
|
||||
#include "./GameEntity.h"
|
||||
#include "Spaceship.h"
|
||||
|
||||
#pragma once
|
||||
class Heart : public GameEntity
|
||||
{
|
||||
public:
|
||||
glm::mat4 modelMatrix;
|
||||
glm::mat4 initialModelMatrix;
|
||||
float healAmount = 10;
|
||||
bool isCollected;
|
||||
|
||||
|
||||
Heart(glm::mat4 initialModelMatrix, float healAmount)
|
||||
:
|
||||
modelMatrix(initialModelMatrix),
|
||||
initialModelMatrix(initialModelMatrix),
|
||||
healAmount(healAmount),
|
||||
isCollected(false),
|
||||
GameEntity(1, 1, 0)
|
||||
{}
|
||||
|
||||
|
||||
virtual ~Heart() = default;
|
||||
|
||||
virtual bool isAlive() {
|
||||
if (this->currentHP <= 0) {
|
||||
isCollected = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::vec3 getPosition() const override
|
||||
{
|
||||
return modelMatrix[3];
|
||||
}
|
||||
glm::mat4 getModelMatrix() override
|
||||
{
|
||||
return modelMatrix;
|
||||
}
|
||||
void respawn() override {
|
||||
this->currentHP = this->maxHP;
|
||||
this->modelMatrix = this->initialModelMatrix;
|
||||
return;
|
||||
}
|
||||
void heal() override {
|
||||
this->currentHP = this->currentHP + 5.0f;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1,55 +0,0 @@
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include "src/Render_Utils.h"
|
||||
#include "./GameEntity.h"
|
||||
#include "Spaceship.h"
|
||||
|
||||
#pragma once
|
||||
class Nitro : public GameEntity
|
||||
{
|
||||
public:
|
||||
glm::mat4 modelMatrix;
|
||||
glm::mat4 initialModelMatrix;
|
||||
float healAmount = 10;
|
||||
bool isCollected;
|
||||
|
||||
|
||||
Nitro(glm::mat4 initialModelMatrix, float healAmount)
|
||||
:
|
||||
modelMatrix(initialModelMatrix),
|
||||
initialModelMatrix(initialModelMatrix),
|
||||
healAmount(healAmount),
|
||||
isCollected(false),
|
||||
GameEntity(1, 1, 0)
|
||||
{}
|
||||
|
||||
|
||||
virtual ~Nitro() = default;
|
||||
|
||||
virtual bool isAlive() {
|
||||
if (this->currentHP <= 0) {
|
||||
isCollected = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::vec3 getPosition() const override
|
||||
{
|
||||
return modelMatrix[3];
|
||||
}
|
||||
glm::mat4 getModelMatrix() override
|
||||
{
|
||||
return modelMatrix;
|
||||
}
|
||||
void respawn() override {
|
||||
this->currentHP = this->maxHP;
|
||||
this->modelMatrix = this->initialModelMatrix;
|
||||
return;
|
||||
}
|
||||
void heal() override {
|
||||
this->currentHP = this->currentHP + 5.0f;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -104,7 +104,7 @@ public:
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void drawParticles(GLuint program, glm::mat4 view, glm::mat4 projection, glm::mat4 modelSrc, float time) {
|
||||
void drawParticles(GLuint program, glm::mat4 view, glm::mat4 projection, float time) {
|
||||
if (shouldGenerateNewParticle(time)) {
|
||||
generateNewParticle(time);
|
||||
}
|
||||
@ -124,8 +124,7 @@ public:
|
||||
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
|
||||
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
|
||||
|
||||
glm::mat4 model = glm::translate(glm::mat4(1), sourcePosition + particle.randomPointOnCircle);
|
||||
model = model * modelSrc;
|
||||
glm::mat4 model = glm::translate(glm::mat4(1.0f), sourcePosition + particle.randomPointOnCircle);
|
||||
model = glm::scale(model, glm::vec3(0.005f, 0.005f, 0.005f));
|
||||
model = glm::translate(model, particle.direction * speed * (time - particle.birthTime));
|
||||
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
|
||||
|
@ -16,8 +16,6 @@ private:
|
||||
glm::mat4 positionMatrix;
|
||||
GLuint textureID;
|
||||
GLuint normalMapID;
|
||||
float startEulerYRotation = 0.f;
|
||||
float startYMovement = 0.f;
|
||||
|
||||
public:
|
||||
Planet(GameObject* center, float distanceFromCenter, float rotationSpeed, float scale, Core::RenderContext sphereContext, GLuint textureID, GLuint normalMapID) {
|
||||
@ -41,16 +39,8 @@ public:
|
||||
}
|
||||
|
||||
float rotationAngle = glm::radians(time * rotationSpeed);
|
||||
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed + startEulerYRotation) * glm::translate(glm::vec3(distanceFromCenter, startYMovement, 0));
|
||||
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed) * glm::translate(glm::vec3(distanceFromCenter, 0, 0));
|
||||
glm::mat4 modelMatrix = positionMatrix * glm::scale(glm::vec3(scale));
|
||||
Core::drawObjectPBRTexture(sphereContext, modelMatrix, textureID, normalMapID, 0.7, 0.0, program);
|
||||
}
|
||||
|
||||
void setStarteulerYRotation(float radians) {
|
||||
startEulerYRotation = radians;
|
||||
}
|
||||
|
||||
void setStartYMovement(float value) {
|
||||
startYMovement = value;
|
||||
Core::drawObjectPBRTexture(sphereContext, modelMatrix, textureID, 0.7, 0.0, program);
|
||||
}
|
||||
};
|
@ -11,7 +11,6 @@
|
||||
class Spaceship : public GameEntity
|
||||
{
|
||||
private:
|
||||
|
||||
std::list<Bullet*> bullets;
|
||||
float lastShootTime = 0.f;
|
||||
float shootInterval = 0.3f;
|
||||
@ -36,12 +35,10 @@ public:
|
||||
}
|
||||
|
||||
glm::vec3 color = glm::vec3(0.3, 0.3, 0.5);
|
||||
float roughness = 0.5;
|
||||
float metallic = 0.6;
|
||||
float turbo = 1.0f;
|
||||
float turboMAX = 1.0f;
|
||||
float roughness = 0.2;
|
||||
float metallic = 1.0;
|
||||
|
||||
glm::vec3 spaceshipPos = glm::vec3(4.065808f, 10.250000f, -20.189549f);
|
||||
glm::vec3 spaceshipPos /*= glm::vec3(0.065808f, 1.250000f, -2.189549f)*/;
|
||||
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
|
||||
|
||||
glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
|
||||
@ -51,30 +48,18 @@ 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;
|
||||
|
||||
glm::mat4 calculateModelMatrix() {
|
||||
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.
|
||||
glm::mat4 specshipCameraRotrationMatrix = 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.,
|
||||
});
|
||||
|
||||
float additionalVerRotationAngle = glm::radians(currentShipVerAngle);
|
||||
additionalVerRotationMatrix = glm::rotate(glm::mat4(1.0f), additionalVerRotationAngle, glm::vec3(1.f, 0.f, 0.f));
|
||||
|
||||
float additionalHorRotationAngle = glm::radians(currentShipHorAngle);
|
||||
additionalHorRotationMatrix = glm::rotate(glm::mat4(1.0f), additionalHorRotationAngle, glm::vec3(0.f, 0.2f, 1.f));
|
||||
|
||||
glm::mat4 modelMatrix = glm::translate(spaceshipPos) * spaceshipCameraRotationMatrix * additionalVerRotationMatrix * additionalHorRotationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.02f));
|
||||
|
||||
return modelMatrix;
|
||||
return glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.02f));
|
||||
}
|
||||
|
||||
void setPerticlesParameters(float speed, float generationInterval) {
|
||||
@ -84,122 +69,6 @@ public:
|
||||
rightParticle->generationInterval = generationInterval;
|
||||
}
|
||||
|
||||
|
||||
const float fromCameraDirHorizontalStateToStateTime = 0.2f;
|
||||
const float CAMERA_DISTANCE_STATIC_HOR = 0.7f;
|
||||
const float CAMERA_DISTANCE_SLOW_HOR = 0.85f;
|
||||
const float CAMERA_DISTANCE_FAST_HOR = 1.f;
|
||||
|
||||
float currentCameraDistanceHor = CAMERA_DISTANCE_STATIC_HOR;
|
||||
float targetCameraDistanceHor = CAMERA_DISTANCE_STATIC_HOR;
|
||||
int currentWState = 0;
|
||||
int currentShiftState = 0;
|
||||
|
||||
float calculateCameraDistanceHor(int wState, int shiftState, float time) {
|
||||
currentWState = wState;
|
||||
currentShiftState = shiftState;
|
||||
|
||||
if (currentWState == 1 && currentShiftState == 0) {
|
||||
targetCameraDistanceHor = CAMERA_DISTANCE_SLOW_HOR;
|
||||
}
|
||||
else if (currentWState == 1 && currentShiftState == 1) {
|
||||
targetCameraDistanceHor = CAMERA_DISTANCE_FAST_HOR;
|
||||
}
|
||||
else {
|
||||
targetCameraDistanceHor = CAMERA_DISTANCE_STATIC_HOR;
|
||||
}
|
||||
|
||||
float diff = targetCameraDistanceHor - currentCameraDistanceHor;
|
||||
float step = diff / fromCameraDirHorizontalStateToStateTime * time;
|
||||
|
||||
currentCameraDistanceHor += step;
|
||||
|
||||
return currentCameraDistanceHor;
|
||||
}
|
||||
|
||||
const float fromCameraDirVerticalStateToStateTime = 0.2f;
|
||||
const float CAMERA_DISTANCE_STATIC_VER = 0.2f;
|
||||
const float CAMERA_DISTANCE_SLOW_VER = 0.25f;
|
||||
const float CAMERA_DISTANCE_FAST_VER = 0.3f;
|
||||
|
||||
float currentCameraDistanceVer = CAMERA_DISTANCE_STATIC_VER;
|
||||
float targetCameraDistanceVer = CAMERA_DISTANCE_STATIC_VER;
|
||||
|
||||
float calculateCameraDistanceVer(float time) {
|
||||
if (currentWState == 1 && currentShiftState == 0) {
|
||||
targetCameraDistanceVer = CAMERA_DISTANCE_SLOW_VER;
|
||||
}
|
||||
else if (currentWState == 1 && currentShiftState == 1) {
|
||||
targetCameraDistanceVer = CAMERA_DISTANCE_FAST_VER;
|
||||
}
|
||||
else {
|
||||
targetCameraDistanceVer = CAMERA_DISTANCE_STATIC_VER;
|
||||
}
|
||||
|
||||
float diff = targetCameraDistanceVer - currentCameraDistanceVer;
|
||||
float step = diff / fromCameraDirVerticalStateToStateTime * time;
|
||||
|
||||
currentCameraDistanceVer += step;
|
||||
|
||||
return currentCameraDistanceVer;
|
||||
}
|
||||
|
||||
const float MAX_VERTICAL_ANGLE = 15.f;
|
||||
float currentShipVerAngle = 0.f;
|
||||
float targetShipVerAngle = 0.f;
|
||||
int currentQState = 0;
|
||||
int currentEState = 0;
|
||||
|
||||
float calculateShipAngleVer(int qState, int eState, float time) {
|
||||
currentQState = qState;
|
||||
currentEState = eState;
|
||||
|
||||
if (currentQState == 1) {
|
||||
targetShipVerAngle = MAX_VERTICAL_ANGLE;
|
||||
}
|
||||
else if (currentEState == 1) {
|
||||
targetShipVerAngle = -MAX_VERTICAL_ANGLE;
|
||||
}
|
||||
else {
|
||||
targetShipVerAngle = 0.f;
|
||||
}
|
||||
|
||||
float diff = targetShipVerAngle - currentShipVerAngle;
|
||||
float step = diff / 0.2f * time;
|
||||
|
||||
currentShipVerAngle += step;
|
||||
|
||||
return currentShipVerAngle;
|
||||
}
|
||||
|
||||
const float MAX_HORIZONTALL_ANGLE = 15.f;
|
||||
float currentShipHorAngle = 0.f;
|
||||
float targetShipHorAngle = 0.f;
|
||||
int currentAState = 0;
|
||||
int currentDState = 0;
|
||||
|
||||
float calculateShipAngleHor(int aState, int dState, float time) {
|
||||
currentAState = aState;
|
||||
currentDState = dState;
|
||||
|
||||
if (currentAState == 1) {
|
||||
targetShipHorAngle = MAX_HORIZONTALL_ANGLE;
|
||||
}
|
||||
else if (currentDState == 1) {
|
||||
targetShipHorAngle = -MAX_HORIZONTALL_ANGLE;
|
||||
}
|
||||
else {
|
||||
targetShipHorAngle = 0.f;
|
||||
}
|
||||
|
||||
float diff = targetShipHorAngle - currentShipHorAngle;
|
||||
float step = diff / 0.2f * time;
|
||||
|
||||
currentShipHorAngle += step;
|
||||
|
||||
return currentShipHorAngle;
|
||||
}
|
||||
|
||||
void processInput(GLFWwindow* window, float deltaTime, float time) {
|
||||
static bool mouseButtonCallbackSet = false;
|
||||
if (!mouseButtonCallbackSet) {
|
||||
@ -212,42 +81,22 @@ public:
|
||||
|
||||
int w = glfwGetKey(window, GLFW_KEY_W);
|
||||
int s = glfwGetKey(window, GLFW_KEY_S);
|
||||
int shiftState = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT);
|
||||
int qState = glfwGetKey(window, GLFW_KEY_Q);
|
||||
int eState = glfwGetKey(window, GLFW_KEY_E);
|
||||
int aState = glfwGetKey(window, GLFW_KEY_A);
|
||||
int dState = glfwGetKey(window, GLFW_KEY_D);
|
||||
|
||||
calculateShipAngleVer(qState, eState, deltaTime);
|
||||
calculateShipAngleHor(aState, dState, deltaTime);
|
||||
//spaceshipDir = glm::vec3(glm::eulerAngleX(verticalAngle) * glm::vec4(spaceshipDir, 0));
|
||||
|
||||
if (w == GLFW_PRESS) {
|
||||
if (shiftState == GLFW_PRESS) {
|
||||
|
||||
turbo = glm::max(0.0f, turbo - 0.003f * deltaTime * 60);
|
||||
if (turbo == 0.0f) {
|
||||
shiftState = GLFW_RELEASE;
|
||||
moveSpeed = 0.05f * deltaTime * 60;
|
||||
setPerticlesParameters(100.f, 0.000001f);
|
||||
}
|
||||
else {
|
||||
moveSpeed *= 2;
|
||||
setPerticlesParameters(200.f, 0.0000005f);
|
||||
}
|
||||
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
|
||||
moveSpeed *= 2;
|
||||
setPerticlesParameters(200.f, 0.00005f);
|
||||
}
|
||||
else {
|
||||
setPerticlesParameters(100.f, 0.000001f);
|
||||
turbo = glm::min(turboMAX, turbo + 0.001f * deltaTime * 60);
|
||||
setPerticlesParameters(100.f, 0.0001f);
|
||||
}
|
||||
}
|
||||
else {
|
||||
setPerticlesParameters(50.f, 0.0002f);
|
||||
turbo = glm::min(turboMAX, turbo + 0.005f * deltaTime * 60);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
@ -259,22 +108,20 @@ public:
|
||||
spaceshipPos += spaceshipSide * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipSide * moveSpeed;
|
||||
if (qState == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipUp * moveSpeed;
|
||||
if (eState == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipUp * moveSpeed;
|
||||
if (aState == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
if (dState == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
|
||||
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;
|
||||
|
||||
cameraPos = spaceshipPos - 1.f * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
|
||||
cameraDir = spaceshipDir;
|
||||
glm::vec3 perpendicularVector = 0.08f * glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
glm::vec3 perpendicularVector = 0.04f * glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
if (leftParticle != nullptr && rightParticle != nullptr) {
|
||||
leftParticle->sourcePosition = spaceshipPos + perpendicularVector - (0.25f * spaceshipDir);
|
||||
rightParticle->sourcePosition = spaceshipPos - perpendicularVector - (0.25f * spaceshipDir);
|
||||
@ -288,9 +135,8 @@ public:
|
||||
|
||||
void renderParticles(GLuint program, glm::mat4 view, glm::mat4 projection, float time) {
|
||||
if (leftParticle != nullptr && rightParticle != nullptr) {
|
||||
glm::mat4 modelSrc = additionalVerRotationMatrix * additionalHorRotationMatrix;
|
||||
leftParticle->drawParticles(program, view, projection, modelSrc, time);
|
||||
rightParticle->drawParticles(program, view, projection, modelSrc, time);
|
||||
leftParticle->drawParticles(program, view, projection, time);
|
||||
rightParticle->drawParticles(program, view, projection, time);
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,9 +192,8 @@ public:
|
||||
|
||||
void shoot(float time) {
|
||||
glm::vec3 perpendicularVector = 0.25f * glm::normalize(glm::cross(cameraDir, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
glm::vec3 dir = glm::vec4(spaceshipDir.x, spaceshipDir.y, spaceshipDir.z, 1.f) * additionalVerRotationMatrix * additionalHorRotationMatrix;
|
||||
bullets.push_back(Bullet::createSimpleBullet(dir, spaceshipPos - perpendicularVector, time));
|
||||
bullets.push_back(Bullet::createSimpleBullet(dir, spaceshipPos + perpendicularVector, time));
|
||||
bullets.push_back(Bullet::createSimpleBullet(cameraDir, spaceshipPos - perpendicularVector, time));
|
||||
bullets.push_back(Bullet::createSimpleBullet(cameraDir, spaceshipPos + perpendicularVector, time));
|
||||
lastShootTime = time;
|
||||
}
|
||||
|
||||
@ -358,48 +203,4 @@ 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;
|
||||
}
|
||||
|
||||
void respawn() override {
|
||||
this->currentHP = this->maxHP;
|
||||
this->turbo = this->turboMAX;
|
||||
this->spaceshipPos = glm::vec3(4.065808f, 10.250000f, -20.189549f);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void heal() override {
|
||||
this->currentHP = this->currentHP + 3.f;
|
||||
}
|
||||
|
||||
void turboBoost() {
|
||||
this->turbo = this->turboMAX;
|
||||
}
|
||||
};
|
@ -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->createCameraMatrixForHUDBar();
|
||||
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
|
||||
|
||||
// Kombinuj macierze transformacji
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
|
@ -14,25 +14,20 @@ public:
|
||||
GLuint program;
|
||||
Core::RenderContext sphereContext;
|
||||
glm::mat4 positionMatrix;
|
||||
GLuint textureID;
|
||||
|
||||
Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, GLuint textureID, glm::vec3 color, double scale) {
|
||||
Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, glm::vec3 color, double scale) {
|
||||
this->program = program;
|
||||
this->sphereContext = sphereContext;
|
||||
this->sunPos = pos;
|
||||
this->sunDir = dir;
|
||||
this->sunColor = color;
|
||||
this->scale = scale;
|
||||
this->textureID = textureID;
|
||||
}
|
||||
|
||||
Sun(){}
|
||||
|
||||
void draw() {
|
||||
glUseProgram(program);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
glUniform1i(glGetUniformLocation(program, "sunTexture"), 0);
|
||||
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance()->createCameraMatrix();
|
||||
positionMatrix = glm::translate(sunPos);
|
||||
glm::mat4 transformation = viewProjectionMatrix * positionMatrix * glm::scale(glm::vec3(scale));
|
||||
|
@ -32,8 +32,6 @@
|
||||
<ClInclude Include="GameEntity.h" />
|
||||
<ClInclude Include="GameObject.h" />
|
||||
<ClInclude Include="GameUtils.h" />
|
||||
<ClInclude Include="Heart.h" />
|
||||
<ClInclude Include="Nitro.h" />
|
||||
<ClInclude Include="ParticleSystem.h" />
|
||||
<ClInclude Include="Planet.h" />
|
||||
<ClInclude Include="Spaceship.h" />
|
||||
|
@ -59,7 +59,7 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="SpriteRenderer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Source.cpp">
|
||||
<Filter>Shader Files</Filter>
|
||||
</ClCompile>
|
||||
@ -123,20 +123,14 @@
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SpriteRenderer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ParticleSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameEntity.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Heart.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Nitro.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\shader_8_sun.vert">
|
||||
@ -169,14 +163,14 @@
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_sprite.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_tex.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_tex.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_tex.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_tex.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="particle.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
|
@ -3,13 +3,9 @@
|
||||
uniform vec3 color;
|
||||
uniform float exposition;
|
||||
|
||||
uniform sampler2D sunTexture;
|
||||
in vec2 TexCoords;
|
||||
|
||||
out vec4 outColor;
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = texture(sunTexture, TexCoords);
|
||||
vec3 brightColor = texColor.rgb * 4.0;
|
||||
outColor = vec4(vec3(1.0) - exp(-brightColor*exposition),texColor.a);
|
||||
}
|
||||
{
|
||||
outColor = vec4(vec3(1.0) - exp(-color*exposition),1);
|
||||
}
|
||||
|
@ -5,11 +5,9 @@ layout(location = 1) in vec3 vertexNormal;
|
||||
layout(location = 2) in vec2 vertexTexCoord;
|
||||
|
||||
uniform mat4 transformation;
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
//gl_Position = vec4(vertexPosition, 1.0);
|
||||
TexCoords = vertexTexCoord;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ uniform vec3 cameraPos;
|
||||
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform sampler2D normalSampler;
|
||||
|
||||
uniform vec3 lightPositions[100];
|
||||
uniform vec3 lightColors[100];
|
||||
@ -27,7 +26,6 @@ uniform float exposition;
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
in vec2 TexCoords;
|
||||
in mat3 TBN;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
@ -102,16 +100,7 @@ void main()
|
||||
|
||||
vec4 texColor = texture(textureSampler, TexCoords);
|
||||
|
||||
|
||||
vec3 normalMapNormal = texture(normalSampler, TexCoords).xyz;
|
||||
normalMapNormal = normalMapNormal * 2.0 - 1.0;
|
||||
//normalMapNormal.y = -normalMapNormal.y;
|
||||
|
||||
vec3 normal = normalize(normalMapNormal * TBN );
|
||||
|
||||
//vec3 normal = normalize(texture(normalSampler, TexCoords).xyz * TBN);
|
||||
//vec3 normal = normalize(vecNormal);
|
||||
|
||||
vec3 normal = normalize(vecNormal);
|
||||
|
||||
vec3 viewDir = normalize(cameraPos-worldPos);
|
||||
|
||||
|
@ -20,21 +20,18 @@ uniform vec3 cameraPos;
|
||||
out vec3 viewDirTS;
|
||||
out vec3 lightDirTS[10];
|
||||
out vec3 spotlightDirTS;
|
||||
out mat3 TBN;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = vertexTexCoord * -1;
|
||||
TexCoords = vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y);
|
||||
|
||||
|
||||
|
||||
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
|
||||
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
|
||||
vec3 w_tangent = normalize(mat3(modelMatrix)*vertexTangent);
|
||||
vec3 w_bitangent = normalize(mat3(modelMatrix)*vertexBitangent);
|
||||
TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
|
||||
mat3 TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
|
||||
|
||||
vec3 V = normalize(cameraPos-worldPos);
|
||||
viewDirTS = TBN*V;
|
||||
|
@ -190,7 +190,7 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalID, float roughness, float metallic, GLuint program) {
|
||||
void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, float roughness, float metallic, GLuint program) {
|
||||
Spaceship* spaceship = Spaceship::getInstance();
|
||||
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
@ -201,12 +201,10 @@ void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMat
|
||||
|
||||
glUniform1f(glGetUniformLocation(program, "roughness"), roughness);
|
||||
glUniform1f(glGetUniformLocation(program, "metallic"), metallic);
|
||||
|
||||
;
|
||||
//glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
|
||||
Core::SetActiveTexture(textureID, "textureSampler", program, 0);
|
||||
glUniform1i(glGetUniformLocation(program, "textureSampler"), 0);
|
||||
|
||||
Core::SetActiveTexture(normalID, "normalSampler", program, 1);
|
||||
glUniform1i(glGetUniformLocation(program, "normalSampler"), 1);
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "cameraPos"), spaceship->cameraPos.x, spaceship->cameraPos.y, spaceship->cameraPos.z);
|
||||
|
||||
|
@ -74,5 +74,5 @@ namespace Core
|
||||
glm::mat4 createPerspectiveMatrix();
|
||||
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic, GLuint program);
|
||||
void loadModelToContext(std::string path, Core::RenderContext& context);
|
||||
void drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalID, float roughness, float metallic, GLuint program);
|
||||
void drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, float roughness, float metallic, GLuint program);
|
||||
}
|
@ -6,10 +6,11 @@
|
||||
#include <cmath>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
|
||||
#include "Shader_Loader.h"
|
||||
#include "Render_Utils.h"
|
||||
#include "texture.h"
|
||||
|
||||
#include "Box.cpp"
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
@ -22,42 +23,24 @@
|
||||
#include "../GameUtils.h"
|
||||
#include "../SpriteRenderer.h"
|
||||
#include "../Enemy.h"
|
||||
#include "../Heart.h"
|
||||
#include "../Nitro.h"
|
||||
|
||||
#include "../ParticleSystem.h"
|
||||
#include "Camera.h"
|
||||
#include <random>
|
||||
|
||||
|
||||
#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 = 1920, HEIGHT = 1080;
|
||||
int WIDTH = 500, HEIGHT = 500;
|
||||
namespace models {
|
||||
Core::RenderContext marbleBustContext;
|
||||
Core::RenderContext spaceshipContext;
|
||||
Core::RenderContext sphereContext;
|
||||
Core::RenderContext cubeContext;
|
||||
Core::RenderContext asteroid;
|
||||
}
|
||||
namespace texture {
|
||||
GLuint cubemapTexture;
|
||||
GLuint spaceshipTexture;
|
||||
GLuint spaceshipNormal;
|
||||
GLuint spriteTexture;
|
||||
GLuint earthTexture;
|
||||
GLuint asteroidTexture;
|
||||
GLuint asteroidNormal;
|
||||
GLuint heartTexture;
|
||||
GLuint boosterTexture;
|
||||
}
|
||||
|
||||
struct TextureTuple {
|
||||
@ -66,7 +49,7 @@ struct TextureTuple {
|
||||
};
|
||||
|
||||
std::vector<TextureTuple> planetTextures;
|
||||
std::vector<GLuint> sunTexturesIds;
|
||||
|
||||
|
||||
void createGalaxy(glm::vec3 galaxyPosition);
|
||||
|
||||
@ -86,8 +69,6 @@ std::list<Planet*> planets;
|
||||
Sun* sun;
|
||||
GLuint VAO,VBO;
|
||||
|
||||
std::vector<Nitro*> nitros;
|
||||
std::vector<Heart*> hearts;
|
||||
std::vector<Enemy*> enemies;
|
||||
std::vector<GameEntity*> gameEntities;
|
||||
|
||||
@ -100,20 +81,9 @@ float lastTime = -1.f;
|
||||
float deltaTime = 0.f;
|
||||
|
||||
Spaceship* spaceship = Spaceship::getInstance();
|
||||
void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId,float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
|
||||
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
|
||||
Core::SpriteRenderer* spriteRenderer;
|
||||
|
||||
const int ENEMY_COUNT = 20;
|
||||
std::vector<glm::vec3> referencePoints = {
|
||||
glm::vec3(0, 2, 0),
|
||||
glm::vec3(150, 5, 0),
|
||||
glm::vec3(-20, -30, 50),
|
||||
glm::vec3(100, 20, -50),
|
||||
glm::vec3(0, 52, 200),
|
||||
glm::vec3(150, 55, 200),
|
||||
glm::vec3(-20, 20, 250),
|
||||
glm::vec3(100, 70, 150)
|
||||
};
|
||||
void updateDeltaTime(float time) {
|
||||
if (lastTime < 0) {
|
||||
lastTime = time;
|
||||
@ -124,101 +94,20 @@ void updateDeltaTime(float time) {
|
||||
if (deltaTime > 0.1) deltaTime = 0.1;
|
||||
lastTime = time;
|
||||
}
|
||||
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));
|
||||
}
|
||||
void renderHUD() {
|
||||
glUseProgram(programSpriteBar);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
spriteRenderer->DrawHUDBar(
|
||||
glm::vec3(0.0824f, 0.5725f, 0.9765f),
|
||||
glm::scale(turboBarPosition, turboBarScale),
|
||||
spaceship->turbo / spaceship->turboMAX,
|
||||
programSpriteBar);
|
||||
|
||||
glm::mat4 spaceshipModelMatrix = spaceship->calculateModelMatrix();
|
||||
glm::mat4 healthBarPosition = glm::translate(spaceshipModelMatrix, glm::vec3(36.0f, -34.0f, 0.0f));
|
||||
spriteRenderer->DrawHUDBar(
|
||||
glm::vec3(0.0f, 1.0f, 0.0f),
|
||||
glm::scale(healthBarPosition, healthBarScale),
|
||||
glm::scale(healthBarPosition, glm::vec3(26.0f, 4.f, 1.0f)),
|
||||
spaceship->currentHP / spaceship->maxHP,
|
||||
programSpriteBar);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
bool isFarFromReferencePoints(float x, float y, float z, const std::vector<glm::vec3>& referencePoints) {
|
||||
float minDistance = 10.0f;
|
||||
|
||||
glm::vec3 currentPoint(x, y, z);
|
||||
|
||||
auto checkDistance = [currentPoint, minDistance](const glm::vec3& referencePoint) {
|
||||
return glm::distance(currentPoint, referencePoint) > minDistance;
|
||||
};
|
||||
|
||||
for (const auto& referencePoint : referencePoints) {
|
||||
if (!checkDistance(referencePoint)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
glm::mat4 generateRandomMatrix(const glm::mat4& startMatrix) {
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_real_distribution<float> disX(-30.0f, 180.0f);
|
||||
std::uniform_real_distribution<float> disY(-50.0f, 60.0f);
|
||||
std::uniform_real_distribution<float> disZ(-30.0f, 210.0f);
|
||||
float randomX, randomY, randomZ;
|
||||
|
||||
do {
|
||||
randomX = disX(gen);
|
||||
randomY = disY(gen);
|
||||
randomZ = disZ(gen);
|
||||
} while (!isFarFromReferencePoints(randomX, randomY, randomZ, referencePoints));
|
||||
|
||||
glm::mat4 randomModelMatrix = glm::translate(startMatrix, glm::vec3(randomX, randomY, randomZ));
|
||||
|
||||
|
||||
return randomModelMatrix;
|
||||
}
|
||||
void renderEnemies() {
|
||||
int counter = 0;
|
||||
glUseProgram(program);
|
||||
for (const auto& enemy : enemies) {
|
||||
if (enemy->isAlive()) {
|
||||
enemy->attack(spaceship->spaceshipPos, glfwGetTime());
|
||||
enemy->renderBullets(glfwGetTime(), program, gameEntities);
|
||||
}
|
||||
else {
|
||||
counter++;
|
||||
}
|
||||
|
||||
}
|
||||
if (counter >= ENEMY_COUNT / 2) {
|
||||
for (const auto& enemy : enemies) {
|
||||
if (!enemy->isAlive()) {
|
||||
enemy->initialModelMatrix = generateRandomMatrix(enemy->getModelMatrix());
|
||||
enemy->respawn();
|
||||
enemy->aggroRange *= 1.1;
|
||||
enemy->dmg *= 1.2;
|
||||
}
|
||||
}
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
|
||||
glUseProgram(programSpriteBar);
|
||||
for (const auto& enemy : enemies) {
|
||||
if (enemy->isAlive()) {
|
||||
@ -241,47 +130,16 @@ void renderEnemies() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void renderHeartsAndNitro() {
|
||||
//if (heart->isAlive()) {
|
||||
//spriteRenderer->DrawSprite(texture::heartTexture, heart->modelMatrix, programSprite);
|
||||
//}
|
||||
|
||||
glUseProgram(programSprite);
|
||||
for (auto it = hearts.begin(); it != hearts.end();) {
|
||||
Heart* heart = *it;
|
||||
if (heart->isAlive()) {
|
||||
spriteRenderer->DrawSprite(texture::heartTexture, heart->modelMatrix, programSprite);
|
||||
}
|
||||
|
||||
if (heart->isCollected) {
|
||||
spaceship->heal();
|
||||
it = hearts.erase(it);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
glUseProgram(program);
|
||||
for (const auto& enemy : enemies) {
|
||||
if (enemy->isAlive()) {
|
||||
enemy->attack(spaceship->spaceshipPos, glfwGetTime());
|
||||
enemy->renderBullets(glfwGetTime(), program, gameEntities);
|
||||
}
|
||||
|
||||
for (auto it = nitros.begin(); it != nitros.end();) {
|
||||
Nitro* nitro = *it;
|
||||
if (nitro->isAlive()) {
|
||||
spriteRenderer->DrawSprite(texture::boosterTexture, nitro->modelMatrix, programSprite);
|
||||
}
|
||||
}
|
||||
|
||||
if (nitro->isCollected) {
|
||||
spaceship->turboBoost();
|
||||
it = nitros.erase(it);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TextureTuple getRandomPlanetTexture() {
|
||||
int textureIndex = rand() % planetTextures.size();
|
||||
TextureTuple selectedTextures = planetTextures[textureIndex];
|
||||
@ -326,13 +184,8 @@ void renderScene(GLFWwindow* window)
|
||||
glUseProgram(program);
|
||||
|
||||
std::vector<GameEntity*> gameEntities(enemies.begin(), enemies.end());
|
||||
//spaceship->renderBullets(glfwGetTime(), program, gameEntities);
|
||||
|
||||
gameEntities.insert(gameEntities.end(), hearts.begin(), hearts.end());
|
||||
gameEntities.insert(gameEntities.end(), nitros.begin(), nitros.end());
|
||||
spaceship->renderBullets(glfwGetTime(), program, gameEntities);
|
||||
|
||||
|
||||
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, program);
|
||||
@ -343,15 +196,14 @@ void renderScene(GLFWwindow* window)
|
||||
drawObjectPBRTexture(models::spaceshipContext,
|
||||
spaceship->calculateModelMatrix(),
|
||||
texture::spaceshipTexture,
|
||||
texture::spaceshipNormal,
|
||||
spaceship->roughness, spaceship->metallic, programTex
|
||||
);
|
||||
|
||||
//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)) *
|
||||
//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);
|
||||
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);
|
||||
|
||||
//glUseProgram(programSprite);
|
||||
//for (const auto& enemy : enemies) {
|
||||
@ -374,17 +226,10 @@ void renderScene(GLFWwindow* window)
|
||||
glm::mat4 viewMatrix = Core::createViewMatrix(spaceship->cameraPos, spaceship->cameraDir, cameraUp);
|
||||
spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time);
|
||||
|
||||
if(!spaceship->isAlive()){
|
||||
spaceship->respawn();
|
||||
for (const auto& enemy : enemies) {
|
||||
enemy->respawn();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
renderHUD(window);
|
||||
renderHUD();
|
||||
renderEnemies();
|
||||
renderHeartsAndNitro();
|
||||
|
||||
//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);
|
||||
|
||||
|
||||
@ -404,51 +249,20 @@ void createSuns() {
|
||||
createGalaxy(glm::vec3(0.f, 50.f, 200.f));
|
||||
}
|
||||
|
||||
float generateRandomFloat(float minValue, float maxValue) {
|
||||
return minValue + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (maxValue - minValue)));
|
||||
}
|
||||
|
||||
|
||||
void createAsteroids() {
|
||||
GameUtils* gu = GameUtils::getInstance();
|
||||
GameObject* center = gu->getSuns()->front();
|
||||
float minDistanceFromCenter = 24.f;
|
||||
float maxDistanceFromCenter = 26.f;
|
||||
float rotationSpeed = 0.05f;
|
||||
float scale = 0.002f;
|
||||
int numAsteroids = 80;
|
||||
float distanceIncrement = 2.f / (minDistanceFromCenter + 1);
|
||||
|
||||
for (int j = -1; j < 2; j++) {
|
||||
for (int i = 0; i < numAsteroids; ++i) {
|
||||
float distanceFromCenter = generateRandomFloat(minDistanceFromCenter, maxDistanceFromCenter);
|
||||
Planet* asteroid = new Planet(center, distanceFromCenter, rotationSpeed, scale, models::asteroid, texture::asteroidTexture, texture::asteroidNormal);
|
||||
asteroid->setStarteulerYRotation(distanceIncrement * i);
|
||||
asteroid->setStartYMovement(generateRandomFloat(-0.5f, 0.5f) + j);
|
||||
planets.push_back(asteroid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createGalaxy(glm::vec3 galaxyPosition) {
|
||||
float planetsSizes[] = { 1.f, 1.5f, 0.8f, 1.2f, 0.2f };
|
||||
GLuint sunTexId = sunTexturesIds[0];
|
||||
createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), sunTexId,3, planetsSizes, 5, 15.f, 0.2f);
|
||||
createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), 3, planetsSizes, 5, 15.f, 0.2f);
|
||||
float planetsSizes2[] = { 0.6f, 1.1f, 0.9f };
|
||||
GLuint sunTexId2 = sunTexturesIds[1];
|
||||
createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), sunTexId2, 2, planetsSizes2, 3, 15.f, 0.2f);
|
||||
createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), 2, planetsSizes2, 3, 15.f, 0.2f);
|
||||
float planetsSizes3[] = { 0.7f, 1.5f, 1.2f, 1.f };
|
||||
GLuint sunTexId3 = sunTexturesIds[2];
|
||||
createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), sunTexId3, 4, planetsSizes3, 4, 20.f, 0.2f);
|
||||
createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), 4, planetsSizes3, 4, 20.f, 0.2f);
|
||||
float planetSizes4[] = { 1.f, 0.5f };
|
||||
GLuint sunTexId4 = sunTexturesIds[3];
|
||||
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), sunTexId4, 5, planetsSizes3, 2, 25.f, 0.2f);
|
||||
createAsteroids();
|
||||
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), 5, planetsSizes3, 2, 25.f, 0.2f);
|
||||
}
|
||||
|
||||
void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
|
||||
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
|
||||
GameUtils* gu = GameUtils::getInstance();
|
||||
sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), sunTexId, glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale);
|
||||
sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale);
|
||||
gu->getSuns()->push_back(sun);
|
||||
for (int i = 0; i < numberOfPlanets; i++) {
|
||||
TextureTuple textures = getRandomPlanetTexture();
|
||||
@ -459,37 +273,19 @@ void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId, float sunScale, float*
|
||||
planets.push_back(planet);
|
||||
}
|
||||
}
|
||||
|
||||
void createEnemies() {
|
||||
|
||||
//enemies.push_back(new Enemy(100.0f,100.0f, glm::mat4(1.0f), 1.0f, 5.0f));
|
||||
//enemies.push_back(new Enemy(100.0f,100.0f, glm::translate(glm::mat4(1.0f) , glm::vec3(1.f,1.f,1.f)), 1.0f, 5.0f));
|
||||
//enemies.push_back(new Enemy(100.0f,100.0f, glm::translate(glm::mat4(1.0f), glm::vec3(-1.f, 2.f, -0.9f)), 1.0f, 5.0f));
|
||||
int j = 0;
|
||||
enemies.push_back(new Enemy(100.0f, 100.0f, glm::translate(glm::translate(glm::mat4(1.0f), spaceship->getPosition()), glm::vec3(1.f, 1.f, 2.f)), 1.0f, 5.0f));
|
||||
for (int i = 0; i < ENEMY_COUNT; ++i) {
|
||||
|
||||
glm::mat4 randomModelMatrix = generateRandomMatrix(glm::mat4(1.0f));
|
||||
enemies.push_back(new Enemy(100.0f, 100.0f, randomModelMatrix, 1.0f, 8.0f));
|
||||
|
||||
if (j % 4 == 0) {
|
||||
hearts.push_back(new Heart(glm::translate(randomModelMatrix, glm::vec3(6.f, 5.f, 8.f)), -5.0f));
|
||||
nitros.push_back(new Nitro(glm::translate(randomModelMatrix, glm::vec3(2.f, -9.f, 3.f)), 10.0f));
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
|
||||
hearts.push_back(new Heart(glm::translate(glm::mat4(1.0f), glm::vec3(25.f, 20.f, 25.f)), 10.0f));
|
||||
nitros.push_back(new Nitro(glm::translate(glm::mat4(1.0f), glm::vec3(20.f, 20.f, 25.f)), 10.0f));
|
||||
enemies.push_back(new Enemy(100.0f,100.0f, glm::mat4(1.0f), 1.0f, 5.0f));
|
||||
enemies.push_back(new Enemy(100.0f,100.0f, glm::translate(glm::mat4(1.0f) , glm::vec3(1.f,1.f,1.f)), 1.0f, 5.0f));
|
||||
enemies.push_back(new Enemy(100.0f,100.0f, glm::translate(glm::mat4(1.0f), glm::vec3(-1.f, 2.f, -0.9f)), 1.0f, 5.0f));
|
||||
|
||||
//obiekty do ktorych bedzie sprawdzana kolizja dla pociskow enemy
|
||||
gameEntities.push_back(spaceship);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void loadPlanetsAndSunTextures() {
|
||||
void loadPlanetsTextures() {
|
||||
planetTextures.clear();
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> texturePaths = {
|
||||
@ -499,23 +295,11 @@ void loadPlanetsAndSunTextures() {
|
||||
{"./textures/planets/planet4.png", "./textures/planets/planet4normal.png"}
|
||||
};
|
||||
|
||||
std::vector<std::string> sunTexturePaths{
|
||||
{"./textures/suns/8k_sun.jpg"},
|
||||
{"./textures/suns/sun2.png"},
|
||||
{"./textures/suns/sun3.jpg"},
|
||||
{"./textures/suns/sun4.jpg"}
|
||||
};
|
||||
|
||||
for (const auto& paths : texturePaths) {
|
||||
GLuint textureID = Core::LoadTexture(paths.first.c_str());
|
||||
GLuint normalMapID = Core::LoadTexture(paths.second.c_str());
|
||||
planetTextures.push_back({ textureID, normalMapID });
|
||||
}
|
||||
|
||||
for (const auto& path : sunTexturePaths) {
|
||||
GLuint sunTextureId = Core::LoadTexture(path.c_str());
|
||||
sunTexturesIds.push_back(sunTextureId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -546,7 +330,6 @@ void init(GLFWwindow* window)
|
||||
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
||||
loadModelToContext("./models/cube.obj", models::cubeContext);
|
||||
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
|
||||
Core::loadModelToContext("./models/Asteroid.obj", models::asteroid);
|
||||
|
||||
texture::spriteTexture = Core::LoadTexture("textures/blinky1.png");
|
||||
|
||||
@ -559,15 +342,10 @@ void init(GLFWwindow* window)
|
||||
"bkg2_back6.png"
|
||||
};
|
||||
|
||||
loadPlanetsAndSunTextures();
|
||||
loadPlanetsTextures();
|
||||
texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
|
||||
texture::spaceshipTexture = Core::LoadTexture("./textures/spaceship/Material.001_Base_color.jpg");
|
||||
texture::spaceshipNormal = Core::LoadTexture("./textures/spaceship/Material.001_Normal_DirectX.jpg");
|
||||
texture::earthTexture = Core::LoadTexture("./textures/planets/8k_earth_daymap.jpg");
|
||||
texture::asteroidTexture = Core::LoadTexture("./textures/asteroids/asteroidtx.jpg");
|
||||
texture::asteroidNormal = Core::LoadTexture("./textures/asteroids/asteroidnn.png");
|
||||
texture::heartTexture = Core::LoadTexture("textures/heart.png");
|
||||
texture::boosterTexture = Core::LoadTexture("textures/boooster.png");
|
||||
|
||||
spaceship->createParticles();
|
||||
createSuns();
|
||||
|
@ -8,11 +8,10 @@
|
||||
|
||||
|
||||
#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);
|
||||
@ -24,7 +23,7 @@ int main(int argc, char** argv)
|
||||
#endif
|
||||
|
||||
// tworzenie okna za pomoca glfw
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "FirstWindow", NULL, NULL);
|
||||
GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL);
|
||||
if (window == NULL)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
@ -35,7 +34,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// ladowanie OpenGL za pomoca glew
|
||||
glewInit();
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
glViewport(0, 0, 500, 500);
|
||||
|
||||
init(window);
|
||||
|
||||
|
Before Width: | Height: | Size: 5.8 MiB |
Before Width: | Height: | Size: 941 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 3.5 MiB |
Before Width: | Height: | Size: 283 KiB |
Before Width: | Height: | Size: 555 KiB |
Before Width: | Height: | Size: 190 KiB |
Before Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 356 KiB |
BIN
images/hp.png
Before Width: | Height: | Size: 1.6 MiB |
Before Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 283 KiB |
BIN
images/turbo.png
Before Width: | Height: | Size: 448 KiB |