summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/view_3d.cpp28
-rw-r--r--src/vk/graphics_pipeline_3d.cpp2
-rw-r--r--src/vk/view_3d.cpp8
-rw-r--r--src/vk/view_3d.hpp1
4 files changed, 31 insertions, 8 deletions
diff --git a/src/view_3d.cpp b/src/view_3d.cpp
index 92e57c9..8f4f14c 100644
--- a/src/view_3d.cpp
+++ b/src/view_3d.cpp
@@ -80,6 +80,28 @@ cg_cView3D_set_camera_rotation(mrb_state *mrb, mrb_value self)
return self;
}
+static mrb_value
+cg_cView3D_get_field_of_view(mrb_state *mrb, mrb_value self)
+{
+ auto ptr = (std::shared_ptr<VK::View3D>*)DATA_PTR(self);
+
+ return mrb_float_value(mrb, (*ptr)->field_of_view);
+
+ return self;
+}
+
+static mrb_value
+cg_cView3D_set_field_of_view(mrb_state *mrb, mrb_value self)
+{
+ mrb_float fov;
+ auto ptr = (std::shared_ptr<VK::View3D>*)DATA_PTR(self);
+
+ mrb_get_args(mrb, "f", &fov);
+ (*ptr)->field_of_view = fov;
+
+ return self;
+}
+
void
cg_view_3d_init(mrb_state *mrb)
{
@@ -96,4 +118,10 @@ cg_view_3d_init(mrb_state *mrb)
mrb_define_method(
mrb, cg_cView3D, "camera_rotation=", cg_cView3D_set_camera_rotation,
MRB_ARGS_REQ(1));
+ mrb_define_method(
+ mrb, cg_cView3D, "field_of_view", cg_cView3D_get_field_of_view,
+ MRB_ARGS_NONE());
+ mrb_define_method(
+ mrb, cg_cView3D, "field_of_view=", cg_cView3D_set_field_of_view,
+ MRB_ARGS_REQ(1));
}
diff --git a/src/vk/graphics_pipeline_3d.cpp b/src/vk/graphics_pipeline_3d.cpp
index d98a27d..6bfd559 100644
--- a/src/vk/graphics_pipeline_3d.cpp
+++ b/src/vk/graphics_pipeline_3d.cpp
@@ -341,7 +341,7 @@ GraphicsPipeline3D::draw(
// Projection matrix.
ubo_view_3d.proj = glm::perspective(
- glm::radians(45.0f),
+ glm::radians(view->field_of_view),
view->region.z / view->region.w,
0.1f, 100.0f);
diff --git a/src/vk/view_3d.cpp b/src/vk/view_3d.cpp
index 9040545..f9cfe5a 100644
--- a/src/vk/view_3d.cpp
+++ b/src/vk/view_3d.cpp
@@ -98,13 +98,6 @@ load_resources_to_descriptor_sets_3d(void *obj)
vkUpdateDescriptorSets(
cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
-
- VK::UDOView3D ubo_view_3d;
- ubo_view_3d.proj = glm::ortho(
- 0.0f, self->region.z,
- 0.0f, self->region.w,
- 0.0f, 100.0f);
- self->ub_3d[i].copy_data(&ubo_view_3d);
}
}
@@ -125,6 +118,7 @@ namespace VK
View3D::View3D(
glm::vec4 region, float projection_width, float projection_height):
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)}
{
diff --git a/src/vk/view_3d.hpp b/src/vk/view_3d.hpp
index 1d51070..52146df 100644
--- a/src/vk/view_3d.hpp
+++ b/src/vk/view_3d.hpp
@@ -24,6 +24,7 @@ namespace VK
struct View3D: public View2D
{
+ float field_of_view;
// FIXME: if this vector get resized, it can cause a segmentation fault!
std::vector<UniformBuffer> ub_3d;