sorting works

This commit is contained in:
dompia5 2024-02-08 02:52:23 +01:00
parent 41ac514aa1
commit 966f3fdc39
1 changed files with 27 additions and 8 deletions

View File

@ -174,10 +174,16 @@ bool sortFunction(std::tuple<int, float> objA, std::tuple<int, float> objB)
float valB = std::get<1>(objB);
return (valA<valB);
}
bool sortFunctionPlantInfo(std::tuple<int, glm::vec3> objA, std::tuple<int, glm::vec3> objB)
{
int valA = std::get<0>(objA);
int valB = std::get<0>(objB);
return (valA < valB);
}
PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plants)
{
float probability=0.5f;
int HOW_MANY_PLANTS = 1000;
int HOW_MANY_PLANTS = 10000;
int PRECISION = 10000;
float NOTHING_SPAWNS_CUTOFF = 0.2;
int sum = 0;
@ -239,6 +245,8 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
std::cout << " " <<planet.Plant_type_count[i] ;
}
std::cout << std::endl;
std::sort(planet.Plant_info.begin(), planet.Plant_info.end(), sortFunctionPlantInfo);
return planet;
@ -651,15 +659,26 @@ void renderScene(GLFWwindow* window)
int plant_type_count = plants.size();
int types_count = 1;
std::vector<glm::vec3> current_type_plant_positions;
for (int i = 0; i < planet.Plant_type_count.size(); i++)
{
if (planet.Plant_type_count[i] > 0)
{
for (int j = 0; j < planet.Plant_type_count[i]; j++)
{
//current_type_plant_positions.push_back(0);
}
placeObjectOnPlanet(plant_specimens[0].modelContext, glm::mat4(), 0.2, current_type_plant_positions, planet, plant_type_count, plant_specimens[0].material);
}
}
for (const auto& plant : plants)
{
current_type_plant_positions.push_back(std::get<1>(plant));
}
for (int i = 0; i < types_count; i++)
{
for (const auto& plant : plants)
{
current_type_plant_positions.push_back(std::get<1>(plant));
}
//placeObjectOnPlanet(plant_specimens[std::get<0>(plant)].modelContext, glm::mat4(), 0.2, std::get<1>(plant), planet, plant_type_count);
placeObjectOnPlanet(plant_specimens[0].modelContext, glm::mat4(), 0.2, current_type_plant_positions, planet, plant_type_count, plant_specimens[0].material);
}
//for (const auto& plant : plants)
@ -740,7 +759,7 @@ void init(GLFWwindow* window)
loadMTLAndGetTextureID("./models/plant_2_1_small.mtl", plant2_1Material);
loadMTLAndGetTextureID("./models/plant_2_1_small.mtl", plant2_1Material);
plant_specimens.push_back(Plant::Plant(50, 3, 50, 3, "plant1_s", "./models/plant_1_1.obj", plant3Material));
plant_specimens.push_back(Plant::Plant(7, 3, 7, 3, "plant1_s", "./models/plant_1_1.obj", plant3Material));
plant_specimens.push_back(Plant::Plant(5, 3, 5, 3, "plant1_m", "./models/plant_2_1.obj", plant2_1Material));
//plant_specimens.push_back(Plant::Plant(1, 0.90, 1, 1, "testPlantCCCCCCCCCCC", "./models/plant_4.ply"));