Code-Cleanup: All samples now use the camera class and it's matrices
Cleaned up base class
This commit is contained in:
parent
27d5abc038
commit
ab38f8b150
42 changed files with 234 additions and 396 deletions
|
|
@ -44,10 +44,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -16.0f;
|
||||
rotation = glm::vec3(-23.75f, 41.25f, 21.0f);
|
||||
title = "Vulkan gears";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 2.5f, -16.0f));
|
||||
camera.setRotation(glm::vec3(-23.75f, 41.25f, 21.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.001f, 256.0f);
|
||||
timerSpeed *= 0.25f;
|
||||
title = "Rotating gears";
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -321,10 +323,9 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
glm::mat4 perspective = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
for (auto& gear : gears)
|
||||
{
|
||||
gear->updateUniformBuffer(perspective, rotation, zoom, timer * 360.0f);
|
||||
gear->updateUniformBuffer(camera.matrices.perspective, camera.matrices.view, timer * 360.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -265,29 +265,17 @@ void VulkanGear::draw(VkCommandBuffer cmdbuffer, VkPipelineLayout pipelineLayout
|
|||
vkCmdDrawIndexed(cmdbuffer, indexCount, 1, 0, 0, 1);
|
||||
}
|
||||
|
||||
void VulkanGear::updateUniformBuffer(glm::mat4 perspective, glm::vec3 rotation, float zoom, float timer)
|
||||
void VulkanGear::updateUniformBuffer(glm::mat4 perspective, glm::mat4 view, float timer)
|
||||
{
|
||||
ubo.projection = perspective;
|
||||
|
||||
ubo.view = glm::lookAt(
|
||||
glm::vec3(0, 0, -zoom),
|
||||
glm::vec3(-1.0, -1.5, 0),
|
||||
glm::vec3(0, 1, 0)
|
||||
);
|
||||
ubo.view = glm::rotate(ubo.view, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
ubo.view = glm::rotate(ubo.view, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
ubo.view = view;
|
||||
ubo.model = glm::mat4(1.0f);
|
||||
ubo.model = glm::translate(ubo.model, pos);
|
||||
rotation.z = (rotSpeed * timer) + rotOffset;
|
||||
ubo.model = glm::rotate(ubo.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
ubo.model = glm::rotate(ubo.model, glm::radians((rotSpeed * timer) + rotOffset), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
ubo.normal = glm::inverseTranspose(ubo.view * ubo.model);
|
||||
|
||||
ubo.lightPos = glm::vec3(0.0f, 0.0f, 2.5f);
|
||||
ubo.lightPos.x = sin(glm::radians(timer)) * 8.0f;
|
||||
ubo.lightPos.z = cos(glm::radians(timer)) * 8.0f;
|
||||
|
||||
memcpy(uniformBuffer.mapped, &ubo, sizeof(ubo));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
#include <glm/gtc/matrix_inverse.hpp>
|
||||
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#include "VulkanTools.h"
|
||||
#include "VulkanDevice.hpp"
|
||||
#include "VulkanBuffer.hpp"
|
||||
|
|
@ -92,7 +91,7 @@ public:
|
|||
VkDescriptorSet descriptorSet;
|
||||
|
||||
void draw(VkCommandBuffer cmdbuffer, VkPipelineLayout pipelineLayout);
|
||||
void updateUniformBuffer(glm::mat4 perspective, glm::vec3 rotation, float zoom, float timer);
|
||||
void updateUniformBuffer(glm::mat4 perspective, glm::mat4 view, float timer);
|
||||
|
||||
void setupDescriptorSet(VkDescriptorPool pool, VkDescriptorSetLayout descriptorSetLayout);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue