Code-Cleanup: All samples now use the camera class and it's matrices

Cleaned up base class
This commit is contained in:
Sascha Willems 2020-04-22 20:58:24 +02:00
parent 27d5abc038
commit ab38f8b150
42 changed files with 234 additions and 396 deletions

View file

@ -62,7 +62,7 @@ public:
struct {
glm::mat4 projection;
glm::mat4 model;
glm::mat4 modelView;
glm::vec4 viewPos;
float lodBias = 0.0f;
} uboVS;
@ -77,9 +77,11 @@ public:
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
{
zoom = -2.5f;
rotation = { 0.0f, 15.0f, 0.0f };
title = "Texture loading";
camera.type = Camera::CameraType::lookat;
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
camera.setRotation(glm::vec3(0.0f, 15.0f, 0.0f));
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
settings.overlay = true;
}
@ -772,26 +774,17 @@ public:
&uniformBufferVS,
sizeof(uboVS),
&uboVS));
VK_CHECK_RESULT(uniformBufferVS.map());
updateUniformBuffers();
}
void updateUniformBuffers()
{
// Vertex shader
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
uboVS.model = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
uboVS.viewPos = glm::vec4(0.0f, 0.0f, -zoom, 0.0f);
VK_CHECK_RESULT(uniformBufferVS.map());
uboVS.projection = camera.matrices.perspective;
uboVS.modelView = camera.matrices.view;
uboVS.viewPos = camera.viewPos;
memcpy(uniformBufferVS.mapped, &uboVS, sizeof(uboVS));
uniformBufferVS.unmap();
}
void prepare()