# getting the direction of objects behind the camera

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

## 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 on other sites
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 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 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).

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013755
×