Compare commits
2 Commits
master
...
planets_te
Author | SHA1 | Date | |
---|---|---|---|
|
90e88b0dc2 | ||
|
7097be100e |
5
.gitignore
vendored
@ -1,5 +0,0 @@
|
||||
|
||||
/grk/.vs/grk-cw
|
||||
/grk/project/Debug
|
||||
/.vs
|
||||
/grk/dependencies/glm/out/build/x64-Debug
|
43
README.md
@ -1,43 +0,0 @@
|
||||
# Nazwa Projektu
|
||||
Projekt z grafiki komputerowej - Interstellar Odyssey
|
||||
|
||||
|
||||
## Opis
|
||||
Interaktywny symulator loty kosmicznego 3D. Celem naszej gry jest zwiedzanie rożnych układów słonecznych.
|
||||
Pokonywanie jak największej ilości wrogów i utrzymywanie się przy życiu za pomocą dostępnych itemków do zebrania.
|
||||
|
||||
|
||||
## Funkcje i możliwości
|
||||
-Physically Based Rendering z mapą normalnych :
|
||||
![normal_map](images/normal_map.png)
|
||||
|
||||
-Sprite Rendering razem z techniką bilboardingu:
|
||||
![sprite_rendering](images/sprite.png)
|
||||
|
||||
- Particle Generator:
|
||||
![Turbo](images/turbo.png)
|
||||
|
||||
- Skybox/Tworzenie wielu galaktyk:
|
||||
![galaktyki](images/galaktyki.png)
|
||||
|
||||
- Strzelanie
|
||||
![strzelanie](images/strzelanie.png)
|
||||
|
||||
- Pas asteroid
|
||||
![pas_asteroid](images/asteroidy.png)
|
||||
|
||||
- Otrzymywanie i zadawanie obrażeń
|
||||
![sprite_dmg](images/sprite_dmg.png)
|
||||
|
||||
- Możliwości uzupełnienia turbo i życia przez zbieranie itemków
|
||||
![hp](images/hp.png)
|
||||
|
||||
oraz dynamiczne poruszanie się statku podczas skrętów, lotów w górę i w dół oraz na ukos
|
||||
|
||||
|
||||
## Skład zespołu
|
||||
Sprite Rendering
|
||||
- Mateusz Kantorski
|
||||
- Paweł Felcyn
|
||||
- Wojciech Goralewski
|
||||
|
BIN
grk/.vs/grk-cw/v16/Browse.VC.db
Normal file
BIN
grk/.vs/grk-cw/v16/Solution.VC.db
Normal file
@ -1,7 +1,5 @@
|
||||
#include "glm.hpp"
|
||||
#include "src/Shader_Loader.h"
|
||||
#include <vector>
|
||||
#include "GameEntity.h"
|
||||
|
||||
#pragma once
|
||||
class Bullet
|
||||
@ -41,50 +39,14 @@ public:
|
||||
return new Bullet(10, 10, directionNormalized, startPosition, birthTime, simpleRenderContext, 0.01f);
|
||||
}
|
||||
|
||||
bool shouldBeDestroyed(float time, GLuint program, std::vector<GameEntity*>& gameEntities, float attackerDmg) {
|
||||
bool shouldBeDestroyed(float time, GLuint program) {
|
||||
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;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
BIN
grk/project/Debug/Box.obj
Normal file
BIN
grk/project/Debug/Camera.obj
Normal file
BIN
grk/project/Debug/Render_Utils.obj
Normal file
BIN
grk/project/Debug/SOIL.obj
Normal file
BIN
grk/project/Debug/Shader_Loader.obj
Normal file
BIN
grk/project/Debug/Texture.obj
Normal file
11
grk/project/Debug/grk-project.exe.recipe
Normal file
@ -0,0 +1,11 @@
|
||||
<?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>
|
BIN
grk/project/Debug/image_DXT.obj
Normal file
BIN
grk/project/Debug/image_helper.obj
Normal file
BIN
grk/project/Debug/main.obj
Normal file
BIN
grk/project/Debug/stb_image_aug.obj
Normal file
@ -1,108 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
};
|
||||
|
@ -1,33 +0,0 @@
|
||||
#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;
|
||||
};
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
#include "Sun.h"
|
||||
#include "Bullet.h"
|
||||
#include "src/Shader_Loader.h"
|
||||
#include "ParticleSystem.h"
|
||||
|
||||
#pragma once
|
||||
class GameUtils
|
||||
@ -13,12 +13,12 @@ private:
|
||||
{
|
||||
this->suns = new std::list<Sun*>();
|
||||
this->shaderLoader = new Core::Shader_Loader();
|
||||
this->particleSystems = new std::list<ParticleSystem*>();
|
||||
this->planetsTextures = new std::list<std::tuple<GLuint, GLuint>>();
|
||||
}
|
||||
std::list<Sun*>* suns;
|
||||
std::list<Bullet*> bullets;
|
||||
std::list<ParticleSystem*>* particleSystems;
|
||||
float aspectRatio;
|
||||
std::list<std::tuple<GLuint, GLuint>>* planetsTextures;
|
||||
|
||||
|
||||
public:
|
||||
@ -38,8 +38,8 @@ public:
|
||||
return suns;
|
||||
}
|
||||
|
||||
std::list<ParticleSystem*>* getParticleSystems() {
|
||||
return particleSystems;
|
||||
std::list<std::tuple<GLuint, GLuint>>* getPlanetsTextures() {
|
||||
return planetsTextures;
|
||||
}
|
||||
|
||||
static GameUtils* getInstance()
|
||||
|
@ -1,55 +0,0 @@
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include "src/Render_Utils.h"
|
||||
#include "./GameEntity.h"
|
||||
#include "Spaceship.h"
|
||||
|
||||
#pragma once
|
||||
class Heart : public GameEntity
|
||||
{
|
||||
public:
|
||||
glm::mat4 modelMatrix;
|
||||
glm::mat4 initialModelMatrix;
|
||||
float healAmount = 10;
|
||||
bool isCollected;
|
||||
|
||||
|
||||
Heart(glm::mat4 initialModelMatrix, float healAmount)
|
||||
:
|
||||
modelMatrix(initialModelMatrix),
|
||||
initialModelMatrix(initialModelMatrix),
|
||||
healAmount(healAmount),
|
||||
isCollected(false),
|
||||
GameEntity(1, 1, 0)
|
||||
{}
|
||||
|
||||
|
||||
virtual ~Heart() = default;
|
||||
|
||||
virtual bool isAlive() {
|
||||
if (this->currentHP <= 0) {
|
||||
isCollected = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::vec3 getPosition() const override
|
||||
{
|
||||
return modelMatrix[3];
|
||||
}
|
||||
glm::mat4 getModelMatrix() override
|
||||
{
|
||||
return modelMatrix;
|
||||
}
|
||||
void respawn() override {
|
||||
this->currentHP = this->maxHP;
|
||||
this->modelMatrix = this->initialModelMatrix;
|
||||
return;
|
||||
}
|
||||
void heal() override {
|
||||
this->currentHP = this->currentHP + 5.0f;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1,55 +0,0 @@
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include "src/Render_Utils.h"
|
||||
#include "./GameEntity.h"
|
||||
#include "Spaceship.h"
|
||||
|
||||
#pragma once
|
||||
class Nitro : public GameEntity
|
||||
{
|
||||
public:
|
||||
glm::mat4 modelMatrix;
|
||||
glm::mat4 initialModelMatrix;
|
||||
float healAmount = 10;
|
||||
bool isCollected;
|
||||
|
||||
|
||||
Nitro(glm::mat4 initialModelMatrix, float healAmount)
|
||||
:
|
||||
modelMatrix(initialModelMatrix),
|
||||
initialModelMatrix(initialModelMatrix),
|
||||
healAmount(healAmount),
|
||||
isCollected(false),
|
||||
GameEntity(1, 1, 0)
|
||||
{}
|
||||
|
||||
|
||||
virtual ~Nitro() = default;
|
||||
|
||||
virtual bool isAlive() {
|
||||
if (this->currentHP <= 0) {
|
||||
isCollected = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::vec3 getPosition() const override
|
||||
{
|
||||
return modelMatrix[3];
|
||||
}
|
||||
glm::mat4 getModelMatrix() override
|
||||
{
|
||||
return modelMatrix;
|
||||
}
|
||||
void respawn() override {
|
||||
this->currentHP = this->maxHP;
|
||||
this->modelMatrix = this->initialModelMatrix;
|
||||
return;
|
||||
}
|
||||
void heal() override {
|
||||
this->currentHP = this->currentHP + 5.0f;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1,143 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include "src/Render_Utils.h"
|
||||
#include <tuple>
|
||||
|
||||
#pragma once
|
||||
class Planet : public GameObject
|
||||
@ -14,21 +15,17 @@ private:
|
||||
float scale;
|
||||
glm::vec3 position;
|
||||
glm::mat4 positionMatrix;
|
||||
GLuint textureID;
|
||||
GLuint normalMapID;
|
||||
float startEulerYRotation = 0.f;
|
||||
float startYMovement = 0.f;
|
||||
std::tuple<GLuint, GLuint> texture;
|
||||
|
||||
public:
|
||||
Planet(GameObject* center, float distanceFromCenter, float rotationSpeed, float scale, Core::RenderContext sphereContext, GLuint textureID, GLuint normalMapID) {
|
||||
Planet(GameObject* center, float distanceFromCenter, float rotationSpeed, float scale, Core::RenderContext sphereContext, std::tuple<GLuint, GLuint> texture) {
|
||||
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;
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
glm::mat4 getPositionMatrix() override {
|
||||
@ -41,16 +38,8 @@ public:
|
||||
}
|
||||
|
||||
float rotationAngle = glm::radians(time * rotationSpeed);
|
||||
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed + startEulerYRotation) * glm::translate(glm::vec3(distanceFromCenter, startYMovement, 0));
|
||||
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed) * glm::translate(glm::vec3(distanceFromCenter, 0, 0));
|
||||
glm::mat4 modelMatrix = positionMatrix * glm::scale(glm::vec3(scale));
|
||||
Core::drawObjectPBRTexture(sphereContext, modelMatrix, textureID, normalMapID, 0.7, 0.0, program);
|
||||
}
|
||||
|
||||
void setStarteulerYRotation(float radians) {
|
||||
startEulerYRotation = radians;
|
||||
}
|
||||
|
||||
void setStartYMovement(float value) {
|
||||
startYMovement = value;
|
||||
Core::drawObjectPBRTexture(sphereContext, modelMatrix, std::get<0>(texture), std::get<1>(texture), 0.3, 0.0, program);
|
||||
}
|
||||
};
|
@ -3,25 +3,19 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <list>
|
||||
#include "Bullet.h"
|
||||
#include "ParticleSystem.h"
|
||||
#include "GameEntity.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
class Spaceship : public GameEntity
|
||||
class Spaceship
|
||||
{
|
||||
private:
|
||||
|
||||
std::list<Bullet*> bullets;
|
||||
float lastShootTime = 0.f;
|
||||
float shootInterval = 0.3f;
|
||||
ParticleSystem* leftParticle;
|
||||
ParticleSystem* rightParticle;
|
||||
|
||||
// Prywatny konstruktor, aby zapobiec zewn<77>trznemu tworzeniu instancji
|
||||
Spaceship() : GameEntity(100.0f, 100.0f, 10.0f)
|
||||
{
|
||||
|
||||
// Prywatny konstruktor, aby zapobiec zewnêtrznemu tworzeniu instancji
|
||||
Spaceship() {
|
||||
|
||||
}
|
||||
|
||||
// Prywatny destruktor, aby zapobiec przypadkowemu usuwaniu instancji
|
||||
@ -36,12 +30,10 @@ public:
|
||||
}
|
||||
|
||||
glm::vec3 color = glm::vec3(0.3, 0.3, 0.5);
|
||||
float roughness = 0.5;
|
||||
float metallic = 0.6;
|
||||
float turbo = 1.0f;
|
||||
float turboMAX = 1.0f;
|
||||
float roughness = 0.2;
|
||||
float metallic = 1.0;
|
||||
|
||||
glm::vec3 spaceshipPos = glm::vec3(4.065808f, 10.250000f, -20.189549f);
|
||||
glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f);
|
||||
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
|
||||
|
||||
glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
|
||||
@ -51,153 +43,18 @@ public:
|
||||
|
||||
glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f);
|
||||
glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f);
|
||||
glm::vec3 cameraPosHUDBar = cameraPos;
|
||||
glm::mat4 additionalHorRotationMatrix;
|
||||
glm::mat4 additionalVerRotationMatrix;
|
||||
|
||||
glm::mat4 calculateModelMatrix() {
|
||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
||||
|
||||
glm::mat4 spaceshipCameraRotationMatrix = glm::mat4({
|
||||
spaceshipSide.x, spaceshipSide.y, spaceshipSide.z, 0,
|
||||
spaceshipUp.x, spaceshipUp.y, spaceshipUp.z, 0,
|
||||
-spaceshipDir.x, -spaceshipDir.y, -spaceshipDir.z, 0,
|
||||
0., 0., 0., 1.
|
||||
glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
|
||||
spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
|
||||
spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
|
||||
-spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0,
|
||||
0.,0.,0.,1.,
|
||||
});
|
||||
|
||||
float additionalVerRotationAngle = glm::radians(currentShipVerAngle);
|
||||
additionalVerRotationMatrix = glm::rotate(glm::mat4(1.0f), additionalVerRotationAngle, glm::vec3(1.f, 0.f, 0.f));
|
||||
|
||||
float additionalHorRotationAngle = glm::radians(currentShipHorAngle);
|
||||
additionalHorRotationMatrix = glm::rotate(glm::mat4(1.0f), additionalHorRotationAngle, glm::vec3(0.f, 0.2f, 1.f));
|
||||
|
||||
glm::mat4 modelMatrix = glm::translate(spaceshipPos) * spaceshipCameraRotationMatrix * additionalVerRotationMatrix * additionalHorRotationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.02f));
|
||||
|
||||
return modelMatrix;
|
||||
}
|
||||
|
||||
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;
|
||||
return glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f));
|
||||
}
|
||||
|
||||
void processInput(GLFWwindow* window, float deltaTime, float time) {
|
||||
@ -210,100 +67,35 @@ 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 (w == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipDir * moveSpeed;
|
||||
if (s == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_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 (qState == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipUp * moveSpeed;
|
||||
if (eState == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipUp * moveSpeed;
|
||||
if (aState == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
if (dState == GLFW_PRESS)
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
|
||||
requestShoot(time);
|
||||
|
||||
cameraPos = spaceshipPos - calculateCameraDistanceHor(w, shiftState, deltaTime) * spaceshipDir + glm::vec3(0, calculateCameraDistanceVer(deltaTime), 0);
|
||||
cameraPosHUDBar = spaceshipPos - 1.f * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
|
||||
|
||||
cameraPos = spaceshipPos - 0.5 * 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)));
|
||||
@ -320,11 +112,11 @@ public:
|
||||
return cameraMatrix;
|
||||
}
|
||||
|
||||
void renderBullets(float time, GLuint program, std::vector<GameEntity*>& gameEntities) {
|
||||
void renderBullets(float time, GLuint program) {
|
||||
for (auto it = bullets.begin(); it != bullets.end();) {
|
||||
Bullet* bullet = *it;
|
||||
|
||||
if (bullet->shouldBeDestroyed(time, program, gameEntities, dmg)) {
|
||||
if (bullet->shouldBeDestroyed(time, program)) {
|
||||
delete bullet;
|
||||
it = bullets.erase(it);
|
||||
}
|
||||
@ -346,60 +138,8 @@ public:
|
||||
|
||||
void shoot(float time) {
|
||||
glm::vec3 perpendicularVector = 0.25f * glm::normalize(glm::cross(cameraDir, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
glm::vec3 dir = glm::vec4(spaceshipDir.x, spaceshipDir.y, spaceshipDir.z, 1.f) * additionalVerRotationMatrix * additionalHorRotationMatrix;
|
||||
bullets.push_back(Bullet::createSimpleBullet(dir, spaceshipPos - perpendicularVector, time));
|
||||
bullets.push_back(Bullet::createSimpleBullet(dir, spaceshipPos + perpendicularVector, time));
|
||||
bullets.push_back(Bullet::createSimpleBullet(cameraDir, spaceshipPos - perpendicularVector, time));
|
||||
bullets.push_back(Bullet::createSimpleBullet(cameraDir, spaceshipPos + perpendicularVector, time));
|
||||
lastShootTime = time;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
@ -1,143 +0,0 @@
|
||||
#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);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#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();
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -14,25 +14,20 @@ public:
|
||||
GLuint program;
|
||||
Core::RenderContext sphereContext;
|
||||
glm::mat4 positionMatrix;
|
||||
GLuint textureID;
|
||||
|
||||
Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, GLuint textureID, glm::vec3 color, double scale) {
|
||||
Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, glm::vec3 color, double scale) {
|
||||
this->program = program;
|
||||
this->sphereContext = sphereContext;
|
||||
this->sunPos = pos;
|
||||
this->sunDir = dir;
|
||||
this->sunColor = color;
|
||||
this->scale = scale;
|
||||
this->textureID = textureID;
|
||||
}
|
||||
|
||||
Sun(){}
|
||||
|
||||
void draw() {
|
||||
glUseProgram(program);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
glUniform1i(glGetUniformLocation(program, "sunTexture"), 0);
|
||||
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance()->createCameraMatrix();
|
||||
positionMatrix = glm::translate(sunPos);
|
||||
glm::mat4 transformation = viewProjectionMatrix * positionMatrix * glm::scale(glm::vec3(scale));
|
||||
|
@ -7,9 +7,7 @@ uniform sampler2D depthMap;
|
||||
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform sampler2D normalSampler;
|
||||
uniform sampler2D colorTexture;
|
||||
|
||||
uniform vec3 lightPositions[100];
|
||||
uniform vec3 lightColors[100];
|
||||
@ -26,18 +24,15 @@ 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;
|
||||
in vec2 vecTextCoord;
|
||||
|
||||
float DistributionGGX(vec3 normal, vec3 H, float roughness){
|
||||
float a = roughness*roughness;
|
||||
@ -72,11 +67,11 @@ 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){
|
||||
vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V, vec3 colorTex){
|
||||
float diffuse=max(0,dot(normal,lightDir));
|
||||
|
||||
vec3 F0 = vec3(0.04);
|
||||
F0 = mix(F0, texcolorRGB , metallic);
|
||||
F0 = mix(F0, colorTex, metallic);
|
||||
|
||||
vec3 H = normalize(V + lightDir);
|
||||
|
||||
@ -93,36 +88,25 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V, vec3 texcolorRG
|
||||
vec3 specular = numerator / denominator;
|
||||
|
||||
float NdotL = max(dot(normal, lightDir), 0.0);
|
||||
return (kD * texcolorRGB / PI + specular) * radiance * NdotL;
|
||||
return (kD * colorTex / 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 normal = normalize(vecNormal);
|
||||
|
||||
vec3 viewDir = normalize(cameraPos-worldPos);
|
||||
|
||||
vec3 lightDirs[4];
|
||||
vec3 ambient = AMBIENT * texColor.rgb;
|
||||
vec3 lightDirs[100];
|
||||
vec3 texColor = texture(colorTexture, vecTextCoord).rgb;
|
||||
vec3 ambient = AMBIENT * texColor;
|
||||
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);
|
||||
ilumination = ilumination+PBRLight(lightDirs[i], attenuatedlightColor * 300, normal, viewDir, texColor);
|
||||
}
|
||||
|
||||
|
||||
@ -132,8 +116,8 @@ void main()
|
||||
|
||||
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);
|
||||
|
||||
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir, texColor);
|
||||
|
||||
|
||||
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
|
||||
}
|
||||
}
|
@ -11,39 +11,36 @@ uniform mat4 modelMatrix;
|
||||
|
||||
out vec3 vecNormal;
|
||||
out vec3 worldPos;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform vec3 lightsPositions[10];
|
||||
uniform vec3 lightsPositions[100];
|
||||
uniform vec3 spotlightPos;
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
out vec3 viewDirTS;
|
||||
out vec3 lightDirTS[10];
|
||||
out vec3 lightDirTS[100];
|
||||
out vec3 spotlightDirTS;
|
||||
out mat3 TBN;
|
||||
out vec2 vecTextCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = vertexTexCoord * -1;
|
||||
TexCoords = vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y);
|
||||
|
||||
|
||||
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
|
||||
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
|
||||
vec3 w_tangent = normalize(mat3(modelMatrix)*vertexTangent);
|
||||
vec3 w_bitangent = normalize(mat3(modelMatrix)*vertexBitangent);
|
||||
TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
|
||||
mat3 TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
|
||||
|
||||
vec3 V = normalize(cameraPos-worldPos);
|
||||
viewDirTS = TBN*V;
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
vec3 L = normalize(lightsPositions[i]-worldPos);
|
||||
lightDirTS[i] = TBN*L;
|
||||
}
|
||||
|
||||
vec3 SL = normalize(spotlightPos-worldPos);
|
||||
spotlightDirTS = TBN*SL;
|
||||
|
||||
vecTextCoord = vertexTexCoord;
|
||||
}
|
@ -13,8 +13,6 @@
|
||||
<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" />
|
||||
@ -28,16 +26,10 @@
|
||||
</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" />
|
||||
@ -53,24 +45,20 @@
|
||||
<ClInclude Include="Sun.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="draw_obj_text_pbr.frag" />
|
||||
<None Include="draw_obj_text_pbr.vert" />
|
||||
<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" />
|
||||
<None Include="tex.frag" />
|
||||
<None Include="tex.vert" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{5BACD057-4B83-4CB6-A367-40A10BCE2149}</ProjectGuid>
|
||||
|
@ -57,12 +57,6 @@
|
||||
<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">
|
||||
@ -119,24 +113,6 @@
|
||||
<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">
|
||||
@ -165,28 +141,16 @@
|
||||
</None>
|
||||
<None Include="fireball.frag" />
|
||||
<None Include="fireball.vert" />
|
||||
<None Include="shaders\shader_sprite.frag">
|
||||
<None Include="draw_obj_text_pbr.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_sprite.vert">
|
||||
<None Include="draw_obj_text_pbr.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_tex.frag">
|
||||
<None Include="tex.vert">
|
||||
<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">
|
||||
<None Include="tex.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
150
grk/project/grk-project.vcxproj.filters.orig
Normal file
@ -0,0 +1,150 @@
|
||||
<?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>
|
@ -1,12 +0,0 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
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
|
||||
|
@ -7,7 +7,7 @@ uniform sampler2D depthMap;
|
||||
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
uniform vec3 color;
|
||||
uniform sampler2D colorTexture;
|
||||
|
||||
uniform vec3 lightPositions[100];
|
||||
uniform vec3 lightColors[100];
|
||||
@ -72,7 +72,7 @@ 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);
|
||||
F0 = mix(F0, texture(colorTexture, vec2(0.5, 0.5)).rgb, metallic);
|
||||
|
||||
vec3 H = normalize(V + lightDir);
|
||||
|
||||
@ -89,7 +89,7 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){
|
||||
vec3 specular = numerator / denominator;
|
||||
|
||||
float NdotL = max(dot(normal, lightDir), 0.0);
|
||||
return (kD * color / PI + specular) * radiance * NdotL;
|
||||
return (kD * texture(colorTexture, vec2(0.5, 0.5)).rgb / PI + specular) * radiance * NdotL;
|
||||
}
|
||||
|
||||
|
||||
@ -100,7 +100,7 @@ void main()
|
||||
vec3 viewDir = normalize(cameraPos-worldPos);
|
||||
|
||||
vec3 lightDirs[4];
|
||||
vec3 ambient = AMBIENT * color;
|
||||
vec3 ambient = AMBIENT * texture(colorTexture, vec2(0.5, 0.5)).rgb;
|
||||
vec3 ilumination = ambient;
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
@ -118,12 +118,6 @@ void main()
|
||||
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);
|
||||
}
|
43
grk/project/shaders/draw_obj_text_pbr.vert
Normal file
@ -0,0 +1,43 @@
|
||||
#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;
|
||||
|
||||
uniform vec3 lightsPositions[100];
|
||||
uniform vec3 spotlightPos;
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
out vec3 viewDirTS;
|
||||
out vec3 lightDirTS[100];
|
||||
out vec3 spotlightDirTS;
|
||||
|
||||
void main()
|
||||
{
|
||||
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);
|
||||
mat3 TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
|
||||
|
||||
vec3 V = normalize(cameraPos-worldPos);
|
||||
viewDirTS = TBN*V;
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
vec3 L = normalize(lightsPositions[i]-worldPos);
|
||||
lightDirTS[i] = TBN*L;
|
||||
}
|
||||
|
||||
vec3 SL = normalize(spotlightPos-worldPos);
|
||||
spotlightDirTS = TBN*SL;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 vertexColor;
|
||||
|
||||
void main() {
|
||||
FragColor = vec4(vertexColor.r, vertexColor.g, vertexColor.b, 1.0);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#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;
|
||||
}
|
@ -3,13 +3,9 @@
|
||||
uniform vec3 color;
|
||||
uniform float exposition;
|
||||
|
||||
uniform sampler2D sunTexture;
|
||||
in vec2 TexCoords;
|
||||
|
||||
out vec4 outColor;
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = texture(sunTexture, TexCoords);
|
||||
vec3 brightColor = texColor.rgb * 4.0;
|
||||
outColor = vec4(vec3(1.0) - exp(-brightColor*exposition),texColor.a);
|
||||
}
|
||||
{
|
||||
outColor = vec4(vec3(1.0) - exp(-color*exposition),1);
|
||||
}
|
||||
|
@ -5,11 +5,9 @@ layout(location = 1) in vec3 vertexNormal;
|
||||
layout(location = 2) in vec2 vertexTexCoord;
|
||||
|
||||
uniform mat4 transformation;
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
//gl_Position = vec4(vertexPosition, 1.0);
|
||||
TexCoords = vertexTexCoord;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ out vec4 outColor;
|
||||
|
||||
|
||||
in vec3 viewDirTS;
|
||||
in vec3 lightDirTS[4];
|
||||
in vec3 lightDirTS[8];
|
||||
in vec3 spotlightDirTS;
|
||||
in vec3 sunDirTS;
|
||||
|
||||
@ -99,7 +99,7 @@ void main()
|
||||
|
||||
vec3 viewDir = normalize(cameraPos-worldPos);
|
||||
|
||||
vec3 lightDirs[4];
|
||||
vec3 lightDirs[8];
|
||||
vec3 ambient = AMBIENT * color;
|
||||
vec3 ilumination = ambient;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
#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);
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#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;
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
#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
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#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;
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Core
|
||||
{
|
||||
glm::mat4 createPerspectiveMatrix(float zNear, float zFar, float frustumScale);
|
||||
glm::mat4 createPerspectiveMatrix(float zNear = 0.1f, float zFar = 100.0f, float frustumScale = 1.f);
|
||||
|
||||
// position - pozycja kamery
|
||||
// forward - wektor "do przodu" kamery (jednostkowy)
|
||||
|
@ -9,8 +9,7 @@
|
||||
#include <assimp/postprocess.h>
|
||||
#include "../GameUtils.h"
|
||||
#include "../Spaceship.h"
|
||||
|
||||
#include "Texture.h"
|
||||
#include "./Texture.h"
|
||||
|
||||
|
||||
|
||||
@ -170,8 +169,8 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
|
||||
|
||||
std::list<Sun*>* suns = GameUtils::getInstance()->getSuns();
|
||||
|
||||
glm::vec3 lightsPositions[100];
|
||||
glm::vec3 lightsColors[100];
|
||||
glm::vec3 lightsPositions[8];
|
||||
glm::vec3 lightsColors[8];
|
||||
|
||||
int i = 0;
|
||||
for (Sun* sun : *suns) {
|
||||
@ -180,8 +179,8 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
|
||||
++i;
|
||||
}
|
||||
|
||||
glUniform3fv(glGetUniformLocation(program, "lightPositions"), 100, glm::value_ptr(lightsPositions[0]));
|
||||
glUniform3fv(glGetUniformLocation(program, "lightColors"), 100, glm::value_ptr(lightsColors[0]));
|
||||
glUniform3fv(glGetUniformLocation(program, "lightPositions"), 8, glm::value_ptr(lightsPositions[0]));
|
||||
glUniform3fv(glGetUniformLocation(program, "lightColors"), 8, 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);
|
||||
@ -190,10 +189,11 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalID, float roughness, float metallic, GLuint program) {
|
||||
void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, GLuint normal, float roughness, float metallic, GLuint program) {
|
||||
Spaceship* spaceship = Spaceship::getInstance();
|
||||
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
Core::SetActiveTexture(texture, "colorTexture", program, 0);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
|
||||
@ -201,13 +201,8 @@ void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMat
|
||||
|
||||
glUniform1f(glGetUniformLocation(program, "roughness"), roughness);
|
||||
glUniform1f(glGetUniformLocation(program, "metallic"), metallic);
|
||||
|
||||
Core::SetActiveTexture(textureID, "textureSampler", program, 0);
|
||||
glUniform1i(glGetUniformLocation(program, "textureSampler"), 0);
|
||||
glUniform1i(glGetUniformLocation(program, "colorTexture"), 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();
|
||||
@ -229,7 +224,6 @@ void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMat
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,6 @@ namespace Core
|
||||
|
||||
glm::mat4 createPerspectiveMatrix();
|
||||
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic, GLuint program);
|
||||
void drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, GLuint normal, 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);
|
||||
}
|
@ -17,22 +17,14 @@ 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);
|
||||
|
||||
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
@ -76,7 +68,8 @@ GLuint Core::LoadCubemap(const std::vector<std::string>& faces)
|
||||
|
||||
void Core::SetActiveTexture(GLuint textureID, const char * shaderVariableName, GLuint programID, int textureUnit)
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(programID, shaderVariableName), textureUnit);
|
||||
int location = glGetUniformLocation(programID, shaderVariableName);
|
||||
glUniform1i(location, textureUnit);
|
||||
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
}
|
||||
|
@ -6,10 +6,11 @@
|
||||
#include <cmath>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
|
||||
#include "Shader_Loader.h"
|
||||
#include "Render_Utils.h"
|
||||
#include "texture.h"
|
||||
|
||||
#include "Box.cpp"
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
@ -20,54 +21,21 @@
|
||||
#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 = 1920, HEIGHT = 1080;
|
||||
int WIDTH = 500, HEIGHT = 500;
|
||||
|
||||
namespace models {
|
||||
Core::RenderContext marbleBustContext;
|
||||
Core::RenderContext spaceshipContext;
|
||||
Core::RenderContext sphereContext;
|
||||
Core::RenderContext cubeContext;
|
||||
Core::RenderContext asteroid;
|
||||
}
|
||||
namespace texture {
|
||||
GLuint cubemapTexture;
|
||||
GLuint spaceshipTexture;
|
||||
GLuint spaceshipNormal;
|
||||
GLuint spriteTexture;
|
||||
GLuint earthTexture;
|
||||
GLuint asteroidTexture;
|
||||
GLuint asteroidNormal;
|
||||
GLuint heartTexture;
|
||||
GLuint boosterTexture;
|
||||
}
|
||||
|
||||
struct TextureTuple {
|
||||
GLuint textureID;
|
||||
GLuint normalMapID;
|
||||
};
|
||||
|
||||
std::vector<TextureTuple> planetTextures;
|
||||
std::vector<GLuint> sunTexturesIds;
|
||||
|
||||
void createGalaxy(glm::vec3 galaxyPosition);
|
||||
|
||||
GLuint depthMapFBO;
|
||||
@ -76,21 +44,14 @@ GLuint depthMap;
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
GLuint programTest;
|
||||
GLuint programSprite;
|
||||
GLuint programCubemap;
|
||||
GLuint programParticle;
|
||||
GLuint programTex;
|
||||
GLuint programSpriteBar;
|
||||
GLuint programCubemap;
|
||||
GLuint programTextPBR;
|
||||
|
||||
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);
|
||||
@ -100,20 +61,8 @@ float lastTime = -1.f;
|
||||
float deltaTime = 0.f;
|
||||
|
||||
Spaceship* spaceship = Spaceship::getInstance();
|
||||
void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId,float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
|
||||
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 createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
|
||||
void loadPlanetsTexturesWithNormals();
|
||||
void updateDeltaTime(float time) {
|
||||
if (lastTime < 0) {
|
||||
lastTime = time;
|
||||
@ -124,172 +73,7 @@ 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);
|
||||
@ -300,7 +84,6 @@ 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();
|
||||
@ -318,76 +101,28 @@ void renderScene(GLFWwindow* window)
|
||||
sun->draw();
|
||||
}
|
||||
|
||||
glUseProgram(programTex);
|
||||
glUseProgram(programTextPBR);
|
||||
|
||||
for (Planet* p : planets) {
|
||||
p->draw(time, programTex);
|
||||
p->draw(time, programTextPBR);
|
||||
}
|
||||
|
||||
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);
|
||||
spaceship->renderBullets(glfwGetTime(), program);
|
||||
|
||||
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
glUseProgram(programTex);
|
||||
//Core::SetActiveTexture(texture::spaceshipTexture, "textureSampler", programTex, 0);
|
||||
drawObjectPBRTexture(models::spaceshipContext,
|
||||
drawObjectPBR(models::spaceshipContext,
|
||||
spaceship->calculateModelMatrix(),
|
||||
texture::spaceshipTexture,
|
||||
texture::spaceshipNormal,
|
||||
spaceship->roughness, spaceship->metallic, programTex
|
||||
spaceship->color,
|
||||
spaceship->roughness, spaceship->metallic, program
|
||||
);
|
||||
|
||||
//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);
|
||||
}
|
||||
@ -399,156 +134,60 @@ 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));
|
||||
}
|
||||
|
||||
float generateRandomFloat(float minValue, float maxValue) {
|
||||
return minValue + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (maxValue - minValue)));
|
||||
}
|
||||
|
||||
|
||||
void createAsteroids() {
|
||||
GameUtils* gu = GameUtils::getInstance();
|
||||
GameObject* center = gu->getSuns()->front();
|
||||
float minDistanceFromCenter = 24.f;
|
||||
float maxDistanceFromCenter = 26.f;
|
||||
float rotationSpeed = 0.05f;
|
||||
float scale = 0.002f;
|
||||
int numAsteroids = 80;
|
||||
float distanceIncrement = 2.f / (minDistanceFromCenter + 1);
|
||||
|
||||
for (int j = -1; j < 2; j++) {
|
||||
for (int i = 0; i < numAsteroids; ++i) {
|
||||
float distanceFromCenter = generateRandomFloat(minDistanceFromCenter, maxDistanceFromCenter);
|
||||
Planet* asteroid = new Planet(center, distanceFromCenter, rotationSpeed, scale, models::asteroid, texture::asteroidTexture, texture::asteroidNormal);
|
||||
asteroid->setStarteulerYRotation(distanceIncrement * i);
|
||||
asteroid->setStartYMovement(generateRandomFloat(-0.5f, 0.5f) + j);
|
||||
planets.push_back(asteroid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createGalaxy(glm::vec3 galaxyPosition) {
|
||||
float planetsSizes[] = { 1.f, 1.5f, 0.8f, 1.2f, 0.2f };
|
||||
GLuint sunTexId = sunTexturesIds[0];
|
||||
createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), sunTexId,3, planetsSizes, 5, 15.f, 0.2f);
|
||||
createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), 3, planetsSizes, 5, 15.f, 0.2f);
|
||||
float planetsSizes2[] = { 0.6f, 1.1f, 0.9f };
|
||||
GLuint sunTexId2 = sunTexturesIds[1];
|
||||
createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), sunTexId2, 2, planetsSizes2, 3, 15.f, 0.2f);
|
||||
createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), 2, planetsSizes2, 3, 15.f, 0.2f);
|
||||
float planetsSizes3[] = { 0.7f, 1.5f, 1.2f, 1.f };
|
||||
GLuint sunTexId3 = sunTexturesIds[2];
|
||||
createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), sunTexId3, 4, planetsSizes3, 4, 20.f, 0.2f);
|
||||
createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), 4, planetsSizes3, 4, 20.f, 0.2f);
|
||||
float planetSizes4[] = { 1.f, 0.5f };
|
||||
GLuint sunTexId4 = sunTexturesIds[3];
|
||||
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), sunTexId4, 5, planetsSizes3, 2, 25.f, 0.2f);
|
||||
createAsteroids();
|
||||
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), 5, planetsSizes3, 2, 25.f, 0.2f);
|
||||
}
|
||||
|
||||
void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
|
||||
std::tuple<GLuint, GLuint> getRandomPlanetTexture() {
|
||||
std::list<std::tuple<GLuint, GLuint>>* planetsTextures = GameUtils::getInstance()->getPlanetsTextures();
|
||||
std::srand(static_cast<unsigned int>(std::time(nullptr)));
|
||||
int index = std::rand() % planetsTextures->size();
|
||||
auto iterator = std::next(planetsTextures->begin(), 0);
|
||||
return *iterator;
|
||||
}
|
||||
|
||||
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
|
||||
GameUtils* gu = GameUtils::getInstance();
|
||||
sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), sunTexId, glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale);
|
||||
sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale);
|
||||
gu->getSuns()->push_back(sun);
|
||||
for (int i = 0; i < numberOfPlanets; i++) {
|
||||
TextureTuple textures = getRandomPlanetTexture();
|
||||
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);
|
||||
Planet* planet = new Planet(sun, distanceFromSum, i * 0.1f + planetSpeedCoef, planetSizes[i], models::sphereContext, getRandomPlanetTexture());
|
||||
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");
|
||||
programTextPBR = gameUtils->shaderLoader->CreateProgram("shaders/draw_obj_text_pbr.vert", "shaders/draw_obj_text_pbr.frag");
|
||||
|
||||
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
|
||||
loadModelToContext("./models/StarShip2.obj", models::spaceshipContext);
|
||||
loadModelToContext("./models/spaceship.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",
|
||||
@ -559,30 +198,29 @@ 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");
|
||||
loadPlanetsTexturesWithNormals();
|
||||
|
||||
|
||||
spaceship->createParticles();
|
||||
createSuns();
|
||||
createEnemies();
|
||||
}
|
||||
|
||||
void loadPlanetsTexturesWithNormals()
|
||||
{
|
||||
std::list<std::tuple<GLuint, GLuint>>* planetsTextures = GameUtils::getInstance()->getPlanetsTextures();
|
||||
std::tuple<GLuint, GLuint> p1 = std::tuple<GLuint, GLuint>(Core::LoadTexture("./textures/planets/lol.png"), Core::LoadTexture("./textures/planets/planet1normal.png"));
|
||||
std::tuple<GLuint, GLuint> p2 = std::tuple<GLuint, GLuint>(Core::LoadTexture("./textures/planets/planet2.png"), Core::LoadTexture("./textures/planets/planet2normal.png"));
|
||||
std::tuple<GLuint, GLuint> p3 = std::tuple<GLuint, GLuint>(Core::LoadTexture("./textures/planets/planet3.png"), Core::LoadTexture("./textures/planets/planet3normal.png"));
|
||||
std::tuple<GLuint, GLuint> p4 = std::tuple<GLuint, GLuint>(Core::LoadTexture("./textures/planets/planet4.png"), Core::LoadTexture("./textures/planets/planet4normal.png"));
|
||||
planetsTextures->push_back(p1);
|
||||
planetsTextures->push_back(p2);
|
||||
planetsTextures->push_back(p3);
|
||||
planetsTextures->push_back(p4);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -21,15 +21,11 @@
|
||||
#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;
|
||||
@ -38,40 +34,21 @@ 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 programSprite;
|
||||
GLuint programCubemap;
|
||||
GLuint programParticle;
|
||||
GLuint programTex;
|
||||
GLuint programSpriteBar;
|
||||
GLuint programCubemap;
|
||||
|
||||
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);
|
||||
@ -81,8 +58,6 @@ 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) {
|
||||
@ -94,60 +69,7 @@ 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);
|
||||
@ -158,7 +80,6 @@ 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();
|
||||
@ -176,72 +97,25 @@ void renderScene(GLFWwindow* window)
|
||||
sun->draw();
|
||||
}
|
||||
|
||||
glUseProgram(programTex);
|
||||
for (Planet* p : planets) {
|
||||
p->draw(time, programTex);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
glUseProgram(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)
|
||||
for (Planet* p : planets) {
|
||||
p->draw(time, program);
|
||||
}
|
||||
|
||||
|
||||
spaceship->renderBullets(glfwGetTime(), program);
|
||||
|
||||
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
glUseProgram(programTex);
|
||||
//Core::SetActiveTexture(texture::spaceshipTexture, "textureSampler", programTex, 0);
|
||||
drawObjectPBRTexture(models::spaceshipContext,
|
||||
drawObjectPBR(models::spaceshipContext,
|
||||
spaceship->calculateModelMatrix(),
|
||||
texture::spaceshipTexture,
|
||||
spaceship->roughness, spaceship->metallic, programTex
|
||||
spaceship->color,
|
||||
spaceship->roughness, spaceship->metallic, program
|
||||
);
|
||||
<<<<<<< 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);
|
||||
@ -254,95 +128,62 @@ 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);
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
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));*/
|
||||
}
|
||||
|
||||
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
|
||||
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");
|
||||
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");
|
||||
|
||||
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
|
||||
loadModelToContext("./models/StarShip2.obj", models::spaceshipContext);
|
||||
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
||||
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
||||
loadModelToContext("./models/cube.obj", models::cubeContext);
|
||||
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
|
||||
|
||||
texture::spriteTexture = Core::LoadTexture("textures/blinky1.png");
|
||||
|
||||
/*std::vector<std::string> cubeFaces = {
|
||||
"space_rt.png",
|
||||
"space_lf.png",
|
||||
"space_up.png",
|
||||
"space_dn.png",
|
||||
"space_bk.png",
|
||||
"space_ft.png"
|
||||
};*/
|
||||
|
||||
std::vector<std::string> cubeFaces = {
|
||||
"bkg2_right1.png",
|
||||
@ -353,25 +194,30 @@ 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");
|
||||
|
||||
spaceship->createParticles();
|
||||
=======
|
||||
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)
|
||||
|
||||
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
|
||||
|
@ -8,11 +8,10 @@
|
||||
|
||||
|
||||
#include "ex_9_1.hpp"
|
||||
int WIDTH = 1920, HEIGHT = 1080;
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
{
|
||||
// inicjalizacja glfw
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
@ -24,7 +23,7 @@ int main(int argc, char** argv)
|
||||
#endif
|
||||
|
||||
// tworzenie okna za pomoca glfw
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "FirstWindow", NULL, NULL);
|
||||
GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL);
|
||||
if (window == NULL)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
@ -35,7 +34,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// ladowanie OpenGL za pomoca glew
|
||||
glewInit();
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
glViewport(0, 0, 500, 500);
|
||||
|
||||
init(window);
|
||||
|
||||
|
Before Width: | Height: | Size: 5.8 MiB |
Before Width: | Height: | Size: 941 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 11 MiB |
Before Width: | Height: | Size: 4.4 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 452 KiB After Width: | Height: | Size: 452 KiB |
BIN
grk/project/textures/planets/lol.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 2.5 MiB |
Before Width: | Height: | Size: 309 KiB |
Before Width: | Height: | Size: 3.1 MiB |
Before Width: | Height: | Size: 2.9 MiB |
Before Width: | Height: | Size: 2.9 MiB |
Before Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 3.5 MiB |
Before Width: | Height: | Size: 283 KiB |
Before Width: | Height: | Size: 555 KiB |
Before Width: | Height: | Size: 190 KiB |
Before Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 356 KiB |
BIN
images/hp.png
Before Width: | Height: | Size: 1.6 MiB |
Before Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 283 KiB |
BIN
images/turbo.png
Before Width: | Height: | Size: 448 KiB |