   Object selection using rays
  HiIm working on a opengl game, and I have come to the point where I need to make a ray for box selection. I found some decent info on the web about how to determine the intersection between the ray and each box, the problem I have is (ofcourse) how to create the ray in the first place, based on the mouse screen coordinates.I believe I can use my view camera's position as the ray start point, but how do I calculate the ray direction vector?From the info I have found so far, it seems that I have to do both "projection back to world coordinates" and "create an inverse matrix".Is there any easier way to do these things?Anyone have any good info or links about this?Making the inverse matrix seems a bit complicated, but acording to one tutorial I was reading, the inverse of a 1x3 matrix (a vector) is as simple as Vector3::inverse(Vector3 v) { return Vector3(1/v.x, 1/v.y, 1/v.z); }Is this correct, or am I missing something here?Does OpenGL have anything similar to DirectX's <create_inverse> and <get_projection_matrix> utility functions?Thanks   
  Yes, there is a counter part it is called gluunproject .But you can use another method without resorting to glut.It goes on like this , generate the ray in eye coordinates, and transform it by the inverse of the ModelView matrix since the modelview matrix is orthogonal you need only to exchange the columns, with rows.In eye coordinates, the pick ray origin is at (0, 0, 0). You can build the pick ray vector from the perspective projection parameters.aspect = window_width/window_height;glMatrixMode( GL_PROJECTION );glLoadIdentity(); glFrustum(-near_height * aspect, near_height * aspect, -near_height,near_height, zNear, zFar );you can build your pick ray vector like this:int window_y = (window_height - mouse_y) - window_height/2;double norm_y = double(window_y)/double(window_height/2);int window_x = mouse_x - window_width/2;double norm_x = double(window_x)/double(window_width/2);When using a glViewport() that doesn't match the window height, the viewport height and viewport Y are used to determine the values for window_y and norm_y.The variables norm_x and norm_y are scaled between -1.0 and 1.0. Use them to find the mouse location on your zNear clipping plane like so:float y = near_height * norm_y;float x = near_height * aspect * norm_x;Now your pick ray vector is (x, y, -zNear).To transform this eye coordinate pick ray into object coordinates, multiply it by the inverse of the ModelView matrix in use when the scene was rendered. When performing this multiplication, remember that the pick ray is made up of a vector and a point, and that vectors and points transform differently. You can translate and rotate points, but vectors only rotate. The way to guarantee that this is working correctly is to define your point and vector as four-element arrays, as the following pseudo-code shows:float ray_pnt[4] = {0.f, 0.f, 0.f, 1.f};float ray_vec[4] = {x, y, -near_distance, 0.f};The one and zero in the last element determines whether an array transforms as a point or a vector when multiplied by the inverse of the ModelView matrix.;  Thanks ketekIts a bit clearer now.That was pretty much the method I was looking at already so I guess theres no way around it.(Looks like Im loosing rate points as soon as I start asking mathematical questions. Anyone feel strongly about mathematical subjects? :D)