Six degrees of freedom camera - 1st installment

This commit is contained in:
Enrico Turri 2020-01-15 12:49:34 +01:00
parent 536514ff03
commit 62e60bcb43
8 changed files with 245 additions and 2 deletions

View file

@ -1792,8 +1792,14 @@ void GLCanvas3D::zoom_to_selection()
void GLCanvas3D::select_view(const std::string& direction)
{
#if ENABLE_6DOF_CAMERA
m_camera.select_view(direction);
if (m_canvas != nullptr)
m_canvas->Refresh();
#else
if (m_camera.select_view(direction) && (m_canvas != nullptr))
m_canvas->Refresh();
#endif // ENABLE_6DOF_CAMERA
}
void GLCanvas3D::update_volumes_colors_by_extruder()
@ -1850,10 +1856,12 @@ void GLCanvas3D::render()
GLfloat position_top[4] = { -0.5f, -0.5f, 1.0f, 0.0f };
glsafe(::glLightfv(GL_LIGHT0, GL_POSITION, position_top));
#if !ENABLE_6DOF_CAMERA
float theta = m_camera.get_theta();
if (theta > 180.f)
// absolute value of the rotation
theta = 360.f - theta;
#endif // !ENABLE_6DOF_CAMERA
wxGetApp().imgui()->new_frame();
@ -1878,7 +1886,11 @@ void GLCanvas3D::render()
_render_objects();
_render_sla_slices();
_render_selection();
#if ENABLE_6DOF_CAMERA
_render_bed(!m_camera.is_looking_downward(), true);
#else
_render_bed(theta, true);
#endif // ENABLE_6DOF_CAMERA
#if ENABLE_RENDER_SELECTION_CENTER
_render_selection_center();
@ -3213,7 +3225,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// we do not want to translate objects if the user just clicked on an object while pressing shift to remove it from the selection and then drag
if (m_selection.contains_volume(get_first_hover_volume_idx()))
{
#if ENABLE_6DOF_CAMERA
if (std::abs(m_camera.get_dir_forward()(2)) < EPSILON)
#else
if (m_camera.get_theta() == 90.0f)
#endif // ENABLE_6DOF_CAMERA
{
// side view -> move selected volumes orthogonally to camera view direction
Linef3 ray = mouse_ray(pos);
@ -3273,9 +3289,15 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
if (m_hover_volume_idxs.empty() && m_mouse.is_start_position_3D_defined())
{
const Vec3d& orig = m_mouse.drag.start_position_3D;
#if ENABLE_6DOF_CAMERA
m_camera.rotate_on_sphere(Geometry::deg2rad((pos(0) - orig(0))* (double)TRACKBALLSIZE),
Geometry::deg2rad((pos(1) - orig(1))* (double)TRACKBALLSIZE),
wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA);
#else
float sign = m_camera.inverted_phi ? -1.0f : 1.0f;
m_camera.phi += sign * ((float)pos(0) - (float)orig(0)) * TRACKBALLSIZE;
m_camera.set_theta(m_camera.get_theta() - ((float)pos(1) - (float)orig(1)) * TRACKBALLSIZE, wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA);
#endif // ENABLE_6DOF_CAMERA
m_dirty = true;
}
m_mouse.drag.start_position_3D = Vec3d((double)pos(0), (double)pos(1), 0.0);
@ -3325,9 +3347,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
if (!evt.ShiftDown() && m_picking_enabled)
deselect_all();
}
#if !ENABLE_6DOF_CAMERA
else if (evt.LeftUp() && m_mouse.dragging)
// Flips X mouse deltas if bed is upside down
m_camera.inverted_phi = (m_camera.get_dir_up()(2) < 0.0);
#endif // !ENABLE_6DOF_CAMERA
else if (evt.RightUp())
{
m_mouse.position = pos.cast<double>();
@ -3932,6 +3956,9 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
Camera camera;
camera.set_type(Camera::Ortho);
#if ENABLE_6DOF_CAMERA
camera.set_scene_box(scene_bounding_box());
#endif // ENABLE_6DOF_CAMERA
camera.zoom_to_volumes(visible_volumes, thumbnail_data.width, thumbnail_data.height);
camera.apply_viewport(0, 0, thumbnail_data.width, thumbnail_data.height);
camera.apply_view_matrix();
@ -3982,7 +4009,11 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
glsafe(::glDisable(GL_DEPTH_TEST));
if (show_bed)
#if ENABLE_6DOF_CAMERA
_render_bed(!camera.is_looking_downward(), false);
#else
_render_bed(camera.get_theta(), false);
#endif // ENABLE_6DOF_CAMERA
if (transparent_background)
glsafe(::glClearColor(1.0f, 1.0f, 1.0f, 1.0f));