summaryrefslogtreecommitdiff
path: root/src/vk
diff options
context:
space:
mode:
Diffstat (limited to 'src/vk')
-rw-r--r--src/vk/core.hpp1
-rw-r--r--src/vk/graphics_pipeline_3d.cpp31
-rw-r--r--src/vk/graphics_pipeline_3d_skeletal.cpp31
-rw-r--r--src/vk/skeletal_model.cpp4
-rw-r--r--src/vk/skeletal_model.hpp5
-rw-r--r--src/vk/sprite_to_draw.hpp8
-rw-r--r--src/vk/static_model.cpp6
-rw-r--r--src/vk/static_model.hpp5
-rw-r--r--src/vk/view_3d.cpp2
-rw-r--r--src/vk/view_3d.hpp2
10 files changed, 40 insertions, 55 deletions
diff --git a/src/vk/core.hpp b/src/vk/core.hpp
index 64d1431..736b8bb 100644
--- a/src/vk/core.hpp
+++ b/src/vk/core.hpp
@@ -19,6 +19,7 @@
// GLM uses some definitions to control their behavior, so you should not
// include it directly. Instead, use this header.
+#define GLM_ENABLE_EXPERIMENTAL
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
diff --git a/src/vk/graphics_pipeline_3d.cpp b/src/vk/graphics_pipeline_3d.cpp
index f657a54..2b6812d 100644
--- a/src/vk/graphics_pipeline_3d.cpp
+++ b/src/vk/graphics_pipeline_3d.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2023 Frederico de Oliveira Linhares
+ * Copyright 2022-2024 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.
@@ -296,14 +296,10 @@ GraphicsPipeline3D::draw(
for(auto &instance: instances)
{ // Object matrix.
- glm::mat4 base_matrix{1.0f};
- base_matrix = glm::translate(base_matrix, *instance->position);
- base_matrix = glm::rotate(
- base_matrix, instance->rotation->x, glm::vec3{1.0, 0.0, 0.0});
- base_matrix = glm::rotate(
- base_matrix, instance->rotation->y, glm::vec3{0.0, 1.0, 0.0});
- base_matrix = glm::rotate(
- base_matrix, instance->rotation->z, glm::vec3{0.0, 0.0, 1.0});
+ glm::mat4 translation_matrix{1.0f};
+ translation_matrix = glm::translate(
+ translation_matrix, *instance->position);
+ glm::mat4 rotation_matrix{glm::toMat4(*instance->orientation)};
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
cg_core.vk_light->descriptor_sets_world[image_index],
@@ -320,7 +316,7 @@ GraphicsPipeline3D::draw(
draw_command_buffer, static_mesh->index_count, 1, 0, 0, 0);
VK::UDOStaticModel udo_static_model{};
- udo_static_model.base_matrix = base_matrix;
+ udo_static_model.base_matrix = translation_matrix * rotation_matrix;
instance->uniform_buffers[image_index].copy_data(&udo_static_model);
}
}
@@ -329,16 +325,11 @@ GraphicsPipeline3D::draw(
VK::UDOView3D ubo_view_3d{};
// View matrix.
- ubo_view_3d.view = glm::mat4{1.0f};
- ubo_view_3d.view = glm::translate(
- ubo_view_3d.view, *view->camera_position);
- ubo_view_3d.view = glm::rotate(
- ubo_view_3d.view, view->camera_rotation->y, glm::vec3{0.0, 1.0, 0.0});
- ubo_view_3d.view = glm::rotate(
- ubo_view_3d.view, view->camera_rotation->x, glm::vec3{1.0, 0.0, 0.0});
- ubo_view_3d.view = glm::rotate(
- ubo_view_3d.view, view->camera_rotation->z, glm::vec3{0.0, 0.0, 1.0});
- ubo_view_3d.view = glm::inverse(ubo_view_3d.view);
+ glm::mat4 translation_matrix{1.0f};
+ translation_matrix = glm::translate(
+ translation_matrix, *view->camera_position);
+ glm::mat4 rotation_matrix{glm::toMat4(*view->camera_orientation)};
+ ubo_view_3d.view = glm::inverse(translation_matrix * rotation_matrix);
// Projection matrix.
ubo_view_3d.proj = glm::perspective(
diff --git a/src/vk/graphics_pipeline_3d_skeletal.cpp b/src/vk/graphics_pipeline_3d_skeletal.cpp
index c4dabdf..364b502 100644
--- a/src/vk/graphics_pipeline_3d_skeletal.cpp
+++ b/src/vk/graphics_pipeline_3d_skeletal.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2023 Frederico de Oliveira Linhares
+ * Copyright 2022-2024 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.
@@ -305,14 +305,10 @@ GraphicsPipeline3DSkeletal::draw(
for(auto &instance: instances)
{ // Object matrix.
- glm::mat4 base_matrix{1.0f};
- base_matrix = glm::translate(base_matrix, *instance->position);
- base_matrix = glm::rotate(
- base_matrix, instance->rotation->x, glm::vec3{1.0, 0.0, 0.0});
- base_matrix = glm::rotate(
- base_matrix, instance->rotation->y, glm::vec3{0.0, 1.0, 0.0});
- base_matrix = glm::rotate(
- base_matrix, instance->rotation->z, glm::vec3{0.0, 0.0, 1.0});
+ glm::mat4 translation_matrix{1.0f};
+ translation_matrix = glm::translate(
+ translation_matrix, *instance->position);
+ glm::mat4 rotation_matrix{glm::toMat4(*instance->orientation)};
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
cg_core.vk_light->descriptor_sets_world[image_index],
@@ -330,7 +326,7 @@ GraphicsPipeline3DSkeletal::draw(
VK::UDOSkeletalModel udo_skeletal_model{};
instance->tick(cg_core.delta_time);
- udo_skeletal_model.base_matrix = base_matrix;
+ udo_skeletal_model.base_matrix = translation_matrix * rotation_matrix;
std::copy(instance->bone_transforms.begin(),
instance->bone_transforms.end(),
udo_skeletal_model.bone_matrices);
@@ -342,16 +338,11 @@ GraphicsPipeline3DSkeletal::draw(
VK::UDOView3D ubo_view_3d{};
// View matrix.
- ubo_view_3d.view = glm::mat4{1.0f};
- ubo_view_3d.view = glm::translate(
- ubo_view_3d.view, *view->camera_position);
- ubo_view_3d.view = glm::rotate(
- ubo_view_3d.view, view->camera_rotation->y, glm::vec3{0.0, 1.0, 0.0});
- ubo_view_3d.view = glm::rotate(
- ubo_view_3d.view, view->camera_rotation->x, glm::vec3{1.0, 0.0, 0.0});
- ubo_view_3d.view = glm::rotate(
- ubo_view_3d.view, view->camera_rotation->z, glm::vec3{0.0, 0.0, 1.0});
- ubo_view_3d.view = glm::inverse(ubo_view_3d.view);
+ glm::mat4 translation_matrix{1.0f};
+ translation_matrix = glm::translate(
+ translation_matrix, *view->camera_position);
+ glm::mat4 rotation_matrix{glm::toMat4(*view->camera_orientation)};
+ ubo_view_3d.view = glm::inverse(translation_matrix * rotation_matrix);
// Projection matrix.
ubo_view_3d.proj = glm::perspective(
diff --git a/src/vk/skeletal_model.cpp b/src/vk/skeletal_model.cpp
index b2d5fc3..d2739c4 100644
--- a/src/vk/skeletal_model.cpp
+++ b/src/vk/skeletal_model.cpp
@@ -148,11 +148,11 @@ namespace VK
SkeletalModel::SkeletalModel(
std::shared_ptr<SkeletalMesh> skeletal_mesh,
std::shared_ptr<Texture> texture, std::shared_ptr<glm::vec3> position,
- std::shared_ptr<glm::vec3> rotation):
+ std::shared_ptr<glm::quat> orientation):
skeletal_mesh{skeletal_mesh},
texture{texture},
position{position},
- rotation{rotation},
+ orientation{orientation},
animation_index{0},
animation_time{0.0f},
bone_transforms(SKELETAL_MESH_MAX_NUM_OF_BONES)
diff --git a/src/vk/skeletal_model.hpp b/src/vk/skeletal_model.hpp
index 1043e0f..db54ac9 100644
--- a/src/vk/skeletal_model.hpp
+++ b/src/vk/skeletal_model.hpp
@@ -31,7 +31,8 @@ struct SkeletalModel
std::shared_ptr<SkeletalMesh> skeletal_mesh;
std::shared_ptr<Texture> texture;
std::vector<UniformBuffer> uniform_buffers;
- std::shared_ptr<glm::vec3> position, rotation;
+ std::shared_ptr<glm::vec3> position;
+ std::shared_ptr<glm::quat> orientation;
int animation_index;
float animation_time;
std::vector<glm::mat4> bone_transforms;
@@ -42,7 +43,7 @@ struct SkeletalModel
SkeletalModel(
std::shared_ptr<SkeletalMesh> skeletal_mesh,
std::shared_ptr<Texture> texture, std::shared_ptr<glm::vec3> position,
- std::shared_ptr<glm::vec3> rotation);
+ std::shared_ptr<glm::quat> orientation);
~SkeletalModel();
void
diff --git a/src/vk/sprite_to_draw.hpp b/src/vk/sprite_to_draw.hpp
index 3bd6af3..84effff 100644
--- a/src/vk/sprite_to_draw.hpp
+++ b/src/vk/sprite_to_draw.hpp
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_VK_SPRITES_TO_DRAW_2D_H
-#define CANDY_GEAR_VK_SPRITES_TO_DRAW_2D_H 1
+#ifndef CANDY_GEAR_VK_SPRITES_TO_DRAW_H
+#define CANDY_GEAR_VK_SPRITES_TO_DRAW_H 1
#include <memory>
@@ -38,7 +38,7 @@ namespace VK
operator<(const SpriteToDraw &a, const SpriteToDraw &b);
bool
- operator<(const SpriteToDraw &a, const SpriteToDraw &b);
+ operator>(const SpriteToDraw &a, const SpriteToDraw &b);
}
-#endif /* CANDY_GEAR_VK_SPRITES_TO_DRAW_2D_H */
+#endif /* CANDY_GEAR_VK_SPRITES_TO_DRAW_H */
diff --git a/src/vk/static_model.cpp b/src/vk/static_model.cpp
index a89d79a..ef53155 100644
--- a/src/vk/static_model.cpp
+++ b/src/vk/static_model.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2023 Frederico de Oliveira Linhares
+ * Copyright 2022-2024 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.
@@ -148,11 +148,11 @@ namespace VK
StaticModel::StaticModel(
std::shared_ptr<StaticMesh> static_mesh,
std::shared_ptr<Texture> texture, std::shared_ptr<glm::vec3> position,
- std::shared_ptr<glm::vec3> rotation):
+ std::shared_ptr<glm::quat> orientation):
static_mesh{static_mesh},
texture{texture},
position{position},
- rotation{rotation}
+ orientation{orientation}
{
loader.execute(this);
}
diff --git a/src/vk/static_model.hpp b/src/vk/static_model.hpp
index 08c68c8..72f4fac 100644
--- a/src/vk/static_model.hpp
+++ b/src/vk/static_model.hpp
@@ -31,7 +31,8 @@ struct StaticModel
std::shared_ptr<StaticMesh> static_mesh;
std::shared_ptr<Texture> texture;
std::vector<UniformBuffer> uniform_buffers;
- std::shared_ptr<glm::vec3> position, rotation;
+ std::shared_ptr<glm::vec3> position;
+ std::shared_ptr<glm::quat> orientation;
VkDescriptorPool descriptor_pool;
std::vector<VkDescriptorSet> descriptor_sets;
@@ -39,7 +40,7 @@ struct StaticModel
StaticModel(
std::shared_ptr<StaticMesh> static_mesh,
std::shared_ptr<Texture> texture, std::shared_ptr<glm::vec3> position,
- std::shared_ptr<glm::vec3> rotation);
+ std::shared_ptr<glm::quat> orientation);
~StaticModel();
};
diff --git a/src/vk/view_3d.cpp b/src/vk/view_3d.cpp
index f9cfe5a..273874c 100644
--- a/src/vk/view_3d.cpp
+++ b/src/vk/view_3d.cpp
@@ -120,7 +120,7 @@ View3D::View3D(
View2D{region, projection_width, projection_height},
field_of_view{45.0f},
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)}
+ camera_orientation{std::make_shared<glm::quat>(0.0f, 0.0f, 0.0f, 0.0f)}
{
::loader.execute(this);
}
diff --git a/src/vk/view_3d.hpp b/src/vk/view_3d.hpp
index 52146df..c5a803b 100644
--- a/src/vk/view_3d.hpp
+++ b/src/vk/view_3d.hpp
@@ -31,7 +31,7 @@ struct View3D: public View2D
std::vector<VkDescriptorSet> descriptor_sets_3d;
std::shared_ptr<glm::vec3> camera_position;
- std::shared_ptr<glm::vec3> camera_rotation;
+ std::shared_ptr<glm::quat> camera_orientation;
View3D(glm::vec4 region, float projection_width, float projection_height);
~View3D();