void BallController::onMouseDown(std::vector <Ball>& balls, float mouseX, float mouseY) { for (size_t i = 0; i < balls.size(); i++) { // Check if the mouse is hovering over a ball if (isMouseOnBall(balls[i], mouseX, mouseY)) { m_grabbedBall = i; // BE AWARE, if you change the order of the balls in the vector, this becomes invalid! m_grabOffset = glm::vec2(mouseX, mouseY) - balls[i].position; m_prevPos = balls[i].position; balls[i].velocity = glm::vec2(0.0f); } } }
void BallController::onMouseDown(std::vector<Ball>& balls, float mouseX, float mouseY) { for (int i = 0; i < balls.size(); i++) { if (isMouseOnBall(balls[i], mouseX, mouseY)) { _grabbedBall = i; _gradOffset = glm::vec2(mouseX, mouseY) - balls[i].position; _prePos = balls[i].position; balls[i].velocity = glm::vec2(0.0f); break; } } }