#include <iostream>
using namespace std;
struct POINT {
int x;
int y;
};
//マウスカーソルが時計回り(正)か反時計回り(負)かの判定
int mouseConvexity(POINT* mousePoints, POINT pt, int threshold, int& s_count, int& s_prev)
{
if ( ++s_count % 4 ) //点の採取・判断は毎回やると不安定になる "4" は要調整
return 0;
int d = (mousePoints[1].x - mousePoints[0].x) * (pt.y - mousePoints[1].y) -
(mousePoints[1].y - mousePoints[0].y) * (pt.x - mousePoints[1].x);
mousePoints[0] = mousePoints[1];
mousePoints[1] = pt;
if ( std::abs(d) < std::abs(threshold) ) //はっきりしないカーブは前回値を返す
return s_prev;
return s_prev = d;
}
int main() {
//.............
static POINT s_mousePoints[2] = {{0,0},{0,0}};
static int s_count = 0;
static int s_prev = 0;
//case WM_MOUSEMOVE: // マウスカーソルが移動したとき
POINT mouseEnd;
//.............
int d = mouseConvexity(s_mousePoints, mouseEnd, 10, s_count, s_prev); //"10" は要調整
//0 < d なら時計回り、d < 0 なら反時計回り
//.............
//break;
//.............
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IFBPSU5UCXsKCWludCB4OwoJaW50IHk7Cn07CgovL+ODnuOCpuOCueOCq+ODvOOCveODq+OBjOaZguioiOWbnuOCiu+8iOato++8ieOBi+WPjeaZguioiOWbnuOCiu+8iOiyoO+8ieOBi+OBruWIpOWumgppbnQgbW91c2VDb252ZXhpdHkoUE9JTlQqIG1vdXNlUG9pbnRzLCBQT0lOVCBwdCwgaW50IHRocmVzaG9sZCwgaW50JiBzX2NvdW50LCBpbnQmIHNfcHJldikKewoJaWYgKCArK3NfY291bnQgJSA0ICkJLy/ngrnjga7mjqHlj5bjg7vliKTmlq3jga/mr47lm57jgoTjgovjgajkuI3lronlrprjgavjgarjgovjgIAiNCIg44Gv6KaB6Kq/5pW0CgkJcmV0dXJuIDA7CglpbnQgZCA9IChtb3VzZVBvaW50c1sxXS54IC0gbW91c2VQb2ludHNbMF0ue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