I am creating a basic game in OpenGl and C++ and want to make it so that when the player gets to the edge of the screen they can\'t move any further. I am having trouble working
If you aren't going to be dynamically changing your projection matrix, the easiest thing to do would be to call
glScalef(.63f,.63f,1);
on your projection matrix.
You can then restrict movement based on these values.
To compute the world space coordinates at any time you should make use of gluUnProject. assuming 'x' and 'y' are the width and height of your window respectively (the values you pass gluPerspective) you can find the world space coordinates like so:
double world_llx,world_lly,world_llz;
//world coordinates of lower left corner of window
gluUnProject(0, 0, 0, view_mat, proj_mat, viewport,&world_llx,&world_lly,&world_llz);
//world coordinate of upper right corner of window
double world_urx,world_ury,world_urz;
gluUnProject(x,y,0,view_mat,proj_mat,viewport,&world_urx,&world_ury,&world_urz);
view_mat is your view matrix. proj_mat is your projection matrix. You can get both of these using glGetDouble* with GL_MODELVIEW_MATRIX and GL_PROJECTION_MATRIX.
The viewport parameter will probably have the same dimensions as your window. In any event, this is what you set with glViewport.
This assumes your XZ plane is at z == 0.