asteroids #18

Merged
s473616 merged 1 commits from satellites into master 2024-02-07 23:14:36 +01:00
6 changed files with 1502 additions and 7 deletions

View File

@ -16,6 +16,8 @@ private:
glm::mat4 positionMatrix;
GLuint textureID;
GLuint normalMapID;
float startEulerYRotation = 0.f;
float startYMovement = 0.f;
public:
Planet(GameObject* center, float distanceFromCenter, float rotationSpeed, float scale, Core::RenderContext sphereContext, GLuint textureID, GLuint normalMapID) {
@ -39,8 +41,16 @@ public:
}
float rotationAngle = glm::radians(time * rotationSpeed);
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed) * glm::translate(glm::vec3(distanceFromCenter, 0, 0));
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed + startEulerYRotation) * glm::translate(glm::vec3(distanceFromCenter, startYMovement, 0));
glm::mat4 modelMatrix = positionMatrix * glm::scale(glm::vec3(scale));
Core::drawObjectPBRTexture(sphereContext, modelMatrix, textureID, normalMapID, 0.7, 0.0, program);
}
void setStarteulerYRotation(float radians) {
startEulerYRotation = radians;
}
void setStartYMovement(float value) {
startYMovement = value;
}
};

View File

@ -229,17 +229,17 @@ public:
if (turbo == 0.0f) {
shiftState = GLFW_RELEASE;
moveSpeed = 0.05f * deltaTime * 60;
setPerticlesParameters(100.f, 0.0001f);
setPerticlesParameters(100.f, 0.000001f);
}
else {
moveSpeed *= 2;
setPerticlesParameters(200.f, 0.00005f);
setPerticlesParameters(200.f, 0.0000005f);
}
}
else {
setPerticlesParameters(100.f, 0.0001f);
setPerticlesParameters(100.f, 0.000001f);
turbo = glm::min(turboMAX, turbo + 0.001f * deltaTime * 60);
}
}
@ -274,7 +274,7 @@ public:
cameraPosHUDBar = spaceshipPos - 1.f * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
cameraDir = spaceshipDir;
glm::vec3 perpendicularVector = 0.04f * glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.0f, 1.0f, 0.0f)));
glm::vec3 perpendicularVector = 0.08f * glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.0f, 1.0f, 0.0f)));
if (leftParticle != nullptr && rightParticle != nullptr) {
leftParticle->sourcePosition = spaceshipPos + perpendicularVector - (0.25f * spaceshipDir);
rightParticle->sourcePosition = spaceshipPos - perpendicularVector - (0.25f * spaceshipDir);

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,10 @@
#include <cmath>
#include <list>
#include <vector>
#include <random>
#include "Shader_Loader.h"
#include "Render_Utils.h"
#include "texture.h"
#include "Box.cpp"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
@ -43,6 +42,7 @@ namespace models {
Core::RenderContext spaceshipContext;
Core::RenderContext sphereContext;
Core::RenderContext cubeContext;
Core::RenderContext asteroid;
}
namespace texture {
GLuint cubemapTexture;
@ -50,6 +50,8 @@ namespace texture {
GLuint spaceshipNormal;
GLuint spriteTexture;
GLuint earthTexture;
GLuint asteroidTexture;
GLuint asteroidNormal;
}
struct TextureTuple {
@ -281,6 +283,32 @@ void createSuns() {
createGalaxy(glm::vec3(0.f, 50.f, 200.f));
}
float generateRandomFloat(float minValue, float maxValue) {
return minValue + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (maxValue - minValue)));
}
void createAsteroids() {
GameUtils* gu = GameUtils::getInstance();
GameObject* center = gu->getSuns()->front();
float minDistanceFromCenter = 24.f;
float maxDistanceFromCenter = 26.f;
float rotationSpeed = 0.05f;
float scale = 0.002f;
int numAsteroids = 160;
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];
@ -294,6 +322,7 @@ void createGalaxy(glm::vec3 galaxyPosition) {
float planetSizes4[] = { 1.f, 0.5f };
GLuint sunTexId4 = sunTexturesIds[3];
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), sunTexId4, 5, planetsSizes3, 2, 25.f, 0.2f);
createAsteroids();
}
void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
@ -378,6 +407,7 @@ void init(GLFWwindow* window)
loadModelToContext("./models/sphere.obj", models::sphereContext);
loadModelToContext("./models/cube.obj", models::cubeContext);
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
Core::loadModelToContext("./models/Asteroid.obj", models::asteroid);
texture::spriteTexture = Core::LoadTexture("textures/blinky1.png");
@ -395,6 +425,8 @@ void init(GLFWwindow* window)
texture::spaceshipTexture = Core::LoadTexture("./textures/spaceship/Material.001_Base_color.jpg");
texture::spaceshipNormal = Core::LoadTexture("./textures/spaceship/Material.001_Normal_DirectX.jpg");
texture::earthTexture = Core::LoadTexture("./textures/planets/8k_earth_daymap.jpg");
texture::asteroidTexture = Core::LoadTexture("./textures/asteroids/asteroidtx.jpg");
texture::asteroidNormal = Core::LoadTexture("./textures/asteroids/asteroidnn.png");
spaceship->createParticles();
createSuns();

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 KiB