View Full Version : How to capture the distance between the center of mesh to the edge of screen?

06-26-2003, 09:47 AM
I have a terrain mesh and there is a ship located at the center of mesh. I want to calculate the distance from the ship to the edge of my computer screen ( not the edge of mesh)? How can I do that?


06-26-2003, 12:40 PM
Well you can maximize your mesh to find a box that just encloses the whole thing. A bounding box if you will. Then from there, transform the point in the center of this box to window space and then compute the distance from your windows space point to which ever screen edge you want.


06-26-2003, 12:45 PM
Hint: gluProject(...)



06-26-2003, 12:49 PM
BTW, you don't HAVE to use a box. It can be a sphere, epsilloid, or whatever.


06-26-2003, 03:20 PM
Originally posted by beachboy1976:
I want to calculate the distance from the ship to the edge of my computer screen.

Use the parameters/vectors you set up your projection matrix, location and direction of camera to construct the point on the "edge of your screen". I suggest you search for camera or viewing transformation if you are unfamiliar with the structure of the camera/viewing matrix.

06-27-2003, 12:58 PM
use your left (or right) screen maximum/minimum coordinate - for example 0 if your rendering window is fullscreen - project this point into your 3D world -> vožla.

06-27-2003, 01:13 PM
Deconstruct your matrix (modelview*projection) into 6 frustum planes (you should do this anyway for culling) and just do a dot product between the objects centre and the planes.