Skip to content

Commit

Permalink
Mouse control multipliers fix (#226)
Browse files Browse the repository at this point in the history
* Remove the mouse pick sphere and replace with constant size points

* Added feature to set mouse control multipliers
  • Loading branch information
adnanmunawar authored Jan 25, 2024
1 parent 2705241 commit f85f44b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
16 changes: 16 additions & 0 deletions adf_loader/version_1_0/adf_loader_1_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1365,6 +1366,21 @@ bool ADFLoader_1_0::loadCameraAttribs(YAML::Node *a_node, afCameraAttributes *at
attribs->m_multiPass = multiPassNode.as<bool>();
}

if (mouseControlMultiplierNode.IsDefined()){
if (mouseControlMultiplierNode["pan"].IsDefined()){
attribs->m_mouseControlScales.m_pan *= mouseControlMultiplierNode["pan"].as<double>();
}
if (mouseControlMultiplierNode["rotate"].IsDefined()){
attribs->m_mouseControlScales.m_rotate *= mouseControlMultiplierNode["rotate"].as<double>();
}
if (mouseControlMultiplierNode["scroll"].IsDefined()){
attribs->m_mouseControlScales.m_scroll *= mouseControlMultiplierNode["scroll"].as<double>();
}
if (mouseControlMultiplierNode["arcball"].IsDefined()){
attribs->m_mouseControlScales.m_arcball *= mouseControlMultiplierNode["arcball"].as<double>();
}
}

return valid;
}

Expand Down
16 changes: 16 additions & 0 deletions ambf_framework/afAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ambf_framework/afFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions ambf_framework/afFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,9 @@ class afCamera: public afBaseObject{

public:
bool m_cam_pressed;

afMouseControlScales m_mouseControlScales;

GLFWwindow* m_window;

static GLFWwindow* s_mainWindow;
Expand Down
39 changes: 15 additions & 24 deletions ambf_simulator/src/ambf_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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{
Expand Down

0 comments on commit f85f44b

Please sign in to comment.