Sign in to follow this  

Finding the horizon position

This topic is 4219 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

This is probably an easy problem, but for some reason the solution escapes me, so don't laugh too hard please. :) What I'd like to do is calculate the height of the horizon (the vanishing point) on-screen, as the camera pitch varies. Simply put, turning the camera downwards the horizon should move upwards, and vice versa. I need the y coordinate of the horizon line in world/view/screen space (whichever is easier). To simplify further, let's assume that we're talking about the horizon of the XZ plane (Y points upwards). I'd be thankful for any and all help.

Share this post


Link to post
Share on other sites
The y-coordinate is not really descriptive enought since it may be rotated..
What you really need is to compute a segment that represents the horizon.

Intersect the clip space planes with z = 0 (or whatever your horizon is). This would give you four lines. Parameterize these lines, such that the directing vector is in the same direction as that of your viewing direction. For each line determine the point that is the limit of the projection of the point respective to the parameter as this parameter approaches infinity. (This might work just by projecting a point whose xyz are that of the direction and the w is 0, but you should consider some rock-solid mathematical reference on this issue)

These four points are collinear, two of which are on the border of your screen.

This algorithm assumes that the projection is perspective, otherwise there is no horizon (unless you are dealing with a large sphere and other implications, but you are probably not)..

Share this post


Link to post
Share on other sites
Quote:
Original post by DragonL
This is probably an easy problem, but for some reason the solution escapes me, so don't laugh too hard please. :)

What I'd like to do is calculate the height of the horizon (the vanishing point) on-screen, as the camera pitch varies. Simply put, turning the camera downwards the horizon should move upwards, and vice versa. I need the y coordinate of the horizon line in world/view/screen space (whichever is easier). To simplify further, let's assume that we're talking about the horizon of the XZ plane (Y points upwards). I'd be thankful for any and all help.
You said world/view/screen space. The world space answer should be obvious: (-infinity, 0, infinity) to (infinity, 0, infinity). You could pick a suitably large number instead of infinity, and then translate that through your world-to-view-space transformation matrix. I assume that there is no roll applied to the transformation matrix.

Please provide some background on this, as there may be a better solution which doesn't even require you to find this out.

Share this post


Link to post
Share on other sites
Thanks for your replies!

arithma, iMalc's assumption that there is no roll applied is correct, so the y coordinate is constant across the screen, and I don't need a segment. I'll freely admit that I don't fully understand the method you describe, although it seems interesting. By clip space planes, do you mean the frustum planes? Intersecting them with the ground plane (y = 0, in my case) would yield four lines forming a rectangle. I'm not sure how I could parameterise those lines using the view vector, since they are not parallell to that vector. Could you clarify a bit for me please?

iMalc, I have a feeling that translating an "infinite" number, as you suggest, might actually do the trick... It does sound simple enough to work! :) As for your question, what I want to do is render an infinite ocean plane, and I need to match the far edge to the horizon.

I'd be happy to hear more suggestions on how to accomplish this! ;)

Share this post


Link to post
Share on other sites
Quote:
By clip space planes, do you mean the frustum planes? Intersecting them with the ground plane (y = 0, in my case) would yield four lines forming a rectangle. I'm not sure how I could parameterise those lines using the view vector, since they are not parallell to that vector. Could you clarify a bit for me please?

Yes frustrum planes. You have two options for the parameterizing vector, two opposite directions. Select the one that yields a positive dot product with the view vector.

Plus you don't actually have to intersect the planes. Thinking about it, you should only find the cross product.

I will go home now, think about it some more and I'll get back to you tomorrow..
Think a bit about it in 2d, it might help

Share this post


Link to post
Share on other sites
If you can assume a flat horizon, with no zoom, then it solely depends on your vertical field of view and the camera pitch. If you are pretending the screen is part of a sphere (i.e. one pixel maps to a° over the whole screen) then the y coord is just ymiddle±(a×cameraPitch) (the sign of the operation depends on whether you're using Windows or PostScript style Y coordinates, and which way +ve pitch is). If you're saying the screen is flat (i.e. y=b tan phi) then similarly the y coord is just ymiddle±(b×tan cameraPitch).

I think a typical projection matrix (gluProjection or equivalent) is the second sort, but I haven't done 3D programming for long enough I forget.

Share this post


Link to post
Share on other sites

This topic is 4219 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this