diff --git a/adf_loader/version_1_0/adf_loader_1_0.cpp b/adf_loader/version_1_0/adf_loader_1_0.cpp index 80343bf82..867a102a1 100644 --- a/adf_loader/version_1_0/adf_loader_1_0.cpp +++ b/adf_loader/version_1_0/adf_loader_1_0.cpp @@ -1254,6 +1254,7 @@ bool ADFLoader_1_0::loadCameraAttribs(YAML::Node *a_node, afCameraAttributes *at YAML::Node preProcessingShaderNode = node["preprocessing shaders"]; YAML::Node depthShaderNode = node["depth compute shaders"]; YAML::Node multiPassNode = node["multipass"]; + YAML::Node mouseControlMultiplierNode = node["mouse control multipliers"]; bool valid = true; @@ -1365,6 +1366,21 @@ bool ADFLoader_1_0::loadCameraAttribs(YAML::Node *a_node, afCameraAttributes *at attribs->m_multiPass = multiPassNode.as(); } + if (mouseControlMultiplierNode.IsDefined()){ + if (mouseControlMultiplierNode["pan"].IsDefined()){ + attribs->m_mouseControlScales.m_pan *= mouseControlMultiplierNode["pan"].as(); + } + if (mouseControlMultiplierNode["rotate"].IsDefined()){ + attribs->m_mouseControlScales.m_rotate *= mouseControlMultiplierNode["rotate"].as(); + } + if (mouseControlMultiplierNode["scroll"].IsDefined()){ + attribs->m_mouseControlScales.m_scroll *= mouseControlMultiplierNode["scroll"].as(); + } + if (mouseControlMultiplierNode["arcball"].IsDefined()){ + attribs->m_mouseControlScales.m_arcball *= mouseControlMultiplierNode["arcball"].as(); + } + } + return valid; } diff --git a/ambf_framework/afAttributes.h b/ambf_framework/afAttributes.h index 1acdce0ba..bc527b73c 100644 --- a/ambf_framework/afAttributes.h +++ b/ambf_framework/afAttributes.h @@ -533,6 +533,21 @@ struct afNoiseModelAttribs{ double m_bias; }; +struct afMouseControlScales{ +public: + afMouseControlScales(){ + m_pan = 0.01; + m_rotate = 0.3; + m_arcball = 0.03; + m_scroll = 0.1; + } + + double m_pan; + double m_rotate; + double m_scroll; + double m_arcball; +}; + /// /// \brief The afCameraAttributes struct /// @@ -576,6 +591,7 @@ struct afCameraAttributes: public afBaseObjectAttributes uint m_publishDepthInterval; afShaderAttributes m_preProcessShaderAttribs; afShaderAttributes m_depthComputeShaderAttribs; + afMouseControlScales m_mouseControlScales; bool m_multiPass; afImageResolutionAttribs m_publishImageResolution; diff --git a/ambf_framework/afFramework.cpp b/ambf_framework/afFramework.cpp index 04dd0a57f..0ad0300b2 100644 --- a/ambf_framework/afFramework.cpp +++ b/ambf_framework/afFramework.cpp @@ -6443,6 +6443,8 @@ bool afCamera::createFromAttribs(afCameraAttributes *a_attribs) setVisibleFlag(a_attribs->m_visible); + m_mouseControlScales = a_attribs->m_mouseControlScales; + // a_attribs->m_visible; createWindow(); diff --git a/ambf_framework/afFramework.h b/ambf_framework/afFramework.h index 30a8b76a9..a764aedeb 100644 --- a/ambf_framework/afFramework.h +++ b/ambf_framework/afFramework.h @@ -1915,6 +1915,9 @@ class afCamera: public afBaseObject{ public: bool m_cam_pressed; + + afMouseControlScales m_mouseControlScales; + GLFWwindow* m_window; static GLFWwindow* s_mainWindow; diff --git a/ambf_simulator/src/ambf_simulator.cpp b/ambf_simulator/src/ambf_simulator.cpp index 1b235d177..f18f73f1d 100644 --- a/ambf_simulator/src/ambf_simulator.cpp +++ b/ambf_simulator/src/ambf_simulator.cpp @@ -1442,12 +1442,9 @@ void mouseBtnsCallback(GLFWwindow* a_window, int a_button, int a_clicked, int a_ void mousePosCallback(GLFWwindow* a_window, double a_xpos, double a_ypos){ afCameraPtr cameraPtr = g_afWorld->getAssociatedCamera(a_window); if (cameraPtr != nullptr){ - int state = glfwGetKey(a_window, GLFW_KEY_LEFT_CONTROL); - double speed_scale = 1.0; - if (state == GLFW_PRESS) - { - speed_scale = 0.1; - } + + double scale_shift = (glfwGetKey(a_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) ? 0.1 : 1.0; + cameraPtr->mouse_x[1] = cameraPtr->mouse_x[0]; cameraPtr->mouse_x[0] = a_xpos; cameraPtr->mouse_y[1] = cameraPtr->mouse_y[0]; @@ -1461,9 +1458,8 @@ void mousePosCallback(GLFWwindow* a_window, double a_xpos, double a_ypos){ g_pickTo = rayTo; } else{ - double scale = 0.01; - double x_vel = speed_scale * scale * ( cameraPtr->mouse_x[0] - cameraPtr->mouse_x[1]); - double y_vel = speed_scale * scale * ( cameraPtr->mouse_y[0] - cameraPtr->mouse_y[1]); + double x_vel = scale_shift * cameraPtr->m_mouseControlScales.m_pan * ( cameraPtr->mouse_x[0] - cameraPtr->mouse_x[1]); + double y_vel = scale_shift * cameraPtr->m_mouseControlScales.m_pan * ( cameraPtr->mouse_y[0] - cameraPtr->mouse_y[1]); if (g_mouse_inverted_y){ y_vel = -y_vel; } @@ -1475,9 +1471,8 @@ void mousePosCallback(GLFWwindow* a_window, double a_xpos, double a_ypos){ if( cameraPtr->mouse_r_clicked ){ cMatrix3d camRot; - double scale = 0.3; - double yawVel = speed_scale * scale * ( cameraPtr->mouse_x[0] - cameraPtr->mouse_x[1]); // Yaw - double pitchVel = speed_scale * scale * ( cameraPtr->mouse_y[0] - cameraPtr->mouse_y[1]); // Pitch + double yawVel = scale_shift * cameraPtr->m_mouseControlScales.m_rotate * ( cameraPtr->mouse_x[0] - cameraPtr->mouse_x[1]); // Yaw + double pitchVel = scale_shift * cameraPtr->m_mouseControlScales.m_rotate * ( cameraPtr->mouse_y[0] - cameraPtr->mouse_y[1]); // Pitch if (g_mouse_inverted_y){ pitchVel = -pitchVel; } @@ -1501,9 +1496,8 @@ void mousePosCallback(GLFWwindow* a_window, double a_xpos, double a_ypos){ if( cameraPtr->mouse_scroll_clicked){ // devCam->showTargetPos(true); - double scale = 0.03; - double horizontalVel = speed_scale * scale * ( cameraPtr->mouse_x[0] - cameraPtr->mouse_x[1]); - double verticalVel = speed_scale * scale * ( cameraPtr->mouse_y[0] - cameraPtr->mouse_y[1]); + double horizontalVel = scale_shift * cameraPtr->m_mouseControlScales.m_arcball * ( cameraPtr->mouse_x[0] - cameraPtr->mouse_x[1]); + double verticalVel = scale_shift * cameraPtr->m_mouseControlScales.m_arcball * ( cameraPtr->mouse_y[0] - cameraPtr->mouse_y[1]); if (g_mouse_inverted_y){ verticalVel = -verticalVel; } @@ -1547,18 +1541,13 @@ void mousePosCallback(GLFWwindow* a_window, double a_xpos, double a_ypos){ void mouseScrollCallback(GLFWwindow *a_window, double a_xpos, double a_ypos){ afCameraPtr cameraPtr = g_afWorld->getAssociatedCamera(a_window); if (cameraPtr != nullptr){ - int state = glfwGetKey(a_window, GLFW_KEY_LEFT_SHIFT); - double speed_scale = 1.0; - if (state == GLFW_PRESS) - { - speed_scale = 0.1; - } + + double scale_shift = (glfwGetKey(a_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) ? 0.1 : 1.0; cameraPtr->mouse_scroll[1] = cameraPtr->mouse_scroll[0]; cameraPtr->mouse_scroll[0] = -a_ypos; - double scale = 0.1; - cVector3d camVelAlongLook(speed_scale * scale * cameraPtr->mouse_scroll[0], 0, 0); + cVector3d camVelAlongLook(scale_shift * cameraPtr->m_mouseControlScales.m_scroll * cameraPtr->mouse_scroll[0], 0, 0); cVector3d newTargetPos = cameraPtr->getTargetPosLocal(); cVector3d newPos = cameraPtr->getLocalTransform() * camVelAlongLook; cVector3d dPos = newPos - newTargetPos; @@ -1567,7 +1556,9 @@ void mouseScrollCallback(GLFWwindow *a_window, double a_xpos, double a_ypos){ } if (cameraPtr->isOrthographic()){ - cameraPtr->getInternalCamera()->setOrthographicView(cameraPtr->getInternalCamera()->getOrthographicViewWidth() + (speed_scale * scale * cameraPtr->mouse_scroll[0])); + cameraPtr->getInternalCamera()->setOrthographicView( + cameraPtr->getInternalCamera()->getOrthographicViewWidth() + + (scale_shift * cameraPtr->m_mouseControlScales.m_scroll * cameraPtr->mouse_scroll[0])); cameraPtr->setLocalPos( cameraPtr->getLocalTransform() * camVelAlongLook ); } else{