R: [Plib-users] gluUnProject help!
Brought to you by:
sjbaker
From: Paolo L. <p.l...@ci...> - 2006-01-27 09:42:59
|
Don't know if it's useful to you, this is the code I use taken from a = recent post to the list: int Project2d3d ( int x2, int y2, float& x3, float& y3, float& z3 ) // does transform 2d into 3d coordinates { GLint viewport[4] ; GLdouble modvmatrix[16], projmatrix[16] ; glGetIntegerv ( GL_VIEWPORT, viewport ) ; /* OpenGL y starts at lower left, X/Windows y starts at top left */ GLdouble y2gl =3D viewport[3] - y2 ; /* Update the Modelview and Projectionmatrix */ glMatrixMode ( GL_MODELVIEW ) ; ssgLoadModelviewMatrix () ; glMatrixMode ( GL_PROJECTION ) ; ssgLoadProjectionMatrix () ; /* Use GL power to find the depth of the projection */ GLfloat z2 ; glReadPixels ( x2, y2gl, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z2 ) ; if ( z2 >=3D 1 ) return 0; /* Some more GL magic. Get the projection and modelview matrices */ glGetDoublev ( GL_MODELVIEW_MATRIX, modvmatrix ) ; glGetDoublev ( GL_PROJECTION_MATRIX, projmatrix ) ; GLdouble dx, dy, dz ; /* convert screen coords to object coords. */ int retcode =3D gluUnProject ( x2, y2gl, z2, modvmatrix, projmatrix, viewport, &dx, &dy, &dz ) ; x3 =3D dx ; y3 =3D dy ; z3 =3D dz ; return retcode; } Greetings - Paolo Leoncini > -----Messaggio originale----- > Da: pli...@li...=20 > [mailto:pli...@li...] Per conto di=20 > Tinoshi Kitazawa > Inviato: luned=EC 23 gennaio 2006 20.40 > A: pli...@li... > Oggetto: [Plib-users] gluUnProject help! >=20 >=20 > Hello everybody! >=20 > Do you know how to use the gluUnProject with PLIB??? I need=20 > to do something=20 > like Sim City, so I have a terrain (a scenegraph) built using=20 > PLIB, and I=20 > need to put objects over it clicking with mouse! I'm trying to=20 > gluUnProject(x,y,0.0,...) and gluUnProject(x,y,1.0,...), and=20 > I create a=20 > sgLineSegment3 to connect the two points. Then I'd like to=20 > ssgLOS() this=20 > line with the scenegraph... but I'm going crazy!!! Do you=20 > know a easier way=20 > to do something like that??? Thanks!!!=20 >=20 >=20 >=20 > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep=20 > through log files for problems? Stop! Download the new AJAX=20 > search engine that makes searching your log files as easy as=20 > surfing the web. DOWNLOAD SPLUNK!=20 > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D103432&bid=3D230486& dat=3D121642 _______________________________________________ plib-users mailing list pli...@li... https://lists.sourceforge.net/lists/listinfo/plib-users |