summaryrefslogtreecommitdiff
path: root/src/vk
diff options
context:
space:
mode:
Diffstat (limited to 'src/vk')
-rw-r--r--src/vk/camera.hpp33
-rw-r--r--src/vk/graphics_pipeline.cpp30
-rw-r--r--src/vk/graphics_pipeline.hpp4
3 files changed, 16 insertions, 51 deletions
diff --git a/src/vk/camera.hpp b/src/vk/camera.hpp
deleted file mode 100644
index 5f09390..0000000
--- a/src/vk/camera.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2022 Frederico de Oliveira Linhares
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CANDY_GEAR_VK_CAMERA_H
-#define CANDY_GEAR_VK_CAMERA_H 1
-
-#include "core.hpp"
-
-namespace VK
-{
-
-struct Camera
-{
- glm::vec3 position;
- glm::vec3 rotation; // Radians
-};
-
-}
-
-#endif /* CANDY_GEAR_VK_CAMERA_H */
diff --git a/src/vk/graphics_pipeline.cpp b/src/vk/graphics_pipeline.cpp
index de08945..3956a99 100644
--- a/src/vk/graphics_pipeline.cpp
+++ b/src/vk/graphics_pipeline.cpp
@@ -845,7 +845,8 @@ namespace VK
GraphicsPipeline::GraphicsPipeline():
current_frame{0},
- camera{std::make_shared<VK::Camera>()},
+ camera_position{std::make_shared<glm::vec3>(0.0f, 0.0f, 0.0f)},
+ camera_rotation{std::make_shared<glm::vec3>(0.0f, 0.0f, 0.0f)},
models_to_draw{cg_core.vk_swapchain->images_count}
{
loader.execute(this);
@@ -952,17 +953,14 @@ GraphicsPipeline::draw()
{
// Object matrix.
glm::mat4 instance_matrix{1.0f};
+ instance_matrix = glm::translate(
+ instance_matrix, instances[i].position);
instance_matrix = glm::rotate(
- instance_matrix, glm::radians(instances[i].rotation.x),
- glm::vec3{1.0, 0.0, 0.0});
+ instance_matrix, instances[i].rotation.x, glm::vec3{1.0, 0.0, 0.0});
instance_matrix = glm::rotate(
- instance_matrix, glm::radians(instances[i].rotation.y),
- glm::vec3{0.0, 1.0, 0.0});
+ instance_matrix, instances[i].rotation.y, glm::vec3{0.0, 1.0, 0.0});
instance_matrix = glm::rotate(
- instance_matrix, glm::radians(instances[i].rotation.z),
- glm::vec3{0.0, 0.0, 1.0});
- instance_matrix = glm::translate(
- instance_matrix, instances[i].position);
+ instance_matrix, instances[i].rotation.z, glm::vec3{0.0, 0.0, 1.0});
ubo_model_instance.model[i] = instance_matrix;
}
@@ -982,16 +980,16 @@ GraphicsPipeline::draw()
// View matrix.
ubo_view_projection.view = glm::mat4{1.0f};
ubo_view_projection.view = glm::translate(
- ubo_view_projection.view, this->camera->position);
+ ubo_view_projection.view, *this->camera_position);
ubo_view_projection.view = glm::rotate(
- ubo_view_projection.view, this->camera->rotation.x,
- glm::vec3{1.0, 0.0, 0.0});
+ ubo_view_projection.view, this->camera_rotation->y,
+ glm::vec3{0.0, 1.0, 0.0});
ubo_view_projection.view = glm::rotate(
- ubo_view_projection.view, this->camera->rotation.y,
- glm::vec3{0.0, 1.0, 0.0});
+ ubo_view_projection.view, this->camera_rotation->x,
+ glm::vec3{1.0, 0.0, 0.0});
ubo_view_projection.view = glm::rotate(
- ubo_view_projection.view, this->camera->rotation.z,
- glm::vec3{0.0, 0.0, 1.0});
+ ubo_view_projection.view, this->camera_rotation->z,
+ glm::vec3{0.0, 0.0, 1.0});
ubo_view_projection.view = glm::inverse(ubo_view_projection.view);
// Projection matrix.
diff --git a/src/vk/graphics_pipeline.hpp b/src/vk/graphics_pipeline.hpp
index dffd6fb..b4a282a 100644
--- a/src/vk/graphics_pipeline.hpp
+++ b/src/vk/graphics_pipeline.hpp
@@ -22,7 +22,6 @@
#include "../command.hpp"
#include "core.hpp"
-#include "camera.hpp"
#include "command_pool.hpp"
#include "model.hpp"
#include "model_instance.hpp"
@@ -64,7 +63,8 @@ struct GraphicsPipeline
std::vector<VkSemaphore> render_finished_semaphores;
std::vector<VkFence> in_flight_fences;
- std::shared_ptr<Camera> camera;
+ std::shared_ptr<glm::vec3> camera_position;
+ std::shared_ptr<glm::vec3> camera_rotation;
std::vector<std::unordered_map<
std::shared_ptr<Model>, std::vector<ModelInstance>>>
models_to_draw;