Fixed object picking when gizmos are rendered on top
This commit is contained in:
parent
08511bfe8b
commit
ed271d66e6
@ -1103,6 +1103,9 @@ GLCanvas3D::Mouse::Drag::Drag()
|
|||||||
GLCanvas3D::Mouse::Mouse()
|
GLCanvas3D::Mouse::Mouse()
|
||||||
: dragging(false)
|
: dragging(false)
|
||||||
, position(DBL_MAX, DBL_MAX)
|
, position(DBL_MAX, DBL_MAX)
|
||||||
|
#if ENABLE_GIZMOS_ON_TOP
|
||||||
|
, scene_position(DBL_MAX, DBL_MAX, DBL_MAX)
|
||||||
|
#endif // ENABLE_GIZMOS_ON_TOP
|
||||||
#if ENABLE_GIZMOS_RESET
|
#if ENABLE_GIZMOS_RESET
|
||||||
, ignore_up_event(false)
|
, ignore_up_event(false)
|
||||||
#endif // ENABLE_GIZMOS_RESET
|
#endif // ENABLE_GIZMOS_RESET
|
||||||
@ -3601,6 +3604,13 @@ void GLCanvas3D::render()
|
|||||||
_render_bed(theta);
|
_render_bed(theta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_GIZMOS_ON_TOP
|
||||||
|
// we need to set the mouse's scene position here because the depth buffer
|
||||||
|
// could be invalidated by the following gizmo render methods
|
||||||
|
// this position is used later into on_mouse() to drag the objects
|
||||||
|
m_mouse.scene_position = _mouse_to_3d(m_mouse.position.cast<int>());
|
||||||
|
#endif // ENABLE_GIZMOS_ON_TOP
|
||||||
|
|
||||||
_render_current_gizmo();
|
_render_current_gizmo();
|
||||||
_render_cutting_plane();
|
_render_cutting_plane();
|
||||||
#if ENABLE_SHOW_CAMERA_TARGET
|
#if ENABLE_SHOW_CAMERA_TARGET
|
||||||
@ -4176,19 +4186,29 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||||||
{
|
{
|
||||||
if (evt.LeftDown() && m_moving_enabled && (m_mouse.drag.move_volume_idx == -1))
|
if (evt.LeftDown() && m_moving_enabled && (m_mouse.drag.move_volume_idx == -1))
|
||||||
{
|
{
|
||||||
|
#if !ENABLE_GIZMOS_ON_TOP
|
||||||
// The mouse_to_3d gets the Z coordinate from the Z buffer at the screen coordinate pos x, y,
|
// The mouse_to_3d gets the Z coordinate from the Z buffer at the screen coordinate pos x, y,
|
||||||
// an converts the screen space coordinate to unscaled object space.
|
// an converts the screen space coordinate to unscaled object space.
|
||||||
Vec3d pos3d = _mouse_to_3d(pos);
|
Vec3d pos3d = _mouse_to_3d(pos);
|
||||||
|
#endif // !ENABLE_GIZMOS_ON_TOP
|
||||||
|
|
||||||
// Only accept the initial position, if it is inside the volume bounding box.
|
// Only accept the initial position, if it is inside the volume bounding box.
|
||||||
BoundingBoxf3 volume_bbox = m_volumes.volumes[m_hover_volume_id]->transformed_bounding_box();
|
BoundingBoxf3 volume_bbox = m_volumes.volumes[m_hover_volume_id]->transformed_bounding_box();
|
||||||
volume_bbox.offset(1.0);
|
volume_bbox.offset(1.0);
|
||||||
|
#if ENABLE_GIZMOS_ON_TOP
|
||||||
|
if (volume_bbox.contains(m_mouse.scene_position))
|
||||||
|
#else
|
||||||
if (volume_bbox.contains(pos3d))
|
if (volume_bbox.contains(pos3d))
|
||||||
|
#endif // ENABLE_GIZMOS_ON_TOP
|
||||||
{
|
{
|
||||||
// The dragging operation is initiated.
|
// The dragging operation is initiated.
|
||||||
m_mouse.drag.move_volume_idx = m_hover_volume_id;
|
m_mouse.drag.move_volume_idx = m_hover_volume_id;
|
||||||
m_selection.start_dragging();
|
m_selection.start_dragging();
|
||||||
|
#if ENABLE_GIZMOS_ON_TOP
|
||||||
|
m_mouse.drag.start_position_3D = m_mouse.scene_position;
|
||||||
|
#else
|
||||||
m_mouse.drag.start_position_3D = pos3d;
|
m_mouse.drag.start_position_3D = pos3d;
|
||||||
|
#endif // ENABLE_GIZMOS_ON_TOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (evt.RightDown())
|
else if (evt.RightDown())
|
||||||
|
@ -337,6 +337,9 @@ class GLCanvas3D
|
|||||||
|
|
||||||
bool dragging;
|
bool dragging;
|
||||||
Vec2d position;
|
Vec2d position;
|
||||||
|
#if ENABLE_GIZMOS_ON_TOP
|
||||||
|
Vec3d scene_position;
|
||||||
|
#endif // ENABLE_GIZMOS_ON_TOP
|
||||||
Drag drag;
|
Drag drag;
|
||||||
#if ENABLE_GIZMOS_RESET
|
#if ENABLE_GIZMOS_RESET
|
||||||
bool ignore_up_event;
|
bool ignore_up_event;
|
||||||
|
Loading…
Reference in New Issue
Block a user