[solved] gluProject

Started by
3 comments, last by O-san 13 years, 6 months ago
I am trying to get the screen coordinates of my world coordinates using gluProject. I am using this bit of code to get my different matrices:

glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-(windowWidth()/2)/Zoom, (windowWidth()/2)/Zoom, -(windowHeight()/2)/Zoom, (windowHeight()/2)/Zoom, -1000, 1000);glGetDoublev( GL_PROJECTION_MATRIX, mProj );glGetIntegerv(GL_VIEWPORT,mViewp);glMatrixMode(GL_MODELVIEW);glLoadIdentity();// ... translate and rotate the camera glGetDoublev( GL_MODELVIEW_MATRIX, mModl );


Then later I want to use gluProject:

gluProject(world.x,world.y,world.z,mModl,mProj,mViewp,&winx,&winy,&winz);
The gluProject function call returns GL_TRUE but my winx, winy and winz do not correspond to screen coordinates. My world is rendered orthographically (using glOrtho). The winX value seem to look better, the winY value is just bad.

The video below shows the problem. The text "The sword" should be laying where the sword is.

" target="_blank">Youtube
Hires

Any help appreciated!

[Edited by - O-san on September 30, 2010 7:09:39 AM]
Advertisement
Seems like both your X and Y values are inverted. Try using Height-Y and Width-X.
Seems like your Y-values are inverted. Try using Height-Y. X looks like it just has a static offset a bit to the right of the sword.
Not sure, but is world.x/y/z the world space position of the sword, or the object/local space position? I think it should be the latter.

Also, I don't know if this matters, but that code doesn't call glViewport().
Thanks for the replies! I am at work right now. I will try inverting the Y value once I get home.
Got it working now. I had to flip the winY value as well as swapping the world.x and world.y and make them negative. I'm using a coordinate system which has larger values coming towards the camera instead of the default, other way around.

I forgot to mention I fetch the mViewp variable when I setup the orthographic view.

For those who are interested, it looks like this in the end:
if(gluProject(-world.y,-world.x,world.z,mModl,mProj,mViewp,&winx,&winy,&winz)==GL_TRUE){    screenx=winx; // OK    screeny=window.getHeight()-winy;}
Thanks!

This topic is closed to new replies.

Advertisement