93 lines
2.1 KiB
C++
93 lines
2.1 KiB
C++
|
#include "Engine.h"
|
||
|
|
||
|
|
||
|
|
||
|
void Core::Engine::initRandomGenerator(std::default_random_engine gen, std::uniform_int_distribution<> distr) {
|
||
|
this->gen = gen;
|
||
|
this->distr = distr;
|
||
|
}
|
||
|
|
||
|
|
||
|
std::vector<glm::vec3> Core::Engine::genBubbleKeyPoints() {
|
||
|
float random1 = this->distr(this->gen);
|
||
|
float random2 = this->distr(this->gen);
|
||
|
std::vector<glm::vec3> bubbleKeyPoints({
|
||
|
glm::vec3(random1 , -this->skyboxVerticeParameter, random2),
|
||
|
glm::vec3(random1 , this->skyboxVerticeParameter, random2)
|
||
|
}
|
||
|
);
|
||
|
return bubbleKeyPoints;
|
||
|
};
|
||
|
|
||
|
void Core::Engine::generateBubbleArray() {
|
||
|
for (int i = 0; i < 300; i++) {
|
||
|
this->bubbleArray[i] = this->genBubbleKeyPoints();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Core::Engine::generateObjectArray() {
|
||
|
std::uniform_int_distribution<> distr(-64, 64);
|
||
|
for (int i = 0; i < 200; i++) {
|
||
|
int random1 = distr(this->gen);
|
||
|
int random2 = distr(this->gen);
|
||
|
float height = -this->skyboxVerticeParameter + this->terrain.heightTable[abs(random1)][abs(random2)] + 15;
|
||
|
this->objectArray[i] = glm::vec3(random1, height, random2) * glm::vec3(3, 1, 3);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Core::Engine::generateObjectSize() {
|
||
|
std::uniform_real_distribution<> distr(0.1f, 0.25f);
|
||
|
for (int i = 0; i < 200; i++) {
|
||
|
float random = distr(this->gen);
|
||
|
objectSize.push_back(random);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Core::Engine::generateObjectRotation() {
|
||
|
std::uniform_real_distribution<> distr(0.0f, 360.0f);
|
||
|
for (int i = 0; i < 200; i++) {
|
||
|
float random = distr(this->gen);
|
||
|
objectRotation.push_back(random);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Core::Engine::initBubbles() {
|
||
|
this->generateBubbleArray();
|
||
|
}
|
||
|
|
||
|
std::vector<glm::vec3> Core::Engine::parse(std::string filename) {
|
||
|
std::ifstream data(filename);
|
||
|
std::string line;
|
||
|
std::vector<glm::vec3> result;
|
||
|
|
||
|
while (std::getline(data, line))
|
||
|
{
|
||
|
std::stringstream lineStream(line);
|
||
|
std::string cell;
|
||
|
glm::vec3 row;
|
||
|
int i = 0;
|
||
|
while (std::getline(lineStream, cell, ','))
|
||
|
{
|
||
|
switch (i % 3) {
|
||
|
case 0:
|
||
|
row.x = std::stof(cell);
|
||
|
break;
|
||
|
case 1:
|
||
|
row.y = std::stof(cell);
|
||
|
break;
|
||
|
case 2:
|
||
|
row.z = std::stof(cell);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
i += 1;
|
||
|
|
||
|
}
|
||
|
result.push_back(row);
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
|