
mouse coords to world coords
Posted Friday, 15 March, 2013 - 15:17 by zgintasz inHi,
I'm making a windows forms application with opengl view. I need to get the mouse coords converted to the opengl world coords. How can I do that? Here is a bit of code, which might be useful:
private void SetupViewport() { ... GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height); Matrix4 projection = Matrix4.CreateOrthographic(Width / zoom, Height / zoom, 1.0f, 64.0f); GL.MatrixMode(MatrixMode.Projection); cameraMatrix = Matrix4.CreateTranslation(0f, 0f, 0f); GL.LoadMatrix(ref projection); } private void RenderView() { GL.MatrixMode(MatrixMode.Modelview); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.LoadMatrix(ref cameraMatrix); ... }
Thanks.


Comments
Re: mouse coords to world coords
bump, really need that.
Re: mouse coords to world coords
I haven't messed with 3d translation of the mouse but I was able to convert mine to 2d using the following code in my mouse button down event handler:
Re: mouse coords to world coords
it doesn't converts coords correctly. The calculation should also somehow use cameraMatrix...
Re: mouse coords to world coords
EDIT: nevermind, fixed it.