diff --git a/rendering/openglrenderer.cpp b/rendering/openglrenderer.cpp index 8c6debdc7..6f807d095 100644 --- a/rendering/openglrenderer.cpp +++ b/rendering/openglrenderer.cpp @@ -4288,7 +4288,8 @@ opengl_renderer::Update_Mouse_Position() { GLfloat pointdepth; ::glReadPixels( mousepos.x, mousepos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pointdepth ); - if( pointdepth < 1.0 ) { + m_mousehit = pointdepth < 1.0; + if( m_mousehit ) { m_worldmousecoordinates = glm::unProject( glm::vec3{ mousepos, pointdepth }, diff --git a/rendering/openglrenderer.h b/rendering/openglrenderer.h index 15c9e7cdb..681b2a98c 100644 --- a/rendering/openglrenderer.h +++ b/rendering/openglrenderer.h @@ -108,6 +108,8 @@ public: Forget_Node( scene::basic_node const *Node ) override; glm::dvec3 Mouse_Position() const override { return m_worldmousecoordinates; } + bool + Mouse_Hit() const override { return m_mousehit; } glm::mat4 Camera_View_Matrix() const override { return glm::mat4( glm::mat3( m_colorpass.camera.modelview() ) ); } glm::mat4 @@ -377,6 +379,7 @@ private: std::vector m_picksceneryitems; scene::basic_node *m_picksceneryitem { nullptr }; glm::vec3 m_worldmousecoordinates { 0.f }; + bool m_mousehit { false }; // the depth under the cursor was of something drawn, not of the far plane std::vector> m_control_pick_requests; std::vector> m_node_pick_requests; #ifdef EU07_USE_DEBUG_CAMERA diff --git a/rendering/renderer.h b/rendering/renderer.h index dec3f752e..897494a6d 100644 --- a/rendering/renderer.h +++ b/rendering/renderer.h @@ -111,7 +111,9 @@ public: } virtual auto Mouse_Position() const -> glm::dvec3 = 0; - virtual auto Mouse_Hit() const -> bool { return true; } + // whether the cursor was over something drawn when Mouse_Position() was read; a renderer which doesn't read it says no, + // so a caller never takes a stale or empty position for a hit + virtual auto Mouse_Hit() const -> bool { return false; } // editor helpers: matrices/position of the most recent color pass camera. // the view matrix is camera-relative (rotation only, camera at origin), matching the // camera-relative rendering used by the engine; build object matrices relative to Camera_Position().