Jump to content
  • Advertisement
Sign in to follow this  
vamseekanth

problems with gluUnproject ()?

This topic is 5031 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

Hello, iam using gluUnproject () function to retrieve the object coordinates from the screen coordinates. when i click on a point (2,2,2) i get the output from the function as(2.218335,2.226619,-0.000000) when i click on a point (3,3,3) i get the output as (2.218335,2.226619,-0.000000) when i click on a point (4,4,4) i get the output as (3.079899,3.084041,-0.000000) when i click on a point (5,5,5) i get the output as (3.079899,3.084041,-0.000000) why is there such a discrepancy in the actual values and the returned values of the function?? is it the nature of the function itself or there is some other problem with my code?? i want to retrieve atleast the x-coordinate more or less exactly?? plz help me ,may be with any other possible solution. thanking you, vamsee. the code is as follows: #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> void display (void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // glu.gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0); // glu.gluLookAt(0.0,0.5,0,0,0.0,0.05,0,0,1); glOrtho(0.0, 5.0, 0.0, 5.0, 0.0, 5.0); //glTranslatef(-5.0f, 0.0f, 0.0f); // gl.glRotatef(rtri,0,6.0f,0); // glu.gluLookAt(camerax, cameray, cameraz, 0, 0.0, 0.05, 0, 1, 1); glPointSize(5); // for (i = 0, j = i + 1; i < array11.size() - 1; i++, j++) // { // if (arraya1[j] == arraya1 + 1) // { glBegin(GL_POINTS); glVertex3d(1,1,1); glVertex3d(2,2,2); glVertex3d(3,3,3); glVertex3d(4,4,4); glVertex3d(5,5,5); glEnd(); // } // } glFlush(); } void reshape(int w, int h) { glViewport(0,0,(GLsizei) w ,(GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(GLfloat) w / (GLfloat) h,1.0,100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void mouse (int button,int state,int x,int y) { GLint viewport[4]; GLdouble mvmatrix[16],projmatrix[16]; GLint realy; GLdouble wx,wy,wz; int returnvalue1=0,returnvalue2=0; // glLoadIdentity(); switch (button) { case GLUT_LEFT_BUTTON: if( state ==GLUT_DOWN) { glGetIntegerv(GL_VIEWPORT,viewport); glGetDoublev(GL_MODELVIEW_MATRIX,mvmatrix); glGetDoublev(GL_PROJECTION_MATRIX,projmatrix); realy = viewport[3]- (GLint) y -1; printf("Coordinates at cursor are (%4d,%4d) \n ",x ,realy); returnvalue1 = gluUnProject((GLdouble) x,(GLdouble) realy,0.0,mvmatrix,projmatrix,viewport,&wx,&wy,&wz); printf("returnvalue1 is %d \n",returnvalue1); printf("World coords at z= 0.0 are (%f,%f,%f) \n",wx,wy,wz); returnvalue2 = gluUnProject((GLdouble) x,(GLdouble) realy,1.0,mvmatrix,projmatrix,viewport,&wx,&wy,&wz); printf("return value2 is %d \n",returnvalue2); printf("World coords at z= 1.0 are (%f,%f,%f) \n",wx,wy,wz); } break; case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) exit(0); break; default: break; } } int main(int argc , char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMainLoop(); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
how could you click on the point 3,3,3

since you can only move the mouse in 2d. Could the discrepancy come from the program thinking that you ar clicking on some point in front or behind the actual point you want?

Share this post


Link to post
Share on other sites
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!