Добавил возможность вращать камерой
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
+2 -2
View File
@@ -2,7 +2,7 @@
#include "Game/SaveMap/SaveMap.hpp"
Vector2D::Vector2D(const double x, const double y) : x(x), y(y)
Vector2D::Vector2D(double x, double y) : x(x), y(y)
{}
Vector2D::Vector2D(const Vector3D& vec3D) : x(vec3D.x), y(vec3D.y)
@@ -31,7 +31,7 @@ void Vector2D::load(std::shared_ptr<SaveMap> save)
y = save->GetDouble("y");
}
Vector3D::Vector3D(const double x, const double y, const double z) : x(x), y(y), z(z)
Vector3D::Vector3D(double x, double y, double z) : x(x), y(y), z(z)
{}
Vector3D::Vector3D(const Vector2D& vec2D) : x(vec2D.x), y(vec2D.y)
+2 -2
View File
@@ -17,8 +17,8 @@
},
"orot": {
"Class name":"Vector3D",
"dx":0.0,
"dy":0.0,
"dx":-2.335,
"dy":-0.785,
"dz":0.0
},
"oscale": {
+7 -2
View File
@@ -1,5 +1,8 @@
#include "TestWorld.h"
#include <glm/glm.hpp>
#include <glm/ext/scalar_constants.hpp>
#include "Game/GameInstance.hpp"
#include "Game/Actors/Camera.hpp"
#include "Game/SaveMap/SaveMap.hpp"
@@ -27,8 +30,10 @@ void TestWorld::Tick(double delta_time)
static double time1 = 0.0;
time1 += delta_time;
double delta = sin(time1);
GetActorsByClass<Camera>()[0].lock()->SetActorLocate(Vector3D{2 + delta, 2 + delta, 2 + delta});
double delta1 = sin(time1);
double delta2 = sin(3*time1);
GetActorsByClass<Camera>()[0].lock()->SetActorLocate(Vector3D{2 + delta2, 2 + delta2, 2 + delta2});
GetActorsByClass<Camera>()[0].lock()->SetActorRotate(Vector3D{-3*glm::pi<double>()/4 + glm::pi<double>()/4 * delta1, glm::pi<double>() / -4, 0});
time += delta_time;
if (time >= 10.0)
@@ -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));