开发者

Getting the Mouse window coordinates in OpenTK (C#~.NET)

I'm creating a GUI that has 1 to many OpenGL view forms. Now the basics are working, I have a list of Viewer Forms and each encapsulates an OpenTK.GLControl member in its designer class.

I need to get the actual cursor position in the window that I drag an icon onto so that when I release left click, it drops it into the GL window at that location. This is simplified from what it actually needs to do but just as a first step, once this can happen, the rest will come easily.

Now when I use GLControl.MousePosition.X, GLControl.MousePosition.Y to get the cursor position, it actual gives me the screen position, rather than the position in the window. Unfortunately this isn't particularly useful for what I need to do.

I have looked at OpenTK.GameWindow.Mouse and this seems to work really well in my little test projects. It get's the exact position of the cursor in the window. However, I can't use the gamewindow in this project because gamewindow doesn't have some of the more GUI form friendly things that GLcontrol has such as Dock, T开发者_JAVA技巧abIndex, Paint and other GUI related members. (or at least I can't seem to find any way for GameWindow to support them anyway, do let me know if I'm wrong)

So what I'm really asking is, does anybody have a really nice/simple way for me to get the window position of the cursor in a form using OpenTK.GLControl

In fact, even if it's tricky please let me know :) I just need to be able to do it!


Your problem lies outside the scope of OpenGL which only deals with drawing stuff amd OpenTK which glues OpenGL to .net. It's a problem of Windows Forms. Windows Forms has a class Control with a method →PointToClient which you can use to transform from screen to client coordinates. If using OpenTK with GTK there is similar for GLWidget/Widget classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜