.
This commit is contained in:
parent
3f1644dbdb
commit
10ad09a79a
@ -156,6 +156,7 @@ struct PlanetParams {
|
||||
float humidity = 0.0f; // Начальное значение для влажности
|
||||
float temperature = 0.0f; // Начальное значение для осадков
|
||||
std::vector < std::tuple<int, glm::vec3 >> Plant_info; // ID , position
|
||||
std::vector <int> Plant_type_count;
|
||||
};
|
||||
|
||||
std::vector<PlanetParams> planets; // Список всех планет
|
||||
@ -170,14 +171,17 @@ bool sortFunction(std::tuple<int, float> objA, std::tuple<int, float> objB)
|
||||
PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plants)
|
||||
{
|
||||
float probability=0.5f;
|
||||
int HOW_MANY_PLANTS = 10000;
|
||||
int HOW_MANY_PLANTS = 1000;
|
||||
int PRECISION = 10000;
|
||||
float NOTHING_SPAWNS_CUTOFF = 0.2;
|
||||
int sum = 0;
|
||||
int chosen_number = 0;
|
||||
std::vector<std::tuple<int, int>> probabilities;
|
||||
int plant_count = 0;
|
||||
|
||||
for (int i = 0; i < plant_specimens.size(); i++)
|
||||
{
|
||||
planet.Plant_type_count.push_back(0);
|
||||
}
|
||||
sum = NOTHING_SPAWNS_CUTOFF * PRECISION;
|
||||
int j = 0;
|
||||
for (auto& plant : plants) {
|
||||
@ -195,6 +199,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
|
||||
}
|
||||
|
||||
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))) ;
|
||||
@ -202,7 +207,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
|
||||
int winnerId = -1;
|
||||
for (auto& probability : probabilities)
|
||||
{
|
||||
if (chosen_number > std::get<1>(probability))
|
||||
if (chosen_number < std::get<1>(probability))
|
||||
{
|
||||
winnerId = std::get<0>(probability);
|
||||
break;
|
||||
@ -213,13 +218,19 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
|
||||
{
|
||||
Plant::Plant plant = plants[winnerId];
|
||||
plant_count += 1;
|
||||
planet.Plant_type_count[winnerId] += 1;
|
||||
plant.pos = glm::vec3((2.0 * (rand() / (RAND_MAX + 1.0))-1), (2.0 * (rand() / (RAND_MAX + 1.0))-1), (2.0 * (rand() / (RAND_MAX + 1.0)))-1);
|
||||
planet.Plant_info.push_back(std::make_tuple(winnerId,plant.pos));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
std::cout <<"plant_count:" << plant_count << std::endl;
|
||||
|
||||
for (int i = 0; i < planet.Plant_type_count.size(); i++)
|
||||
{
|
||||
std::cout << " " <<planet.Plant_type_count[i] ;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return planet;
|
||||
|
||||
|
||||
@ -363,7 +374,7 @@ void renderImGui() {
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::Begin("Dodawanie nowej planety");
|
||||
ImGui::Begin("Dodawanie nowej planety");
|
||||
|
||||
static PlanetParams newPlanetParams;
|
||||
ImGui::InputFloat3("Pozycja", &newPlanetParams.position[0]);
|
||||
@ -374,6 +385,8 @@ void renderImGui() {
|
||||
if (ImGui::Button("Dodac")) {
|
||||
newPlanetParams =populatePlanet(newPlanetParams, plant_specimens);
|
||||
planets.push_back(newPlanetParams);
|
||||
newPlanetParams.Plant_info.clear();
|
||||
newPlanetParams.Plant_type_count.clear();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user