鼠标移动轨迹判定 问题描述:鼠标左键down,鼠标move,释放鼠标,左键UP,在这一系列过程中,我记录下了鼠标移动的每个点的坐标。怎样通过这些坐标来精确的判断出,鼠标是顺时针移动的还是逆时针移动的?各位同志给点好的思路啊。我自己实现了一个,但效果不是特别好。期待各位的答案。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #ifndef JUDGEDIRECTION_H__#define JUDGEDIRECTION_H__#include <Windows.h>#include <vector>typedef enum {CLOCKWISE=0,COUNTER_CLOCKWISE,ERROR_DIRECTION} MouseMoveDirection;class CMouseMoveDirection{public: CMouseMoveDirection(); MouseMoveDirection GetMouseMoveDirection(const std::vector<POINT>& pPoint,int nNumOfPoints,int nAccuracy=1);private: bool IsClockwise(); bool IsCounterClockwise(); void FindTopBottomLeftRightPoint();private: int m_nNumOfPoints; int m_nAccuracy; PPOINT m_pOriginalPoint; int m_nIndexOfToppestPoint; int m_nIndexOfBottomestPoint; int m_nIndexOfLeftestPoint; int m_nIndexOfRightestPoint;};#endif//JUDGEDIRECTION_H__ #include "stdafx.h"#include "JudgeDirection.h"CMouseMoveDirection::CMouseMoveDirection(){ m_nNumOfPoints = 0; m_nAccuracy = 0; m_pOriginalPoint = NULL; m_nIndexOfToppestPoint = 0; m_nIndexOfBottomestPoint = 0; m_nIndexOfLeftestPoint = 0; m_nIndexOfRightestPoint = 0;}bool CMouseMoveDirection::IsClockwise(){ if ((m_nIndexOfLeftestPoint<m_nIndexOfToppestPoint) &&(m_nIndexOfToppestPoint<m_nIndexOfRightestPoint)) { return true; }else if ((m_nIndexOfBottomestPoint<m_nIndexOfLeftestPoint)&& (m_nIndexOfLeftestPoint<m_nIndexOfToppestPoint)) { return true; }else if((m_nIndexOfRightestPoint<m_nIndexOfBottomestPoint)&& (m_nIndexOfBottomestPoint<m_nIndexOfLeftestPoint)) { return true; }else if ((m_nIndexOfToppestPoint<m_nIndexOfRightestPoint)&& (m_nIndexOfRightestPoint<m_nIndexOfBottomestPoint)) { return true; }else { return false; }}bool CMouseMoveDirection::IsCounterClockwise(){ if ((m_nIndexOfLeftestPoint<m_nIndexOfBottomestPoint)&& (m_nIndexOfBottomestPoint<m_nIndexOfRightestPoint)) { return true; } else if ((m_nIndexOfBottomestPoint<m_nIndexOfRightestPoint)&& m_nIndexOfRightestPoint<m_nIndexOfToppestPoint) { return true; } else if (m_nIndexOfRightestPoint<m_nIndexOfToppestPoint &&m_nIndexOfToppestPoint<m_nIndexOfLeftestPoint) { return true; } else if ((m_nIndexOfToppestPoint<m_nIndexOfLeftestPoint) &&(m_nIndexOfLeftestPoint<m_nIndexOfBottomestPoint)) { return true; } else { return false; }}void CMouseMoveDirection::FindTopBottomLeftRightPoint(){ POINT TempTopPoint,TempBottomPoint,TempLeftPoint,TempRightPoint; TempTopPoint = *m_pOriginalPoint; TempBottomPoint = *m_pOriginalPoint; TempLeftPoint = *m_pOriginalPoint; TempRightPoint = *m_pOriginalPoint; PPOINT pPoint = m_pOriginalPoint; int nNum = m_nNumOfPoints -10; for (int i=0;i<nNum;i+=m_nAccuracy,pPoint+=m_nAccuracy) { if (pPoint->y<TempTopPoint.y) { TempTopPoint.y = pPoint->y; TempTopPoint.x = pPoint->x; m_nIndexOfToppestPoint = i; } if (pPoint->y>TempBottomPoint.y) { TempBottomPoint.y = pPoint->y; TempBottomPoint.x = pPoint->x; m_nIndexOfBottomestPoint = i; } if (pPoint->x<TempLeftPoint.x) { TempLeftPoint.x = pPoint->x; TempLeftPoint.y = pPoint->y; m_nIndexOfLeftestPoint = i; } if (pPoint->x>TempRightPoint.x) { TempRightPoint.x = pPoint->x; TempRightPoint.y = pPoint->y; m_nIndexOfRightestPoint = i; } }}MouseMoveDirection CMouseMoveDirection::GetMouseMoveDirection(const std::vector<POINT>& pPoint,int nNumOfPoints,int nAccuracy/* =1 */){ if (pPoint.size()<10) { return ERROR_DIRECTION; } m_nNumOfPoints = nNumOfPoints; m_nAccuracy = nAccuracy; m_pOriginalPoint = (PPOINT)&pPoint[0]; FindTopBottomLeftRightPoint(); if (IsClockwise()) { return CLOCKWISE; } else if (IsCounterClockwise()) { return COUNTER_CLOCKWISE; } else { return ERROR_DIRECTION; }} 自由曲线怎么实现重绘 求助:帮忙下载万方资料!!! 求助:mfc程序如何注册自己运行需要但尚未注册的ocx? 有谁看过FileZilla源代码的 求救:xml查找结点,为何不支持contains?不支持setProperty? VC中换数据源的问题 请问怎么样在自己的BLOG中发表文章和修改? 怎样模拟发送水平滚动条的SB_LINELEFT消息?谢谢先。 急救!!文本框内容更新问题 祝大家又顺利过了一年! 请问怎么在程序内部注册 ODBC ? 请问这个操作用VC可以实现吗?
#ifndef JUDGEDIRECTION_H__
#define JUDGEDIRECTION_H__
#include <Windows.h>
#include <vector>
typedef enum {CLOCKWISE=0,COUNTER_CLOCKWISE,ERROR_DIRECTION} MouseMoveDirection;class CMouseMoveDirection
{
public:
CMouseMoveDirection();
MouseMoveDirection GetMouseMoveDirection(const std::vector<POINT>& pPoint,int nNumOfPoints,int nAccuracy=1);
private:
bool IsClockwise();
bool IsCounterClockwise();
void FindTopBottomLeftRightPoint();
private:
int m_nNumOfPoints;
int m_nAccuracy;
PPOINT m_pOriginalPoint;
int m_nIndexOfToppestPoint;
int m_nIndexOfBottomestPoint;
int m_nIndexOfLeftestPoint;
int m_nIndexOfRightestPoint;
};#endif//JUDGEDIRECTION_H__
#include "stdafx.h"
#include "JudgeDirection.h"CMouseMoveDirection::CMouseMoveDirection()
{
m_nNumOfPoints = 0;
m_nAccuracy = 0;
m_pOriginalPoint = NULL;
m_nIndexOfToppestPoint = 0;
m_nIndexOfBottomestPoint = 0;
m_nIndexOfLeftestPoint = 0;
m_nIndexOfRightestPoint = 0;
}bool CMouseMoveDirection::IsClockwise()
{
if ((m_nIndexOfLeftestPoint<m_nIndexOfToppestPoint)
&&(m_nIndexOfToppestPoint<m_nIndexOfRightestPoint))
{
return true;
}else if ((m_nIndexOfBottomestPoint<m_nIndexOfLeftestPoint)&&
(m_nIndexOfLeftestPoint<m_nIndexOfToppestPoint))
{
return true;
}else if((m_nIndexOfRightestPoint<m_nIndexOfBottomestPoint)&&
(m_nIndexOfBottomestPoint<m_nIndexOfLeftestPoint))
{
return true;
}else if ((m_nIndexOfToppestPoint<m_nIndexOfRightestPoint)&&
(m_nIndexOfRightestPoint<m_nIndexOfBottomestPoint))
{
return true;
}else
{
return false;
}
}bool CMouseMoveDirection::IsCounterClockwise()
{
if ((m_nIndexOfLeftestPoint<m_nIndexOfBottomestPoint)&&
(m_nIndexOfBottomestPoint<m_nIndexOfRightestPoint))
{
return true;
} else if ((m_nIndexOfBottomestPoint<m_nIndexOfRightestPoint)&&
m_nIndexOfRightestPoint<m_nIndexOfToppestPoint)
{
return true;
} else if (m_nIndexOfRightestPoint<m_nIndexOfToppestPoint
&&m_nIndexOfToppestPoint<m_nIndexOfLeftestPoint)
{
return true;
} else if ((m_nIndexOfToppestPoint<m_nIndexOfLeftestPoint)
&&(m_nIndexOfLeftestPoint<m_nIndexOfBottomestPoint))
{
return true;
} else
{
return false;
}
}
void CMouseMoveDirection::FindTopBottomLeftRightPoint()
{
POINT TempTopPoint,TempBottomPoint,TempLeftPoint,TempRightPoint;
TempTopPoint = *m_pOriginalPoint;
TempBottomPoint = *m_pOriginalPoint;
TempLeftPoint = *m_pOriginalPoint;
TempRightPoint = *m_pOriginalPoint;
PPOINT pPoint = m_pOriginalPoint;
int nNum = m_nNumOfPoints -10;
for (int i=0;i<nNum;i+=m_nAccuracy,pPoint+=m_nAccuracy)
{
if (pPoint->y<TempTopPoint.y)
{
TempTopPoint.y = pPoint->y;
TempTopPoint.x = pPoint->x;
m_nIndexOfToppestPoint = i;
}
if (pPoint->y>TempBottomPoint.y)
{
TempBottomPoint.y = pPoint->y;
TempBottomPoint.x = pPoint->x;
m_nIndexOfBottomestPoint = i;
}
if (pPoint->x<TempLeftPoint.x)
{
TempLeftPoint.x = pPoint->x;
TempLeftPoint.y = pPoint->y;
m_nIndexOfLeftestPoint = i;
}
if (pPoint->x>TempRightPoint.x)
{
TempRightPoint.x = pPoint->x;
TempRightPoint.y = pPoint->y;
m_nIndexOfRightestPoint = i;
}
}
}MouseMoveDirection CMouseMoveDirection::GetMouseMoveDirection(const std::vector<POINT>& pPoint,int nNumOfPoints,int nAccuracy/* =1 */)
{
if (pPoint.size()<10)
{
return ERROR_DIRECTION;
} m_nNumOfPoints = nNumOfPoints;
m_nAccuracy = nAccuracy;
m_pOriginalPoint = (PPOINT)&pPoint[0]; FindTopBottomLeftRightPoint(); if (IsClockwise())
{
return CLOCKWISE;
}
else if (IsCounterClockwise())
{
return COUNTER_CLOCKWISE;
}
else
{
return ERROR_DIRECTION;
}
}