Some fixing
This commit is contained in:
parent
06362ba989
commit
c8d8f9bd38
@ -11,6 +11,6 @@ Pos=4,3
|
||||
Size=218,129
|
||||
|
||||
[Window][Dodawanie nowej planety]
|
||||
Pos=7,7
|
||||
Pos=8,7
|
||||
Size=403,182
|
||||
|
||||
|
@ -34,6 +34,17 @@ struct PlanetParams {
|
||||
|
||||
};
|
||||
|
||||
struct Climate {
|
||||
float tempMin, tempMax;
|
||||
float precipMin, precipMax;
|
||||
GLuint textureID;
|
||||
};
|
||||
|
||||
|
||||
// Глобальный массив климатов
|
||||
std::vector<Climate> climates;
|
||||
|
||||
|
||||
std::vector<PlanetParams> planets; // Список всех планет
|
||||
|
||||
|
||||
@ -58,7 +69,7 @@ GLuint plantProgram;
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
GLuint programBiomes;
|
||||
|
||||
GLuint defaultTexture;
|
||||
|
||||
Core::RenderContext plantContext;
|
||||
|
||||
@ -68,6 +79,10 @@ Core::RenderContext plant3Context;
|
||||
glm::vec3 cameraPos = glm::vec3(-4.f, 0, 0);
|
||||
glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
|
||||
|
||||
glm::vec3 sunPosition = glm::vec3(0.0f, 0.0f, 0.0f); // Позиция солнца
|
||||
glm::vec3 sunColor = glm::vec3(1.0f, 1.0f, 1.0f); // Цвет солнца
|
||||
|
||||
|
||||
|
||||
GLuint VAO,VBO;
|
||||
|
||||
@ -86,6 +101,19 @@ struct ModelContext {
|
||||
GLuint EBO;
|
||||
};
|
||||
|
||||
GLuint selectTextureForPlanet(float temperature, float precipitation) {
|
||||
|
||||
|
||||
for (const auto& climate : climates) {
|
||||
if (temperature >= climate.tempMin && temperature <= climate.tempMax &&
|
||||
precipitation >= climate.precipMin && precipitation <= climate.precipMax) {
|
||||
return climate.textureID;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultTexture; // Вернуть текстуру по умолчанию, если не найдено соответствий
|
||||
}
|
||||
|
||||
float aspectRatio = 1.f;
|
||||
bool DoTheImportThing(const std::string& pFile) {
|
||||
// Create an instance of the Importer class
|
||||
@ -133,6 +161,7 @@ void renderImGui() {
|
||||
ImGui::SliderFloat("Opady", &newPlanetParams.precipitation, 0.0f, 400.0f); // Слайдер для осадков
|
||||
|
||||
if (ImGui::Button("Dodac")) {
|
||||
newPlanetParams.texture = selectTextureForPlanet(newPlanetParams.temperature, newPlanetParams.precipitation);
|
||||
planets.push_back(newPlanetParams);
|
||||
}
|
||||
|
||||
@ -166,12 +195,15 @@ glm::mat4 createPerspectiveMatrix()
|
||||
void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, GLuint program) {
|
||||
GLuint prog = program;
|
||||
glUseProgram(prog);
|
||||
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(prog, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(prog, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniform3f(glGetUniformLocation(prog, "color"), color.x, color.y, color.z);
|
||||
glUniform3f(glGetUniformLocation(prog, "lightPos"), 0,0,0);
|
||||
//glUniform3f(glGetUniformLocation(prog, "lightPos"), 0,0,0);
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z);
|
||||
|
||||
|
||||
GLuint colorStartLocation = glGetUniformLocation(prog, "colorStart");
|
||||
GLuint colorEndLocation = glGetUniformLocation(prog, "colorEnd");
|
||||
@ -193,7 +225,9 @@ void drawObjectBiomes(Core::RenderContext& context, glm::mat4 modelMatrix, GLuin
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(prog, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(prog, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniform3f(glGetUniformLocation(prog, "lightPos"), 0, 0, 0);
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z);
|
||||
|
||||
Core::DrawContext(context);
|
||||
glUseProgram(0);
|
||||
|
||||
@ -206,19 +240,21 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0);
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z);
|
||||
Core::DrawContext(context);
|
||||
glUseProgram(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix,glm::vec3 placePoint, Core::RenderContext& planetContext, glm::mat4 planetMatrix) {
|
||||
//placePoint is described by normalized vector that points to a point on a sphere from inside of itself
|
||||
placePoint = glm::normalize(placePoint);
|
||||
|
||||
//float diameter = ?;
|
||||
float diameter = 10;
|
||||
float diameter = 25;
|
||||
//objectMatrix = objectMatrix * glm::translate(placePoint * 0.1f);
|
||||
glm::vec3 base = glm::vec3(0.f, 0.f, 1.f);
|
||||
glm::vec3 base = glm::vec3(0.f, 1.f, 0.f);
|
||||
glm::vec3 axis;
|
||||
float angle;
|
||||
//odpowiednio obrócić
|
||||
@ -228,7 +264,7 @@ void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMat
|
||||
angle = acos(angle);
|
||||
glm::mat4 cobjectMatrix = objectMatrix;
|
||||
// wysunąć w dobrą stronę
|
||||
cobjectMatrix = cobjectMatrix * glm::translate(base * diameter)* glm::rotate(cobjectMatrix, angle, axis);
|
||||
cobjectMatrix = cobjectMatrix * glm::rotate(cobjectMatrix, angle, axis) * glm::translate(base * diameter);
|
||||
|
||||
|
||||
//objectMatrix = objectMatrix * glm::lookAt(
|
||||
@ -241,10 +277,20 @@ void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMat
|
||||
//*glm::translate(placePoint)
|
||||
//TEMPORARY DRAW FUNCTION
|
||||
drawObjectBiomes(objectContext, cobjectMatrix , programBiomes);
|
||||
}
|
||||
|
||||
void renderSun() {
|
||||
glUseProgram(programSun);
|
||||
|
||||
// Установка uniform-параметров для солнца, например, позиции и цвета
|
||||
glUniform3f(glGetUniformLocation(programSun, "sunPosition"), sunPosition.x, sunPosition.y, sunPosition.z);
|
||||
glUniform3f(glGetUniformLocation(programSun, "sunColor"), sunColor.x, sunColor.y, sunColor.z);
|
||||
|
||||
|
||||
// Отрисовка объекта солнца (может быть простой сферой или кастомной моделью)
|
||||
// ...
|
||||
|
||||
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void renderScene(GLFWwindow* window)
|
||||
@ -254,9 +300,14 @@ void renderScene(GLFWwindow* window)
|
||||
glm::mat4 transformation;
|
||||
float time = glfwGetTime();
|
||||
|
||||
glUseProgram(program);
|
||||
glUniform3f(glGetUniformLocation(program, "sunPosition"), sunPosition.x, sunPosition.y, sunPosition.z);
|
||||
glUniform3f(glGetUniformLocation(program, "sunColor"), sunColor.x, sunColor.y, sunColor.z);
|
||||
|
||||
// Рендеринг объектов в сцене
|
||||
for (const auto& planet : planets) {
|
||||
glm::mat4 modelMatrix = glm::translate(planet.position) * glm::scale(glm::vec3(planet.size));
|
||||
drawObjectTexture(sphereContext, modelMatrix, planet.texture, program);
|
||||
drawObjectTexture(sphereContext, modelMatrix, planet.texture, programTex);
|
||||
}
|
||||
|
||||
drawObjectBiomes(sphereContext, glm::mat4(), programBiomes);
|
||||
@ -276,7 +327,9 @@ void renderScene(GLFWwindow* window)
|
||||
//drawObjectBiomes(plantContext, glm::eulerAngleY(glm::radians(90.f)) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes);
|
||||
//drawObjectBiomes(plantContext, glm::eulerAngleX(30.f) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes);
|
||||
|
||||
placeObjectOnPlanet(plant2Context, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(1.0, 0.0, 1.0)), sphereContext, planetMatrix);
|
||||
|
||||
renderSun();
|
||||
|
||||
glm::vec3 plantPosition = glm::vec3(1.f, 0.f, 3.5f) ;
|
||||
float scaleFactor = 0.1f;
|
||||
@ -321,17 +374,17 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
context.initFromAssimpMesh(scene->mMeshes[0]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void init(GLFWwindow* window)
|
||||
{
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glm::vec3 lightPosition = glm::vec3(0.0f, 10.0f, 0.0f);
|
||||
glm::vec3 lightColor = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||
float lightIntensity = 1.0f;
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
program = shaderLoader.CreateProgram("shaders/shader_5_1.vert", "shaders/shader_5_1.frag");
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_5_1_tex.vert", "shaders/shader_5_1_tex.frag");
|
||||
@ -352,8 +405,12 @@ void init(GLFWwindow* window)
|
||||
texture::grid = Core::LoadTexture("textures/grid.png");
|
||||
texture::planet1 = Core::LoadTexture("textures/tek_1.jpg");
|
||||
|
||||
|
||||
|
||||
defaultTexture = Core::LoadTexture("textures/1.png");
|
||||
if (defaultTexture == 0) {
|
||||
std::cout << "Failed to load default texture" << std::endl;
|
||||
}
|
||||
climates.push_back({ -10, 0, 0, 50, Core::LoadTexture("textures/1.png") });
|
||||
climates.push_back({ 0, 10, 50, 100, Core::LoadTexture("textures/2.png") });
|
||||
}
|
||||
|
||||
|
||||
@ -389,21 +446,6 @@ void processInput(GLFWwindow* window)
|
||||
cameraPos -= glm::vec3(0.0f, cameraSpeed, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
//// funkcja jest glowna petla
|
||||
//void renderLoop(GLFWwindow* window) {
|
||||
// while (!glfwWindowShouldClose(window))
|
||||
// {
|
||||
// processInput(window);
|
||||
//
|
||||
// renderScene(window);
|
||||
// glfwPollEvents();
|
||||
// }
|
||||
//}
|
||||
////}
|
||||
|
||||
|
||||
|
||||
void renderLoop(GLFWwindow* window) {
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
BIN
PlanetCreator/cw 6/textures/1.png
Normal file
BIN
PlanetCreator/cw 6/textures/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 MiB |
BIN
PlanetCreator/cw 6/textures/2.png
Normal file
BIN
PlanetCreator/cw 6/textures/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.9 MiB |
BIN
PlanetCreator/cw 6/textures/3.png
Normal file
BIN
PlanetCreator/cw 6/textures/3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.0 MiB |
Loading…
Reference in New Issue
Block a user