fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct POINT {
  5. int x;
  6. int y;
  7. };
  8.  
  9. //マウスカーソルが時計回り(正)か反時計回り(負)かの判定
  10. int mouseConvexity(POINT* mousePoints, POINT pt, int threshold, int& s_count, int& s_prev)
  11. {
  12. if ( ++s_count % 4 ) //点の採取・判断は毎回やると不安定になる "4" は要調整
  13. return 0;
  14. int d = (mousePoints[1].x - mousePoints[0].x) * (pt.y - mousePoints[1].y) -
  15. (mousePoints[1].y - mousePoints[0].y) * (pt.x - mousePoints[1].x);
  16. mousePoints[0] = mousePoints[1];
  17. mousePoints[1] = pt;
  18. if ( std::abs(d) < std::abs(threshold) ) //はっきりしないカーブは前回値を返す
  19. return s_prev;
  20. return s_prev = d;
  21. }
  22.  
  23. int main() {
  24. //.............
  25. static POINT s_mousePoints[2] = {{0,0},{0,0}};
  26. static int s_count = 0;
  27. static int s_prev = 0;
  28. //case WM_MOUSEMOVE: // マウスカーソルが移動したとき
  29. POINT mouseEnd;
  30. //.............
  31. int d = mouseConvexity(s_mousePoints, mouseEnd, 10, s_count, s_prev); //"10" は要調整
  32. //0 < d なら時計回り、d < 0 なら反時計回り
  33. //.............
  34. //break;
  35. //.............
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty