Добавил возможность вращать камерой
CMake on a single platform / build (pull_request) Successful in 1m30s

This commit is contained in:
2026-06-01 14:10:54 +07:00
parent e1db9fd588
commit a1cf661286
4 changed files with 21 additions and 8 deletions
@@ -872,19 +872,27 @@ void UwURenderEngine::record_command_buffer(VkCommandBuffer command_buffer, uint
void UwURenderEngine::update_uniform_buffer(uint32_t current_frame) const
{
glm::vec3 eye{0, 0, 0};
glm::vec3 center{0, 0, 0};
glm::vec3 up{0, 1, 0};
if (active_camera_.expired() == false)
{
std::shared_ptr<Camera> camera = active_camera_.lock();
Vector3D loc = camera->GetActorLocate();
eye = {loc.x, loc.y, loc.z};
Vector3D rot = camera->GetActorRotate();
glm::vec3 direction{glm::cos(rot.x)*glm::cos(rot.y), glm::sin(rot.x)*glm::cos(rot.y), glm::sin(rot.y)};
center = eye + direction;
up = {0, glm::sin(rot.z), glm::cos(rot.z)};
}
static auto start_time = std::chrono::high_resolution_clock::now();
auto current_time = std::chrono::high_resolution_clock::now();
float time = std::chrono::duration_cast<std::chrono::duration<float>>(current_time - start_time).count();
UniformBufferObject ubo;
ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(45.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.view = glm::lookAt(eye, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.model = glm::rotate(glm::mat4(1.0f), /*time * glm::radians(45.0f)*/0.f, glm::vec3(0.0f, 0.0f, 1.0f));
ubo.view = glm::lookAt(eye, center, up);
ubo.proj = glm::perspective(glm::radians(45.0f), static_cast<float>(swapchain_extent_.width) / static_cast<float>(swapchain_extent_.height), 0.1f, 256.0f);
ubo.proj[1][1] *= -1;
memcpy(uniform_buffers_mapped_[current_frame], &ubo, sizeof(ubo));