osgEphemeris C++ API
An example of building a viewer which include the osgEphemeris::EphemerisModel
class is provided in the distribution under src/Viewer. In essence, the
osgEphermeris::EphemerisModel is added to the scene graph like any other
osg::Node. osgEphemeris::EphemerisModel is the highest level
class in the osgEphemeris library and provides the highest level interface
for the programmer
The following is main.cpp from the viewer example.
/*
-------------------------------------------------------------------------------
| osgEphemeris - Copyright (C) 2007 Don Burns |
| |
| This library is free software; you can redistribute it and/or modify |
| it under the terms of the GNU Lesser General Public License as published |
| by the Free Software Foundation; either version 3 of the License, or |
| (at your option) any later version. |
| |
| This library is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| License for more details. |
| |
| You should have received a copy of the GNU Lesser General Public License |
| along with this software; if not, write to the Free Software Foundation, |
| Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| |
-------------------------------------------------------------------------------
*/
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osgProducer/Viewer>
#include <osgEphemeris/EphemerisModel.h>
int main(int argc, char **argv)
{
// Parse command line arguments
osg::ArgumentParser args( &argc, argv );
// Set up the viewer
osgProducer::Viewer viewer(args);
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
// Tell the viewer what to display for a help message
viewer.getUsage(*args.getApplicationUsage());
// Load up the models specified on the command line
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(args);
if( model.valid() )
root->addChild( model.get() );
// Define the Ephemeris Model and its radius
osg::BoundingSphere bs = model->getBound();
osg::ref_ptr<osgEphemeris::EphemerisModel> ephemerisModel = new osgEphemeris::EphemerisModel;
ephemerisModel->setSkyDomeRadius( bs.radius()*2 );
ephemerisModel->setSkyDomeCenter( bs.center() );
// Optionally, Set the AutoDate and Time to false so we can control it with the GUI
//ephemerisModel->setAutoDateTime( false );
// Optionally, uncomment this if you want to move the Skydome, Moon, Planets and StarField with the mouse
//ephemerisModel->setMoveWithEyePoint(false);
root->addChild( ephemerisModel.get() );
osgUtil::Optimizer optimizer;
optimizer.optimize(root.get());
// set the scene to render
viewer.setSceneData(root.get());
// Realize the viewer
viewer.realize();
while( !viewer.done() )
{
viewer.sync();
viewer.update();
viewer.frame();
}
viewer.sync();
return 0;
}
|
The following lines set up and add the osgEphemeris::EphemerisModel
class:
// Define the Ephemeris Model and its radius
osg::BoundingSphere bs = model->getBound();
osg::ref_ptr<osgEphemeris::EphemerisModel> ephemerisModel = new osgEphemeris::EphemerisModel;
ephemerisModel->setSkyDomeRadius( bs.radius()*2 );
ephemerisModel->setSkyDomeCenter( bs.center() );
root->addChild( ephemerisModel.get() );
|
setSkyDomeRadius( bs.radius()*2) and setSkyDomeCenter(bs.center())
is the only real essential call required for practical use of osgEphemeris.
All other defaults should result in desired default behavior. Note that we use the
bounding sphere of the model loaded on the command line as the parameter for defining
the radius of the SkyDome.
Other parameters that can be set at initialization time are AutoDateTime,
MoveWithEyepoint, and setting an UpdateCallback.
AutoDateTime gets a boolean value and is set with the api thusly,
ephemerisMode->setAutoDateTime( false );
|
AutoDateTime tells the Ephemeris Model to update the date and time
automatically by reading the computer's clock. Thus, the position of the
heavenly bodies will reflect the current time as set on the computer.
This value is set to true by default. Set this to false
if you intend to change the date and time dynamically or by some method
other than the current time of the computer's clock.
MoveWithEyePoint gets a boolean value and is set with the API thusly,
ephemerisMode->setMoveWithEyePoint( true );
|
MoveWithEyePoint tells the Ephemeris Model to keep the skydome and
position of the view of the heavenly bodies always centered at the eyepoint.
This value is set to true by default. Set this to false if
you intend to be able to manipulate the camera to points outside the
ephemeris SkyDome. This is useful for debugging or simply getting a sense
of the osgEphemeris implementation.
The parameters discussed in this section are settable only at initialization
time and remain static for the life of the EphemerisModel class instance.
Dynamic changes are discussed in the following sections. Dynamic changes
can be set by using a callback method. This UpdateCallack is set
statically as well, and is discussed in the next section.