Compare commits

...

49 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
5d2405774b Add starter enemy 2024-02-08 00:43:24 +01:00
23b1f0c124 Add constant enemies respawn when half of them is defeated 2024-02-08 00:23:07 +01:00
6737f14356 Add respawn for spaceship and enemies 2024-02-07 23:44:53 +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
91c2dca35b Change spaceship starting position and lower nitro consumption 2024-02-07 22:54:19 +01:00
1579e92b35 Add random location enemy generator 2024-02-07 22:46:33 +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
7c410aee09 Add turbo bar 2024-02-07 16:29:16 +01:00
598d709910 Fix healthbar is visible in maximized window 2024-02-07 16:26:33 +01:00
dc73f3b5f1 Fix hud bars are no longer moving and rotating with spaceship movement 2024-02-07 16:26:33 +01:00
6f85812a35 Change window size to 1920x1080 2024-02-07 16:26:33 +01:00
1f70717502 Merge pull request 'normal map on ship' (#15) from fix_normal_map into master
Reviewed-on: #15
2024-02-07 14:02:31 +01:00
Wojtek
ec331f322b normal map on ship 2024-02-07 13:59:41 +01:00
203110adf5 Merge pull request 'sun_textures+ship_texturing_works' (#14) from sun_textures into master
Reviewed-on: #14
2024-02-05 23:50:36 +01:00
Wojtek
8090c8ec1c sun_textures+ship_texturing_works 2024-02-05 22:22:25 +01:00
06edddcbdc Merge pull request 'spaceship animations' (#13) from movement into master
Reviewed-on: #13
2024-02-04 20:32:07 +01:00
Pawel Felcyn
6df3b595d7 spaceship animations 2024-02-04 20:31:21 +01:00
99c3fab77b Merge pull request 'normal mapping - sth wrong with the ship' (#12) from noramal into master
Reviewed-on: #12
2024-02-04 18:11:24 +01:00
Pawel Felcyn
3fe71e0f93 normal mapping - sth wrong with the ship 2024-02-04 18:10:19 +01:00
3b506455c6 Merge pull request 'health_bar' (#11) from health_bar into master
Reviewed-on: #11
2024-02-03 21:51:29 +01:00
61170baa47 Adjust hud postion to the new scale 2024-02-03 21:50:55 +01:00
1f09c40bb5 Add collision detection and taking dmg 2024-02-03 21:31:46 +01:00
94b22aad78 Add drawing HUD HP bar 2024-02-03 21:28:49 +01:00
de13bc43a4 Add drawing health bars for enemies 2024-02-03 21:28:12 +01:00
057d07c3b3 Merge pull request 'prbTexture+ammo_count' (#10) from prbTexture+ammo_count into master
Reviewed-on: #10
2024-02-02 22:15:39 +01:00
Wojtek
2a4d52c235 merge 2024-02-02 22:12:09 +01:00
Wojtek
48fcc13278 gitignore 2024-02-02 22:00:18 +01:00
Wojtek
e4d1460f2e usuniecie tekstury 2024-02-02 21:59:37 +01:00
Wojtek
54c3674f24 all planets has random textures 2024-02-02 21:59:37 +01:00
Wojtek
2054a2919e refractoring 2024-02-02 21:58:14 +01:00
Wojtek
6e7c437aa8 earth_texture works 2024-02-02 21:57:31 +01:00
Wojtek
67fa38035c new ship + texturing 2024-02-02 21:55:47 +01:00
a15c1f9c6c Merge pull request 'fix gitignore' (#9) from fire into master
Reviewed-on: #9
2024-02-02 21:33:58 +01:00
Pawel Felcyn
b3893d1587 fix gitignore 2024-02-02 21:31:27 +01:00
2c5a971405 Merge pull request 'fire from spaceship' (#7) from fire into master
Reviewed-on: #7
2024-01-30 21:16:16 +01:00
Pawel Felcyn
69d7db83fa fire from spaceship 2024-01-30 21:15:07 +01:00
cf07257222 Merge pull request 'enemies' (#6) from enemies into master
Reviewed-on: #6
2024-01-29 16:14:31 +01:00
Qumpell
79d0069a52 modify gitignore 2024-01-29 16:11:15 +01:00
4e3264ad2a Fix billboarding of enemies and their shooting positions 2024-01-29 16:11:15 +01:00
f1c3a1b57b Add enemy class 2024-01-29 16:10:54 +01:00
6b60c55af7 Add sprite renderer and sprite shaders 2024-01-29 16:07:55 +01:00
91 changed files with 64824 additions and 309 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@

/grk/.vs/grk-cw
/grk/project/Debug
/.vs
/grk/dependencies/glm/out/build/x64-Debug

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

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,7 @@
#include "glm.hpp"
#include "src/Shader_Loader.h"
#include <vector>
#include "GameEntity.h"
#pragma once
class Bullet
@ -39,14 +41,50 @@ public:
return new Bullet(10, 10, directionNormalized, startPosition, birthTime, simpleRenderContext, 0.01f);
}
bool shouldBeDestroyed(float time, GLuint program) {
bool shouldBeDestroyed(float time, GLuint program, std::vector<GameEntity*>& gameEntities, float attackerDmg) {
float age = getAge(time);
if (age > lifetime) {
return true;
}
glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), startPosition) * glm::translate(directionNormalized * speed * age) * glm::scale(glm::vec3(scale));
Core::drawObjectPBR(renderContext, modelMatrix, glm::vec3(1.f, 0.f, 0.f), 0.3, 0, program);
//std::cout << "x: " << modelMatrix[3].x << std::endl;
//std::cout << "y: " << modelMatrix[3].y << std::endl;
//std::cout << "z: " << modelMatrix[3].z << std::endl;
if (checkCollisionWithGameEntities(gameEntities, modelMatrix, attackerDmg)) {
return true;
}
return false;
}
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;
}
}
return false;
}
bool checkAABBCollision(const glm::mat4& obj1ModelMatrix, const glm::mat4& obj2ModelMatrix) {
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));
glm::vec3 obj2Min = glm::vec3(obj2ModelMatrix * glm::vec4(-0.5f, -0.5f, -0.5f, 1.0f));
glm::vec3 obj2Max = glm::vec3(obj2ModelMatrix * glm::vec4(0.5f, 0.5f, 0.5f, 1.0f));
// SprawdŸ kolizjê wzd³u¿ trzech osi (x, y, z)
bool collisionX = obj1Max.x >= obj2Min.x && obj1Min.x <= obj2Max.x;
bool collisionY = obj1Max.y >= obj2Min.y && obj1Min.y <= obj2Max.y;
bool collisionZ = obj1Max.z >= obj2Min.z && obj1Min.z <= obj2Max.z;
// Kolizja wystêpuje tylko wtedy, gdy zachodzi kolizja na wszystkich trzech osiach
return collisionX && collisionY && collisionZ;
}
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\KOMP\Documents\projekt_grafika_komputerowa\grafika_komputerowa\grk\Debug\grk-project.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

108
grk/project/Enemy.h Normal file
View File

@ -0,0 +1,108 @@
#include "glm.hpp"
#include "ext.hpp"
#include "src/Render_Utils.h"
#include "Bullet.h"
#include "./GameEntity.h"
#include "Spaceship.h"
#pragma once
class Enemy : public GameEntity
{
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)
{}
virtual ~Enemy() = default;
virtual void attack(const glm::vec3& shipPos, float time) {
if (isInAggroRange(shipPos)) {
requestShoot(time);
}
}
virtual bool isAlive() const {
if (this->currentHP <= 0) {
return false;
}
return true;
}
virtual bool isInAggroRange(const glm::vec3& shipPos) const {
float distanceFromShip = glm::length(shipPos - glm::vec3(this->modelMatrix[3]));
if (distanceFromShip > this->aggroRange) {
return false;
}
return true;
}
void renderBullets(float time, GLuint program, std::vector<GameEntity*>& gameEntities) {
for (auto it = bullets.begin(); it != bullets.end();) {
Bullet* bullet = *it;
if (bullet->shouldBeDestroyed(time, program, gameEntities, dmg)) {
delete bullet;
it = bullets.erase(it);
}
else {
it++;
}
}
}
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;
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)) {
shoot(time);
}
}
bool canShoot(float time) {
return this->lastShootTime == 0 || time - this->lastShootTime > this->shootInterval;
}
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]));
//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;
}
};

33
grk/project/GameEntity.h Normal file
View File

@ -0,0 +1,33 @@
#include "glm.hpp"
#pragma once
class GameEntity
{
public:
float currentHP;
float dmg;
float maxHP;
float initDMG;
GameEntity(float currentHP, float maxHP, float initialDmg)
: currentHP(currentHP), maxHP(maxHP), dmg(initialDmg), initDMG(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;
};

View File

@ -2,6 +2,7 @@
#include "Sun.h"
#include "Bullet.h"
#include "src/Shader_Loader.h"
#include "ParticleSystem.h"
#pragma once
class GameUtils
@ -12,9 +13,11 @@ private:
{
this->suns = new std::list<Sun*>();
this->shaderLoader = new Core::Shader_Loader();
this->particleSystems = new std::list<ParticleSystem*>();
}
std::list<Sun*>* suns;
std::list<Bullet*> bullets;
std::list<ParticleSystem*>* particleSystems;
float aspectRatio;
@ -35,6 +38,10 @@ public:
return suns;
}
std::list<ParticleSystem*>* getParticleSystems() {
return particleSystems;
}
static GameUtils* getInstance()
{
static GameUtils instance; // Jedna i jedyna instancja

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

@ -0,0 +1,143 @@
#pragma once
#include "glew.h"
#include <GLFW/glfw3.h>
#include "glm.hpp"
#include <list>
#include "ext.hpp"
struct Particle
{
public:
float birthTime;
glm::vec3 startPosition;
glm::vec3 direction;
glm::vec3 randomPointOnCircle;
float getAge(float time) {
return time - birthTime;
}
};
class ParticleSystem
{
private:
std::list<Particle> particles;
GLuint VBO;
GLuint VAO;
GLfloat vertices[9];
float lastGenerated = -1.f;
bool shouldGenerateNewParticle(float time) {
return lastGenerated == -1.f || time - lastGenerated > generationInterval;
}
glm::vec3 generateRandomPointOnCircle() {
float distanceFromCenter = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/sourceRadius);
float radians = static_cast <float> (rand()) / static_cast <float> (RAND_MAX / 6.28f);
glm::vec3 referenceVector(0.0f, 1.0f, 0.0f);
glm::vec3 output = glm::normalize(glm::cross(sourceDirection, referenceVector)) * distanceFromCenter;
glm::mat4 rotationMatrix = glm::rotate(glm::mat4(1.0f), radians, sourceDirection);
output = glm::vec3(rotationMatrix * glm::vec4(output, 1.0f));
return output;
}
void generateNewParticle(float time) {
Particle newParticle;
newParticle.birthTime = time;
newParticle.startPosition = sourcePosition;
newParticle.randomPointOnCircle = generateRandomPointOnCircle();
newParticle.direction = sourceDirection;
particles.push_back(newParticle);
lastGenerated = time;
}
void deleteOld(float time) {
auto it = particles.begin();
while (it != particles.end()) {
if ((*it).getAge(time) > lifetime) {
it = particles.erase(it);
}
else {
++it;
}
}
}
glm::vec3 calculateParticleColor(float age) {
float rate = glm::clamp(age / lifetime, 0.f, 1.f);
glm::vec3 mixedColor = (1.0f - rate) * startColor + rate * endColor;
return mixedColor;
}
public:
glm::vec3 sourcePosition;
float sourceRadius = 0.02f;
glm::vec3 sourceDirection = glm::vec3(1.f, 0.f, 0.f);
float generationInterval = 0.0025f;
float lifetime = 0.5f;
float speed = 100.f;
glm::vec3 startColor = glm::vec3(1.f, 0.f, 0.f);
glm::vec3 endColor = glm::vec3(1.f, 1.f, 0.f);
ParticleSystem() {
// Inicjalizacja wierzcho³ków trójk¹ta w 3D
vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = 0.0f;
vertices[3] = 0.5f; vertices[4] = -0.5f; vertices[5] = 0.0f;
vertices[6] = 0.0f; vertices[7] = 0.5f; vertices[8] = 0.0f;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void*)0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
}
void drawParticles(GLuint program, glm::mat4 view, glm::mat4 projection, glm::mat4 modelSrc, float time) {
if (shouldGenerateNewParticle(time)) {
generateNewParticle(time);
}
deleteOld(time);
glUseProgram(program);
GLuint modelLoc = glGetUniformLocation(program, "model");
GLuint viewLoc = glGetUniformLocation(program, "view");
GLuint projectionLoc = glGetUniformLocation(program, "projection");
GLuint colorLoc = glGetUniformLocation(program, "color");
int i = 0;
for (auto particle : particles) {
glm::vec3 color = calculateParticleColor(particle.getAge(time));
glUniform3f(colorLoc, color.x, color.y, color.z);
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;
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));
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
i++;
}
glBindVertexArray(0);
}
};

View File

@ -14,15 +14,21 @@ private:
float scale;
glm::vec3 position;
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) {
Planet(GameObject* center, float distanceFromCenter, float rotationSpeed, float scale, Core::RenderContext sphereContext, GLuint textureID, GLuint normalMapID) {
this->center = center;
this->distanceFromCenter = distanceFromCenter;
this->rotationSpeed = rotationSpeed;
this->sphereContext = sphereContext;
this->scale = scale;
this->position = glm::vec3(0);
this->textureID = textureID;
this->normalMapID = normalMapID;
}
glm::mat4 getPositionMatrix() override {
@ -35,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::drawObjectPBR(sphereContext, modelMatrix, glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
Core::drawObjectPBRTexture(sphereContext, modelMatrix, textureID, normalMapID, 0.7, 0.0, program);
}
void setStarteulerYRotation(float radians) {
startEulerYRotation = radians;
}
void setStartYMovement(float value) {
startYMovement = value;
}
};

0
grk/project/Source.cpp Normal file
View File

View File

@ -3,19 +3,25 @@
#include <GLFW/glfw3.h>
#include <list>
#include "Bullet.h"
#include "ParticleSystem.h"
#include "GameEntity.h"
#pragma once
class Spaceship
class Spaceship : public GameEntity
{
private:
std::list<Bullet*> bullets;
float lastShootTime = 0.f;
float shootInterval = 0.3f;
ParticleSystem* leftParticle;
ParticleSystem* rightParticle;
// Prywatny konstruktor, aby zapobiec zewnêtrznemu tworzeniu instancji
Spaceship() {
// Prywatny konstruktor, aby zapobiec zewn<77>trznemu tworzeniu instancji
Spaceship() : GameEntity(100.0f, 100.0f, 10.0f)
{
}
// Prywatny destruktor, aby zapobiec przypadkowemu usuwaniu instancji
@ -30,10 +36,12 @@ public:
}
glm::vec3 color = glm::vec3(0.3, 0.3, 0.5);
float roughness = 0.2;
float metallic = 1.0;
float roughness = 0.5;
float metallic = 0.6;
float turbo = 1.0f;
float turboMAX = 1.0f;
glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f);
glm::vec3 spaceshipPos = glm::vec3(4.065808f, 10.250000f, -20.189549f);
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
@ -43,18 +51,153 @@ 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 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.,
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) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f));
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;
}
void setPerticlesParameters(float speed, float generationInterval) {
leftParticle->speed = speed;
leftParticle->generationInterval = generationInterval;
rightParticle->speed = speed;
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) {
@ -67,35 +210,100 @@ public:
float angleSpeed = 0.05f * deltaTime * 60;
float moveSpeed = 0.05f * deltaTime * 60;
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);
}
}
else {
setPerticlesParameters(100.f, 0.000001f);
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) {
glfwSetWindowShouldClose(window, true);
}
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
if (w == GLFW_PRESS)
spaceshipPos += spaceshipDir * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
if (s == GLFW_PRESS)
spaceshipPos -= spaceshipDir * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
spaceshipPos += spaceshipSide * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
spaceshipPos -= spaceshipSide * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
if (qState == GLFW_PRESS)
spaceshipPos += spaceshipUp * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
if (eState == GLFW_PRESS)
spaceshipPos -= spaceshipUp * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
if (aState == GLFW_PRESS)
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
if (dState == 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 - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
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.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);
leftParticle->sourceDirection = -spaceshipDir;
rightParticle->sourceDirection = -spaceshipDir;
}
spotlightPos = spaceshipPos + 0.2 * spaceshipDir;
spotlightConeDir = spaceshipDir;
}
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);
}
}
void createParticles() {
if (leftParticle != nullptr && rightParticle != nullptr) {
delete leftParticle;
delete rightParticle;
}
leftParticle = new ParticleSystem();
rightParticle = new ParticleSystem();
}
glm::mat4 createCameraMatrix()
{
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
@ -112,11 +320,11 @@ public:
return cameraMatrix;
}
void renderBullets(float time, GLuint program) {
void renderBullets(float time, GLuint program, std::vector<GameEntity*>& gameEntities) {
for (auto it = bullets.begin(); it != bullets.end();) {
Bullet* bullet = *it;
if (bullet->shouldBeDestroyed(time, program)) {
if (bullet->shouldBeDestroyed(time, program, gameEntities, dmg)) {
delete bullet;
it = bullets.erase(it);
}
@ -138,8 +346,60 @@ public:
void shoot(float time) {
glm::vec3 perpendicularVector = 0.25f * glm::normalize(glm::cross(cameraDir, glm::vec3(0.0f, 1.0f, 0.0f)));
bullets.push_back(Bullet::createSimpleBullet(cameraDir, spaceshipPos - perpendicularVector, time));
bullets.push_back(Bullet::createSimpleBullet(cameraDir, spaceshipPos + perpendicularVector, time));
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));
lastShootTime = time;
}
glm::vec3 getPosition() const override {
return spaceshipPos;
}
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;
}
};

View File

@ -0,0 +1,143 @@
#include "SpriteRenderer.h"
#include <iostream>
Core::SpriteRenderer::SpriteRenderer()
{
this->initRenderData();
}
Core::SpriteRenderer::~SpriteRenderer()
{
glDeleteVertexArrays(1, &this ->VAO);
glDeleteBuffers(1, &this->VBO);
glDeleteBuffers(1, &this->EBO);
}
void Core::SpriteRenderer::DrawHUDBar(const glm::vec3 color, const glm::mat4 modelMatrix, const float progress, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance();
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrixForHUDBar();
// Kombinuj macierze transformacji
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
// Przeka¿ macierze do shadera
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, glm::value_ptr(transformation));
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniform3fv(glGetUniformLocation(program, "activeColor"), 1, glm::value_ptr(color));
glUniform1f(glGetUniformLocation(program, "progress"), progress);
glBindVertexArray(this->VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
};
void Core::SpriteRenderer::DrawSpriteBar(const glm::vec3 color, const glm::mat4 modelMatrix,const float progress, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance();
// Pobierz pozycjê kamery
glm::vec3 cameraPosition = spaceship->cameraPos;
glm::vec3 spritePosition = glm::vec3(modelMatrix[3]);
// Oblicz wektor skierowany od sprita do kamery
glm::vec3 spriteToCamera = glm::normalize(cameraPosition - spritePosition);
// Oblicz k¹t rotacji w stopniach wokó³ osi Y
float angle = glm::degrees(atan2(spriteToCamera.x, spriteToCamera.z));
// Utwórz macierz rotacji wok³ osi Y
glm::mat4 rotationMatrix = glm::rotate(glm::mat4(1.0f), glm::radians(angle), glm::vec3(0.0f, 1.0f, 0.0f));
// Utwórz macierz widoku-projekcji
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
// Kombinuj macierze transformacji
glm::mat4 transformation = viewProjectionMatrix * modelMatrix * rotationMatrix;
// Przeka¿ macierze do shadera
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, glm::value_ptr(transformation));
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniform3fv(glGetUniformLocation(program, "activeColor"), 1, glm::value_ptr(color));
glUniform1f(glGetUniformLocation(program, "progress"), progress);
glBindVertexArray(this->VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
};
void Core::SpriteRenderer::DrawSprite(GLuint spriteTexture, const glm::mat4 modelMatrix, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance();
// Pobierz pozycjê kamery
glm::vec3 cameraPosition = spaceship->cameraPos;
glm::vec3 spritePosition = glm::vec3(modelMatrix[3]);
// Oblicz wektor skierowany od sprita do kamery
glm::vec3 spriteToCamera = glm::normalize(cameraPosition - spritePosition);
// Oblicz k¹t rotacji w stopniach wokó³ osi Y
float angle = glm::degrees(atan2(spriteToCamera.x, spriteToCamera.z));
// Utwórz macierz rotacji wok³ osi Y
glm::mat4 rotationMatrix = glm::rotate(glm::mat4(1.0f), glm::radians(angle), glm::vec3(0.0f, 1.0f, 0.0f));
// Utwórz macierz widoku-projekcji
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
// Kombinuj macierze transformacji
glm::mat4 transformation = viewProjectionMatrix * modelMatrix * rotationMatrix;
// Przeka¿ macierze do shadera
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, glm::value_ptr(transformation));
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
Core::SetActiveTexture(spriteTexture, "colorTexture", program, 0);
glBindVertexArray(this->VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}
void Core::SpriteRenderer::initRenderData()
{
// Definicja wierzcho³ków kwadratu
float vertices[] = {
// Postions //colors // texture coordiantes
-0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Left down
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,1.0f, // Left up
0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,// Right up
0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f,0.0f// Right down
};
// Definicja indeksów wierzcho³ków dla kwadratu
unsigned int indices[] = {
0, 2, 1, // Upper triangle
0, 3, 2 // Lower triangle
};
glGenVertexArrays(1, &this->VAO);
glGenBuffers(1, &this->VBO);
glGenBuffers(1, &this->EBO);
glBindVertexArray(this->VAO);
// Wype³nij bufor wierzcho³ków
glBindBuffer(GL_ARRAY_BUFFER, this->VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Wype³nij bufor indeksów
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
// Konfiguracja atrybutu koordynatow kolorow
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(2);
// Konfiguracja atrybutu koordynatow tekstury
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
glBindVertexArray(0);
}

View File

@ -0,0 +1,27 @@
#include "src/Render_Utils.h"
#include "src/Texture.h"
#include "Spaceship.h"
#pragma once
namespace Core {
class SpriteRenderer
{
public:
SpriteRenderer();
~SpriteRenderer();
void DrawSprite(GLuint spriteTexture, const glm::mat4 modelMatrix, GLuint program);
void DrawSpriteBar(const glm::vec3 color, const glm::mat4 modelMatrix,const float progress, GLuint program);
void DrawHUDBar(const glm::vec3 color, const glm::mat4 modelMatrix, const float progress, GLuint program);
private:
unsigned int VAO;
unsigned int VBO;
unsigned int EBO;
// Initializes and configures the quad's buffer and vertex attributes
void initRenderData();
};
}

View File

@ -14,20 +14,25 @@ public:
GLuint program;
Core::RenderContext sphereContext;
glm::mat4 positionMatrix;
GLuint textureID;
Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, glm::vec3 color, double scale) {
Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, GLuint textureID, 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));

View File

@ -13,6 +13,8 @@
<ItemGroup>
<ClCompile Include="GameObject.cpp" />
<ClCompile Include="Planet.cpp" />
<ClCompile Include="SpriteRenderer.cpp" />
<ClCompile Include="Source.cpp" />
<ClCompile Include="src\Box.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\main.cpp" />
@ -26,10 +28,16 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Bullet.h" />
<ClInclude Include="Enemy.h" />
<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" />
<ClInclude Include="SpriteRenderer.h" />
<ClInclude Include="src\Camera.h" />
<ClInclude Include="src\ex_9_1.hpp" />
<ClInclude Include="src\objload.h" />
@ -47,12 +55,20 @@
<ItemGroup>
<None Include="fireball.frag" />
<None Include="fireball.vert" />
<None Include="particle.frag" />
<None Include="particle.vert" />
<None Include="shaders\shader_9_1.frag" />
<None Include="shaders\shader_9_1.vert" />
<None Include="shaders\shader_8_sun.frag" />
<None Include="shaders\shader_8_sun.vert" />
<None Include="shaders\shader_skybox.frag" />
<None Include="shaders\shader_skybox.vert" />
<None Include="shaders\shader_sprite.frag" />
<None Include="shaders\shader_sprite.vert" />
<None Include="shaders\shader_tex.frag" />
<None Include="shaders\shader_tex.vert" />
<None Include="shaders\shader_sprite_bar.frag" />
<None Include="shaders\shader_sprite_bar.vert" />
<None Include="shaders\test.frag" />
<None Include="shaders\test.vert" />
</ItemGroup>

View File

@ -57,6 +57,12 @@
<ClCompile Include="Planet.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpriteRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source.cpp">
<Filter>Shader Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\objload.h">
@ -113,6 +119,24 @@
<ClInclude Include="Bullet.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Enemy.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpriteRenderer.h">
<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">
@ -139,5 +163,31 @@
<None Include="shaders\shader_skybox.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="fireball.frag" />
<None Include="fireball.vert" />
<None Include="shaders\shader_sprite.frag">
<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>
<None Include="particle.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="particle.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_sprite_bar.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_sprite_bar.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

View File

@ -1,150 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Shader Files">
<UniqueIdentifier>{0a247bb8-2e8e-4a90-b0ef-17415b0941ba}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\SOIL">
<UniqueIdentifier>{0af44075-33f4-4953-b1d6-1d28d61d758f}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Render_Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Shader_Loader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Box.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Texture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\SOIL\SOIL.c">
<Filter>Source Files\SOIL</Filter>
</ClCompile>
<ClCompile Include="src\SOIL\stb_image_aug.c">
<Filter>Source Files\SOIL</Filter>
</ClCompile>
<ClCompile Include="src\SOIL\image_DXT.c">
<Filter>Source Files\SOIL</Filter>
</ClCompile>
<ClCompile Include="src\SOIL\image_helper.c">
<Filter>Source Files\SOIL</Filter>
</ClCompile>
<ClCompile Include="GameObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Planet.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\objload.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Render_Utils.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Shader_Loader.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Camera.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\Texture.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\image_helper.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\SOIL.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\stb_image_aug.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\stbi_DDS_aug.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\stbi_DDS_aug_c.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\SOIL\image_DXT.h">
<Filter>Source Files\SOIL</Filter>
</ClInclude>
<ClInclude Include="src\ex_9_1.hpp">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="Sun.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Spaceship.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GameUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GameObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Planet.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Bullet.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_8_sun.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_8_sun.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_9_1.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_9_1.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\test.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\test.vert">
<Filter>Shader Files</Filter>
</None>
<<<<<<< HEAD
<None Include="shaders\shader_skybox.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_skybox.vert">
=======
<None Include="fireball.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="fireball.frag">
>>>>>>> 62afe67 (add shooting)
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
#
#
#
newmtl Siatka _Material.003
illum 2
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ns 0.000000
map_Kd Material.001_Base_color.jpg

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
#version 330 core
out vec4 FragColor;
in vec3 vertexColor;
void main() {
FragColor = vec4(vertexColor.r, vertexColor.g, vertexColor.b, 1.0);
}

View File

@ -0,0 +1,14 @@
#version 330 core
layout (location = 0) in vec3 inPosition;
out vec3 vertexColor;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform vec3 color;
void main() {
gl_Position = projection * view * model * vec4(inPosition, 1.0);
vertexColor = color;
}

View File

@ -3,9 +3,13 @@
uniform vec3 color;
uniform float exposition;
uniform sampler2D sunTexture;
in vec2 TexCoords;
out vec4 outColor;
void main()
{
outColor = vec4(vec3(1.0) - exp(-color*exposition),1);
}
{
vec4 texColor = texture(sunTexture, TexCoords);
vec3 brightColor = texColor.rgb * 4.0;
outColor = vec4(vec3(1.0) - exp(-brightColor*exposition),texColor.a);
}

View File

@ -5,9 +5,11 @@ 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;
}

View File

@ -9,8 +9,8 @@ uniform vec3 cameraPos;
uniform vec3 color;
uniform vec3 lightPositions[100];
uniform vec3 lightColors[100];
uniform vec3 lightPositions[8];
uniform vec3 lightColors[8];
uniform vec3 spotlightPos;
uniform vec3 spotlightColor;
@ -103,7 +103,7 @@ void main()
vec3 ambient = AMBIENT * color;
vec3 ilumination = ambient;
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < 8; ++i) {
lightDirs[i] = normalize(lightPositions[i] - worldPos);
vec3 attenuatedlightColor = lightColors[i] / pow(length(lightPositions[i] - worldPos), 2);
ilumination = ilumination+PBRLight(lightDirs[i], attenuatedlightColor * 300, normal, viewDir);
@ -118,6 +118,6 @@ void main()
vec3 attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
}

View File

@ -0,0 +1,129 @@
#version 430 core
float AMBIENT = 0.03;
float PI = 3.14;
uniform sampler2D depthMap;
uniform vec3 cameraPos;
uniform vec3 color;
uniform vec3 lightPositions[100];
uniform vec3 lightColors[100];
uniform vec3 spotlightPos;
uniform vec3 spotlightColor;
uniform vec3 spotlightConeDir;
uniform vec3 spotlightPhi;
uniform float metallic;
uniform float roughness;
uniform float exposition;
in vec3 vecNormal;
in vec3 worldPos;
out vec4 outColor;
in vec3 viewDirTS;
in vec3 lightDirTS[4];
in vec3 spotlightDirTS;
in vec3 sunDirTS;
in vec3 test;
float DistributionGGX(vec3 normal, vec3 H, float roughness){
float a = roughness*roughness;
float a2 = a*a;
float NdotH = max(dot(normal, H), 0.0);
float NdotH2 = NdotH*NdotH;
float num = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return num / denom;
}
float GeometrySchlickGGX(float NdotV, float roughness){
float r = (roughness + 1.0);
float k = (r*r) / 8.0;
float num = NdotV;
float denom = NdotV * (1.0 - k) + k;
return num / denom;
}
float GeometrySmith(vec3 normal, vec3 V, vec3 lightDir, float roughness){
float NdotV = max(dot(normal, V), 0.0);
float NdotL = max(dot(normal, lightDir), 0.0);
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
return ggx1 * ggx2;
}
vec3 fresnelSchlick(float cosTheta, vec3 F0){
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){
float diffuse=max(0,dot(normal,lightDir));
vec3 F0 = vec3(0.04);
F0 = mix(F0, color, metallic);
vec3 H = normalize(V + lightDir);
float NDF = DistributionGGX(normal, H, roughness);
float G = GeometrySmith(normal, V, lightDir, roughness);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
kD *= 1.0 - metallic;
vec3 numerator = NDF * G * F;
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, lightDir), 0.0) + 0.0001;
vec3 specular = numerator / denominator;
float NdotL = max(dot(normal, lightDir), 0.0);
return (kD * color / PI + specular) * radiance * NdotL;
}
void main()
{
vec3 normal = normalize(vecNormal);
vec3 viewDir = normalize(cameraPos-worldPos);
vec3 lightDirs[4];
vec3 ambient = AMBIENT * color;
vec3 ilumination = ambient;
for (int i = 0; i < 100; ++i) {
lightDirs[i] = normalize(lightPositions[i] - worldPos);
vec3 attenuatedlightColor = lightColors[i] / pow(length(lightPositions[i] - worldPos), 2);
ilumination = ilumination+PBRLight(lightDirs[i], attenuatedlightColor * 300, normal, viewDir);
}
vec3 spotlightDir= normalize(spotlightPos-worldPos);
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
vec3 attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
<<<<<<< HEAD
=======
//sun
//ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir);
>>>>>>> c0971c9 (Add enemy class)
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
}

View File

@ -12,12 +12,12 @@ uniform mat4 modelMatrix;
out vec3 vecNormal;
out vec3 worldPos;
uniform vec3 lightsPositions[100];
uniform vec3 lightsPositions[8];
uniform vec3 spotlightPos;
uniform vec3 cameraPos;
out vec3 viewDirTS;
out vec3 lightDirTS[100];
out vec3 lightDirTS[8];
out vec3 spotlightDirTS;
void main()
@ -33,7 +33,7 @@ void main()
vec3 V = normalize(cameraPos-worldPos);
viewDirTS = TBN*V;
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < 8; ++i) {
vec3 L = normalize(lightsPositions[i]-worldPos);
lightDirTS[i] = TBN*L;
}

View File

@ -0,0 +1,16 @@
#version 430 core
uniform sampler2D colorTexture;
in vec3 worldPos;
in vec2 texCoord;
in vec3 color;
out vec4 outColor;
void main()
{
outColor = texture(colorTexture, texCoord);
outColor *= vec4(color, 1.0);
}

View File

@ -0,0 +1,21 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 aColor;
layout(location = 2) in vec2 vertexTexCoord;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec3 worldPos;
out vec2 texCoord;
out vec3 color;
void main()
{
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
gl_Position = transformation * vec4(vertexPosition, 1.0);
texCoord = vertexTexCoord;
texCoord.y = 1.0 - texCoord.y; // so that it is turned correctly
color = aColor;
}

View File

@ -0,0 +1,24 @@
#version 430 core
uniform float progress;
uniform vec3 activeColor;
in vec3 worldPos;
in vec2 texCoord;
in vec3 color;
out vec4 outColor;
void main()
{
vec4 inactiveColor = vec4(0.5, 0.5, 0.5, 1.0);
if (texCoord.x > progress) {
outColor = inactiveColor; // Ustawienie koloru dla obszaru nieaktywnego
return;
}
outColor = vec4(activeColor,1.0); // Ustawienie koloru dla obszaru aktywnego
}

View File

@ -0,0 +1,20 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 aColor;
layout(location = 2) in vec2 vertexTexCoord;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec3 worldPos;
out vec2 texCoord;
out vec3 color;
void main()
{
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
gl_Position = transformation * vec4(vertexPosition, 1.0);
texCoord = vertexTexCoord;
color = aColor;
}

View File

@ -0,0 +1,139 @@
#version 430 core
float AMBIENT = 0.03;
float PI = 3.14;
uniform sampler2D depthMap;
uniform vec3 cameraPos;
uniform sampler2D textureSampler;
uniform sampler2D normalSampler;
uniform vec3 lightPositions[100];
uniform vec3 lightColors[100];
uniform vec3 spotlightPos;
uniform vec3 spotlightColor;
uniform vec3 spotlightConeDir;
uniform vec3 spotlightPhi;
uniform float metallic;
uniform float roughness;
uniform float exposition;
in vec3 vecNormal;
in vec3 worldPos;
in vec2 TexCoords;
in mat3 TBN;
out vec4 outColor;
in vec3 viewDirTS;
in vec3 lightDirTS[4];
in vec3 spotlightDirTS;
in vec3 sunDirTS;
in vec3 test;
float DistributionGGX(vec3 normal, vec3 H, float roughness){
float a = roughness*roughness;
float a2 = a*a;
float NdotH = max(dot(normal, H), 0.0);
float NdotH2 = NdotH*NdotH;
float num = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return num / denom;
}
float GeometrySchlickGGX(float NdotV, float roughness){
float r = (roughness + 1.0);
float k = (r*r) / 8.0;
float num = NdotV;
float denom = NdotV * (1.0 - k) + k;
return num / denom;
}
float GeometrySmith(vec3 normal, vec3 V, vec3 lightDir, float roughness){
float NdotV = max(dot(normal, V), 0.0);
float NdotL = max(dot(normal, lightDir), 0.0);
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
return ggx1 * ggx2;
}
vec3 fresnelSchlick(float cosTheta, vec3 F0){
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V, vec3 texcolorRGB){
float diffuse=max(0,dot(normal,lightDir));
vec3 F0 = vec3(0.04);
F0 = mix(F0, texcolorRGB , metallic);
vec3 H = normalize(V + lightDir);
float NDF = DistributionGGX(normal, H, roughness);
float G = GeometrySmith(normal, V, lightDir, roughness);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
kD *= 1.0 - metallic;
vec3 numerator = NDF * G * F;
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, lightDir), 0.0) + 0.0001;
vec3 specular = numerator / denominator;
float NdotL = max(dot(normal, lightDir), 0.0);
return (kD * texcolorRGB / PI + specular) * radiance * NdotL;
}
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 viewDir = normalize(cameraPos-worldPos);
vec3 lightDirs[4];
vec3 ambient = AMBIENT * texColor.rgb;
vec3 ilumination = ambient;
for (int i = 0; i < 100; ++i) {
lightDirs[i] = normalize(lightPositions[i] - worldPos);
vec3 attenuatedlightColor = lightColors[i] / pow(length(lightPositions[i] - worldPos), 2);
ilumination = ilumination+PBRLight(lightDirs[i], attenuatedlightColor * 300, normal, viewDir, texColor.rgb);
}
vec3 spotlightDir= normalize(spotlightPos-worldPos);
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
vec3 attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir, texColor.rgb);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
}

View File

@ -0,0 +1,49 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec3 vecNormal;
out vec3 worldPos;
out vec2 TexCoords;
uniform vec3 lightsPositions[10];
uniform vec3 spotlightPos;
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));
vec3 V = normalize(cameraPos-worldPos);
viewDirTS = TBN*V;
for (int i = 0; i < 9; ++i) {
vec3 L = normalize(lightsPositions[i]-worldPos);
lightDirTS[i] = TBN*L;
}
vec3 SL = normalize(spotlightPos-worldPos);
spotlightDirTS = TBN*SL;
}

View File

@ -4,7 +4,7 @@
namespace Core
{
glm::mat4 createPerspectiveMatrix(float zNear = 0.1f, float zFar = 100.0f, float frustumScale = 1.f);
glm::mat4 createPerspectiveMatrix(float zNear, float zFar, float frustumScale);
// position - pozycja kamery
// forward - wektor "do przodu" kamery (jednostkowy)

View File

@ -10,6 +10,8 @@
#include "../GameUtils.h"
#include "../Spaceship.h"
#include "Texture.h"
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
@ -188,6 +190,49 @@ 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) {
Spaceship* spaceship = Spaceship::getInstance();
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform1f(glGetUniformLocation(program, "exposition"), 1.f);
glUniform1f(glGetUniformLocation(program, "roughness"), roughness);
glUniform1f(glGetUniformLocation(program, "metallic"), metallic);
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);
std::list<Sun*>* suns = GameUtils::getInstance()->getSuns();
glm::vec3 lightsPositions[100];
glm::vec3 lightsColors[100];
int i = 0;
for (Sun* sun : *suns) {
lightsPositions[i] = sun->getPosition();
lightsColors[i] = sun->getColor();
++i;
}
glUniform3fv(glGetUniformLocation(program, "lightPositions"), 100, glm::value_ptr(lightsPositions[0]));
glUniform3fv(glGetUniformLocation(program, "lightColors"), 100, glm::value_ptr(lightsColors[0]));
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spaceship->spotlightConeDir.x, spaceship->spotlightConeDir.y, spaceship->spotlightConeDir.z);
glUniform3f(glGetUniformLocation(program, "spotlightPos"), spaceship->spotlightPos.x, spaceship->spotlightPos.y, spaceship->spotlightPos.z);
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spaceship->spotlightColor.x, spaceship->spotlightColor.y, spaceship->spotlightColor.z);
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spaceship->spotlightPhi);
Core::DrawContext(context);
}
void Core::drawSkybox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance();
glDisable(GL_DEPTH_TEST);

View File

@ -74,4 +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);
}

View File

@ -17,14 +17,22 @@ GLuint Core::LoadTexture( const char * filepath )
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
int w, h;
unsigned char* image = SOIL_load_image(filepath, &w, &h, 0, SOIL_LOAD_RGBA);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
SOIL_free_image_data(image);
if (image) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
SOIL_free_image_data(image);
}
else {
std::cerr << "Texture loading failed for path: " << filepath << std::endl;
}
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
//glGenerateMipmap(GL_TEXTURE_2D);
//SOIL_free_image_data(image);
return id;
}

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>
@ -21,21 +20,54 @@
#include "../Planet.h"
#include "../GameObject.h"
#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 = 500, HEIGHT = 500;
//int WIDTH = 1920, HEIGHT = 1080;
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 {
GLuint textureID;
GLuint normalMapID;
};
std::vector<TextureTuple> planetTextures;
std::vector<GLuint> sunTexturesIds;
void createGalaxy(glm::vec3 galaxyPosition);
GLuint depthMapFBO;
@ -44,13 +76,21 @@ GLuint depthMap;
GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
GLuint programSprite;
GLuint programCubemap;
GLuint programParticle;
GLuint programTex;
GLuint programSpriteBar;
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;
float exposition = 1.f;
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
@ -60,7 +100,20 @@ float lastTime = -1.f;
float deltaTime = 0.f;
Spaceship* spaceship = Spaceship::getInstance();
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId,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;
@ -71,7 +124,172 @@ 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));
}
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);
spriteRenderer->DrawHUDBar(
glm::vec3(0.0f, 1.0f, 0.0f),
glm::scale(healthBarPosition, healthBarScale),
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()) {
spriteRenderer->DrawSpriteBar(
glm::vec3(1.0f, 0.0f, 0.0f),
glm::scale(
glm::translate(enemy->modelMatrix, glm::vec3(0.0f, 0.7f, 0.0f)
),
glm::vec3(1.0f, 0.2f, 1.0f)
),
enemy->currentHP / enemy->maxHP,
programSpriteBar);
}
}
glUseProgram(programSprite);
for (const auto& enemy : enemies) {
if (enemy->isAlive()) {
spriteRenderer->DrawSprite(texture::spriteTexture, enemy->modelMatrix, programSprite);
}
}
}
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];
//GLuint textureID = selectedTextures.textureID;
//GLuint normalMapID = selectedTextures.normalMapID;
return planetTextures[textureIndex];
}
void renderShadowapSun() {
float time = glfwGetTime();
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
@ -82,6 +300,7 @@ void renderShadowapSun() {
}
void renderScene(GLFWwindow* window)
{
glClearColor(0.4f, 0.4f, 0.8f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float time = glfwGetTime();
@ -99,26 +318,76 @@ void renderScene(GLFWwindow* window)
sun->draw();
}
glUseProgram(program);
glUseProgram(programTex);
for (Planet* p : planets) {
p->draw(time, program);
p->draw(time, programTex);
}
spaceship->renderBullets(glfwGetTime(), program);
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(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(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);
drawObjectPBR(models::spaceshipContext,
glUseProgram(programTex);
//Core::SetActiveTexture(texture::spaceshipTexture, "textureSampler", programTex, 0);
drawObjectPBRTexture(models::spaceshipContext,
spaceship->calculateModelMatrix(),
spaceship->color,
spaceship->roughness, spaceship->metallic, program
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);
//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);
//glUseProgram(programSprite);
//for (const auto& enemy : enemies) {
// if (enemy->isAlive()) {
// spriteRenderer->DrawSprite(texture::spriteTexture, enemy->modelMatrix, programSprite);
// }
//}
//glUseProgram(program);
//for (const auto& enemy : enemies) {
// if (enemy->isAlive()) {
// enemy->attack(spaceship->spaceshipPos, glfwGetTime());
// enemy->renderBullets(glfwGetTime(), program, gameEntities);
// }
//}
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::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);
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);
glUseProgram(0);
glfwSwapBuffers(window);
}
@ -130,51 +399,156 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
HEIGHT = height;
}
void createSuns() {
createGalaxy(glm::vec3(0.f));
createGalaxy(glm::vec3(0.f, 50.f, 200.f));
}
void createGalaxy(glm::vec3 galaxyPosition) {
float planetsSizes[] = { 1.f, 1.5f, 0.8f, 1.2f, 0.2f };
createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), 3, planetsSizes, 5, 15.f, 0.2f);
float planetsSizes2[] = { 0.6f, 1.1f, 0.9f };
createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), 2, planetsSizes2, 3, 15.f, 0.2f);
float planetsSizes3[] = { 0.7f, 1.5f, 1.2f, 1.f };
createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), 4, planetsSizes3, 4, 20.f, 0.2f);
float planetSizes4[] = { 1.f, 0.5f };
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), 5, planetsSizes3, 2, 25.f, 0.2f);
float generateRandomFloat(float minValue, float maxValue) {
return minValue + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (maxValue - minValue)));
}
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
void createAsteroids() {
GameUtils* gu = GameUtils::getInstance();
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);
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);
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);
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);
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) {
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);
gu->getSuns()->push_back(sun);
for (int i = 0; i < numberOfPlanets; i++) {
TextureTuple textures = getRandomPlanetTexture();
GLuint texID = textures.textureID;
GLuint norMapID = textures.normalMapID;
float distanceFromSum = (i + 1) * planetsDistance;
Planet* planet = new Planet(sun, distanceFromSum, i * 0.1f + planetSpeedCoef, planetSizes[i], models::sphereContext);
Planet* planet = new Planet(sun, distanceFromSum, i * 0.1f + planetSpeedCoef, planetSizes[i], models::sphereContext, texID, norMapID);
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));
//obiekty do ktorych bedzie sprawdzana kolizja dla pociskow enemy
gameEntities.push_back(spaceship);
}
void loadPlanetsAndSunTextures() {
planetTextures.clear();
std::vector<std::pair<std::string, std::string>> texturePaths = {
{"./textures/planets/planet1.png", "./textures/planets/planet1normal.png"},
{"./textures/planets/planet2.png", "./textures/planets/planet2normal.png"},
{"./textures/planets/planet3.png", "./textures/planets/planet3normal.png"},
{"./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);
}
}
void init(GLFWwindow* window)
{
GameUtils* gameUtils = GameUtils::getInstance();
spriteRenderer = new Core::SpriteRenderer();
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glEnable(GL_DEPTH_TEST);
program = gameUtils->shaderLoader->CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.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");
programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.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");
programSpriteBar = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite_bar.vert", "shaders/shader_sprite_bar.frag");
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag");
programParticle = gameUtils->shaderLoader->CreateProgram("shaders/particle.vert", "shaders/particle.frag");
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
loadModelToContext("./models/StarShip2.obj", models::spaceshipContext);
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");
std::vector<std::string> cubeFaces = {
"bkg2_right1.png",
@ -185,14 +559,30 @@ void init(GLFWwindow* window)
"bkg2_back6.png"
};
loadPlanetsAndSunTextures();
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();
createEnemies();
}
void shutdown(GLFWwindow* window)
{
GameUtils::getInstance()->shaderLoader->DeleteProgram(program);
delete spriteRenderer;
// Dealokacja pamięci po obiektach Enemy
for (const auto& enemy : enemies) {
delete enemy;
}
}
//obsluga wejscia

View File

@ -21,11 +21,15 @@
#include "../Planet.h"
#include "../GameObject.h"
#include "../GameUtils.h"
#include "../SpriteRenderer.h"
#include "../Enemy.h"
#include "../ParticleSystem.h"
#include "Camera.h"
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
int WIDTH = 500, HEIGHT = 500;
namespace models {
Core::RenderContext marbleBustContext;
Core::RenderContext spaceshipContext;
@ -34,21 +38,40 @@ namespace models {
}
namespace texture {
GLuint cubemapTexture;
GLuint spaceshipTexture;
GLuint spriteTexture;
GLuint earthTexture;
}
struct TextureTuple {
GLuint textureID;
GLuint normalMapID;
};
std::vector<TextureTuple> planetTextures;
void createGalaxy(glm::vec3 galaxyPosition);
GLuint depthMapFBO;
GLuint depthMap;
GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
GLuint programSprite;
GLuint programCubemap;
GLuint programParticle;
GLuint programTex;
GLuint programSpriteBar;
std::list<Planet*> planets;
Sun* sun;
GLuint VAO,VBO;
std::vector<Enemy*> enemies;
std::vector<GameEntity*> gameEntities;
float exposition = 1.f;
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
@ -58,6 +81,8 @@ float lastTime = -1.f;
float deltaTime = 0.f;
Spaceship* spaceship = Spaceship::getInstance();
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
Core::SpriteRenderer* spriteRenderer;
void updateDeltaTime(float time) {
if (lastTime < 0) {
@ -69,7 +94,60 @@ void updateDeltaTime(float time) {
if (deltaTime > 0.1) deltaTime = 0.1;
lastTime = time;
}
void renderHUD() {
glUseProgram(programSpriteBar);
glDisable(GL_DEPTH_TEST);
glm::mat4 spaceshipModelMatrix = spaceship->calculateModelMatrix();
glm::mat4 healthBarPosition = glm::translate(spaceshipModelMatrix, glm::vec3(12.0f, -9.0f, 0.0f));
spriteRenderer->DrawHUDBar(
glm::vec3(0.0f, 1.0f, 0.0f),
glm::scale(healthBarPosition, glm::vec3(9.0f, 1.1f, 1.0f)),
spaceship->currentHP / spaceship->maxHP,
programSpriteBar);
glEnable(GL_DEPTH_TEST);
}
void renderEnemies() {
glUseProgram(programSpriteBar);
for (const auto& enemy : enemies) {
if (enemy->isAlive()) {
spriteRenderer->DrawSpriteBar(
glm::vec3(1.0f, 0.0f, 0.0f),
glm::scale(
glm::translate(enemy->modelMatrix, glm::vec3(0.0f, 0.7f, 0.0f)
),
glm::vec3(1.0f, 0.2f, 1.0f)
),
enemy->currentHP / enemy->maxHP,
programSpriteBar);
}
}
glUseProgram(programSprite);
for (const auto& enemy : enemies) {
if (enemy->isAlive()) {
spriteRenderer->DrawSprite(texture::spriteTexture, enemy->modelMatrix, programSprite);
}
}
glUseProgram(program);
for (const auto& enemy : enemies) {
if (enemy->isAlive()) {
enemy->attack(spaceship->spaceshipPos, glfwGetTime());
enemy->renderBullets(glfwGetTime(), program, gameEntities);
}
}
}
TextureTuple getRandomPlanetTexture() {
int textureIndex = rand() % planetTextures.size();
TextureTuple selectedTextures = planetTextures[textureIndex];
//GLuint textureID = selectedTextures.textureID;
//GLuint normalMapID = selectedTextures.normalMapID;
return planetTextures[textureIndex];
}
void renderShadowapSun() {
float time = glfwGetTime();
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
@ -80,6 +158,7 @@ void renderShadowapSun() {
}
void renderScene(GLFWwindow* window)
{
glClearColor(0.4f, 0.4f, 0.8f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float time = glfwGetTime();
@ -97,25 +176,72 @@ void renderScene(GLFWwindow* window)
sun->draw();
}
glUseProgram(programTex);
for (Planet* p : planets) {
p->draw(time, programTex);
}
<<<<<<< HEAD
glUseProgram(program);
for (Planet* p : planets) {
p->draw(time, program);
}
spaceship->renderBullets(glfwGetTime(), program);
=======
std::vector<GameEntity*> gameEntities(enemies.begin(), enemies.end());
spaceship->renderBullets(glfwGetTime(), program, gameEntities);
>>>>>>> 9586849 (Add collision detection and taking dmg)
//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(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);
drawObjectPBR(models::spaceshipContext,
glUseProgram(programTex);
//Core::SetActiveTexture(texture::spaceshipTexture, "textureSampler", programTex, 0);
drawObjectPBRTexture(models::spaceshipContext,
spaceship->calculateModelMatrix(),
spaceship->color,
spaceship->roughness, spaceship->metallic, program
texture::spaceshipTexture,
spaceship->roughness, spaceship->metallic, programTex
);
<<<<<<< HEAD
<<<<<<< HEAD
//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);
//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);
glUseProgram(programSprite);
for (const auto& enemy : enemies) {
if (enemy->isAlive()) {
spriteRenderer->DrawSprite(texture::spriteTexture, enemy->modelMatrix, programSprite);
}
}
glUseProgram(program);
for (const auto& enemy : enemies) {
if (enemy->isAlive()) {
enemy->attack(spaceship->spaceshipPos, glfwGetTime());
enemy->renderBullets(glfwGetTime(), program);
}
}
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::mat4 viewMatrix = Core::createViewMatrix(spaceship->cameraPos, spaceship->cameraDir, cameraUp);
spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time);
=======
=======
renderHUD();
>>>>>>> 9586849 (Add collision detection and taking dmg)
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);
>>>>>>> 6ccdec5 (Add drawing health bars for enemies)
glUseProgram(0);
glfwSwapBuffers(window);
@ -128,62 +254,95 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
HEIGHT = height;
}
void createSuns() {
GameUtils* gu = GameUtils::getInstance();
sun = new Sun(programSun, models::sphereContext, glm::vec3(0, 2, 0), glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, 1);
Planet* planet = new Planet(sun, 20.f, 0.25f, 1.f, models::sphereContext);
planets.push_back(planet);
Planet* moon = new Planet(planet, 5.f, 1.f, 0.2f, models::sphereContext);
planets.push_back(moon);
gu->getSuns()->push_back(sun);
Planet* planet2 = new Planet(sun, 50.f, 0.5f, 1.5f, models::sphereContext);
planets.push_back(planet2);
/*suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-80, 20, 50), glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(1.0f, 0.8f, 0.2f), 4.0));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(50, 40, -30), glm::vec3(-0.73633f, 0.451106, 0.023226f), glm::vec3(0.9f, 0.5f, 0.1f), 3.5));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(0, -60, 100), glm::vec3(-0.53633f, 0.551106, 0.043226f), glm::vec3(0.8f, 0.2f, 0.2f), 4.5));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(20, 80, -70), glm::vec3(0.33633f, 0.651106, 0.063226f), glm::vec3(0.5f, 0.7f, 0.9f), 3.8));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-60, -20, 30), glm::vec3(-0.23633f, 0.751106, 0.083226f), glm::vec3(0.7f, 0.2f, 0.7f), 4.2));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(70, -50, -80), glm::vec3(-0.03633f, 0.851106, 0.103226f), glm::vec3(0.1f, 0.3f, 0.9f), 3.9));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(10, 30, 60), glm::vec3(0.13633f, -0.951106, -0.123226f), glm::vec3(0.6f, 0.9f, 0.4f), 4.3));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-40, -80, -50), glm::vec3(0.33633f, -0.851106, -0.143226f), glm::vec3(0.7f, 0.5f, 0.2f), 3.7));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(90, 70, 20), glm::vec3(0.53633f, -0.751106, -0.163226f), glm::vec3(0.4f, 0.1f, 0.9f), 4.1));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-30, 10, -40), glm::vec3(0.73633f, -0.651106, -0.183226f), glm::vec3(0.8f, 0.4f, 0.1f), 4.4));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(150, -100, 80), glm::vec3(0.33633f, -0.951106, -0.143226f), glm::vec3(0.2f, 0.8f, 0.5f), 3.9));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-120, 50, -60), glm::vec3(0.73633f, 0.551106, 0.103226f), glm::vec3(0.9f, 0.2f, 0.7f), 3.6));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(0, 120, -150), glm::vec3(-0.23633f, -0.751106, 0.083226f), glm::vec3(0.5f, 0.6f, 0.9f), 3.4));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-180, -50, 120), glm::vec3(0.13633f, 0.351106, -0.003226f), glm::vec3(0.7f, 0.9f, 0.2f), 4.2));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(60, -150, 180), glm::vec3(-0.93633f, -0.451106, -0.023226f), glm::vec3(0.3f, 0.7f, 0.8f), 3.8));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(100, 80, -120), glm::vec3(0.53633f, -0.651106, 0.163226f), glm::vec3(0.8f, 0.1f, 0.4f), 4.5));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-50, -180, 150), glm::vec3(-0.33633f, 0.951106, -0.083226f), glm::vec3(0.4f, 0.8f, 0.6f), 3.5));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(200, 150, -100), glm::vec3(0.03633f, 0.151106, 0.103226f), glm::vec3(0.6f, 0.2f, 0.9f), 3.9));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-150, -100, -50), glm::vec3(0.83633f, -0.251106, -0.123226f), glm::vec3(0.7f, 0.5f, 0.8f), 4.1));*/
createGalaxy(glm::vec3(0.f));
createGalaxy(glm::vec3(0.f, 50.f, 200.f));
}
void createGalaxy(glm::vec3 galaxyPosition) {
float planetsSizes[] = { 1.f, 1.5f, 0.8f, 1.2f, 0.2f };
createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), 3, planetsSizes, 5, 15.f, 0.2f);
float planetsSizes2[] = { 0.6f, 1.1f, 0.9f };
createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), 2, planetsSizes2, 3, 15.f, 0.2f);
float planetsSizes3[] = { 0.7f, 1.5f, 1.2f, 1.f };
createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), 4, planetsSizes3, 4, 20.f, 0.2f);
float planetSizes4[] = { 1.f, 0.5f };
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), 5, planetsSizes3, 2, 25.f, 0.2f);
}
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), 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();
GLuint texID = textures.textureID;
GLuint norMapID = textures.normalMapID;
float distanceFromSum = (i + 1) * planetsDistance;
Planet* planet = new Planet(sun, distanceFromSum, i * 0.1f + planetSpeedCoef, planetSizes[i], models::sphereContext, texID, norMapID);
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));
//obiekty do ktorych bedzie sprawdzana kolizja dla pociskow enemy
gameEntities.push_back(spaceship);
}
void loadPlanetsTextures() {
planetTextures.clear();
std::vector<std::pair<std::string, std::string>> texturePaths = {
{"./textures/planets/planet1.png", "./textures/planets/planet1normal.png"},
{"./textures/planets/planet2.png", "./textures/planets/planet2normal.png"},
{"./textures/planets/planet3.png", "./textures/planets/planet3normal.png"},
{"./textures/planets/planet4.png", "./textures/planets/planet4normal.png"}
};
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 });
}
}
void init(GLFWwindow* window)
{
GameUtils* gameUtils = GameUtils::getInstance();
spriteRenderer = new Core::SpriteRenderer();
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glEnable(GL_DEPTH_TEST);
program = gameUtils->shaderLoader->CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.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");
programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
<<<<<<< HEAD
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
programCubemap = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.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");
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");
programParticle = gameUtils->shaderLoader->CreateProgram("shaders/particle.vert", "shaders/particle.frag");
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
loadModelToContext("./models/StarShip2.obj", models::spaceshipContext);
loadModelToContext("./models/sphere.obj", models::sphereContext);
loadModelToContext("./models/cube.obj", models::cubeContext);
/*std::vector<std::string> cubeFaces = {
"space_rt.png",
"space_lf.png",
"space_up.png",
"space_dn.png",
"space_bk.png",
"space_ft.png"
};*/
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
texture::spriteTexture = Core::LoadTexture("textures/blinky1.png");
std::vector<std::string> cubeFaces = {
"bkg2_right1.png",
@ -194,30 +353,25 @@ void init(GLFWwindow* window)
"bkg2_back6.png"
};
loadPlanetsTextures();
texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
texture::spaceshipTexture = Core::LoadTexture("./textures/spaceship/Material.001_Base_color.jpg");
texture::earthTexture = Core::LoadTexture("./textures/planets/8k_earth_daymap.jpg");
=======
program = gameUtils->shaderLoader->CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.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");
//loadModelToContext("./models/sphere.obj", sphereContext);
//loadModelToContext("./models/spaceship.obj", spaceship.context);
Core::loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
Core::loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
Core::loadModelToContext("./models/sphere.obj", models::sphereContext);
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
>>>>>>> 62afe67 (add shooting)
spaceship->createParticles();
createSuns();
createEnemies();
}
void shutdown(GLFWwindow* window)
{
GameUtils::getInstance()->shaderLoader->DeleteProgram(program);
delete spriteRenderer;
// Dealokacja pamięci po obiektach Enemy
for (const auto& enemy : enemies) {
delete enemy;
}
}
//obsluga wejscia

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

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: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 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