Sign in to follow this  
O-san

[solved] gluProject

Recommended Posts

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.

Youtube
Hires

Any help appreciated!

[Edited by - O-san on September 30, 2010 7:09:39 AM]

Share this post


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

Share this post


Link to post
Share on other sites
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().

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this