diff --git a/PlanetCreator/cw 6/imgui.ini b/PlanetCreator/cw 6/imgui.ini index 5850082..25b2b36 100644 --- a/PlanetCreator/cw 6/imgui.ini +++ b/PlanetCreator/cw 6/imgui.ini @@ -11,6 +11,6 @@ Pos=4,3 Size=218,129 [Window][Dodawanie nowej planety] -Pos=7,7 +Pos=154,43 Size=282,170 diff --git a/PlanetCreator/cw 6/src/ex_6_1.hpp b/PlanetCreator/cw 6/src/ex_6_1.hpp index b690a9f..fd2e80c 100644 --- a/PlanetCreator/cw 6/src/ex_6_1.hpp +++ b/PlanetCreator/cw 6/src/ex_6_1.hpp @@ -345,24 +345,30 @@ void drawObjectTexture_plant(Core::RenderContext& context, glm::mat4 modelMatrix glUseProgram(0); } -void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix,glm::vec3 placePoint, Core::RenderContext& planetContext, glm::mat4 planetMatrix) { +void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix,float scale,glm::vec3 placePoint, PlanetParams planetParams) { + float planetScale = planetParams.size; //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; + glm::mat4 cobjectMatrix = objectMatrix; + cobjectMatrix = glm::scale(cobjectMatrix, glm::vec3(scale)); + float diameter = 24.4 * planetScale; //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ć - - axis = glm::cross( placePoint,base); - angle = dot(base, placePoint); + axis = glm::cross(placePoint, base); + angle = dot(base,placePoint); angle = acos(angle); - glm::mat4 cobjectMatrix = objectMatrix; + cobjectMatrix = cobjectMatrix * glm::rotate(cobjectMatrix, angle, axis) * glm::translate(base * diameter); + drawObjectBiomes(objectContext, cobjectMatrix, programBiomes); + + //*glm::translate(planetParams.position) + // wysunąć w dobrą stronę - cobjectMatrix = cobjectMatrix * glm::translate(base * diameter)* glm::rotate(cobjectMatrix, angle, axis); + //objectMatrix = objectMatrix * glm::lookAt( @@ -374,13 +380,14 @@ void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMat //* objectMatrix; //*glm::translate(placePoint) //TEMPORARY DRAW FUNCTION - drawObjectBiomes(objectContext, cobjectMatrix , programBiomes); } Material plant3Material; +PlanetParams TestPlanet = PlanetParams(); + void renderScene(GLFWwindow* window) { glClearColor(0.0f, 0.3f, 0.3f, 1.0f); @@ -388,20 +395,16 @@ void renderScene(GLFWwindow* window) glm::mat4 transformation; float time = glfwGetTime(); - for (const auto& planet : planets) { - glm::mat4 modelMatrix = glm::translate(planet.position) * glm::scale(glm::vec3(planet.size)); - drawObjectTexture(sphereContext, modelMatrix, planet.texture, program); - } - drawObjectBiomes(sphereContext, glm::mat4(), programBiomes); - for (int i = 0; i < 5; i++) { - placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1*i, 0.f, 0.f)), sphereContext, planetMatrix); - placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, 1.f)), sphereContext, planetMatrix); - placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1 * i, 0.f, -1.f)), sphereContext, planetMatrix); - placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, -1.f)), sphereContext, planetMatrix); - placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1 * i, 0.f, 0.f)), sphereContext, planetMatrix); - placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, 0.f)), sphereContext, planetMatrix); - } + + + //for (int i = 0; i < 5; i++) { + // placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, 1.f)), sphereContext, planetMatrix); + // placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1 * i, 0.f, -1.f)), sphereContext, planetMatrix); + // placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, -1.f)), sphereContext, planetMatrix); + // placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1 * i, 0.f, 0.f)), sphereContext, planetMatrix); + // placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, 0.f)), sphereContext, planetMatrix); + //} //placeObjectOnPlanet(plantContext ,glm::scale(glm::mat4(),glm::vec3(0.2)), normalize(glm::vec3(1.f,0.f,1.f)), sphereContext, planetMatrix); //placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.f, 0.f, -1.f)), sphereContext, planetMatrix); @@ -409,8 +412,13 @@ void renderScene(GLFWwindow* window) //drawObjectBiomes(plantContext, glm::eulerAngleY(glm::radians(60.f)) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes); //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); + for (const auto& planet : planets) { + glm::mat4 modelMatrix = glm::translate(planet.position) * glm::scale(glm::vec3(planet.size)); + drawObjectTexture(sphereContext, modelMatrix, planet.texture, program); + placeObjectOnPlanet(plant2Context, glm::mat4(),0.2, normalize(glm::vec3(0.1, 0.f, 1.f)), planet); + } + - glm::vec3 plantPosition = glm::vec3(1.f, 0.f, 3.5f) ; float scaleFactor = 0.1f; @@ -454,6 +462,7 @@ void loadModelToContext(std::string path, Core::RenderContext& context) void init(GLFWwindow* window) { + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glEnable(GL_DEPTH_TEST); @@ -488,7 +497,7 @@ void shutdown(GLFWwindow* window) void processInput(GLFWwindow* window) { float cameraSpeed = 0.1f; - float angleSpeed = 0.001f; + float angleSpeed = 0.02f; if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true);