|
|
@@ -6,18 +6,34 @@
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
#include <glm/gtx/rotate_vector.hpp>
|
|
|
|
|
|
+#include <glm/gtx/string_cast.hpp>
|
|
|
+
|
|
|
#include <boost/asio/post.hpp>
|
|
|
|
|
|
#include <vtkSphereSource.h>
|
|
|
|
|
|
using boost::asio::post;
|
|
|
|
|
|
+void camera_augment_helper_v2::impl::freedom_info_type::reset() {
|
|
|
+ if (auto &mat = pimpl->tracked_transform; mat.has_value()) {
|
|
|
+ static constexpr auto default_focal_length = 8.0f; // 8mm
|
|
|
+ eye = glm::vec3((*mat)[3]);
|
|
|
+ auto rot_part = glm::mat3(*mat);
|
|
|
+ center = eye + rot_part[2] * default_focal_length;
|
|
|
+ view_up = -rot_part[1];
|
|
|
+ } else {
|
|
|
+ eye = glm::vec3();
|
|
|
+ center = glm::vec3(0.f, 0.f, 100.f);
|
|
|
+ view_up = glm::vec3(0.0f, -1.0f, 0.0f);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
glm::mat4 camera_augment_helper_v2::impl::freedom_info_type::to_transform() {
|
|
|
// normalize view up
|
|
|
view_up -= view_dir() * glm::dot(view_up, view_dir());
|
|
|
view_up = glm::normalize(view_up);
|
|
|
|
|
|
- auto ret = glm::lookAt(eye, center, view_up);
|
|
|
+ auto ret = glm::inverse(glm::lookAt(eye, center, view_up));
|
|
|
ret = glm::rotate(ret, glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)); // viewport -> camera
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -84,13 +100,16 @@ camera_augment_helper_v2::impl::impl(const create_config &conf) {
|
|
|
switch (conf.camera.index()) {
|
|
|
case 1: {
|
|
|
mode = MODE_FREEDOM;
|
|
|
+ auto info = std::get<1>(conf.camera);
|
|
|
+ transform_var = info.transform_var;
|
|
|
+ freedom_info.pimpl = this;
|
|
|
break;
|
|
|
}
|
|
|
case 2: {
|
|
|
mode = MODE_FIXED;
|
|
|
auto info = std::get<2>(conf.camera);
|
|
|
fov = info.fov;
|
|
|
- fixed_info.transform_var = info.transform_var;
|
|
|
+ transform_var = info.transform_var;
|
|
|
break;
|
|
|
}
|
|
|
case 3: {
|
|
|
@@ -111,18 +130,30 @@ camera_augment_helper_v2::impl::~impl() {
|
|
|
pre_render_conn.disconnect();
|
|
|
}
|
|
|
|
|
|
+void camera_augment_helper_v2::impl::update_tracked_transform() {
|
|
|
+ if (sophiar_conn == nullptr) return;
|
|
|
+ auto trans = sophiar_conn->
|
|
|
+ query_transform_variable(transform_var);
|
|
|
+ is_missing = !trans.has_value();
|
|
|
+ if (trans.has_value()) {
|
|
|
+ tracked_transform = to_mat4(*trans);
|
|
|
+ } else {
|
|
|
+ tracked_transform = {};
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void camera_augment_helper_v2::impl::update_freedom() {
|
|
|
+ update_tracked_transform();
|
|
|
transform = freedom_info.to_transform();
|
|
|
is_missing = false;
|
|
|
}
|
|
|
|
|
|
void camera_augment_helper_v2::impl::update_fixed() {
|
|
|
assert(sophiar_conn != nullptr);
|
|
|
- auto trans = sophiar_conn->
|
|
|
- query_transform_variable(fixed_info.transform_var);
|
|
|
- is_missing = !trans.has_value();
|
|
|
- if (trans.has_value()) {
|
|
|
- transform = to_mat4(*trans) * fixed_info.extra_transform();
|
|
|
+ update_tracked_transform();
|
|
|
+ if (tracked_transform.has_value()) {
|
|
|
+ auto extra_mat = fixed_info.extra_transform();
|
|
|
+ transform = *tracked_transform * extra_mat;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -178,6 +209,10 @@ void camera_augment_helper_v2::impl::render_image(output_config conf) {
|
|
|
void camera_augment_helper_v2::impl::show_freedom() {
|
|
|
auto &info = freedom_info;
|
|
|
|
|
|
+ if (ImGui::Button("Reset")) {
|
|
|
+ freedom_info.reset();
|
|
|
+ }
|
|
|
+
|
|
|
if (ImGui::TreeNode("Center")) {
|
|
|
if (ImGui::Button("X+")) { info.move_right(info.linear_speed); }
|
|
|
ImGui::SameLine();
|