问题描述:鼠标左键down,鼠标move,释放鼠标,左键UP,在这一系列过程中,我记录下了鼠标移动的每个点的坐标。怎样通过这些坐标来精确的判断出,鼠标是顺时针移动的还是逆时针移动的?各位同志给点好的思路啊。我自己实现了一个,但效果不是特别好。期待各位的答案。

解决方案 »

  1.   


    #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__
      

  2.   


    #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;
    }
    }