different aproach to rotating but not working :(

This commit is contained in:
Dominik Piasecki 2024-01-29 00:53:42 +01:00
parent d06bc6b54a
commit f02f02acf7

View File

@ -139,7 +139,6 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix); glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0); glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0);
Core::DrawContext(context); Core::DrawContext(context);
glUseProgram(0); glUseProgram(0);
@ -150,15 +149,30 @@ void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMat
//float diameter = ?; //float diameter = ?;
float diameter = 10; float diameter = 10;
//objectMatrix = objectMatrix * glm::translate(placePoint * 0.1f);
glm::vec3 base = glm::vec3(0.f, 0.f, 1.f);
glm::vec3 axis;
float angle;
//odpowiednio obrócić
axis = glm::cross( placePoint,base);
angle = dot(base, placePoint);
angle = acos(angle);
glm::mat4 cobjectMatrix = objectMatrix;
// wysunąć w dobrą stronę
cobjectMatrix = cobjectMatrix * glm::translate(base * diameter)* glm::rotate(cobjectMatrix, angle, axis);
//objectMatrix = objectMatrix * glm::lookAt(
// placePoint,
// glm::vec3(0, 0, 0),
// glm::vec3(0.0f, 0.0f, 1.0f));
objectMatrix = objectMatrix*glm::translate(placePoint * diameter) * glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f),
placePoint,
glm::vec3(0.0f, 1.0f, 0.0f));
objectMatrix = objectMatrix;
//* objectMatrix; //* objectMatrix;
//*glm::translate(placePoint) //*glm::translate(placePoint)
//TEMPORARY DRAW FUNCTION //TEMPORARY DRAW FUNCTION
drawObjectBiomes(objectContext, objectMatrix , programBiomes); drawObjectBiomes(objectContext, cobjectMatrix , programBiomes);
@ -175,7 +189,7 @@ void renderScene(GLFWwindow* window)
drawObjectBiomes(sphereContext, glm::mat4(), programBiomes); drawObjectBiomes(sphereContext, glm::mat4(), programBiomes);
for (int i = 0; i < 5; i++) { 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, 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, -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);