From a1cf661286d09093353f92f3cbce9666cffa35ea Mon Sep 17 00:00:00 2001 From: Jiga228 Date: Mon, 1 Jun 2026 14:10:54 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D1=82=D1=8C=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BC=D0=B5=D1=80=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Math/Vector.cpp | 4 ++-- TestGame/Worlds/TestWorld.world | 4 ++-- TestGame/src/Worlds/TestWorld.cpp | 9 +++++++-- UwURenderEngine/RenderEngine/UwURenderEngine.cpp | 12 ++++++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Core/Math/Vector.cpp b/Core/Math/Vector.cpp index a86d94b..c87dfee 100644 --- a/Core/Math/Vector.cpp +++ b/Core/Math/Vector.cpp @@ -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 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) diff --git a/TestGame/Worlds/TestWorld.world b/TestGame/Worlds/TestWorld.world index 614de31..c95ad06 100644 --- a/TestGame/Worlds/TestWorld.world +++ b/TestGame/Worlds/TestWorld.world @@ -17,8 +17,8 @@ }, "orot": { "Class name":"Vector3D", - "dx":0.0, - "dy":0.0, + "dx":-2.335, + "dy":-0.785, "dz":0.0 }, "oscale": { diff --git a/TestGame/src/Worlds/TestWorld.cpp b/TestGame/src/Worlds/TestWorld.cpp index 9cdbf37..6788a84 100644 --- a/TestGame/src/Worlds/TestWorld.cpp +++ b/TestGame/src/Worlds/TestWorld.cpp @@ -1,5 +1,8 @@ #include "TestWorld.h" +#include +#include + #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()[0].lock()->SetActorLocate(Vector3D{2 + delta, 2 + delta, 2 + delta}); + double delta1 = sin(time1); + double delta2 = sin(3*time1); + GetActorsByClass()[0].lock()->SetActorLocate(Vector3D{2 + delta2, 2 + delta2, 2 + delta2}); + GetActorsByClass()[0].lock()->SetActorRotate(Vector3D{-3*glm::pi()/4 + glm::pi()/4 * delta1, glm::pi() / -4, 0}); time += delta_time; if (time >= 10.0) diff --git a/UwURenderEngine/RenderEngine/UwURenderEngine.cpp b/UwURenderEngine/RenderEngine/UwURenderEngine.cpp index 31a5960..562088d 100644 --- a/UwURenderEngine/RenderEngine/UwURenderEngine.cpp +++ b/UwURenderEngine/RenderEngine/UwURenderEngine.cpp @@ -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 = 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>(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(swapchain_extent_.width) / static_cast(swapchain_extent_.height), 0.1f, 256.0f); ubo.proj[1][1] *= -1; memcpy(uniform_buffers_mapped_[current_frame], &ubo, sizeof(ubo));