English 中文(简体)
开放式广播电视摄像机 在使用SetaCursorPos(x,y)时,将照相机停泊,而不会被击退?
原标题:OpenGL Camera - Move the camera without it snapping back when using SetCursorPos(x,y);?

在我试图更新我的摄像机时,我有问题。

I want to change the pitch and yaw of the the camera (where its looking) via the mouse But I want the mouse to stay positioned to the center of the window.

//where MouseP.x .y is the mouse position 
//(which is centered to the current window)

//get old position of the mouse
OldP.x = MouseP.x;
OldP.y = MouseP.y;

//work out the distance traveled
Delta.x = MouseP.x - OldP.x;
Delta.y = MouseP.y - OldP.y;

//update the camera(using  distance traveled)
Rot.Yaw -=Delta.x/5;
Rot.Pitch -= Delta.y/5;

//move mouse to the center of the screen
SetCursorPos(CENTER_SCREEN_X,CENTER_SCREEN_Y);

问题在于,照相机na回某一点,因为烟.要返回原方。

我想通过从原产地出发的距离,而不是从离原地的距离,更新该照相机。

如果我看不到这一点,它会非常好,但当时的花.可以走出窗户。

最佳回答

我认为,这里的问题是,你的守则可能属于<代码>的捕获范围。 WM_MOUSEMOVE event?

当你打电话<代码>SetCursorPos时,该编码本身产生另一个<编码>WM_MOUSEMOVE的活动,因此,在你搬动时,以及当你打电话<代码>时,你将处理这一编号。 SetCursorPos,正好相反。

You probably don t want to put SetCursorPos inside of a WM_MOUSEMOVE event catch, or else you ll generate an endless loop of messages (every SetCursorPos generates another one).

也许你可以在电传泵之外转移这一代码,在你更新的路程中,仅将其操作一次:询问目前的湿度,使你的照相转变,然后将 cur子重新归到底。

问题回答

One has to be careful with cursor and 3D mouse movement. People tend to think it is related, but in fact it is not. read the article from the msdn: http://msdn.microsoft.com/en-us/library/windows/desktop/ee418864%28v=vs.85%29.aspx "Taking Advantage of High-Definition Mouse Movement" this is how one must get mouse input in a 3D application. the cursor should be hidden.

如果你试图更新,就会形成一种可怕的麻风情绪,使治疗者试图逃离该中心,让使用者搬动该词,但被看不到的春天 kept住。 哪一种情况看上去非常专业。 你们不能打仗,因为你的申请没有在潮湿的曲线显示之前安排。

if(g_States::Instance().MouseLook())
{
    //Test the mouse input
    POINT mousePos;
    GetCursorPos(&mousePos);

    mouseX = mousePos.x; //g_InputEngine::Instance().GetX();
    mouseY = mousePos.y; //g_InputEngine::Instance().GetY();

    mouseX = mouseX - m_HalfWidth;
    mouseY = mouseY - m_HalfHeight;

    mouseFloat = mouseX * C_MOUSESMOOTHINGFACTOR;
    g_Scene::Instance().GetCamera()->RotateYaw(-mouseFloat);

    mouseFloat = mouseY * C_MOUSESMOOTHINGFACTOR;
    g_Scene::Instance().GetCamera()->RotatePitch(mouseFloat);

    //Reset mouse to center on the screen
    SetCursorPos(m_HalfWidth,m_HalfHeight);
}

So this is the Mouselook function of a spacegame prototype I was developing for fun a while back what I did was change it to use GetCursorPos(&mousePos); instead. This will get the current position of the cursor no matter when your input code updates the mouse cursor location. The rest of the math in the function is just for the sensitivity and actually rotating the camera. Hopefully this code helps a little getting yours working.

Let me know if you need more explanation.

Edit:我只记得这样做的原因。 这是因为该屏幕是碎块,但随后输入引擎将通过<代码>SetCursorPos()电话更新,因为i是利用WM_MOUSEMOVE更新输入引擎。 我不敢肯定你们如何获得你们的意见,但这仍然应当帮助你们。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签