Skip to content

Commit

Permalink
Merge pull request #198 from ABRG-Models/issue/194/ortho_scrollwheel
Browse files Browse the repository at this point in the history
Issue/194/ortho scrollwheel
  • Loading branch information
sebjameswml authored Jun 13, 2024
2 parents 8521708 + 0a710d8 commit 9057191
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
8 changes: 8 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ if(ARMADILLO_FOUND)
target_link_libraries(grid_simple GLEW::GLEW)
endif()

# grid_simple, but orthographic view is the default
add_executable(grid_ortho grid_simple.cpp)
target_compile_definitions(grid_ortho PUBLIC ORTHOGRAPHIC=1)
target_link_libraries(grid_ortho OpenGL::GL glfw Freetype::Freetype)
if(USE_GLEW)
target_link_libraries(grid_ortho GLEW::GLEW)
endif()

add_executable(grid_image grid_image.cpp)
target_link_libraries(grid_image OpenGL::GL glfw Freetype::Freetype)
if(USE_GLEW)
Expand Down
5 changes: 5 additions & 0 deletions examples/grid_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ int main()
{
morph::Visual v(1600, 1000, "morph::GridVisual");

#ifdef ORTHOGRAPHIC
// Here's how to set your Visual to do an orthographic projection rather than perspective
v.ptype = morph::perspective_type::orthographic;
#endif

// Create a grid to show in the scene
constexpr unsigned int Nside = 100;
constexpr morph::vec<float, 2> grid_spacing = {0.01f, 0.01f};
Expand Down
33 changes: 22 additions & 11 deletions morph/Visual.h
Original file line number Diff line number Diff line change
Expand Up @@ -1543,18 +1543,29 @@ namespace morph {

if (this->sceneLocked) { return false; }

// xoffset does what mouse drag left/right in rotateModMode does (L/R scene trans)
this->scenetrans[0] -= xoffset * this->scenetrans_stepsize;
this->cyl_cam_pos[0] += xoffset * this->scenetrans_stepsize;

// yoffset does the 'in-out zooming'
morph::vec<float, 4> scroll_move_y = { 0.0f, static_cast<float>(yoffset) * this->scenetrans_stepsize, 0.0f, 1.0f };
this->scenetrans[2] += scroll_move_y[1];
// Translate scroll_move_y then add it to cyl_cam_pos here
morph::TransformMatrix<float> sceneview_rotn;
sceneview_rotn.rotate (this->rotation);
this->cyl_cam_pos += sceneview_rotn * scroll_move_y;
if (this->ptype == perspective_type::orthographic) {
// In orthographic, the wheel should scale ortho_lb and ortho_rt
morph::vec<float, 2> _lb = this->ortho_lb + (yoffset * this->scenetrans_stepsize);
morph::vec<float, 2> _rt = this->ortho_rt - (yoffset * this->scenetrans_stepsize);
if (_lb < 0.0f && _rt > 0.0f) {
this->ortho_lb = _lb;
this->ortho_rt = _rt;
}

} else { // perspective_type::perspective or perspective_type::cylindrical

// xoffset does what mouse drag left/right in rotateModMode does (L/R scene trans)
this->scenetrans[0] -= xoffset * this->scenetrans_stepsize;
this->cyl_cam_pos[0] += xoffset * this->scenetrans_stepsize;

// yoffset does the 'in-out zooming'
morph::vec<float, 4> scroll_move_y = { 0.0f, static_cast<float>(yoffset) * this->scenetrans_stepsize, 0.0f, 1.0f };
this->scenetrans[2] += scroll_move_y[1];
// Translate scroll_move_y then add it to cyl_cam_pos here
morph::TransformMatrix<float> sceneview_rotn;
sceneview_rotn.rotate (this->rotation);
this->cyl_cam_pos += sceneview_rotn * scroll_move_y;
}
return true; // needs_render
}

Expand Down

0 comments on commit 9057191

Please sign in to comment.