Compare commits

..

10 Commits

Author SHA1 Message Date
e3b66ef977 Merge pull request 'final commit' (#21) from final_comit into master
Reviewed-on: #21
2024-02-08 19:54:38 +01:00
Wojtek
3dc84f2df1 final commit 2024-02-08 19:51:39 +01:00
f28de5f2be Merge pull request 'hearts' (#20) from hearts into master
Reviewed-on: #20
2024-02-08 05:10:34 +01:00
Wojtek
abf896ce6d nitroes 2 2024-02-08 04:55:27 +01:00
Wojtek
a49a76f8ef nitroes 2024-02-08 04:54:48 +01:00
Wojtek
1421b90c66 Opis projektu 2024-02-08 04:44:22 +01:00
630438b1bc Merge pull request 'enemies_placement' (#19) from enemies_placement into master
Reviewed-on: #19
2024-02-08 00:44:07 +01:00
de54348411 Merge pull request 'asteroids' (#18) from satellites into master
Reviewed-on: #18
2024-02-07 23:14:35 +01:00
Pawel Felcyn
d949505204 asteroids 2024-02-07 23:13:51 +01:00
ebbda6e21e Merge pull request 'enemies_placement' (#17) from enemies_placement into master
Reviewed-on: #17
2024-02-07 16:32:08 +01:00
25 changed files with 1754 additions and 22 deletions

BIN
Opis_Projektu.pdf Normal file

Binary file not shown.

43
README.md Normal file
View File

@ -0,0 +1,43 @@
# 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

View File

@ -61,7 +61,6 @@ public:
bool checkCollisionWithGameEntities(std::vector<GameEntity*>& gameEntities, glm::mat4 bulletModelMatrix, float attackerDmg) {
for (const auto& entity : gameEntities) {
glm::mat4 entityModelMatrix = entity->getModelMatrix();
if (checkAABBCollision(bulletModelMatrix, entityModelMatrix)) {
entity->applyDamage(attackerDmg);
return true;

View File

@ -82,6 +82,9 @@ public:
this->dmg = this->initDMG;
return;
}
void heal() override {
this->currentHP = this->currentHP + 5.0f;
}
private:
void requestShoot(float time) {
if (canShoot(time)) {

View File

@ -10,11 +10,12 @@ public:
float initDMG;
GameEntity(float currentHP, float maxHP, float initialDmg)
: currentHP(currentHP), maxHP(maxHP), dmg(initialDmg),initDMG(initialDmg)
: currentHP(currentHP), maxHP(maxHP), dmg(initialDmg), initDMG(initialDmg)
{
}
virtual void applyDamage(float attackerDmg) {
currentHP = currentHP - attackerDmg;
};
@ -27,5 +28,6 @@ public:
return true;
};
virtual void respawn() = 0;
virtual void heal() = 0;
};

55
grk/project/Heart.h Normal file
View File

@ -0,0 +1,55 @@
#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;
}
};

55
grk/project/Nitro.h Normal file
View File

@ -0,0 +1,55 @@
#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;
}
};

View File

@ -16,6 +16,8 @@ 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) {
@ -39,8 +41,16 @@ public:
}
float rotationAngle = glm::radians(time * rotationSpeed);
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed) * glm::translate(glm::vec3(distanceFromCenter, 0, 0));
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed + startEulerYRotation) * glm::translate(glm::vec3(distanceFromCenter, startYMovement, 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;
}
};

View File

@ -229,17 +229,17 @@ public:
if (turbo == 0.0f) {
shiftState = GLFW_RELEASE;
moveSpeed = 0.05f * deltaTime * 60;
setPerticlesParameters(100.f, 0.0001f);
setPerticlesParameters(100.f, 0.000001f);
}
else {
moveSpeed *= 2;
setPerticlesParameters(200.f, 0.00005f);
setPerticlesParameters(200.f, 0.0000005f);
}
}
else {
setPerticlesParameters(100.f, 0.0001f);
setPerticlesParameters(100.f, 0.000001f);
turbo = glm::min(turboMAX, turbo + 0.001f * deltaTime * 60);
}
}
@ -274,7 +274,7 @@ public:
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)));
glm::vec3 perpendicularVector = 0.08f * 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);
@ -394,4 +394,12 @@ public:
return;
}
void heal() override {
this->currentHP = this->currentHP + 3.f;
}
void turboBoost() {
this->turbo = this->turboMAX;
}
};

View File

@ -32,6 +32,8 @@
<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" />

View File

@ -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,14 +123,20 @@
<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">
@ -163,14 +169,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>

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,10 @@
#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>
@ -23,6 +22,8 @@
#include "../GameUtils.h"
#include "../SpriteRenderer.h"
#include "../Enemy.h"
#include "../Heart.h"
#include "../Nitro.h"
#include "../ParticleSystem.h"
#include "Camera.h"
@ -45,6 +46,7 @@ namespace models {
Core::RenderContext spaceshipContext;
Core::RenderContext sphereContext;
Core::RenderContext cubeContext;
Core::RenderContext asteroid;
}
namespace texture {
GLuint cubemapTexture;
@ -52,6 +54,10 @@ namespace texture {
GLuint spaceshipNormal;
GLuint spriteTexture;
GLuint earthTexture;
GLuint asteroidTexture;
GLuint asteroidNormal;
GLuint heartTexture;
GLuint boosterTexture;
}
struct TextureTuple {
@ -80,6 +86,8 @@ 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;
@ -234,6 +242,46 @@ 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;
}
}
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];
@ -278,8 +326,13 @@ 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);
@ -331,7 +384,7 @@ void renderScene(GLFWwindow* window)
renderHUD(window);
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);
@ -351,6 +404,32 @@ 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];
@ -364,6 +443,7 @@ void createGalaxy(glm::vec3 galaxyPosition) {
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();
}
void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
@ -384,20 +464,31 @@ 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));
//obiekty do ktorych bedzie sprawdzana kolizja dla pociskow enemy
gameEntities.push_back(spaceship);
}
void loadPlanetsAndSunTextures() {
planetTextures.clear();
@ -455,6 +546,7 @@ 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");
@ -472,6 +564,10 @@ void init(GLFWwindow* window)
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();

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
images/asteroidy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

BIN
images/galaktyki.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

BIN
images/hp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

BIN
images/normal_map.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

BIN
images/sprite.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
images/sprite_dmg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
images/strzelanie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

BIN
images/turbo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB