C# mouse coordinates to opengl
Hi
I was googling all night and still dont know how to do this.
I want to use C# motion mouse class, to catch x,y coordinates and use them in my opengl scene.
1 idea was to set ortho scene and draw my own cursor.
But it works only with 2D scene ;)
How to check what are x,y,z coordinates of the selected pixel ? I d checked many examples, but still doesnet work.
I use C# and TAO framework.
Plz give some advice.
You can convert your mouse co-ordinates to world co-ordinates using gluUnProject.
Just make sure you invert your mouse Y coordinates since .NET measures from the top left of the screen, but gluUnProject is from the bottom right.
x1, y1, z1 will contain where you've clicked in 3D space given a mouse depth of zero. You can call this method twice with a mouse depth of 1 to get a ray that you can use for things like collision tests.
double x1, y1, z1;Glu.gluUnProject(Mouse.X, Height - Mouse.Y, 0, ModelviewMatrix, ProjectionMatrix, ViewMatrix, out x1, out y1, out z1);
Just make sure you invert your mouse Y coordinates since .NET measures from the top left of the screen, but gluUnProject is from the bottom right.
x1, y1, z1 will contain where you've clicked in 3D space given a mouse depth of zero. You can call this method twice with a mouse depth of 1 to get a ray that you can use for things like collision tests.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement