Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Universe Class Reference

#include <universe.h>

Collaboration diagram for Universe:

Collaboration graph
List of all members.

Public Member Functions

SolarSystemcreateSolarSystem (Star *star) const
Selection find (const std::string &s, Selection *contexts=NULL, int nContexts=0, bool i18n=false)
Selection findChildObject (const Selection &sel, const string &name, bool i18n=false) const
Selection findObjectInContext (const Selection &sel, const string &name, bool i18n=false) const
Selection findPath (const std::string &s, Selection *contexts=NULL, int nContexts=0, bool i18n=false)
AsterismListgetAsterisms () const
ConstellationBoundariesgetBoundaries () const
std::vector< std::stringgetCompletion (const std::string &s, Selection *contexts=NULL, int nContexts=0, bool withLocations=false)
std::vector< std::stringgetCompletionPath (const std::string &s, Selection *contexts=NULL, int nContexts=0, bool withLocations=false)
DSODatabasegetDSOCatalog () const
MarkerListgetMarkers () const
SolarSystemgetNearestSolarSystem (const UniversalCoord &position) const
void getNearStars (const UniversalCoord &position, float maxDistance, std::vector< const Star * > &stars) const
SolarSystemgetSolarSystem (const Selection &) const
SolarSystemgetSolarSystem (const Star *star) const
SolarSystemCataloggetSolarSystemCatalog () const
StarDatabasegetStarCatalog () const
bool isMarked (const Selection &, int priority) const
void markObject (const Selection &, float size, Color color, Marker::Symbol symbol, int priority)
Selection pick (const UniversalCoord &origin, const Vec3f &direction, double when, float faintestMag, float tolerance=0.0f)
Selection pickDeepSkyObject (const UniversalCoord &, const Vec3f &, float faintest, float tolerance=0.0f)
Selection pickStar (const UniversalCoord &, const Vec3f &, double when, float faintest, float tolerance=0.0f)
void setAsterisms (AsterismList *)
void setBoundaries (ConstellationBoundaries *)
void setDSOCatalog (DSODatabase *)
void setSolarSystemCatalog (SolarSystemCatalog *)
void setStarCatalog (StarDatabase *)
 Universe ()
void unmarkAll ()
void unmarkObject (const Selection &, int priority)
 ~Universe ()

Private Member Functions

Selection pickPlanet (SolarSystem &solarSystem, const UniversalCoord &, const Vec3f &, double when, float faintestMag, float tolerance)

Private Attributes

AsterismListasterisms
ConstellationBoundariesboundaries
std::vector< const Star * > closeStars
DSODatabasedsoCatalog
MarkerListmarkers
SolarSystemCatalogsolarSystemCatalog
StarDatabasestarCatalog

Constructor & Destructor Documentation

Universe::Universe  ) 
 

Definition at line 27 of file universe.cpp.

References markers.

00027                    :
00028     starCatalog(NULL),
00029     solarSystemCatalog(NULL),
00030     dsoCatalog(NULL),
00031     asterisms(NULL),
00032     /*boundaries(NULL),*/
00033     markers(NULL)
00034 {
00035     markers = new MarkerList();
00036 }

Universe::~Universe  ) 
 

Definition at line 38 of file universe.cpp.

References markers.

00039 {
00040     delete markers;
00041     // TODO: Clean up!
00042 }


Member Function Documentation

SolarSystem * Universe::createSolarSystem Star star  )  const
 

Definition at line 147 of file universe.cpp.

References getSolarSystem(), and solarSystemCatalog.

00148 {
00149     SolarSystem* solarSystem = getSolarSystem(star);
00150     if (solarSystem != NULL)
00151         return solarSystem;
00152 
00153     solarSystem = new SolarSystem(star);
00154     solarSystemCatalog->insert(SolarSystemCatalog::
00155                                value_type(star->getCatalogNumber(),
00156                                           solarSystem));
00157 
00158     return solarSystem;
00159 }

Selection Universe::find const std::string s,
Selection contexts = NULL,
int  nContexts = 0,
bool  i18n = false
 

Definition at line 1043 of file universe.cpp.

References dsoCatalog, Selection::empty(), DSODatabase::find(), StarDatabase::find(), findObjectInContext(), and starCatalog.

Referenced by Simulation::findObject(), SelectionPopup::getSelectionFromId(), handlePopupMenu(), SelectionPopup::insert(), menuContext(), and object_getchildren().

01047 {
01048     if (starCatalog != NULL)
01049     {
01050     Star* star = starCatalog->find(s);
01051     if (star != NULL)
01052         return Selection(star);
01053     }
01054 
01055     if (dsoCatalog != NULL)
01056     {
01057         DeepSkyObject* dso = dsoCatalog->find(s);
01058         if (dso != NULL)
01059             return Selection(dso);
01060     }
01061 
01062     for (int i=0; i<nContexts; ++i)
01063     {
01064         Selection sel = findObjectInContext(contexts[i], s, i18n);
01065         if (!sel.empty())
01066             return sel;
01067     }
01068 
01069     return Selection();
01070 }

Selection Universe::findChildObject const Selection sel,
const string name,
bool  i18n = false
const
 

Definition at line 936 of file universe.cpp.

References PlanetarySystem::find(), Body::findLocation(), SolarSystem::getPlanets(), and getSolarSystem().

00939 {
00940     switch (sel.getType())
00941     {
00942     case Selection::Type_Star:
00943         {
00944             SolarSystem* sys = getSolarSystem(sel.star());
00945             if (sys != NULL)
00946             {
00947                 PlanetarySystem* planets = sys->getPlanets();
00948                 if (planets != NULL)
00949                     return Selection(planets->find(name, false, i18n));
00950             }
00951         }
00952         break;
00953 
00954     case Selection::Type_Body:
00955         {
00956             // First, search for a satellite
00957             PlanetarySystem* sats = sel.body()->getSatellites();
00958             if (sats != NULL)
00959             {
00960                 Body* body = sats->find(name, false, i18n);
00961                 if (body != NULL)
00962                     return Selection(body);
00963             }
00964 
00965             // If a satellite wasn't found, check this object's locations
00966             Location* loc = sel.body()->findLocation(name, i18n);
00967             if (loc != NULL)
00968                 return Selection(loc);
00969         }
00970         break;
00971 
00972     case Selection::Type_Location:
00973         // Locations have no children
00974         break;
00975 
00976     case Selection::Type_DeepSky:
00977         // Deep sky objects have no children
00978         break;
00979 
00980     default:
00981         break;
00982     }
00983 
00984     return Selection();
00985 }

Selection Universe::findObjectInContext const Selection sel,
const string name,
bool  i18n = false
const
 

Definition at line 992 of file universe.cpp.

References PlanetarySystem::find(), Body::findLocation(), SolarSystem::getPlanets(), and getSolarSystem().

Referenced by find().

00995 {
00996     Body* contextBody = NULL;
00997 
00998     switch (sel.getType())
00999     {
01000     case Selection::Type_Body:
01001         contextBody = sel.body();
01002         break;
01003 
01004     case Selection::Type_Location:
01005         contextBody = sel.location()->getParentBody();
01006         break;
01007 
01008     default:
01009         break;
01010     }
01011 
01012     // First, search for bodies . . .
01013     SolarSystem* sys = getSolarSystem(sel);
01014     if (sys != NULL)
01015     {
01016         PlanetarySystem* planets = sys->getPlanets();
01017         if (planets != NULL)
01018         {
01019             Body* body = planets->find(name, true, i18n);
01020             if (body != NULL)
01021                 return Selection(body);
01022         }
01023     }
01024 
01025     // . . . and then locations.
01026     if (contextBody != NULL)
01027     {
01028         Location* loc = contextBody->findLocation(name, i18n);
01029         if (loc != NULL)
01030             return Selection(loc);
01031     }
01032 
01033     return Selection();
01034 }

Selection Universe::findPath const std::string s,
Selection contexts = NULL,
int  nContexts = 0,
bool  i18n = false
 

Referenced by Simulation::findObjectFromPath(), and getCompletionPath().

AsterismList * Universe::getAsterisms  )  const
 

Definition at line 78 of file universe.cpp.

References asterisms.

00079 {
00080     return asterisms;
00081 }

ConstellationBoundaries * Universe::getBoundaries  )  const
 

Definition at line 88 of file universe.cpp.

References boundaries.

00089 {
00090     return boundaries;
00091 }

vector< string > Universe::getCompletion const std::string s,
Selection contexts = NULL,
int  nContexts = 0,
bool  withLocations = false
 

Definition at line 1114 of file universe.cpp.

References Selection::body(), dsoCatalog, StarDatabase::getCompletion(), DSODatabase::getCompletion(), PlanetarySystem::getCompletion(), Body::getLocations(), SolarSystem::getPlanets(), getSolarSystem(), starCatalog, stars, and UTF8StringCompare().

Referenced by getCompletionPath().

01118 {
01119     vector<string> completion;
01120 
01121     // Solar bodies first:
01122     for (int i = 0; i < nContexts; i++)
01123     {
01124         if (withLocations && contexts[i].getType() == Selection::Type_Body)
01125         {
01126             vector<Location*>* locations = contexts[i].body()->getLocations();
01127             if (locations != NULL)
01128             {
01129                 for (vector<Location*>::const_iterator iter = locations->begin();
01130                      iter != locations->end(); iter++)
01131                 {
01132                     if (!UTF8StringCompare(s, (*iter)->getName(true), s.length()))
01133                         completion.push_back((*iter)->getName(true));
01134                 }
01135             }
01136         }
01137 
01138         SolarSystem* sys = getSolarSystem(contexts[i]);
01139         if (sys != NULL)
01140         {
01141             PlanetarySystem* planets = sys->getPlanets();
01142             if (planets != NULL)
01143             {
01144                 vector<string> bodies = planets->getCompletion(s);
01145                 completion.insert(completion.end(),
01146                                   bodies.begin(), bodies.end());
01147             }
01148         }
01149     }
01150 
01151     // Deep sky objects:
01152     if (dsoCatalog != NULL)
01153         {
01154         vector<string> dsos  = dsoCatalog->getCompletion(s);
01155         completion.insert(completion.end(), dsos.begin(), dsos.end());
01156     }
01157 
01158     // and finally stars;
01159     if (starCatalog != NULL)
01160     {
01161         vector<string> stars  = starCatalog->getCompletion(s);
01162     completion.insert(completion.end(), stars.begin(), stars.end());
01163     }
01164 
01165     return completion;
01166 }

vector< string > Universe::getCompletionPath const std::string s,
Selection contexts = NULL,
int  nContexts = 0,
bool  withLocations = false
 

Definition at line 1169 of file universe.cpp.

References Selection::body(), Selection::deepsky(), dsoCatalog, Selection::empty(), findPath(), PlanetarySystem::getCompletion(), getCompletion(), DSODatabase::getDSOName(), Body::getLocations(), SolarSystem::getPlanets(), Body::getSatellites(), getSolarSystem(), Selection::getType(), Selection::star(), and UTF8StringCompare().

Referenced by Simulation::getObjectCompletion().

01173 {
01174     vector<string> completion;
01175     vector<string> locationCompletion;
01176     string::size_type pos = s.rfind('/', s.length());
01177 
01178     if (pos == string::npos)
01179         return getCompletion(s, contexts, nContexts, withLocations);
01180 
01181     string base(s, 0, pos);
01182     Selection sel = findPath(base, contexts, nContexts, true);
01183 
01184     if (sel.empty())
01185     {
01186         cerr << "nothing found" << endl;
01187         return completion;
01188     }
01189 
01190     if (sel.getType() == Selection::Type_DeepSky)
01191     {
01192         completion.push_back(dsoCatalog->getDSOName(sel.deepsky()));
01193         return completion;
01194     }
01195 
01196     PlanetarySystem* worlds = NULL;
01197     if (sel.getType() == Selection::Type_Body)
01198     {cerr << "body found" << endl;
01199         worlds = sel.body()->getSatellites();
01200         vector<Location*>* locations = sel.body()->getLocations();
01201         if (locations != NULL && withLocations)
01202         {
01203             string search = s.substr(pos + 1);
01204             for (vector<Location*>::const_iterator iter = locations->begin();
01205                  iter != locations->end(); iter++)
01206             {
01207                 if (!UTF8StringCompare(search, (*iter)->getName(true),
01208                                        search.length()))
01209                 {
01210                     locationCompletion.push_back((*iter)->getName(true));
01211                 }
01212             }
01213         }
01214     }
01215     else if (sel.getType() == Selection::Type_Star)
01216     {
01217         SolarSystem* ssys = getSolarSystem(sel.star());
01218         if (ssys != NULL)
01219             worlds = ssys->getPlanets();
01220     }
01221 
01222     if (worlds != NULL)
01223         completion = worlds->getCompletion(s.substr(pos + 1), false);
01224 
01225     completion.insert(completion.end(), locationCompletion.begin(), locationCompletion.end());
01226 
01227     return completion;
01228 }

DSODatabase * Universe::getDSOCatalog  )  const
 

Definition at line 67 of file universe.cpp.

References dsoCatalog.

Referenced by Url::getSelectionName(), SelectionPopup::getSelectionName(), handlePopupMenu(), SelectionPopup::init(), menuContext(), SelectionPopup::process(), and CelestiaCore::renderOverlay().

00068 {
00069     return dsoCatalog;
00070 }

MarkerList * Universe::getMarkers  )  const
 

Definition at line 162 of file universe.cpp.

References markers.

Referenced by SelectionPopup::init(), and SelectionPopup::process().

00163 {
00164     return markers;
00165 }

SolarSystem * Universe::getNearestSolarSystem const UniversalCoord position  )  const
 

Definition at line 1233 of file universe.cpp.

References ClosestStarFinder::closestStar, StarDatabase::findCloseStars(), getSolarSystem(), starCatalog, Point3< T >::x, Point3< T >::y, and Point3< T >::z.

Referenced by pick(), and Simulation::update().

01234 {
01235     Point3f pos = (Point3f) position;
01236     Point3f lyPos(pos.x * 1.0e-6f, pos.y * 1.0e-6f, pos.z * 1.0e-6f);
01237     ClosestStarFinder closestFinder(1.0f);
01238     starCatalog->findCloseStars(closestFinder, lyPos, 1.0f);
01239     return getSolarSystem(closestFinder.closestStar);
01240 }

void Universe::getNearStars const UniversalCoord position,
float  maxDistance,
std::vector< const Star * > &  stars
const
 

Definition at line 1244 of file universe.cpp.

References StarDatabase::findCloseStars(), starCatalog, Point3< T >::x, Point3< T >::y, and Point3< T >::z.

Referenced by pick().

01247 {
01248     Point3f pos = (Point3f) position;
01249     Point3f lyPos(pos.x * 1.0e-6f, pos.y * 1.0e-6f, pos.z * 1.0e-6f);
01250     NearStarFinder finder(1.0f, nearStars);
01251     starCatalog->findCloseStars(finder, lyPos, maxDistance);
01252 }

SolarSystem * Universe::getSolarSystem const Selection  )  const
 

Definition at line 115 of file universe.cpp.

References PlanetarySystem::getPrimaryBody(), getSolarSystem(), PlanetarySystem::getStar(), and Body::getSystem().

00116 {
00117     switch (sel.getType())
00118     {
00119     case Selection::Type_Star:
00120         return getSolarSystem(sel.star());
00121 
00122     case Selection::Type_Body:
00123         {
00124             PlanetarySystem* system = sel.body()->getSystem();
00125             while (system != NULL)
00126             {
00127                 Body* parent = system->getPrimaryBody();
00128                 if (parent != NULL)
00129                     system = parent->getSystem();
00130                 else
00131                     return getSolarSystem(Selection(system->getStar()));
00132             }
00133             return NULL;
00134         }
00135 
00136     case Selection::Type_Location:
00137         return getSolarSystem(Selection(sel.location()->getParentBody()));
00138 
00139     default:
00140         return NULL;
00141     }
00142 }

SolarSystem * Universe::getSolarSystem const Star star  )  const
 

Definition at line 99 of file universe.cpp.

References solarSystemCatalog.

Referenced by createSolarSystem(), findChildObject(), findObjectInContext(), getCompletion(), getCompletionPath(), getNearestSolarSystem(), Simulation::getObjectCompletion(), getSolarSystem(), pick(), and Simulation::selectPlanet().

00100 {
00101     if (star == NULL)
00102         return NULL;
00103 
00104     uint32 starNum = star->getCatalogNumber();
00105     SolarSystemCatalog::iterator iter = solarSystemCatalog->find(starNum);
00106     if (iter == solarSystemCatalog->end())
00107         return NULL;
00108     else
00109         return iter->second;
00110 }

SolarSystemCatalog * Universe::getSolarSystemCatalog  )  const
 

Definition at line 56 of file universe.cpp.

References solarSystemCatalog.

Referenced by SelectionPopup::getSelectionFromId(), handlePopupMenu(), InitStarBrowserItems(), SelectionPopup::insert(), StarBrowser::listStars(), menuContext(), object_getchildren(), and CelestialBrowser::slotRefresh().

00057 {
00058     return solarSystemCatalog;
00059 }

StarDatabase * Universe::getStarCatalog  )  const
 

Definition at line 45 of file universe.cpp.

References starCatalog.

Referenced by celestia_getstar(), celestia_getstarcount(), CelestiaCore::charEntered(), Url::getSelectionName(), SelectionPopup::getSelectionName(), handlePopupMenu(), SelectionPopup::init(), CelestiaCore::initRenderer(), CelestiaCore::initSimulation(), InitStarBrowserItems(), StarBrowser::listStars(), menuContext(), StarBrowser::nearestStar(), CelestiaCore::renderOverlay(), CelestialBrowser::slotRefresh(), and StarBrowserDisplayItem().

00046 {
00047     return starCatalog;
00048 }

bool Universe::isMarked const Selection ,
int  priority
const
 

Definition at line 224 of file universe.cpp.

References Marker::getPriority(), and markers.

Referenced by CelestiaCore::charEntered(), handlePopupMenu(), SelectionPopup::insert(), and menuContext().

00225 {
00226     for (MarkerList::iterator iter = markers->begin();
00227          iter != markers->end(); iter++)
00228     {
00229         if (iter->getObject() == sel)
00230             return iter->getPriority() >= priority;
00231     }
00232 
00233     return false;
00234 }

void Universe::markObject const Selection ,
float  size,
Color  color,
Marker::Symbol  symbol,
int  priority
 

Definition at line 168 of file universe.cpp.

References markers, Marker::setColor(), Marker::setPriority(), Marker::setSize(), and Marker::setSymbol().

Referenced by celestia_mark(), CelestiaCore::charEntered(), MainWindowProc(), menuMark(), object_mark(), SelectionPopup::process(), and Simulation::setSelection().

00173 {
00174     for (MarkerList::iterator iter = markers->begin();
00175          iter != markers->end(); iter++)
00176     {
00177         if (iter->getObject() == sel)
00178         {
00179             // Handle the case when the object is already marked.  If the
00180             // priority is higher than the existing marker, replace it.
00181             // Otherwise, do nothing.
00182             if (priority > iter->getPriority())
00183             {
00184                 markers->erase(iter);
00185                 break;
00186             }
00187             else
00188             {
00189                 return;
00190             }
00191         }
00192     }
00193 
00194     Marker marker(sel);
00195     marker.setColor(color);
00196     marker.setSymbol(symbol);
00197     marker.setSize(size);
00198     marker.setPriority(priority);
00199     markers->insert(markers->end(), marker);
00200 }

Selection Universe::pick const UniversalCoord origin,
const Vec3f direction,
double  when,
float  faintestMag,
float  tolerance = 0.0f
 

Definition at line 887 of file universe.cpp.

References closeStars, Selection::empty(), getNearestSolarSystem(), getNearStars(), getSolarSystem(), pickDeepSkyObject(), pickPlanet(), and pickStar().

Referenced by Simulation::pickObject().

00892 {
00893     Selection sel;
00894 
00895     closeStars.clear();
00896     getNearStars(origin, 1.0f, closeStars);
00897     for (vector<const Star*>::const_iterator iter = closeStars.begin();
00898          iter != closeStars.end(); iter++)
00899     {
00900         SolarSystem* solarSystem = getSolarSystem(*iter);
00901         if (solarSystem != NULL)
00902         {
00903             sel = pickPlanet(*solarSystem,
00904                              origin, direction,
00905                              when,
00906                              faintestMag,
00907                              tolerance);
00908             if (!sel.empty())
00909                 break;
00910         }
00911     }
00912     
00913 #if 0
00914     SolarSystem* closestSolarSystem = getNearestSolarSystem(origin);
00915     if (closestSolarSystem != NULL)
00916     {
00917         sel = pickPlanet(*closestSolarSystem,
00918                          origin, direction,
00919                          when,
00920                          faintestMag,
00921                          tolerance);
00922     }
00923 #endif
00924 
00925     if (sel.empty())
00926         sel = pickStar(origin, direction, when, faintestMag, tolerance);
00927 
00928     if (sel.empty())
00929         sel = pickDeepSkyObject(origin, direction, faintestMag, tolerance);
00930 
00931     return sel;
00932 }

Selection Universe::pickDeepSkyObject const UniversalCoord ,
const Vec3f ,
float  faintest,
float  tolerance = 0.0f
 

Definition at line 833 of file universe.cpp.

References ANGULAR_RES, CloseDSOPicker::closestDSO, dsoCatalog, DSODatabase::findCloseDSOs(), DSODatabase::findVisibleDSOs(), Vector3< T >::normalize(), PI, DSOPicker::pickedDSO, Quaternion< T >::setAxisAngle(), sqrt(), Vector3< T >::x, Point3< T >::x, Vector3< T >::y, Point3< T >::y, Vector3< T >::z, and Point3< T >::z.

Referenced by pick().

00837 {
00838     Point3d orig = (Point3d) origin;
00839     orig.x *= 1e-6;
00840     orig.y *= 1e-6;
00841     orig.z *= 1e-6;
00842 
00843     Vec3d dir   = Vec3d(direction.x, direction.y, direction.z);
00844 
00845     CloseDSOPicker closePicker(orig, dir, 1e9, tolerance);
00846 
00847     dsoCatalog->findCloseDSOs(closePicker, orig, 1e9);
00848     if (closePicker.closestDSO != NULL)
00849     {
00850         return Selection(const_cast<DeepSkyObject*>(closePicker.closestDSO));
00851     }
00852 
00853     Quatf rotation;
00854     Vec3d n(0, 0, -1);
00855     Vec3d Miss       = n - dir;
00856     double sinAngle2 = sqrt(Miss * Miss)/2.0;
00857 
00858     if (sinAngle2 <= ANGULAR_RES)
00859     {
00860         rotation.setAxisAngle(Vec3f(1, 0, 0), 0);
00861     }
00862     else if (sinAngle2 >= 1.0 - 0.5 * ANGULAR_RES * ANGULAR_RES)
00863     {
00864         rotation.setAxisAngle(Vec3f(1, 0, 0), (float) PI);
00865     }
00866     else
00867     {
00868         Vec3f axis = direction ^ Vec3f((float)n.x, (float)n.y, (float)n.z);
00869         axis.normalize();
00870         rotation.setAxisAngle(axis, (float) (2.0 * asin(sinAngle2)));
00871     }
00872 
00873     DSOPicker picker(orig, dir, tolerance);
00874     dsoCatalog->findVisibleDSOs(picker,
00875                                 orig,
00876                                 rotation,
00877                                 tolerance,
00878                                 1.0f,
00879                                 faintestMag);
00880     if (picker.pickedDSO != NULL)
00881         return Selection(const_cast<DeepSkyObject*>(picker.pickedDSO));
00882     else
00883         return Selection();
00884 }

Selection Universe::pickPlanet SolarSystem solarSystem,
const UniversalCoord ,
const Vec3f ,
double  when,
float  faintestMag,
float  tolerance
[private]
 

Definition at line 424 of file universe.cpp.

References ANGULAR_RES, ApproxPlanetPickTraversal(), PlanetPickInfo::atanTolerance, PlanetPickInfo::closestApproxDistance, PlanetPickInfo::closestBody, PlanetPickInfo::closestDistance, ExactPlanetPickTraversal(), Star::getPosition(), PlanetPickInfo::jd, PlanetPickInfo::pickRay, sin(), PlanetPickInfo::sinAngle2Closest, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

Referenced by pick().

00430 {
00431     double sinTol2 = (sin(tolerance/2.0) >  ANGULAR_RES ? 
00432                       sin(tolerance/2.0) : ANGULAR_RES);
00433     PlanetPickInfo pickInfo;
00434 
00435     Star* star = solarSystem.getStar();
00436     assert(star != NULL);
00437 
00438     // Transform the pick ray origin into astrocentric coordinates
00439     UniversalCoord starPos = star->getPosition(when);
00440     Vec3d v = origin - starPos;
00441     Point3d astrocentricOrigin(astro::microLightYearsToKilometers(v.x),
00442                                astro::microLightYearsToKilometers(v.y),
00443                                astro::microLightYearsToKilometers(v.z));
00444 
00445     pickInfo.pickRay = Ray3d(astrocentricOrigin,
00446                              Vec3d(direction.x, direction.y, direction.z));
00447                              
00448     pickInfo.sinAngle2Closest = 1.0;
00449     pickInfo.closestDistance = 1.0e50;
00450     pickInfo.closestApproxDistance = 1.0e50;
00451     pickInfo.closestBody = NULL;
00452     pickInfo.jd = when;
00453     pickInfo.atanTolerance = (float) atan(tolerance);
00454 
00455     // First see if there's a planet|moon that the pick ray intersects.
00456     // Select the closest planet|moon intersected.
00457 
00458     solarSystem.getPlanets()->traverse(ExactPlanetPickTraversal,
00459                                        (void*) &pickInfo);
00460 
00461     if (pickInfo.closestBody != NULL)
00462     {
00463         // Retain that body
00464         Body* closestBody = pickInfo.closestBody;
00465 
00466         // Check if there is a satellite in front of the primary body that is
00467         // sufficiently close to the pickRay 
00468 
00469         solarSystem.getPlanets()->traverse(ApproxPlanetPickTraversal,
00470                                            (void*) &pickInfo);
00471         if (pickInfo.closestBody == closestBody)
00472           return  Selection(closestBody); 
00473         // Nothing else around, select the body and return
00474 
00475         // Are we close enough to the satellite and is it in front of the body?
00476         if ((pickInfo.sinAngle2Closest <= sinTol2) && 
00477             (pickInfo.closestDistance > pickInfo.closestApproxDistance)) 
00478         return Selection(pickInfo.closestBody);
00479             // Yes, select the satellite
00480         else
00481             return  Selection(closestBody); 
00482            //  No, select the primary body 
00483     }
00484 
00485     // If no planet was intersected by the pick ray, choose the planet|moon
00486     // with the smallest angular separation from the pick ray.  Very distant
00487     // planets are likley to fail the intersection test even if the user
00488     // clicks on a pixel where the planet's disc has been rendered--in order
00489     // to make distant planets visible on the screen at all, their apparent
00490     // size has to be greater than their actual disc size.
00491 
00492     solarSystem.getPlanets()->traverse(ApproxPlanetPickTraversal,
00493                                        (void*) &pickInfo);
00494     if (pickInfo.sinAngle2Closest <= sinTol2)
00495         return Selection(pickInfo.closestBody);
00496     else
00497         return Selection();
00498 }

Selection Universe::pickStar const UniversalCoord ,
const Vec3f ,
double  when,
float  faintest,
float  tolerance = 0.0f
 

Definition at line 660 of file universe.cpp.

References ANGULAR_RES, CloseStarPicker::closestStar, StarDatabase::findCloseStars(), StarDatabase::findVisibleStars(), Vector3< T >::normalize(), PI, StarPicker::pickedStar, Quaternion< T >::setAxisAngle(), sqrt(), starCatalog, Vector3< T >::x, Point3< T >::x, Vector3< T >::y, Point3< T >::y, Vector3< T >::z, and Point3< T >::z.

Referenced by pick().

00665 {
00666     Point3f o = (Point3f) origin;
00667     o.x *= 1e-6f;
00668     o.y *= 1e-6f;
00669     o.z *= 1e-6f;
00670 
00671     // Use a high precision pick test for any stars that are close to the
00672     // observer.  If this test fails, use a low precision pick test for stars
00673     // which are further away.  All this work is necessary because the low
00674     // precision pick test isn't reliable close to a star and the high
00675     // precision test isn't nearly fast enough to use on our database of
00676     // over 100k stars.
00677     CloseStarPicker closePicker(origin, direction, when, 1.0f, tolerance);
00678     starCatalog->findCloseStars(closePicker, o, 1.0f);
00679     if (closePicker.closestStar != NULL)
00680         return Selection(const_cast<Star*>(closePicker.closestStar));
00681 
00682     // Find visible stars expects an orientation, but we just have a direction
00683     // vector.  Convert the direction vector into an orientation by computing
00684     // the rotation required to map (0, 0, -1) to the direction.
00685     Quatf rotation;
00686     Vec3f n(0, 0, -1);
00687     Vec3f Missf = n - direction;
00688     Vec3d Miss = Vec3d(Missf.x, Missf.y, Missf.z); 
00689     double sinAngle2 = sqrt(Miss * Miss)/2.0;
00690 
00691     if (sinAngle2 <= ANGULAR_RES)
00692     {
00693         rotation.setAxisAngle(Vec3f(1, 0, 0), 0);
00694     }
00695     else if (sinAngle2 >= 1.0 - 0.5 * ANGULAR_RES * ANGULAR_RES)
00696     {
00697         rotation.setAxisAngle(Vec3f(1, 0, 0), (float) PI);
00698     }
00699     else
00700     {
00701         Vec3f axis = direction ^ n;
00702         axis.normalize();
00703         rotation.setAxisAngle(axis, (float) (2.0 * asin(sinAngle2)));
00704     }
00705     StarPicker picker(o, direction, when, tolerance);
00706     starCatalog->findVisibleStars(picker,
00707                                   o,
00708                                   rotation,
00709                                   tolerance, 1.0f,
00710                                   faintestMag);
00711     if (picker.pickedStar != NULL)
00712         return Selection(const_cast<Star*>(picker.pickedStar));
00713     else
00714         return Selection();
00715 }

void Universe::setAsterisms AsterismList  ) 
 

Definition at line 83 of file universe.cpp.

References asterisms.

Referenced by CelestiaCore::initSimulation().

00084 {
00085     asterisms = _asterisms;
00086 }

void Universe::setBoundaries ConstellationBoundaries  ) 
 

Definition at line 93 of file universe.cpp.

References boundaries.

Referenced by CelestiaCore::initSimulation().

00094 {
00095     boundaries = _boundaries;
00096 }

void Universe::setDSOCatalog DSODatabase  ) 
 

Definition at line 72 of file universe.cpp.

References dsoCatalog.

Referenced by CelestiaCore::initSimulation().

00073 {
00074     dsoCatalog = catalog;
00075 }

void Universe::setSolarSystemCatalog SolarSystemCatalog  ) 
 

Definition at line 61 of file universe.cpp.

References solarSystemCatalog.

Referenced by CelestiaCore::initSimulation().

00062 {
00063     solarSystemCatalog = catalog;
00064 }

void Universe::setStarCatalog StarDatabase  ) 
 

Definition at line 50 of file universe.cpp.

References starCatalog.

Referenced by CelestiaCore::readStars().

00051 {
00052     starCatalog = catalog;
00053 }

void Universe::unmarkAll  ) 
 

Definition at line 218 of file universe.cpp.

References markers.

Referenced by celestia_unmarkall(), and SelectionPopup::process().

00219 {
00220     markers->erase(markers->begin(), markers->end());
00221 }

void Universe::unmarkObject const Selection ,
int  priority
 

Definition at line 203 of file universe.cpp.

References markers.

Referenced by celestia_unmark(), CelestiaCore::charEntered(), MainWindowProc(), menuUnMark(), object_unmark(), SelectionPopup::process(), and Simulation::setSelection().

00204 {
00205     for (MarkerList::iterator iter = markers->begin();
00206          iter != markers->end(); iter++)
00207     {
00208         if (iter->getObject() == sel)
00209         {
00210             if (priority >= iter->getPriority())
00211                 markers->erase(iter);
00212             break;
00213         }
00214     }
00215 }


Member Data Documentation

AsterismList* Universe::asterisms [private]
 

Definition at line 121 of file universe.h.

Referenced by getAsterisms(), and setAsterisms().

ConstellationBoundaries* Universe::boundaries [private]
 

Definition at line 122 of file universe.h.

Referenced by getBoundaries(), and setBoundaries().

std::vector<const Star*> Universe::closeStars [private]
 

Definition at line 125 of file universe.h.

Referenced by pick().

DSODatabase* Universe::dsoCatalog [private]
 

Definition at line 119 of file universe.h.

Referenced by find(), getCompletion(), getCompletionPath(), getDSOCatalog(), pickDeepSkyObject(), and setDSOCatalog().

MarkerList* Universe::markers [private]
 

Definition at line 123 of file universe.h.

Referenced by getMarkers(), isMarked(), markObject(), Universe(), unmarkAll(), unmarkObject(), and ~Universe().

SolarSystemCatalog* Universe::solarSystemCatalog [private]
 

Definition at line 120 of file universe.h.

Referenced by createSolarSystem(), getSolarSystem(), getSolarSystemCatalog(), and setSolarSystemCatalog().

StarDatabase* Universe::starCatalog [private]
 

Definition at line 118 of file universe.h.

Referenced by find(), getCompletion(), getNearestSolarSystem(), getNearStars(), getStarCatalog(), pickStar(), and setStarCatalog().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:40 2006 for Celestia by  doxygen 1.4.1