# marking the edge of the screen

What im wanting to do is if an object is not currently onscreen, is draw a marker on the side of the screen showing which direction the object is in.

currently im doing the following,

Project the objects position into screenspace + see if its with the viewport
if its not depending on what the x+y number returned back from the Project(…) function to see what plane to test against + find the intersection point

return_intersection_point_of_PLANE_LINESEGMENT( viewfrustum_plane, LINESEGMENT(…) )

this works perfectly but i feel its rather messy, is there a more logical way of achieving what im trying to do?
ta zed

Here’s what I would do:

1. Test if the bounding box is visible, if so, goto 2 else goto 3.

2. Draw model, goto 6.

3. Transform object center (Oc) to eye space (Ec)

4. Construct a plane from viewing direction and Ec
P = crossproduct(vec3(0,0,1),Ec)
plane P is defined by all points where Pxx+Pyy+Pz*z=0

5. Find intersection points of this plane with the line segments (or only the relevant one like you said) at the near plane (left,right,bottom,top and near coordinates of your glfrustum calls)
Intersections are found by using parameterization of the line segment e.g. line is defined as

t*vec3(left,bottom,-near)+(1-t)*vec3(right,bottom,-near)

if t is in the range [0,1] it intersects at the bottom of your frustum. Because t is in the range [0,1] you can perform the viewport transformation easily by multiplying t with the window width.

1. End

So in the end it’s basically the same as you’re already doing

cheers NiCo, yes thats similar to what i have at the moment, though im doing the reverse where the planes are the actual viewfrustum planes.

on second thoughts wont that give u more than one answer
A
|
|.p
|…
B------C
…\

A,B,C are 3 corners of the near viewfrustum, the infinite plane intesects 2 of the linesegments.

dont worry about spending time answering, as what ive got works, it just doesnt ‘feel’ like the best method

There are indeed 2 possibilities but you can disambiguate between them based on the direction of the plane normal.

I know it feels messy but it doesn’t take up much computation time so it doesn’t matter how it’s implemented as long as it’s correct.