Compare commits

...

6 Commits

Author SHA1 Message Date
Pawel Felcyn
69d7db83fa fire from spaceship 2024-01-30 21:15:07 +01:00
cf07257222 Merge pull request 'enemies' (#6) from enemies into master
Reviewed-on: #6
2024-01-29 16:14:31 +01:00
Qumpell
79d0069a52 modify gitignore 2024-01-29 16:11:15 +01:00
4e3264ad2a Fix billboarding of enemies and their shooting positions 2024-01-29 16:11:15 +01:00
f1c3a1b57b Add enemy class 2024-01-29 16:10:54 +01:00
6b60c55af7 Add sprite renderer and sprite shaders 2024-01-29 16:07:55 +01:00
33 changed files with 771 additions and 232 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@

/grk/project/shaders
/grk/.vs/grk-cw
/grk/project/Debug

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

@ -0,0 +1,81 @@
#include "glm.hpp"
#include "ext.hpp"
#include "src/Render_Utils.h"
#include "Bullet.h"
#include "Spaceship.h"
#pragma once
class Enemy
{
private:
std::list<Bullet*> bullets;
float lastShootTime = 0.f;
float shootInterval = 0.3f;
public:
glm::mat4 modelMatrix;
int hp;
int dmg;
float aggroRange;
Enemy(int initialHp, glm::mat4 initialModelMatrix, int initialDmg, float initialAggroRange)
: hp(initialHp), modelMatrix(initialModelMatrix), dmg(initialDmg), aggroRange(initialAggroRange)
{}
virtual ~Enemy() = default;
virtual void attack(const glm::vec3& shipPos, float time) {
if (isInAggroRange(shipPos)) {
requestShoot(time);
}
}
virtual bool isAlive() const {
if (this->hp < 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) {
for (auto it = bullets.begin(); it != bullets.end();) {
Bullet* bullet = *it;
if (bullet->shouldBeDestroyed(time, program)) {
delete bullet;
it = bullets.erase(it);
}
else {
it++;
}
}
}
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]));
this->bullets.push_back(Bullet::createSimpleBullet(bulletDirection, this->modelMatrix[3], time));
this->lastShootTime = time;
}
};

View File

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

View File

@ -0,0 +1,142 @@
#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, 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.0f), sourcePosition + particle.randomPointOnCircle);
model = glm::scale(model, glm::vec3(0.005f, 0.005f, 0.005f));
model = glm::translate(model, particle.direction * speed * (time - particle.birthTime));
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
i++;
}
glBindVertexArray(0);
}
};

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

View File

@ -3,6 +3,7 @@
#include <GLFW/glfw3.h>
#include <list>
#include "Bullet.h"
#include "ParticleSystem.h"
#pragma once
@ -12,10 +13,12 @@ private:
std::list<Bullet*> bullets;
float lastShootTime = 0.f;
float shootInterval = 0.3f;
ParticleSystem* leftParticle;
ParticleSystem* rightParticle;
// Prywatny konstruktor, aby zapobiec zewnêtrznemu tworzeniu instancji
Spaceship() {
}
// Prywatny destruktor, aby zapobiec przypadkowemu usuwaniu instancji
@ -33,7 +36,7 @@ public:
float roughness = 0.2;
float metallic = 1.0;
glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.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);
@ -57,6 +60,13 @@ public:
return glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f));
}
void setPerticlesParameters(float speed, float generationInterval) {
leftParticle->speed = speed;
leftParticle->generationInterval = generationInterval;
rightParticle->speed = speed;
rightParticle->generationInterval = generationInterval;
}
void processInput(GLFWwindow* window, float deltaTime, float time) {
static bool mouseButtonCallbackSet = false;
if (!mouseButtonCallbackSet) {
@ -67,12 +77,30 @@ 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);
if (w == GLFW_PRESS) {
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
moveSpeed *= 2;
setPerticlesParameters(200.f, 0.00005f);
}
else {
setPerticlesParameters(100.f, 0.0001f);
}
}
else {
setPerticlesParameters(50.f, 0.0002f);
}
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
if (w == GLFW_PRESS)
spaceshipPos += spaceshipDir * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
if (s == GLFW_PRESS)
spaceshipPos -= spaceshipDir * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
spaceshipPos += spaceshipSide * moveSpeed;
@ -89,13 +117,37 @@ public:
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
requestShoot(time);
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
cameraPos = spaceshipPos - 1.f * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
cameraDir = spaceshipDir;
glm::vec3 perpendicularVector = 0.04f * glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.0f, 1.0f, 0.0f)));
if (leftParticle != nullptr && rightParticle != nullptr) {
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) {
leftParticle->drawParticles(program, view, projection, time);
rightParticle->drawParticles(program, view, projection, 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)));

View File

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

View File

@ -0,0 +1,26 @@
#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);
private:
unsigned int VAO;
unsigned int VBO;
unsigned int EBO;
// Initializes and configures the quad's buffer and vertex attributes
void initRenderData();
};
}

View File

@ -13,6 +13,8 @@
<ItemGroup>
<ClCompile Include="GameObject.cpp" />
<ClCompile Include="Planet.cpp" />
<ClCompile Include="SpriteRenderer.cpp" />
<ClCompile Include="Source.cpp" />
<ClCompile Include="src\Box.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\main.cpp" />
@ -26,10 +28,13 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Bullet.h" />
<ClInclude Include="Enemy.h" />
<ClInclude Include="GameObject.h" />
<ClInclude Include="GameUtils.h" />
<ClInclude Include="ParticleSystem.h" />
<ClInclude Include="Planet.h" />
<ClInclude Include="Spaceship.h" />
<ClInclude Include="SpriteRenderer.h" />
<ClInclude Include="src\Camera.h" />
<ClInclude Include="src\ex_9_1.hpp" />
<ClInclude Include="src\objload.h" />
@ -47,12 +52,16 @@
<ItemGroup>
<None Include="fireball.frag" />
<None Include="fireball.vert" />
<None Include="particle.frag" />
<None Include="particle.vert" />
<None Include="shaders\shader_9_1.frag" />
<None Include="shaders\shader_9_1.vert" />
<None Include="shaders\shader_8_sun.frag" />
<None Include="shaders\shader_8_sun.vert" />
<None Include="shaders\shader_skybox.frag" />
<None Include="shaders\shader_skybox.vert" />
<None Include="shaders\shader_sprite.frag" />
<None Include="shaders\shader_sprite.vert" />
<None Include="shaders\test.frag" />
<None Include="shaders\test.vert" />
</ItemGroup>

View File

@ -57,6 +57,11 @@
<ClCompile Include="Planet.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpriteRenderer.cpp">
<Filter>Source Files</Filter>
<ClCompile Include="Source.cpp">
<Filter>Shader Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\objload.h">
@ -113,6 +118,13 @@
<ClInclude Include="Bullet.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Enemy.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpriteRenderer.h">
<ClInclude Include="ParticleSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_8_sun.vert">
@ -139,5 +151,17 @@
<None Include="shaders\shader_skybox.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="fireball.frag" />
<None Include="fireball.vert" />
<None Include="shaders\shader_sprite.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_sprite.vert">
<None Include="particle.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="particle.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

View File

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

View File

@ -118,6 +118,6 @@ void main()
vec3 attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,6 @@ 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);

View File

@ -21,6 +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;
@ -34,6 +39,7 @@ namespace models {
}
namespace texture {
GLuint cubemapTexture;
GLuint spriteTexture;
}
void createGalaxy(glm::vec3 galaxyPosition);
@ -44,13 +50,17 @@ GLuint depthMap;
GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
GLuint programSprite;
GLuint programCubemap;
GLuint programParticle;
std::list<Planet*> planets;
Sun* sun;
GLuint VAO,VBO;
std::vector<Enemy*> enemies;
float exposition = 1.f;
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
@ -61,6 +71,8 @@ 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) {
lastTime = time;
@ -107,8 +119,6 @@ void renderScene(GLFWwindow* window)
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);
@ -119,6 +129,27 @@ void renderScene(GLFWwindow* window)
spaceship->roughness, spaceship->metallic, program
);
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);
glUseProgram(0);
glfwSwapBuffers(window);
}
@ -158,9 +189,18 @@ void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int
}
}
void createEnemies() {
enemies.push_back(new Enemy(100, glm::mat4(1.0f), 20, 5.0f));
enemies.push_back(new Enemy(100, glm::translate(glm::mat4(1.0f) , glm::vec3(1.f,1.f,1.f)), 15, 5.0f));
enemies.push_back(new Enemy(100, glm::translate(glm::mat4(1.0f), glm::vec3(-1.f, 2.f, -0.9f)), 25, 5.0f));
}
void init(GLFWwindow* window)
{
GameUtils* gameUtils = GameUtils::getInstance();
spriteRenderer = new Core::SpriteRenderer();
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glEnable(GL_DEPTH_TEST);
@ -169,12 +209,16 @@ void init(GLFWwindow* window)
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");
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag");
programParticle = gameUtils->shaderLoader->CreateProgram("shaders/particle.vert", "shaders/particle.frag");
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
loadModelToContext("./models/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 = {
"bkg2_right1.png",
@ -187,12 +231,20 @@ void init(GLFWwindow* window)
texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
spaceship->createParticles();
createSuns();
createEnemies();
}
void shutdown(GLFWwindow* window)
{
GameUtils::getInstance()->shaderLoader->DeleteProgram(program);
delete spriteRenderer;
// Dealokacja pamięci po obiektach Enemy
for (const auto& enemy : enemies) {
delete enemy;
}
}
//obsluga wejscia

View File

@ -21,6 +21,14 @@
#include "../Planet.h"
#include "../GameObject.h"
#include "../GameUtils.h"
<<<<<<< HEAD
#include "../SpriteRenderer.h"
#include "../Enemy.h"
=======
#include "../ParticleSystem.h"
#include "Camera.h"
>>>>>>> 2162820 (fire from ship)
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
@ -34,21 +42,28 @@ namespace models {
}
namespace texture {
GLuint cubemapTexture;
GLuint spriteTexture;
}
void createGalaxy(glm::vec3 galaxyPosition);
GLuint depthMapFBO;
GLuint depthMap;
GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
GLuint programSprite;
GLuint programCubemap;
GLuint programParticle;
std::list<Planet*> planets;
Sun* sun;
GLuint VAO,VBO;
std::vector<Enemy*> enemies;
float exposition = 1.f;
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
@ -58,6 +73,8 @@ float lastTime = -1.f;
float deltaTime = 0.f;
Spaceship* spaceship = Spaceship::getInstance();
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
Core::SpriteRenderer* spriteRenderer;
void updateDeltaTime(float time) {
if (lastTime < 0) {
@ -105,8 +122,6 @@ void renderScene(GLFWwindow* window)
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);
@ -117,6 +132,38 @@ void renderScene(GLFWwindow* window)
spaceship->roughness, spaceship->metallic, program
);
<<<<<<< HEAD
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);
}
}
//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);
=======
std::list<ParticleSystem*>* particleSystems = GameUtils::getInstance()->getParticleSystems();
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);
/*for (auto particleSystem : *particleSystems) {
particleSystem->drawParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time);
}*/
>>>>>>> 2162820 (fire from ship)
glUseProgram(0);
glfwSwapBuffers(window);
}
@ -130,60 +177,66 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
void createSuns() {
GameUtils* gu = GameUtils::getInstance();
sun = new Sun(programSun, models::sphereContext, glm::vec3(0, 2, 0), glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, 1);
Planet* planet = new Planet(sun, 20.f, 0.25f, 1.f, models::sphereContext);
planets.push_back(planet);
Planet* moon = new Planet(planet, 5.f, 1.f, 0.2f, models::sphereContext);
planets.push_back(moon);
gu->getSuns()->push_back(sun);
Planet* planet2 = new Planet(sun, 50.f, 0.5f, 1.5f, models::sphereContext);
planets.push_back(planet2);
/*suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-80, 20, 50), glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(1.0f, 0.8f, 0.2f), 4.0));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(50, 40, -30), glm::vec3(-0.73633f, 0.451106, 0.023226f), glm::vec3(0.9f, 0.5f, 0.1f), 3.5));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(0, -60, 100), glm::vec3(-0.53633f, 0.551106, 0.043226f), glm::vec3(0.8f, 0.2f, 0.2f), 4.5));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(20, 80, -70), glm::vec3(0.33633f, 0.651106, 0.063226f), glm::vec3(0.5f, 0.7f, 0.9f), 3.8));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-60, -20, 30), glm::vec3(-0.23633f, 0.751106, 0.083226f), glm::vec3(0.7f, 0.2f, 0.7f), 4.2));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(70, -50, -80), glm::vec3(-0.03633f, 0.851106, 0.103226f), glm::vec3(0.1f, 0.3f, 0.9f), 3.9));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(10, 30, 60), glm::vec3(0.13633f, -0.951106, -0.123226f), glm::vec3(0.6f, 0.9f, 0.4f), 4.3));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-40, -80, -50), glm::vec3(0.33633f, -0.851106, -0.143226f), glm::vec3(0.7f, 0.5f, 0.2f), 3.7));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(90, 70, 20), glm::vec3(0.53633f, -0.751106, -0.163226f), glm::vec3(0.4f, 0.1f, 0.9f), 4.1));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-30, 10, -40), glm::vec3(0.73633f, -0.651106, -0.183226f), glm::vec3(0.8f, 0.4f, 0.1f), 4.4));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(150, -100, 80), glm::vec3(0.33633f, -0.951106, -0.143226f), glm::vec3(0.2f, 0.8f, 0.5f), 3.9));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-120, 50, -60), glm::vec3(0.73633f, 0.551106, 0.103226f), glm::vec3(0.9f, 0.2f, 0.7f), 3.6));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(0, 120, -150), glm::vec3(-0.23633f, -0.751106, 0.083226f), glm::vec3(0.5f, 0.6f, 0.9f), 3.4));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-180, -50, 120), glm::vec3(0.13633f, 0.351106, -0.003226f), glm::vec3(0.7f, 0.9f, 0.2f), 4.2));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(60, -150, 180), glm::vec3(-0.93633f, -0.451106, -0.023226f), glm::vec3(0.3f, 0.7f, 0.8f), 3.8));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(100, 80, -120), glm::vec3(0.53633f, -0.651106, 0.163226f), glm::vec3(0.8f, 0.1f, 0.4f), 4.5));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-50, -180, 150), glm::vec3(-0.33633f, 0.951106, -0.083226f), glm::vec3(0.4f, 0.8f, 0.6f), 3.5));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(200, 150, -100), glm::vec3(0.03633f, 0.151106, 0.103226f), glm::vec3(0.6f, 0.2f, 0.9f), 3.9));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-150, -100, -50), glm::vec3(0.83633f, -0.251106, -0.123226f), glm::vec3(0.7f, 0.5f, 0.8f), 4.1));*/
createGalaxy(glm::vec3(0.f));
createGalaxy(glm::vec3(0.f, 50.f, 200.f));
}
void createGalaxy(glm::vec3 galaxyPosition) {
float planetsSizes[] = { 1.f, 1.5f, 0.8f, 1.2f, 0.2f };
createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), 3, planetsSizes, 5, 15.f, 0.2f);
float planetsSizes2[] = { 0.6f, 1.1f, 0.9f };
createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), 2, planetsSizes2, 3, 15.f, 0.2f);
float planetsSizes3[] = { 0.7f, 1.5f, 1.2f, 1.f };
createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), 4, planetsSizes3, 4, 20.f, 0.2f);
float planetSizes4[] = { 1.f, 0.5f };
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), 5, planetsSizes3, 2, 25.f, 0.2f);
}
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
GameUtils* gu = GameUtils::getInstance();
sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale);
gu->getSuns()->push_back(sun);
for (int i = 0; i < numberOfPlanets; i++) {
float distanceFromSum = (i + 1) * planetsDistance;
Planet* planet = new Planet(sun, distanceFromSum, i * 0.1f + planetSpeedCoef, planetSizes[i], models::sphereContext);
planets.push_back(planet);
}
}
void createEnemies() {
enemies.push_back(new Enemy(100, glm::mat4(1.0f), 20, 5.0f));
enemies.push_back(new Enemy(100, glm::translate(glm::mat4(1.0f) , glm::vec3(1.f,1.f,1.f)), 15, 5.0f));
enemies.push_back(new Enemy(100, glm::translate(glm::mat4(1.0f), glm::vec3(-1.f, 2.f, -0.9f)), 25, 5.0f));
}
void init(GLFWwindow* window)
{
GameUtils* gameUtils = GameUtils::getInstance();
spriteRenderer = new Core::SpriteRenderer();
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glEnable(GL_DEPTH_TEST);
program = gameUtils->shaderLoader->CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
<<<<<<< HEAD
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
programCubemap = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag");
=======
programParticle = gameUtils->shaderLoader->CreateProgram("shaders/particle.vert", "shaders/particle.frag");
>>>>>>> 2162820 (fire from ship)
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
loadModelToContext("./models/sphere.obj", models::sphereContext);
loadModelToContext("./models/cube.obj", models::cubeContext);
/*std::vector<std::string> cubeFaces = {
"space_rt.png",
"space_lf.png",
"space_up.png",
"space_dn.png",
"space_bk.png",
"space_ft.png"
};*/
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
texture::spriteTexture = Core::LoadTexture("textures/blinky1.png");
std::vector<std::string> cubeFaces = {
"bkg2_right1.png",
@ -196,28 +249,20 @@ void init(GLFWwindow* window)
texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
=======
program = gameUtils->shaderLoader->CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
//loadModelToContext("./models/sphere.obj", sphereContext);
//loadModelToContext("./models/spaceship.obj", spaceship.context);
Core::loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
Core::loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
Core::loadModelToContext("./models/sphere.obj", models::sphereContext);
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
>>>>>>> 62afe67 (add shooting)
spaceship->createParticles();
createSuns();
createEnemies();
}
void shutdown(GLFWwindow* window)
{
GameUtils::getInstance()->shaderLoader->DeleteProgram(program);
delete spriteRenderer;
// Dealokacja pamięci po obiektach Enemy
for (const auto& enemy : enemies) {
delete enemy;
}
}
//obsluga wejscia

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB