简体   繁体   English

Windows鼠标坐标VS OpenGL鼠标坐标

[英]Windows mouse coordinates VS OpenGL mouse coordinates

How can I determine(this isn't the right term to use I know) that, for every position of mouse in a window space , it gets converted to OGL space (-1, 1). 我如何确定(这不是我所知道的正确术语),对于window space中鼠标的每个位置,它都会转换为OGL space (-1,1)。 In this case, the user moves the mouse very fast, that I assume all of its previous positions are converted into OGL coordinates. 在这种情况下,用户非常快地移动鼠标,我假设它的所有先前位置都转换为OGL坐标。 What I am trying to say is that...is a common CPU fast enough to do that (to track all previous events) even if my C++ OGL coordinates converter is very computational expensive? 我想说的是......即使我的C++ OGL coordinates converter的计算成本非常高,但它是一个足够快的通用CPU(跟踪所有先前的事件)? lets say I put very time consuming loops in there? 假设我把非常耗时的循环放在那里? or.. very fast method() . 或..非常快的method() How can I assure that no OGL coordinates are skipped out if I move the mouse fast enough? 如果我足够快地移动鼠标,我如何确保不会跳过任何OGL坐标? I'm not jumping to any conclusion here or assuming something else might you think. 我不是在这里得出任何结论或假设你能想到别的东西。

Edit: 编辑:

My program main loop is like this(pseudocode): 我的程序主循环是这样的(伪代码):

void Pollevents()
{
    for everyt_obj in this
    {
        if Not Collide()
        {

            Move(x, y) //

        }
    }
}

void MousePos()
{
    mouse.pos = To_OGL_Coord2f()
}

These are separate threads to be executed (But not actually a real thread) Suppose mouse.pos = (0, 0) then I moved the mouse fast enough to make the new mouse.pos to (10, 10). 这些是要执行的单独线程(但实际上并不是真正的线程)假设mouse.pos = (0, 0)然后我移动鼠标足够快以使新mouse.pos到(10,10)。 In a single execution of a loop, the mouse position changed very far from where it was before. 在循环的单次执行中,鼠标位置与之前的位置相差很远。 Now, how can I tell to my program, by implementing Bresenham's line algorithm as mentioned by Christian Rau, that those values generated by that algorithm(not being tracked) have been crossed by the mouse. 现在,我如何通过实施Christian Rau提到的Bresenham's line algorithm来告诉我的程序,该算法生成的那些值(未被跟踪)已被鼠标划过。 Will I add another loop for that to step for all those positions? 我是否会为所有这些职位添加另一个循环?

How can I assure that no OGL coordinates are skipped out if I move the mouse fast enough? 如果我足够快地移动鼠标,我如何确保不会跳过任何OGL坐标?

That's not possible, since there is no way to let the OS generate mouse events for each and every point a mouse move would have crossed when tracked with theoretically infinite precision. 这是不可能的,因为没有办法让操作系统为每个点生成鼠标事件,鼠标移动在理论上无限精度跟踪时会越过。

The only way to ensure this is to fill the missing points between the two (possibly far away) mouse positions yourself. 确保这一点的唯一方法是自己填充两个(可能很远的)鼠标位置之间的缺失点。 If you just want to draw a point for each position the mosue moved over (maybe using OpenGL), draw a line instead. 如果你只想为每个位置绘制一个点,那么mosue会移动(也许使用OpenGL),而是画一条线。

If you on the other hand need those intermediary mouse positions yourself for further computations, you won't get around computing them yourself using some common line rasterization algorithm (like the Bresenham Algorithm , the school book algorithm for line rasterization). 另一方面,如果你需要那些中间鼠标定位自己进行进一步的计算,你将无法使用一些常见的线光栅化算法(如Bresenham算法 ,用于线光栅化学校书算法)自行计算它们。 What this basically does is compute each point on a discrete grid that a line from one point to another would have crossed (similar to what your graphics card does when converting a line into discrete pixels), so this will generate each discrete mouse position your virtual mouse path has crossed (ignoring any non-linear mouse movement between measurement points). 这基本上做的是计算离散网格上的每个点,从一个点到另一个点的线将交叉(类似于图形卡在将线转换为离散像素时所执行的操作),因此这将生成虚拟的每个离散鼠标位置鼠标路径已越过(忽略测量点之间的任何非线性鼠标移动)。

EDIT: If you don't need a discrete line with proper equal-width characteristics a much easier way than messing with line rasterization would also be to just work with floating point positions and do a simple linear interpolation of the end points, like datenwolf writes in his comment. 编辑:如果你不需要一个具有适当等宽特性的离散线,比使用线光栅化更简单的方法也只是使用浮点位置并对端点进行简单的线性插值,如datenwolf写道在他的评论中。 This will also give you a better timing precision than discrete mouse positions. 这也将为您提供比离散鼠标位置更好的计时精度。 But it all depends on what you actually want to do with those mouse positions (and now would be a good way to tell us). 但这一切都取决于你真正想要用这些鼠标位置做什么(现在是告诉我们的好方法)。

EDIT: From your updated question it looks like you need the mouse positions at a high granularity in order to compute the collision of the mouse with some objects. 编辑:从您更新的问题看起来您需要高粒度的鼠标位置,以计算鼠标与某些对象的碰撞。 In this case you don't actually need the intermediary points at all. 在这种情况下,您根本不需要中间点。 Just take the line from the current mouse position to the previous one (represented as just a pair of points, or whatever theoretical line representation) and compute the collision of the objects with that line instead of the individual points. 只需从当前鼠标位置到前一个位置(仅表示为一对点,或任何理论线表示),并计算对象与该线的碰撞,而不是单个点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM