How to capture the distance between the center of mesh to the edge of screen?

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?

Thanks

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.

-SirKnight

Hint: gluProject(…)

-SirKnight

BTW, you don’t HAVE to use a box. It can be a sphere, epsilloid, or whatever.

-SirKnight

Originally posted by beachboy1976:
I want to calculate the distance from the ship to the edge of my computer screen.
Thanks

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.

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.

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.