Jump to content
  • Advertisement
Sign in to follow this  
buzzy84

OpenGL gluUnProject (...) help needed!!

This topic is 4515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hy guys, I'm developing a c# app, and I've spent a lot of time serching for correct way to map 2d coord of mouse to 3d world coords of the ogl scene, particullary I want to select some point in my scene. I have used this code snippet: public static Point3d GetOGLCoords(int x, int y) { int[] viewport = new int[4]; double[] modelview = new double[16]; double[] projection = new double[16]; float winX, winY, winZ; double posX, posY, posZ; GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelview); GL.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection); GL.glGetIntegerv(GL.GL_VIEWPORT, viewport); winX = (float)x; winY = (float)viewport[3] - (float)y; GL.glReadPixels(x, (int)winY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, out winZ); GLU.gluUnProject(winX, winY, winZ, modelview, projection, viewport, out posX, out posY, out posZ); return new Point3d(posX, posY, posZ); } (from NeHe article #13) where "GL" and "GLU" are related glu and opengl wrapping classes. In my code also I have implemented a simple camera based upon translate and rotate func and gluLookAt(...). my draw func are: protected override void OnPaint(PaintEventArgs e) { if (DC == 0 || RC == 0) return; WGL.wglMakeCurrent(DC, RC); GL.glLoadIdentity(); GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); GL.glOrtho(...); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); GLU.gluLookAt(...); } I have also drawed the point result of the GetOpenGLCoords this is the result: Free Image Hosting at www.ImageShack.us The code seems to work except that the mouse arrow is not at the same position of drawed points Where is my mistake? Thankyou a lot in advance. Mirko (buzzy84)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!