changed percipation to temperature, plant calculates probability of spawning on new planet
This commit is contained in:
parent
3f409f9c8e
commit
00471a1b93
@ -1,31 +1,8 @@
|
||||
#include "Distribution.h"
|
||||
#include "glm.hpp"
|
||||
#include <string>
|
||||
#include "Render_Utils.h"
|
||||
#include <math.h>
|
||||
namespace Plant
|
||||
{
|
||||
class Plant {
|
||||
public:
|
||||
float humMean; float humSD; float tempMean; float tempSD; std::string name; std::string fileName; glm::mat4 modelMatrix;
|
||||
Plant(float humMean, float humSD, float tempMean, float tempSD, std::string name, std::string fileName) {
|
||||
this->humMean = humMean;
|
||||
this->humSD = humSD;
|
||||
this->tempMean = tempMean;
|
||||
this->tempSD = tempSD;
|
||||
this->name = name;
|
||||
this->fileName = fileName;
|
||||
//this->modelContext = Core::RenderContext{};
|
||||
this->modelMatrix = glm::mat4();
|
||||
}
|
||||
|
||||
float calcProbability(float xValue, float mean, float sd)
|
||||
{
|
||||
float temp = (xValue - mean) / sd * sqrt(2);
|
||||
return (1 + erf(temp)) / 2;
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -30,12 +30,71 @@ struct PlanetParams {
|
||||
// Добавьте другие параметры по мере необходимости
|
||||
|
||||
float humidity = 0.0f; // Начальное значение для влажности
|
||||
float precipitation = 0.0f; // Начальное значение для осадков
|
||||
float temperature = 0.0f; // Начальное значение для осадков
|
||||
|
||||
};
|
||||
|
||||
std::vector<PlanetParams> planets; // Список всех планет
|
||||
|
||||
void loadModelToContext2(std::string path, Core::RenderContext& context)
|
||||
{
|
||||
Assimp::Importer import;
|
||||
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_FindInvalidData);
|
||||
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
|
||||
{
|
||||
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
context.initFromAssimpMesh2(scene->mMeshes[0]);
|
||||
}
|
||||
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;
|
||||
Plant(float humMean, float humSD, float tempMean, float tempSD, std::string name, std::string fileName) {
|
||||
this->humMean = humMean;
|
||||
this->humSD = humSD;
|
||||
this->tempMean = tempMean;
|
||||
this->tempSD = tempSD;
|
||||
this->name = name;
|
||||
this->fileName = fileName;
|
||||
this->modelContext = Core::RenderContext();
|
||||
loadModelToContext2("./models/plants/polygon.obj", modelContext);
|
||||
this->modelMatrix = glm::mat4();
|
||||
}
|
||||
|
||||
float calcProbability(float xValue, float mean, float sd)
|
||||
{
|
||||
float temp = (xValue - mean) / sd * sqrt(2);
|
||||
return (1 + erf(temp)) / 2;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::vector<Plant::Plant> plants;
|
||||
std::vector<Plant::Plant> plant_specimens;
|
||||
|
||||
void 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];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace texture {
|
||||
GLuint earth;
|
||||
@ -117,12 +176,13 @@ void renderImGui() {
|
||||
ImGui::InputFloat3("Pozicja", &newPlanetParams.position[0]);
|
||||
ImGui::SliderFloat("Rozmiar", &newPlanetParams.size, 0.1f, 10.0f);
|
||||
ImGui::SliderFloat("Wilgotnosc", &newPlanetParams.humidity, 0.0f, 10.0f); // Слайдер для влажности
|
||||
ImGui::SliderFloat("Opady", &newPlanetParams.precipitation, 0.0f, 10.0f); // Слайдер для осадков
|
||||
ImGui::SliderFloat("Temperatura", &newPlanetParams.temperature, 0.0f, 10.0f); // Слайдер для осадков
|
||||
|
||||
if (ImGui::Button("Dodac")) {
|
||||
planets.push_back(newPlanetParams);
|
||||
}
|
||||
populatePlanet(newPlanetParams, plant_specimens);
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Render();
|
||||
@ -280,19 +340,7 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
|
||||
}
|
||||
//TODO :REMOVE THIS
|
||||
void loadModelToContext2(std::string path, Core::RenderContext& context)
|
||||
{
|
||||
Assimp::Importer import;
|
||||
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate| aiProcess_FindInvalidData);
|
||||
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
|
||||
{
|
||||
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
context.initFromAssimpMesh2(scene->mMeshes[0]);
|
||||
}
|
||||
|
||||
void loadModelToContext(std::string path, Core::RenderContext& context)
|
||||
{
|
||||
@ -323,9 +371,8 @@ void init(GLFWwindow* window)
|
||||
loadModelToContext2("./models/plants/polygon.obj", plantContext);
|
||||
|
||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
||||
|
||||
loadModelToContext("models/plant_2.ply", plant2Context);
|
||||
loadModelToContext("models/plant_4.ply", plant3Context);
|
||||
loadModelToContext2("models/plant_2.ply", plant2Context);
|
||||
loadModelToContext2("models/plant_4.ply", plant3Context);
|
||||
|
||||
texture::earth=Core::LoadTexture("textures/earth2.png");
|
||||
texture::clouds = Core::LoadTexture("textures/clouds.jpg");
|
||||
@ -346,6 +393,7 @@ void shutdown(GLFWwindow* window)
|
||||
void processInput(GLFWwindow* window)
|
||||
{
|
||||
float cameraSpeed = 0.1f;
|
||||
float angleSpeed = 0.001f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
@ -362,13 +410,18 @@ void processInput(GLFWwindow* window)
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
cameraPos += glm::normalize(glm::cross(cameraDir, glm::vec3(0.0f, 1.0f, 0.0f))) * cameraSpeed;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
||||
cameraDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(cameraDir, 0));
|
||||
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||
cameraDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(cameraDir, 0));
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
cameraPos += glm::vec3(0.0f, cameraSpeed, 0.0f);
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||
cameraPos -= glm::vec3(0.0f, cameraSpeed, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//// funkcja jest glowna petla
|
||||
//void renderLoop(GLFWwindow* window) {
|
||||
|
Loading…
Reference in New Issue
Block a user