Friday, March 20, 2009

The Mathematics of Field of View and Vanishing Points

In order to understand the vanishing point in Plane-Maker, we first have to look at field of view and the process by which X-Plane simulates a 3-d world on a 2-d monitor.

Field of View

Field of View is the angle that you get if you go from the left edge of your vision to your eye, then back up the right edge.  In the case of a monitor, we can calculate this (depending on how far back I am sitting).  For example, my 19" LCD is 14.8 inches across the top; to have a 45 degree FOV I need to sit about 17.8 inches away from the monitor.

X-Plane lets you set the field of view.  Imagine that you were sitting in front of a window on an airplane.  As you put your face closer to the window, you can see more of the world outside. Effectively you are increasing your field of view.  X-Plane works the same way - turning up the field of view parameter will increase the amount of "stuff" you can see.

Where Is The Horizon?

So where is the horizon?  The answer is: it depends.  Assuming you are looking straight forward, the most logical place to put the horizon is exactly half-way up the monitor.  And this is what X-Plane does in any external view.

As you rotate your head up and down, the center of your vision changes relative to the horizon. But if you simply move your head up and down, the horizon doesn't move.  This is due to parallax.  The closer an object is, the more it moves as you move your head.  This is what lets me look "over" the dashboard of the car by sitting on a phone book: as my head goes higher, the dash board (close) appears a lot lower but the road (far) appears only a little bit lower.  The horizon (very, very far away) doesn't move at all.

This effect works in X-Plane.  Try moving the view point up and down in a plane with a full 3-d cockpit, like the Cessna 172.  As you move your head up and down, your ability to see the runway out the window will change.

2-D Panels

Things get weirder when we have a 2-d panel.  A 2-d panel is sort of a flat image of what a 3-d cockpit might look like.  We need some kind of correlation between the 2-d world and 3-d world...that is, where does the horizon appear through this 2-d panel.  That location is the "vanishing point" in Plane-Maker.

Here's where things get strange: what do we do when we scroll the panel?  Do we move our head or tilt our head?  The answer is: neither.  Scrolling the 2-d panel simply scrolls the "window" within the 3-d world that we look through.  This has the effect of moving the horizon (by the exact number of pixels the panel scrolled) without rotating your view point.

This isn't necessarily the best way to scroll the panel, but it looks pretty good, and anything we do with 2-d panels is going to be an approximation.

And Now The Bug

Of course, there must be a bug in here somewhere...these blog posts are usually the result of an investigation into an edge-case in the sim.  In X-Plane 930b6, we pick a vanishing point based on the 2-d panel when we are in 3-d cockpit mode.

Why would we do such a silly thing?  Originally it was to keep the horizon from jumping when there is no 3-d cockpit object.  This behavior is okay in that case, but here's how we get burned: if the 2-d cockpit has to scroll, the vanishing point might be off the top of the screen.  Authors who have made very large 2-d panels and separate 3-d cockpits see this as the 3-d viewpoint being stuck straight down.  What's happening is the vanishing point (and thus the center for the mouse) are off the top of the screen.

For beta 7 I am fixing this:
  • If there is a 3-d cockpit object, the vanishing point will be the center of the screen, which is almost certainly the right thing to do for a real fully 3-d view.
  • If there is no 3-d cockpit object (but instead X-Plane's default of the 2-d panel floating in space) the vanishing point will match the 2-d view, but taking the default scroll position into account. This should keep the horizon at a reasonably sane point.
As a final note, it is possible to specify a 3-d panel without a 3-d cockpit object in X-Plane. Don't make a plane like this.  It's a silly thing to do!


AWC said...

I am confused (not a surprise)

So if you use a cockpit obj say for a pilot figure and check the show cockpit object box, will the horizon be messed up now with a 2D panel?

Benjamin Supnik said...

AWC - I _think_ that "w" view will always use the horizon setting based on other words, we go by the view type, not whether the object is shown.

(The same thing applies for side views that might show the 3-d cockpit object.)

P.P. said...

I believe there is not a good idea.
Lowering the vanishing point, it also lowers the panel to full 3D, so the feeling is that the cabin has been reduced, or that we have uploaded a lot of pilot seat. This is not real: it is normal that the pilot has to stretch his neck to see over the panel.

Benjamin Supnik said...


I don't agree with your assertion.

- If the pilot has to move his head up (I think this is what you mean) to see over the dash board, that just means that a normal-height pilot's head position (represented by the pilot viewpoint in Plane-Maker, which is really a starting viewpoint before the user moves his head) is simply not that high up relative to the dash board.

- Moving the horizon's mapping to the screen has _absolutely no effect_ on the relative positioning of the dash board and the pilot's head. If you set the pilot's head position to have trouble seeing the runway without "sitting up a bit", you will get the same results with the old horizon and new horizon.


P.P. said...

Ben, I agree with you that the most natural situation for the vanishing point is in the vertical center of the screen, but ...
... as you can see in this images
the center of the screen results in a down of the 3D cabin plane, all the planes (the only diference in teh images is the version: one is 9.30b5 and the other is 9.30b7).
Is possible to code something in plane-maker for batch convert all the 3D panels to the new view?

Benjamin Supnik said...


Are you saying that we should change the default pilot head position (because it is now necessary to change the head position to get the same ratio of sky to panel as before)?

If so, the necessary change is not a change in head _height_ (translation) but head angle (roation) - that is, you need to look down, not scroll down.

I would argue that the requirement to look down is _more_ correct...920 basically lets you see the entire glass display with peripheral vision, which is IMO unrealistic. In real life you'd have to look down (and if it isn't at an angle, it will be sloped away from you) or move your head lower (and losing the ability to see the runway).

In other words, the geometry of the cockpit and view position should be based on real world values, not optimal viewing. It is up to the user to change the view dynamically to see the content desired (more sky, or more panel), and in virtually any real setup I expect the user not to be able to see everything at once.


Havner said...

But this changed one thing that is incoherent IMO. If you've got a plane with only 3D pit that is displayed also in 2D view, when you switch between those views your point of view changes.

This was not a case in previous betas or 9.2x

Benjamin Supnik said...

Havner, this should not be true - the logic place only applies to 3-d cockpit view type, not whether the 3-d cockpit is drawn. (Similarly, 2-d side views are not affected by this.

If you observe different in beta 7, please report a bug.

The change is only for the "real" 3-d view, where we have 5 DOF and can thus adjust the relationship between the panel and horizon by moving our heads (which induces parallax).

Havner said...

Well, this is true (I reported a bug some time ago).

Just open a plane with 3d pit only (no such plane in default X-Plane ones afaik) and repeatedly hit ctrl-o to switch 2d<->3d (in both cases 3d should be drawn but in 3d mode it will be shifted up). You should see what I mean.

Havner said...

Additionally if I get you correctly you confirmed that with that sentence:

"the logic place only applies to 3-d cockpit view type, not whether the 3-d cockpit is drawn."

So 3-d cockpit view type changed, 2d cockpit view type (even if 3 cockpit is being drawn here) didn't. Hence to incoherence and shift when you switch between those view types (if I get it correctly).

Benjamin Supnik said...

I guess I don't see a horizon jump as a bug. The horizon jumps if you change to tower view, circling view, or some side're changing views!

Havner said...

But you are changing views not for tower or anything similar.

Your changing views that both of them draw 3d panel (whatever view type there is) and look through the front glass.

Since 9.0 both of them drew the same view, now they don't. For me it's less then expected.

Benjamin Supnik said...


Here's how the 3-d and 2-d views are different: in the 2-d view, you don't have much freedom to move your head. Given this, if we don't honor the horizon level, the 2-d view might somewhat unusable. Furthermore, honoring the horizon level in the 2-d view lets us provide a "2-d like" behavior in the 2-d view which is what users expect.

(The point of having the 3-d cockpit in 2-d view is _not_ to make the 2-d view into a 3-d one - that's what the 3-d view is for. It is to allow authors who have invested a lot in 3-d and very little in 2-d to reuse their 3-d art assets.)

In the 3-d view you have 5 DOF..under that situation, having the "natural" center of the field of view be not the middle of the screen means unequal real-estate in all viewpoints.

In the end, I don't believe that the horizon reference is a matter of "acf spec" in the 3-d view - there has never been a setting for it, and X-Plane's legacy behavior (using the 2-d setting, sometimes producing absurd results) doesn't strike me as a good idea.