plants are placed on planet but only on positive coords
This commit is contained in:
parent
b364a755fc
commit
97e8b8a8df
@ -11,6 +11,6 @@ Pos=4,3
|
||||
Size=218,129
|
||||
|
||||
[Window][Dodawanie nowej planety]
|
||||
Pos=154,43
|
||||
Pos=155,40
|
||||
Size=282,170
|
||||
|
||||
|
@ -86,19 +86,7 @@ void loadMTLAndGetTextureID(const std::string& filePath, Material& material) {
|
||||
}
|
||||
|
||||
|
||||
// Глобальные переменные для хранения параметров новой планеты
|
||||
struct PlanetParams {
|
||||
glm::vec3 position = glm::vec3(0.0f);
|
||||
float size = 1.0f;
|
||||
GLuint texture;
|
||||
// Добавьте другие параметры по мере необходимости
|
||||
|
||||
float humidity = 0.0f; // Начальное значение для влажности
|
||||
float temperature = 0.0f; // Начальное значение для осадков
|
||||
std::vector<Plant::Plant> plants;
|
||||
};
|
||||
|
||||
std::vector<PlanetParams> planets; // Список всех планет
|
||||
|
||||
void loadModelToContext2(std::string path, Core::RenderContext& context)
|
||||
{
|
||||
@ -119,7 +107,7 @@ namespace Plant
|
||||
class Plant {
|
||||
|
||||
public:
|
||||
float humMean; float humSD; float tempMean; float tempSD; std::string name; std::string fileName; glm::mat4 modelMatrix; Core::RenderContext modelContext; glm::vec3 pos;
|
||||
float humMean; float humSD; float tempMean; float tempSD; std::string name; std::string fileName; Core::RenderContext modelContext; glm::vec3 pos;
|
||||
Plant(float humMean, float humSD, float tempMean, float tempSD, std::string name, std::string fileName) {
|
||||
this->humMean = humMean;
|
||||
this->humSD = humSD;
|
||||
@ -129,8 +117,9 @@ namespace Plant
|
||||
this->fileName = fileName;
|
||||
this->modelContext = Core::RenderContext();
|
||||
loadModelToContext2("./models/plants/polygon.obj", modelContext);
|
||||
this->modelMatrix = glm::mat4();
|
||||
this->pos = glm::vec3((rand() % 100) / 100, (rand() % 100) / 100, (rand() % 100) / 100);
|
||||
|
||||
this->pos = glm::vec3(1,0,0);
|
||||
//this->pos = glm::vec3((rand() % 100) / 100, (rand() % 100) / 100, (rand() % 100) / 100);
|
||||
}
|
||||
|
||||
float calcProbability(float xValue, float mean, float sd)
|
||||
@ -143,19 +132,82 @@ namespace Plant
|
||||
}
|
||||
|
||||
std::vector<Plant::Plant> plant_specimens;
|
||||
// Глобальные переменные для хранения параметров новой планеты
|
||||
struct PlanetParams {
|
||||
glm::vec3 position = glm::vec3(0.0f);
|
||||
float size = 1.0f;
|
||||
GLuint texture;
|
||||
// Добавьте другие параметры по мере необходимости
|
||||
|
||||
void populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plants)
|
||||
float humidity = 0.0f; // Начальное значение для влажности
|
||||
float temperature = 0.0f; // Начальное значение для осадков
|
||||
std::vector<Plant::Plant> plants = std::vector<Plant::Plant>();
|
||||
};
|
||||
|
||||
std::vector<PlanetParams> planets; // Список всех планет
|
||||
|
||||
|
||||
bool sortFunction(std::tuple<int, float> objA, std::tuple<int, float> objB)
|
||||
{
|
||||
float valA=std::get<1>(objA);
|
||||
float valB = std::get<1>(objB);
|
||||
return (valA<valB);
|
||||
}
|
||||
PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plants)
|
||||
{
|
||||
Plant::Plant plant=Plant::Plant(5.f,0.1f, 2.f, 0.5f,"something","somethingFile");
|
||||
float probability=0.5f;
|
||||
for (int i = 0; i < plant_specimens.size(); i++)
|
||||
//Plant::Plant& plant = plant_specimens[i];
|
||||
int HOW_MANY_PLANTS = 100;
|
||||
int PRECISION = 10000;
|
||||
float NOTHING_SPAWNS_CUTOFF = 0.0;
|
||||
int sum = 0;
|
||||
int chosen_number = 0;
|
||||
std::vector<std::tuple<int, int>> probabilities;
|
||||
|
||||
|
||||
sum = NOTHING_SPAWNS_CUTOFF * PRECISION;
|
||||
int j = 0;
|
||||
for (auto& plant : plants) {
|
||||
|
||||
//TODO: add humidity calculations
|
||||
probability = plant.calcProbability(planet.humidity, plant.humMean, plant.humSD);
|
||||
probability = int(probability * PRECISION);
|
||||
std::tuple<int,int>probIdPair = std::make_tuple(j ,probability);
|
||||
probabilities.push_back(probIdPair);
|
||||
j++;
|
||||
}
|
||||
for (auto& probability : probabilities) {
|
||||
sum += std::get<1>(probability);
|
||||
}
|
||||
|
||||
std::sort(probabilities.begin(), probabilities.end(), sortFunction);
|
||||
for (int i = 0; i < HOW_MANY_PLANTS; i++) {
|
||||
|
||||
chosen_number = int(sum * (rand() / (RAND_MAX + 1.0))) ;
|
||||
int counter=0;
|
||||
int winnerId = -1;
|
||||
for (auto& probability : probabilities)
|
||||
{
|
||||
if (counter + chosen_number < std::get<1>(probability))
|
||||
{
|
||||
winnerId = std::get<0>(probability);
|
||||
break;
|
||||
}
|
||||
else counter += std::get<1>(probability);
|
||||
}
|
||||
if (winnerId > -1)
|
||||
{
|
||||
Plant::Plant plant = plants[winnerId];
|
||||
std::cout << "got a winner " << plant.name << std::endl;
|
||||
plant.pos = glm::vec3((1.0 * (rand() / (RAND_MAX + 1.0))), (1.0 * (rand() / (RAND_MAX + 1.0))), (1.0 * (rand() / (RAND_MAX + 1.0))));
|
||||
planet.plants.push_back(plant);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return planet;
|
||||
|
||||
|
||||
probability = plant.calcProbability(planet.humidity, plant.humMean, plant.humSD);
|
||||
std::cout << "Humidity: "<< probability << std::endl;
|
||||
probability=plant.calcProbability(planet.temperature, plant.tempMean, plant.tempSD);
|
||||
std::cout << "Temperature: " << probability << std::endl;
|
||||
plants.push_back(plant);
|
||||
}
|
||||
|
||||
|
||||
@ -243,9 +295,8 @@ void renderImGui() {
|
||||
ImGui::SliderFloat("Temperatura", &newPlanetParams.temperature, 0.0f, 10.0f); // Слайдер для осадков
|
||||
|
||||
if (ImGui::Button("Dodac")) {
|
||||
newPlanetParams =populatePlanet(newPlanetParams, plant_specimens);
|
||||
planets.push_back(newPlanetParams);
|
||||
populatePlanet(newPlanetParams, plant_specimens);
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
@ -363,7 +414,7 @@ void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMat
|
||||
angle = dot(base,placePoint);
|
||||
angle = acos(angle);
|
||||
cobjectMatrix = cobjectMatrix * glm::rotate(cobjectMatrix, angle, axis) * glm::translate(base * diameter);
|
||||
cobjectMatrix = cobjectMatrix * glm::translate(planetParams.position*1/scale);
|
||||
cobjectMatrix = cobjectMatrix * glm::translate(planetParams.position*(1/scale));
|
||||
drawObjectBiomes(objectContext, cobjectMatrix, programBiomes);
|
||||
|
||||
|
||||
@ -416,8 +467,10 @@ void renderScene(GLFWwindow* window)
|
||||
for (const auto& planet : planets) {
|
||||
glm::mat4 modelMatrix = glm::translate(planet.position) * glm::scale(glm::vec3(planet.size));
|
||||
drawObjectTexture(sphereContext, modelMatrix, planet.texture, program);
|
||||
for (const auto& plant : planet.plants)
|
||||
placeObjectOnPlanet(plant2Context, glm::mat4(),0.2, plant.pos, planet);
|
||||
std::vector<Plant::Plant>plants = planet.plants;
|
||||
for (const auto& plant : plants)
|
||||
//TODO: REMOVE PLACEHOLDER
|
||||
placeObjectOnPlanet(plant2Context, glm::mat4(), 0.2, plant.pos, planet);
|
||||
}
|
||||
|
||||
|
||||
@ -484,10 +537,16 @@ void init(GLFWwindow* window)
|
||||
texture::moon = Core::LoadTexture("textures/moon_normals.png");
|
||||
texture::grid = Core::LoadTexture("textures/grid.png");
|
||||
texture::planet1 = Core::LoadTexture("textures/tek_1.jpg");
|
||||
|
||||
loadMTLAndGetTextureID("./models/plant_1_1.mtl", plant3Material);
|
||||
|
||||
|
||||
plant_specimens.push_back(Plant::Plant(1, 0.99, 1, 1, "testPlant2", "./models/plant_4.ply"));
|
||||
plant_specimens.push_back(Plant::Plant(1, 0.95, 1, 1, "testPlantXXXXX", "./models/plant_4.ply"));
|
||||
plant_specimens.push_back(Plant::Plant(1, 0.93, 1, 1, "testPlantAAAAAAAAA", "./models/plant_4.ply"));
|
||||
plant_specimens.push_back(Plant::Plant(1, 0.90, 1, 1, "testPlantCCCCCCCCCCC", "./models/plant_4.ply"));
|
||||
plant_specimens.push_back(Plant::Plant(1, 0.5, 1, 1, "testPlantBBBBBBBBB", "./models/plant_4.ply"));
|
||||
plant_specimens.push_back(Plant::Plant(1, 1, 1, 1, "testPlantFFFFFFFFFFFF", "./models/plant_4.ply"));
|
||||
plant_specimens.push_back(Plant::Plant(1, 0.2, 1, 1, "testPlant!!!!!!!!!!!!!!!!", "./models/plant_4.ply"));
|
||||
plant_specimens.push_back(Plant::Plant(1, 0.1, 1, 1, "testPlant_MAYBE", "./models/plant_4.ply"));
|
||||
}
|
||||
|
||||
void shutdown(GLFWwindow* window)
|
||||
|
Loading…
Reference in New Issue
Block a user