Compare commits

...

5 Commits

Author SHA1 Message Date
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
18 changed files with 531 additions and 68 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
################################################################################
# Ten plik .gitignore został utworzony automatycznie przez Microsoft(R) Visual Studio.
################################################################################
/grk/project/shaders

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

@ -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,7 @@
<ItemGroup>
<ClCompile Include="GameObject.cpp" />
<ClCompile Include="Planet.cpp" />
<ClCompile Include="SpriteRenderer.cpp" />
<ClCompile Include="src\Box.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\main.cpp" />
@ -26,10 +27,12 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Bullet.h" />
<ClInclude Include="Enemy.h" />
<ClInclude Include="GameObject.h" />
<ClInclude Include="GameUtils.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,6 +56,8 @@
<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,9 @@
<ClCompile Include="Planet.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpriteRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\objload.h">
@ -113,6 +116,12 @@
<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>
</ItemGroup>
<ItemGroup>
<None Include="shaders\shader_8_sun.vert">
@ -139,5 +148,13 @@
<None Include="shaders\shader_skybox.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="fireball.frag" />
<None Include="fireball.vert" />
<None Include="shaders\shader_sprite.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_sprite.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

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

@ -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,9 @@
#include "../Planet.h"
#include "../GameObject.h"
#include "../GameUtils.h"
#include "../SpriteRenderer.h"
#include "../Enemy.h"
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
@ -34,6 +37,7 @@ namespace models {
}
namespace texture {
GLuint cubemapTexture;
GLuint spriteTexture;
}
void createGalaxy(glm::vec3 galaxyPosition);
@ -44,13 +48,16 @@ GLuint depthMap;
GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
GLuint programSprite;
GLuint programCubemap;
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 +68,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 +116,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 +126,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);
}
}
//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);
}
@ -158,9 +186,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,6 +206,7 @@ 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");
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
@ -176,6 +214,8 @@ void init(GLFWwindow* window)
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",
"bkg2_left2.png",
@ -188,11 +228,18 @@ void init(GLFWwindow* window)
texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
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,9 @@
#include "../Planet.h"
#include "../GameObject.h"
#include "../GameUtils.h"
#include "../SpriteRenderer.h"
#include "../Enemy.h"
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
@ -34,21 +37,27 @@ 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;
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,7 +67,12 @@ float lastTime = -1.f;
float deltaTime = 0.f;
Spaceship* spaceship = Spaceship::getInstance();
<<<<<<< HEAD
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
=======
Core::SpriteRenderer* spriteRenderer;
>>>>>>> c0971c9 (Add enemy class)
void updateDeltaTime(float time) {
if (lastTime < 0) {
lastTime = time;
@ -105,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);
@ -116,6 +128,26 @@ void renderScene(GLFWwindow* window)
spaceship->color,
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);
}
}
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
glUseProgram(0);
glfwSwapBuffers(window);
@ -130,60 +162,63 @@ 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);
}
}
<<<<<<< HEAD
=======
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));
}
>>>>>>> c0971c9 (Add enemy class)
void init(GLFWwindow* window)
{
GameUtils* gameUtils = GameUtils::getInstance();
spriteRenderer = new Core::SpriteRenderer();
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glEnable(GL_DEPTH_TEST);
<<<<<<< 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");
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");
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.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);
/*std::vector<std::string> cubeFaces = {
"space_rt.png",
"space_lf.png",
"space_up.png",
"space_dn.png",
"space_bk.png",
"space_ft.png"
};*/
texture::spriteTexture = Core::LoadTexture("textures/blinky1.png");
std::vector<std::string> cubeFaces = {
"bkg2_right1.png",
@ -196,28 +231,19 @@ 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)
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