C++鼠标读取非常被动
C++ Mouse Reading very unreactive
直截了当,我正在开发一个dll,它只是读取鼠标坐标并将它们转换为旋转,然后转换为一些坐标,用于fps风格的相机。
问题是鼠标阅读器非常不敏感,如果我缓慢移动鼠标,它不会记录任何内容,但如果我移动得非常快,它会记录更改。
现在的代码:
主.cpp
#define DLL_EXPORT
#define BOOST_THREAD_USE_DLL
#include "DLLViewport.h"
#include "MouseReader.h"
#include <boostthreadthread.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
很抱歉,这篇文章没有提供更多的信息,但我的时间很短。
请问我有什么事。
谢谢。
CalcCLA_XYZ()
你把MouseCoordChange
除以 20,这就是我认为的问题。首先将所有20
替换为MOUSE_SENSITIVITY
,并将其# define
为较小的数字。看看它如何从1
开始响应;此外,您可能希望将其转换为双精度或浮点数以使其成为浮点除法,以防止截断小数部分,因为现在MouseCoordChange[0]/20
是整数除法。您还可以将MOUSE_SENSITIVITY
定义为1.0
,以使其成为浮点分。
相关文章:
- OpenGL大的3D纹理(>2GB)非常慢
- 为什么需要复制构造函数,在哪些情况下它们非常有用
- 为什么std::互斥需要很长的、非常不规则的时间来共享
- G++ C++17 类模板参数推导在非常特殊的情况下不起作用
- 使用浮点数和双精度数的非常小数字的数学
- 在打开多个其他窗口时使用全屏窗口时帧速率非常低
- 我从int x[3]得到的一个非常奇怪的输出;
- 反向迭代器在C++中非常奇怪的行为
- 将非常大的 int 转换为双倍,在某些计算机上会损失精度
- 我的自定义使用 std::unordered_map 的性能非常慢
- ifstream 尝试读取 9 到 13 之间的无符号字符时非常奇怪的行为
- 一个非常简单的win32套接字代码,但工作错误
- 非常快速地阅读 CSV 文件
- max_element() 给出非常奇怪的错误消息
- 将 mmap 内存用于开销非常低的循环缓冲区
- 内存映射文件访问非常慢
- 超过CPU时间限制:当MPI_Sent一个非常大的int*时
- QtWebengine 5.7.1的性能非常慢
- 如何非常快速地将数字添加到 Vector 中的一系列元素中
- C++鼠标读取非常被动