©2004,2009 Jim E. Brooks http://www.palomino3d.org
[2009/10]
Module to create a window with one or more views. The purpose of this module is to serve as a layer to allow app-level code to manipulate views in a way independent of the graphics system.
abstraction: | Window ![]() |
View ![]() |
Observer Matrix ![]() |
Viewpoint / View Matrix |
implementation: | osg::Viewer ![]() |
osg::Camera ![]() |
modelview matrix |
[2008/06]
Window class contains Views, defines the SceneGraph, executes main loop, broadcasts draw events. Window automatically creates the main view. Window is based on OSG::Viewer.
[2009/10]
View defines both a 2D viewport and 3D viewpoint. The order of rendering Views is the same order Views were attached to Window. View is based on osg::Camera.
Logical views are composed with a View and a Viewpoint object. Viewpoint is a functor class containing an algorithm to compute the View Matrix which is called before rendering a new frame. This composition can be changed dynamically by View::SetViewpoint() to switch to view modes (first-person, chase-plane, etc).
The View class is a Mediator over osg::Viewer, osg::View, and osg::Camera. View::SetViewMatrix() is a pass-thru to osg::Camera::setViewMatrix(). Despite changing the viewpoint, View keeps the same underlying osg::Camera object.
[2009/10]
As described in View, Viewpoint is a functor class whose purpose is to compute the View Matrix from an observer.
A View has a Viewpoint object. Every frame, View calls Viewpoint::ComputeViewMatrix() to recompute the viewpoint.
[2009/10]
View Matrix corresponds to the OpenGL modelview matrix. It is computed from the Observer Matrix according to view modes. For example, the View Matrix will be computed appropriately for OTW_FRONT or OTW_LEFT (the Observer Matrix exists independently of view modes).
The coordinates of the origin of the View Matrix are negative (osg::Camera's view matrix is also negatve).
[2009/10]
In general terms, every view of the scene has an object that is the observer. The observer is an abstraction: it can be the player's craft, a chase-plane, trackball position, a matrix, etc. An observer is defined by an Observer Matrix. The Observer is the source of the Viewpoint and View Matrix. An Observer Matrix is converted to a lower-level View Matrix which is used to render a view.
The generalized Viewpoint class that uses the Observer functor class is OtwViewpoint. The normal front-view is supported by OTW_FRONT mode. OtwViewpoint::ComputeViewMatrix() calls Observer::GetObserverMatrix(). New derivatives of Observer can be created to define any kind of observer object.
Multiple Observers can exist. For example, one View can have the player's craft as an Observer, while another View has a missile as an Observer.
The main Observer is ObserverCurrentCraft. ObserverCurrentCraft drives the main View (depending on program mode).
Implementation:
For implementation reasons, multiple instances of ObserverCurrentCraft are possible.
But regardless, ObserverCurrentCraft can be thought of as Singleton in disguise (or a link/proxy),
because it is based on the unique current craft.
[2009/10]
Movement in the simulator is driven by a Viewpoint object recomputing the View Matrix of a View every frame.
Specifically, how does the player cause the viewpoint to move (in an OTW view)? The main View can be composed with an OtwViewpoint object. The OtwViewpoint is constructed with a ObserverCurrentCraft object (derivative of the Observer class). Every frame, View calls Viewpoint::ComputeViewMatrix(), which in this case, actually calls OtwViewpoint::ComputeViewMatrix(). In turn, ObserverCurrentCraft::GetObserverMatrix() is called which gets the Observer Matrix from the current craft which is what the player controls and is the observer. Then the Observer Matrix is converted to a View Matrix according to the OTW mode (front/left/right/rear).
Last modified: Wed Feb 10 15:31:34 CST 2010