Jump to content
  • Advertisement
Sign in to follow this  
ehmdjii

getting the direction of objects behind the camera

This topic is 3987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, i have a fps-like camera and i want to display in the userinterface (2d) the shortest direction to certain objects, which are not inside the camera frustum. so that the user knows in which direction he has to move the camer in order to see the object. what i tried so far, is to get the window coordinates using gluProject(t.x, t.y, t.z, model_matrix, projection_matrix, viewport, winpos); and then check if they are outside the frustum by if (winpos[0]<0 || winpos[0]>viewport[2] || winpos[1]<0 || winpos[1]>viewport[3]) { this works so far, but then its pretty hard to get the direction out of it, cause things seem to go upside down when the object is behind the camera, or behind the near clipping plane. im not sure... anyone got any better ideas to solve this?

Share this post


Link to post
Share on other sites
Advertisement
I'd suggest to calculate the direction in world space, i.e. from current camera forward to cam.pos->object vector.

With those vectors you should be able to get the (smallest) yaw and pitch angles needed to make the camera face the object. Bring them to a range of [-180, 180] degrees of [-PI, PI] radians.

If you know the viewing angles of your frustum (you should be able to calculate them if you don't know) you now should be able to display the arrows. Let's say your field of view is 140 degrees (so 70 degrees to the left and right) and your yaw angle is -120 degrees. You now get abs(-120) > 70 -> outside frustum, -120 < 0 -> left (or right, depending on your coordinate system).

Share this post


Link to post
Share on other sites
ok thanks a lot!

i think i understand what you mean, but it sounds a bit complicated.

first of all, how can i calculate the viewing frustums horizontal and vertical angles?
i guess the horizontal is what i put in gluPerspective ?

Share this post


Link to post
Share on other sites
Yes, horizontal is what you put in perspective. And IIRC the vertical angle is horizontal/aspect.

Or you could use you method. I don't see a problem if you know coordinates are inverted (since you seem to want just the direction in screen space). For those objects that are not behind the camera but just outside the frustum (e.g. to the far left) you could do the same without inversion if z >= 0 (z < 0 is defined as behind the camera).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!