diff --git a/src/application.cpp b/src/application.cpp index 356946d..48d113a 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -189,9 +189,11 @@ void Application::render() { // We do this here rather than on mouse move, because some platforms generate // an excessive number of mouse move events which incurs a performance hit. if(pickDrawCountdown < 0) { - Vector2D p(mouseX, screenH - mouseY); - scene->getHoveredObject(p); - pickDrawCountdown += pickDrawInterval; + if (pickDrawFlag) { + updateHoveredObject(); + pickDrawCountdown += pickDrawInterval; + pickDrawFlag = false; + } } else { pickDrawCountdown--; } @@ -1213,10 +1215,7 @@ void Application::to_pose_action() { } void Application::mouse_pressed(e_mouse_button b) { - - Vector2D p(mouseX, screenH - mouseY); - scene->getHoveredObject(p); - + updateHoveredObject(); switch (b) { case LEFT: leftDown = true; @@ -1504,8 +1503,14 @@ void Application::mouse_moved(float x, float y) { // Vector2D p(x * 2 / screenW - 1, y * 2 / screenH - 1); Vector2D p(x, y); update_gl_camera(); + + pickDrawFlag = true; +} + +void Application::updateHoveredObject() { + Vector2D p(mouseX, screenH - mouseY); if (mode == MODEL_MODE) { - // scene->getHoveredObject(p); // Nick: This kills performance on some platforms which generate A LOT of mouse_moved events. + scene->getHoveredObject(p); } else if (mode == ANIMATE_MODE) { if (action == Action::Wave) { scene->getHoveredObject(p, true, true); diff --git a/src/application.h b/src/application.h index d172db6..3508e6a 100644 --- a/src/application.h +++ b/src/application.h @@ -222,6 +222,7 @@ class Application : public Renderer { // as an optimization. int pickDrawCountdown = 0; int pickDrawInterval = 5; + bool pickDrawFlag = false; // Event handling // void mouse_pressed(e_mouse_button b); // Mouse pressed. @@ -236,6 +237,8 @@ class Application : public Renderer { void dragSelection(float x, float y, float dx, float dy, const Matrix4x4& modelViewProj); + /* Update the object that is currently being hovered by the mouse */ + void updateHoveredObject(); /** * If the cursor is hovering over something, mark it as selected. */