diff --git a/cppvolrend/app_freeglut.cpp b/cppvolrend/app_freeglut.cpp index 7ae0ee0..f190af0 100644 --- a/cppvolrend/app_freeglut.cpp +++ b/cppvolrend/app_freeglut.cpp @@ -62,6 +62,8 @@ void ApplicationFreeGLUT::s_OnMotion (int x, int y) void ApplicationFreeGLUT::s_MouseWheel (int wheel, int direction, int x, int y) { + RenderingManager::Instance()->MouseWheel(wheel, direction, x, y); + // ImGui callback ImGui_ImplGLUT_MouseWheelFunc(wheel, direction, x, y); } diff --git a/cppvolrend/renderingmanager.cpp b/cppvolrend/renderingmanager.cpp index 173d60e..55654bb 100644 --- a/cppvolrend/renderingmanager.cpp +++ b/cppvolrend/renderingmanager.cpp @@ -369,6 +369,13 @@ void RenderingManager::MouseMotion (int x, int y) PostRedisplay(); } +void RenderingManager::MouseWheel(int wheel, int direction, int x, int y) +{ + curr_rdr_parameters.GetCamera()->MouseWheel(wheel, direction, x, y); + + PostRedisplay(); +} + void RenderingManager::CloseFunc () { gl::PipelineShader::Unbind(); diff --git a/cppvolrend/renderingmanager.h b/cppvolrend/renderingmanager.h index fd35e04..c1fc9a5 100644 --- a/cppvolrend/renderingmanager.h +++ b/cppvolrend/renderingmanager.h @@ -60,6 +60,8 @@ class RenderingManager void KeyboardUp (unsigned char key, int x, int y); void MouseButton (int bt, int st, int x, int y); void MouseMotion (int x, int y); + void MouseWheel(int wheel, int direction, int x, int y); + void CloseFunc (); void IdleFunc (); void PostRedisplay (); diff --git a/libs/vis_utils/camera.cpp b/libs/vis_utils/camera.cpp index 4bcbbab..75b4d87 100644 --- a/libs/vis_utils/camera.cpp +++ b/libs/vis_utils/camera.cpp @@ -81,6 +81,7 @@ namespace vis radius = 50; speed = 0.001f; speed_radius = 1.0f; + speed_zoom = 50.0f; min_radius = 0; max_radius = 1000; @@ -104,7 +105,8 @@ namespace vis radius = _radius; speed = 0.001f; speed_radius = 1.0f; - + speed_zoom = 50.0f; + min_radius = _min_rad; max_radius = _max_rad; @@ -236,6 +238,25 @@ namespace vis return 0; } + int Camera::MouseWheel(int wheel, int direction, int x, int y) + { + if (wheel == 0) { + radius += -direction * speed_zoom; + if (radius < min_radius) + radius = min_radius; + if (radius > max_radius) + radius = max_radius; + + glm::vec3 c_e = glm::normalize(glm::vec3(c_data.eye - c_data.center)); + + c_data.eye = c_e * radius; + + m_changing_camera = true; + return 1; + } + return 0; + } + float Camera::GetSpeedKeyboardMovement () { return speed_keyboard_movement; diff --git a/libs/vis_utils/camera.h b/libs/vis_utils/camera.h index e11bea5..4203a12 100644 --- a/libs/vis_utils/camera.h +++ b/libs/vis_utils/camera.h @@ -104,6 +104,7 @@ namespace vis bool KeyboardUp (unsigned char key, int x, int y); int MouseButton (int bt, int st, int x, int y); int MouseMotion (int x, int y); + int MouseWheel(int wheel, int direction, int x, int y); float GetSpeedKeyboardMovement (); void SetSpeedKeyboardMovement (float sskm); @@ -165,6 +166,7 @@ namespace vis float radius; float speed; float speed_radius; + float speed_zoom = 50.0f; float min_radius; float max_radius;