camera fix

This commit is contained in:
Damian 2022-01-15 16:39:40 +01:00
parent c235df208b
commit 4f5a9f2e7e

View File

@ -22,7 +22,7 @@ Core::RenderContext sharkModel;
Core::RenderContext sphereContext;
Camera camera(600, 600, glm::vec3(0.0f, 0.0f, 5.0f));
Camera camera(600, 600, glm::vec3(0.0f, 0.0f, 0.0f));
glm::mat4 cameraMatrix;
@ -63,7 +63,7 @@ void drawObjectColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::ve
glUniform3f(glGetUniformLocation(program, "lightPos"), lightDir.x, lightDir.y, lightDir.z);
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glm::mat4 transformation = cameraMatrix;
glm::mat4 transformation = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "modelViewProjectionMatrix"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
@ -100,10 +100,8 @@ void renderScene()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0.0f, -0.5f, 0.0f)) * glm::scale(glm::vec3(0.25f));
//glm::mat4 shipModelMatrix = glm::translate(camera.getPosition() + camera.getOrientation() * 0.5f) * glm::mat4_cast(glm::inverse(rotation)) * shipInitialTransformation;
//glm::mat4 shipModelMatrix = glm::translate(camera.getPosition()) * glm::mat4_cast(glm::inverse(rotation)) * shipInitialTransformation;
glm::mat4 shipModelMatrix = glm::inverse(cameraMatrix) * glm::mat4_cast(glm::inverse(rotation)) * shipInitialTransformation;
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0.0f, -0.4f, -2.0f)) * glm::rotate(glm::radians(10.0f), glm::vec3(1, 0, 0)) * glm::rotate(glm::radians(-180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
glm::mat4 shipModelMatrix = glm::inverse(camera.getRotationAngle()) * shipInitialTransformation;
drawObjectTexture(sharkModel, shipModelMatrix, sharkTexture);
@ -111,7 +109,7 @@ void renderScene()
drawObjectColor(sphereContext, glm::translate(coords), coords);
}
drawObjectTexture(sharkModel, glm::mat4() * glm::scale(glm::vec3(0.25f)), sharkTexture);
drawObjectTexture(sharkModel, shipInitialTransformation, sharkTexture);
glutSwapBuffers();
}