Skip to content

Commit

Permalink
fix camera controls (zoom)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bvallon-sl committed May 17, 2021
1 parent bba06c2 commit 964fe15
Show file tree
Hide file tree
Showing 4 changed files with 680 additions and 677 deletions.
6 changes: 3 additions & 3 deletions depth sensing/cpp/include/GLViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#define M_PI 3.141592653f
#endif

#define MOUSE_R_SENSITIVITY 0.015f
#define MOUSE_UZ_SENSITIVITY 0.75f
#define MOUSE_R_SENSITIVITY 0.03f
#define MOUSE_UZ_SENSITIVITY 0.5f
#define MOUSE_DZ_SENSITIVITY 1.25f
#define MOUSE_T_SENSITIVITY 10.f
#define MOUSE_T_SENSITIVITY 0.05f
#define KEY_T_SENSITIVITY 0.1f


Expand Down
45 changes: 23 additions & 22 deletions depth sensing/cpp/src/GLViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ GLenum GLViewer::init(int argc, char **argv, sl::CameraParameters param) {

// Create the camera
camera_ = CameraGL(sl::Translation(0, 0, 0), sl::Translation(0, 0, -100));
camera_.setOffsetFromPosition(sl::Translation(0, 0, 5000));

frustum = createFrustum(param);
frustum.pushToGPU();
Expand Down Expand Up @@ -178,27 +177,29 @@ void GLViewer::update() {
return;
}

// Rotate camera with mouse
if (mouseButton_[MOUSE_BUTTON::LEFT]) {
camera_.rotate(sl::Rotation((float) mouseMotion_[1] * MOUSE_R_SENSITIVITY, camera_.getRight()));
camera_.rotate(sl::Rotation((float) mouseMotion_[0] * MOUSE_R_SENSITIVITY, camera_.getVertical() * -1.f));
}

// Translate camera with mouse
if (mouseButton_[MOUSE_BUTTON::RIGHT]) {
camera_.translate(camera_.getUp() * (float) mouseMotion_[1] * MOUSE_T_SENSITIVITY);
camera_.translate(camera_.getRight() * (float) mouseMotion_[0] * MOUSE_T_SENSITIVITY);
}

// Zoom in with mouse wheel
if (mouseWheelPosition_ != 0) {
float distance = sl::Translation(camera_.getOffsetFromPosition()).norm();
if (mouseWheelPosition_ > 0 && distance > camera_.getZNear()) { // zoom
camera_.setOffsetFromPosition(camera_.getOffsetFromPosition() * MOUSE_UZ_SENSITIVITY);
} else if (distance < camera_.getZFar()) {// unzoom
camera_.setOffsetFromPosition(camera_.getOffsetFromPosition() * MOUSE_DZ_SENSITIVITY);
}
}
// Rotate camera with mouse
if (mouseButton_[MOUSE_BUTTON::LEFT]) {
camera_.rotate(sl::Rotation((float)mouseMotion_[1] * MOUSE_R_SENSITIVITY, camera_.getRight()));
camera_.rotate(sl::Rotation((float)mouseMotion_[0] * MOUSE_R_SENSITIVITY, camera_.getVertical() * -1.f));
}

// Translate camera with mouse
if (mouseButton_[MOUSE_BUTTON::RIGHT]) {
camera_.translate(camera_.getUp() * (float)mouseMotion_[1] * MOUSE_T_SENSITIVITY * 1000);
camera_.translate(camera_.getRight() * (float)mouseMotion_[0] * MOUSE_T_SENSITIVITY * 1000);
}

// Zoom in with mouse wheel
if (mouseWheelPosition_ != 0) {
//float distance = sl::Translation(camera_.getOffsetFromPosition()).norm();
if (mouseWheelPosition_ > 0 /* && distance > camera_.getZNear()*/) { // zoom
camera_.translate(camera_.getForward() * MOUSE_UZ_SENSITIVITY * 1000 * -1);
}
else if (/*distance < camera_.getZFar()*/ mouseWheelPosition_ < 0) {// unzoom
//camera_.setOffsetFromPosition(camera_.getOffsetFromPosition() * MOUSE_DZ_SENSITIVITY);
camera_.translate(camera_.getForward() * MOUSE_UZ_SENSITIVITY * 1000);
}
}

// Update point cloud buffers
pointCloud_.mutexData.lock();
Expand Down
6 changes: 3 additions & 3 deletions object detection/birds eye viewer/cpp/include/GLViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#define M_PI 3.141592653f
#endif

#define MOUSE_R_SENSITIVITY 0.04f
#define MOUSE_UZ_SENSITIVITY 0.75f
#define MOUSE_R_SENSITIVITY 0.03f
#define MOUSE_UZ_SENSITIVITY 0.5f
#define MOUSE_DZ_SENSITIVITY 1.25f
#define MOUSE_T_SENSITIVITY 100.f
#define MOUSE_T_SENSITIVITY 0.05f
#define KEY_T_SENSITIVITY 0.1f

// Utils
Expand Down
Loading

0 comments on commit 964fe15

Please sign in to comment.