diff --git a/camera/lava-extras/camera/GenericCamera.cc b/camera/lava-extras/camera/GenericCamera.cc index 4852a19d0072221acedf4e96e1527b5f72d0d488..0e09c5c5bd4928bda062a52a6b7ab9b07154800f 100644 --- a/camera/lava-extras/camera/GenericCamera.cc +++ b/camera/lava-extras/camera/GenericCamera.cc @@ -64,42 +64,49 @@ GenericCamera::GenericCamera(const std::string &_state) { setStateFromString(_state); } -void GenericCamera::FPSstyleLookAround(float _deltaX, float _deltaY) { - float yaw = 0.0f; - float pitch = 0.0f; - glm::mat3 R = getRotationMatrix3(); - - // get roll / pitch / yaw from the current rotation matrix: - float yaw1 = asin(-R[2][0]); - float yaw2 = glm::pi<float>() - asin(-R[2][0]); - - float pitch1 = - (cos(yaw1) > 0) ? atan2(R[2][1], R[2][2]) : atan2(-R[2][1], -R[2][2]); - float pitch2 = - (cos(yaw2) > 0) ? atan2(R[2][1], R[2][2]) : atan2(-R[2][1], -R[2][2]); - - float roll1 = - (cos(yaw1) > 0) ? atan2(R[1][0], R[0][0]) : atan2(-R[1][0], -R[0][0]); - float roll2 = - (cos(yaw2) > 0) ? atan2(R[1][0], R[0][0]) : atan2(-R[1][0], -R[0][0]); - - // we assume no roll at all, in that case one of the roll variants will be - // 0.0 - // if not, use the smaller one -> minimize the camera "jump" as this will - // destroy - // information - if (std::abs(roll1) <= std::abs(roll2)) { - yaw = -yaw1; - pitch = -pitch1; - } else { - yaw = -yaw2; - pitch = -pitch2; - } +void GenericCamera::getPitchYaw(float& pitch, float& yaw) +{ + glm::mat3 R = getRotationMatrix3(); + + // get roll / pitch / yaw from the current rotation matrix: + float yaw1 = asin(-R[2][0]); + float yaw2 = glm::pi<float>() - asin(-R[2][0]); + + float pitch1 = + (cos(yaw1) > 0) ? atan2(R[2][1], R[2][2]) : atan2(-R[2][1], -R[2][2]); + float pitch2 = + (cos(yaw2) > 0) ? atan2(R[2][1], R[2][2]) : atan2(-R[2][1], -R[2][2]); + + float roll1 = + (cos(yaw1) > 0) ? atan2(R[1][0], R[0][0]) : atan2(-R[1][0], -R[0][0]); + float roll2 = + (cos(yaw2) > 0) ? atan2(R[1][0], R[0][0]) : atan2(-R[1][0], -R[0][0]); + + // we assume no roll at all, in that case one of the roll variants will be + // 0.0 + // if not, use the smaller one -> minimize the camera "jump" as this will + // destroy + // information + if (std::abs(roll1) <= std::abs(roll2)) { + yaw = -yaw1; + pitch = -pitch1; + } + else { + yaw = -yaw2; + pitch = -pitch2; + } +} - // add rotation diffs given: - yaw = yaw + _deltaX; - pitch = glm::clamp(pitch + _deltaY, -0.5f * glm::pi<float>(), - 0.5f * glm::pi<float>()); +void GenericCamera::FPSstyleLookAround(float _deltaX, float _deltaY) { + + float pitch = 0.0f; + float yaw = 0.0f; + getPitchYaw(pitch, yaw); + + // add rotation diffs given: + yaw = yaw + _deltaX; + pitch = glm::clamp(pitch + _deltaY, -0.5f * glm::pi<float>(), + 0.5f * glm::pi<float>()); // create rotation matices, seperated so we have full control over the // order: diff --git a/camera/lava-extras/camera/GenericCamera.hh b/camera/lava-extras/camera/GenericCamera.hh index 7fc7cc81ec3c880cb3edca87fae2bdc9b5292884..2c78ef0d18ef13ad660a757d1e9941390477759d 100644 --- a/camera/lava-extras/camera/GenericCamera.hh +++ b/camera/lava-extras/camera/GenericCamera.hh @@ -332,6 +332,8 @@ public: /// Gets the translation matrix of this object (no rotational element) glm::mat4 getTranslationMatrix4() const; + void getPitchYaw(float& pitch, float& yaw); + /////////////////////////////////////////////////////////////////////////////////////////// // // Generic model matrices. diff --git a/imgui/lava-extras/imgui/ImGui.cc b/imgui/lava-extras/imgui/ImGui.cc index baf80cb1deb5f3295d999778647327857793e524..57578b5eee2ed837e0c3a9ef3b06f95dc42c4e54 100644 --- a/imgui/lava-extras/imgui/ImGui.cc +++ b/imgui/lava-extras/imgui/ImGui.cc @@ -45,12 +45,12 @@ void ImGui::prepare(const std::vector<SharedImageView> &views) { } } -void ImGui::connectViews(const std::vector<SharedImageView> &views) { +void ImGui::connectViews(const std::vector<SharedImageView> &views, bool clear) { assert(!views.empty()); ::ImGui::SetCurrentContext(mContext); mUsage = TO_TEXTURE; - setupPass(false, views[0]->format()); + setupPass(clear, views[0]->format()); prepare(views); ImGuiIO &io = ::ImGui::GetIO(); diff --git a/imgui/lava-extras/imgui/ImGui.hh b/imgui/lava-extras/imgui/ImGui.hh index be35653c10398a0833b21bf8e9a2b7f83c9c8663..edea83fe7198c512a3050303b03489093f81d944 100644 --- a/imgui/lava-extras/imgui/ImGui.hh +++ b/imgui/lava-extras/imgui/ImGui.hh @@ -28,8 +28,8 @@ class ImGui { /// ...or connect ImageView(s) (all of which must have the same size), mind /// that you need to use ImGuiIO to pipe in controls still. - /// (images will be cleared before rendering) - void connectViews(std::vector<SharedImageView> const &views); + /// (images will be cleared before rendering by default) + void connectViews(std::vector<SharedImageView> const &views, bool clear = true); void render(int viewindex, RecordingCommandBuffer &cmd);