here’s something that i think would work. ignore everything i had previously said though… i just didn’t understand what you were asking.
first you need to get a definition of the plane that you want to intersect in world space. you have the distance from the center of projection (which i assume is the eye point in standard opengl terms), and the normalized view direction. multiply the distance by the view direction and add it to the eye location. this will get you a point in the plane. the normal to the plane is the vector from the point you just computed to the eye location. now you have a complete specification of a plane.
next you can find a line segment to intersect against the plane. take your (x,y) screen coordinates and supply them to gluUnProject(), specifying a z value of 0.0 and the appropriate transformations. this’ll get you the world space location of the point projected onto the near clip plane. now do the same thing, except specify a z value of 1.0. this’ll get you the world space location of the screen point projected onto the back clipping plane. these two points specify your line segment. one thing to watch out for is that you don’t include the modeling transformation when you call gluUnProject(), or else you’ll get coordinates in object space instead of world space. just specify the viewing transformation and the unprojected points should be in world space.
now interset this line segment with the plane to get the world coordinates. code for line segment-plane intersection can be found almost anywhere, including here .
eh… may as well do up some pseudo code.
Vector3 eyeLoc; //initialize to your eye location in world coordinates
Vector3 viewDir; //make sure this is normalized
float focalPtDistanceFromEye; //initialize as appropriate
//first form the plane
Vector3 ptOnPlane = eyeLoc + focalPtDistanceFromEye*viewDir;
Vector3 planeNormal = eyeLoc - ptOnPlane;
//now compute the line segment in world space
int x, y; //screen coordinates
Matrix modelView, projection;
Rect viewport;
//initialize transformations as appropriate
//make sure to only include the viewing transformation in the modelview matrix
Vector3 worldPtOnNearPlane = gluUnProject(x,y,0.0,modelView,projection,viewport);
Vector3 worldPtOnFarPlane = gluUnProject(x,y,1.0,modelView,projection,viewport);
Vector3 intersectionLocation = SegmentPlaneIntersection(worldPtOnNearPlane,worldPtOnFarPlane,planeNormal,ptOnPlane);
as before, that code hasn’t been tested or anything, so be careful. hope i have the right idea here.
-steve