Skip to main content
GameDev.net gamedev.net
🔒 Locked

problem converting windows coordinates to object coordinates

Started by nextengine Sep 7, 2006 at 10:11 AM 2 replies 550+ views
Original Post
nextengine
nextengine
i am trying to convert windows coordinates to object ( gl ) coordinates, i am having random values as a result. Also, opengl cooordinates start from leftbottom corner of window, but my origin is at the middle of the window, and objects are drawn in respect to origin. i am confused, somebody clarify. following is the code..getting weird values. void getOGLPos(int x, int y, GLdouble* glX, GLdouble* glY, GLdouble* glZ ) { GLint viewport[4]; GLdouble modelview[16]; GLdouble projection[16]; GLfloat winX, winY, winZ; glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); glGetIntegerv( GL_VIEWPORT, viewport ); winX = (float)x; winY = (float)viewport[3] - (float)y; glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); gluUnProject( winX, winY, winZ, modelview, projection, viewport, glX, glY, glZ); } //Calls GLdouble glX=0.0,glY=0.0,glZ=0.0; getOGLPos( 240,0,&glX,&glY,&glZ); Values I am getting, for Windows values x=0, y = 240. Point should be close to left bottom, as my width and height of window are 600. glX = -4.342......e-0.12 glY = 2.17.................e-011
MARS_999
MARS_999
Well from your example you aren't sending x = 0 y = 240 its backwards...
You are sending x = 240 and y = 0...
nextengine
nextengine
>> values x=0, y = 240. Point should be close to left bottom, as my width and height of window are 600.

I meant to say x=240 y=0. sorry

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.