Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cppvolrend/app_freeglut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions cppvolrend/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions cppvolrend/renderingmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
23 changes: 22 additions & 1 deletion libs/vis_utils/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions libs/vis_utils/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -165,6 +166,7 @@ namespace vis
float radius;
float speed;
float speed_radius;
float speed_zoom = 50.0f;

float min_radius;
float max_radius;
Expand Down