-1

直截了当,我正在开发一个 dll,它只是读取鼠标坐标并将它们转换为旋转,然后转换为一些坐标,用于 fps 风格的相机。

问题是鼠标阅读器非常不敏感,如果我缓慢移动鼠标,它不会记录任何内容,但如果我移动它非常快,它会记录更改。

现在代码:

主文件

#define DLL_EXPORT
#define BOOST_THREAD_USE_DLL

#include "DLL\Viewport.h"
#include "MouseReader.h"
#include <boost\thread\thread.hpp>
#include <assert.h>

using namespace std;

#define PHI 3.141592653589

MouseListenerObject MouseListener;
double clax, clay, claz;
double Altitude, Azimuth;

bool IsActive;

static void CalcCLA_XYZ();
void FPSThread();

boost::thread *fpsstylethread;

void ViewportManagerObject::StartFPSStyle()
{
    IsActive = true;
    fpsstylethread = new boost::thread(&FPSThread);

    assert(fpsstylethread->joinable());
}

void ViewportManagerObject::StopFPSStyle()
{
    IsActive = false;
    fpsstylethread->detach();
}

void FPSThread()
{
    while(IsActive == true)
    {
        CalcCLA_XYZ();
    }
}

vector<double> ViewportManagerObject::ReturnCLA_XYZ()
{
    vector<double> returnval;
    returnval.insert(returnval.begin(), clax);
    returnval.insert(returnval.begin()+1, clay);
    returnval.insert(returnval.begin()+2, claz);

    return returnval;
}

void CalcCLA_XYZ()
{
    MouseListener.ReadMouse();

    vector<int> MouseCoordChange = MouseListener.Change;

    bool hasoperated = false;
    if (Azimuth + (MouseCoordChange[0] / 20) > 360)
    {
        Azimuth = (Azimuth + (MouseCoordChange[0] / 20)) - 360;
        hasoperated = true;
    }

    if (Azimuth + (MouseCoordChange[0] / 20) < 0)
    {
        Azimuth = (Azimuth + (MouseCoordChange[0] / 20)) + 360;
        hasoperated = true;
    }

    if (hasoperated == false)
    {
        Azimuth += (MouseCoordChange[0] / 20);
    }

    if (!((Altitude - (MouseCoordChange[1] / 20)) > 160) && !((Altitude - (MouseCoordChange[1] / 20)) < 5))
    {
        Altitude -= (MouseCoordChange[1] / 20);
    }

    clax = 1 * cos((Altitude/360)*(2*PHI)) * cos((Azimuth/360)*(2*PHI));
    clay = 1 * sin((Altitude/360)*(2*PHI));
    claz = 1 * cos((Altitude/360)*(2*PHI)) * sin((Azimuth/360)*(2*PHI));
}

鼠标阅读器.h

#ifndef MR_H
#define MR_H

#include <Windows.h>
#include <vector>

using namespace std;

class MouseListenerObject
{
    int newposx;
    int newposy;

    int oldposx;
    int oldposy;

    bool first;

public: vector<int> Change;

public: MouseListenerObject()
    {
        first = true;
    }

public: void ReadMouse()
    {
        POINT MousePoint;
        GetCursorPos(&MousePoint);

        if (first != false)
        {
            oldposx = MousePoint.x;
            oldposy = MousePoint.y;

            first = false;

            vector<int> nullvector;
            nullvector.insert(nullvector.begin(), 0);
            nullvector.insert(nullvector.begin() + 1, 0);
            Change = nullvector;

            return;
        }

        oldposx = newposx; // Lets make the previous values old...
        oldposy = newposy;

        newposx = MousePoint.x; // Update the new ones.
        newposy = MousePoint.y;

        int changex, changey; // Calc. the change and put it in a vector.

        changex = newposx - oldposx;
        changey = newposy - oldposy;

        vector<int> returnval;
        returnval.insert(returnval.begin(), changex);
        returnval.insert(returnval.begin() + 1, changey);

        Change = returnval;
    }
};

#endif

视口.h

#ifndef CVP_H
#define CVP_H

#include <vector>
using namespace std;

#if defined DLL_EXPORT
    #define DECLDIR __declspec(dllexport)
#else
    #define DECLDIR __declspec(dllimport)
#endif

class ViewportManagerObject
{
    public:DECLDIR void StartFPSStyle();

    public:DECLDIR void StopFPSStyle();

    public:DECLDIR vector<double> ReturnCLA_XYZ();
};

#endif

很抱歉这篇文章没有提供更多信息,但我的时间很短。

请问各位大佬有没有。

谢谢你。

4

1 回答 1

2

CalcCLA_XYZ()你除以MouseCoordChange20 时,这是我认为的问题。首先将所有替换20MOUSE_SENSITIVITY# define它作为一个较小的数字。1从;开始看看它是如何响应的 您也可能希望将其转换为 double 或 float 以使其成为浮点除法以防止截断小数部分,因为现在MouseCoordChange[0]/20是整数除法。您也可以定义MOUSE_SENSITIVITY1.0使其成为浮点除法。

于 2012-08-19T05:39:31.527 回答