#include <cstdio>#include <iostream>#include <fstream>#include <iomanip>#include <algorithm>#include <cstdlib>#include <cctype>#include <cstring>#include <cassert>#include <ctime>#include <celengine/gl.h>#include <celmath/vecmath.h>#include <celmath/quaternion.h>#include <celmath/mathlib.h>#include <celutil/util.h>#include <celutil/filetype.h>#include <celutil/directory.h>#include <celutil/formatnum.h>#include <celengine/astro.h>#include <celengine/overlay.h>#include <celengine/console.h>#include <celengine/execution.h>#include <celengine/cmdparser.h>#include <celengine/multitexture.h>#include "favorites.h"#include "celestiacore.h"#include <celutil/debug.h>#include <celutil/utf8.h>#include "url.h"Include dependency graph for celestiacore.cpp:

Go to the source code of this file.
Typedefs | |
| typedef CatalogLoader< DSODatabase > | DeepSkyLoader |
| typedef CatalogLoader< StarDatabase > | StarLoader |
Functions | |
| bool | checkMask (int modifiers, int mask) |
| float | ComputeRotationCoarseness (Simulation &sim) |
| static Console | console (200, 120) |
| static void | displayAcronym (Overlay &overlay, char *s) |
| static void | displayAngle (Overlay &overlay, double angle) |
| static void | displayApparentDiameter (Overlay &overlay, double radius, double distance) |
| static void | displayApparentMagnitude (Overlay &overlay, float absMag, double distance) |
| static void | displayDistance (Overlay &overlay, double distance) |
| static void | displayDSOinfo (Overlay &overlay, const DeepSkyObject &dso, double distance) |
| static void | displayDuration (Overlay &overlay, double days) |
| static void | displayLocationInfo (Overlay &overlay, Location &location, double distance) |
| static void | displayPlanetInfo (Overlay &overlay, int detail, Body &body, double t, double distance, Vec3d viewVec) |
| static void | displaySelectionName (Overlay &overlay, const Selection &sel, const Universe &univ) |
| static void | displayStarInfo (Overlay &overlay, int detail, Star &star, const Universe &universe, double distance) |
| static void | loadCrossIndex (StarDatabase *starDB, StarDatabase::Catalog catalog, const string &filename) |
| static void | scrollConsole (Console &con, int lines) |
| void | showSelectionInfo (const Selection &sel) |
| static void | showViewFrame (const View *v, int width, int height) |
| static FormattedNumber | SigDigitNum (double v, int digits) |
| static void | warning (string s) |
Variables | |
| static const int | ConsolePageRows = 10 |
| static const int | DragThreshold = 3 |
| static const float | fAltitudeThreshold = 4.0f |
| static const double | fMaxKeyAccel = 20.0 |
| static const double | fMinSlewRate = 3.0 |
| static float | KeyRotationAccel = degToRad(120.0f) |
| static const float | MaximumFOV = degToRad(120.0f) |
| static const double | MaximumTimeRate = 1.0e15 |
| static const float | MinimumFOV = degToRad(0.001f) |
| static float | MouseRotationSensitivity = degToRad(1.0f) |
| vector< OverlayImage > | overlayImages |
| static const float | RotationBraking = 10.0f |
| static const float | RotationDecay = 2.0f |
| static const float | stdFOV = degToRad(45.0f) |
| static const double | timeScaleFactor = 10.0f |
|
|
Definition at line 3538 of file celestiacore.cpp. |
|
|
Definition at line 3537 of file celestiacore.cpp. |
|
||||||||||||
|
Definition at line 598 of file celestiacore.cpp. References modifiers(). Referenced by CelestiaCore::mouseMove(). 00599 {
00600 return (modifiers & mask) == mask;
00601 }
|
|
|
Definition at line 127 of file celestiacore.cpp. References distance(), UniversalCoord::distanceTo(), Selection::getPosition(), Selection::getType(), max, astro::microLightYearsToKilometers(), and Selection::radius(). Referenced by CelestiaCore::mouseMove(), and CelestiaCore::tick(). 00128 {
00129 float coarseness = 1.5f;
00130
00131 Selection selection = sim.getActiveObserver()->getFrame().refObject;
00132 if (selection.getType() == Selection::Type_Star ||
00133 selection.getType() == Selection::Type_Body)
00134 {
00135 double radius = selection.radius();
00136 double t = sim.getTime();
00137 UniversalCoord observerPosition = sim.getActiveObserver()->getPosition();
00138 UniversalCoord selectionPosition = selection.getPosition(t);
00139 double distance = astro::microLightYearsToKilometers(observerPosition.distanceTo(selectionPosition));
00140 double altitude = distance - radius;
00141 if (altitude > 0.0 && altitude < radius)
00142 {
00143 coarseness *= (float) max(0.01, altitude / radius);
00144 }
00145 }
00146
00147 return coarseness;
00148 }
|
|
||||||||||||
|
Referenced by CelestiaCore::CelestiaCore(), CelestiaCore::draw(), CelestiaCore::keyDown(), CelestiaCore::resize(), and scrollConsole(). |
|
||||||||||||
|
Definition at line 2629 of file celestiacore.cpp. Referenced by CelestiaCore::renderOverlay(). 02630 {
02631 if (strchr(s, ' ') != NULL)
02632 {
02633 int length = strlen(s);
02634 char lastChar = ' ';
02635
02636 for (int i = 0; i < length; i++)
02637 {
02638 if (lastChar == ' ' && s[i] != ' ')
02639 overlay << s[i];
02640 lastChar = s[i];
02641 }
02642 }
02643 else
02644 {
02645 overlay << s;
02646 }
02647 }
|
|
||||||||||||
|
Definition at line 2570 of file celestiacore.cpp. References astro::decimalToDegMinSec(), and UTF8_DEGREE_SIGN. Referenced by displayApparentDiameter(), and CelestiaCore::renderOverlay(). 02571 {
02572 int degrees, minutes;
02573 double seconds;
02574 astro::decimalToDegMinSec(angle, degrees, minutes, seconds);
02575
02576 if (degrees > 0)
02577 {
02578 overlay.printf("%d%s %02d' %.1f\"",
02579 degrees, UTF8_DEGREE_SIGN, minutes, seconds);
02580 }
02581 else if (minutes > 0)
02582 {
02583 overlay.printf("%02d' %.1f\"", minutes, seconds);
02584 }
02585 else
02586 {
02587 overlay.printf("%.1f\"", seconds);
02588 }
02589 }
|
|
||||||||||||||||
|
Definition at line 2592 of file celestiacore.cpp. References _, displayAngle(), distance(), and radToDeg(). Referenced by displayDSOinfo(), displayPlanetInfo(), and displayStarInfo(). 02595 {
02596 if (distance > radius)
02597 {
02598 double arcSize = radToDeg(asin(radius / distance) * 2.0);
02599
02600 // Only display the arc size if it's less than 160 degrees and greater
02601 // than one second--otherwise, it's probably not interesting data.
02602 if (arcSize < 160.0 && arcSize > 1.0 / 3600.0)
02603 {
02604 overlay << _("Apparent diameter: ");
02605 displayAngle(overlay, arcSize);
02606 overlay << '\n';
02607 }
02608 }
02609 }
|
|
||||||||||||||||
|
Definition at line 2611 of file celestiacore.cpp. References _, astro::absToAppMag(), and distance(). Referenced by displayDSOinfo(). 02614 {
02615 float appMag = absMag;
02616 if (distance > 32.6167)
02617 {
02618 appMag = astro::absToAppMag(absMag, (float) distance);
02619 overlay << _("Apparent magnitude: ");
02620 }
02621 else
02622 {
02623 overlay << _("Absolute magnitude: ");
02624 }
02625
02626 overlay.printf("%.1f\n", appMag);
02627 }
|
|
||||||||||||
|
Definition at line 2519 of file celestiacore.cpp. References abs(), distance(), astro::lightYearsToAU(), astro::lightYearsToKilometers(), astro::lightYearsToParsecs(), and SigDigitNum(). Referenced by displayDSOinfo(), displayLocationInfo(), displayPlanetInfo(), and displayStarInfo(). 02520 {
02521 const char* units = "";
02522
02523 if (abs(distance) >= astro::parsecsToLightYears(1e+6))
02524 {
02525 units = "Mpc";
02526 distance = astro::lightYearsToParsecs(distance) / 1e+6;
02527 }
02528 else if (abs(distance) >= 0.5 * astro::parsecsToLightYears(1e+3))
02529 {
02530 units = "Kpc";
02531 distance = astro::lightYearsToParsecs(distance) / 1e+3;
02532 }
02533 else if (abs(distance) >= astro::AUtoLightYears(1000.0f))
02534 {
02535 units = "ly";
02536 }
02537 else if (abs(distance) >= astro::kilometersToLightYears(10000000.0))
02538 {
02539 units = "au";
02540 distance = astro::lightYearsToAU(distance);
02541 }
02542 else if (abs(distance) > astro::kilometersToLightYears(1.0f))
02543 {
02544 units = "km";
02545 distance = astro::lightYearsToKilometers(distance);
02546 }
02547 else
02548 {
02549 units = "m";
02550 distance = astro::lightYearsToKilometers(distance) * 1000.0f;
02551 }
02552
02553 overlay << SigDigitNum(distance, 5) << ' ' << units;
02554 }
|
|
||||||||||||||||
|
Definition at line 2702 of file celestiacore.cpp. References _, displayApparentDiameter(), displayApparentMagnitude(), displayDistance(), distance(), and DSO_DEFAULT_ABS_MAGNITUDE. Referenced by CelestiaCore::renderOverlay(). 02703 {
02704 char descBuf[128];
02705
02706 dso.getDescription(descBuf, sizeof(descBuf));
02707 overlay << descBuf << '\n';
02708 if (distance >= 0)
02709 {
02710 overlay << _("Distance: ");
02711 displayDistance(overlay, distance);
02712 }
02713 else
02714 {
02715 overlay << _("Distance from center: ");
02716 displayDistance(overlay, distance + dso.getRadius());
02717 }
02718 overlay << '\n';
02719 overlay << _("Radius: ");
02720 displayDistance(overlay, dso.getRadius());
02721 overlay << '\n';
02722
02723 displayApparentDiameter(overlay, dso.getRadius(), distance);
02724 if (dso.getAbsoluteMagnitude() > DSO_DEFAULT_ABS_MAGNITUDE)
02725 {
02726 displayApparentMagnitude(overlay,
02727 dso.getAbsoluteMagnitude(),
02728 distance);
02729 }
02730 }
|
|
||||||||||||
|
Definition at line 2557 of file celestiacore.cpp. References _. Referenced by displayPlanetInfo(), and displayStarInfo(). 02558 {
02559 if (days > 1.0)
02560 overlay << days << _(" days");
02561 else if (days > 1.0 / 24.0)
02562 overlay << days * 24.0 << _(" hours");
02563 else if (days > 1.0 / (24.0 * 60.0))
02564 overlay << days * 24.0 * 60.0 << _(" minutes");
02565 else
02566 overlay << days * 24.0 * 60.0 * 60.0 << " seconds";
02567 }
|
|
||||||||||||||||
|
Definition at line 2790 of file celestiacore.cpp. References _, abs(), Body::cartesianToPlanetocentric(), displayDistance(), distance(), Body::getEclipticalToEquatorial(), Body::getName(), radToDeg(), Quaternion< T >::toMatrix3(), Vector3< T >::x, Quaternion< T >::y, and Vector3< T >::y. Referenced by CelestiaCore::renderOverlay(). 02793 {
02794 overlay << _("Distance: ");
02795 displayDistance(overlay, distance);
02796 overlay << '\n';
02797
02798 Body* body = location.getParentBody();
02799 if (body != NULL)
02800 {
02801 Vec3f lonLatAlt = body->cartesianToPlanetocentric(location.getPosition());
02802 char ewHemi = ' ';
02803 char nsHemi = ' ';
02804 float lon = 0.0f;
02805 float lat = 0.0f;
02806
02807 // Terrible hack for Earth and Moon longitude conventions. Fix by
02808 // adding a field to specify the longitude convention in .ssc files.
02809 if (body->getName() == "Earth" || body->getName() == "Moon")
02810 {
02811 if (lonLatAlt.y < 0.0f)
02812 nsHemi = 'S';
02813 else if (lonLatAlt.y > 0.0f)
02814 nsHemi = 'N';
02815
02816 if (lonLatAlt.x < 0.0f)
02817 ewHemi = 'W';
02818 else if (lonLatAlt.x > 0.0f)
02819 ewHemi = 'E';
02820
02821 lon = abs(radToDeg(lonLatAlt.x));
02822 lat = abs(radToDeg(lonLatAlt.y));
02823 }
02824 else
02825 {
02826 // Swap hemispheres if the object is a retrograde rotator
02827 Quatd q = ~body->getEclipticalToEquatorial(astro::J2000);
02828 bool retrograde = (Vec3d(0.0, 1.0, 0.0) * q.toMatrix3()).y < 0.0;
02829
02830 if ((lonLatAlt.y < 0.0f) ^ retrograde)
02831 nsHemi = 'S';
02832 else if ((lonLatAlt.y > 0.0f) ^ retrograde)
02833 nsHemi = 'N';
02834
02835 if (retrograde)
02836 ewHemi = 'E';
02837 else
02838 ewHemi = 'W';
02839
02840 lon = -radToDeg(lonLatAlt.x);
02841 if (lon < 0.0f)
02842 lon += 360.0f;
02843 lat = abs(radToDeg(lonLatAlt.y));
02844 }
02845
02846 overlay << body->getName(true).c_str() << " ";
02847 overlay.unsetf(ios::fixed);
02848 overlay << setprecision(6);
02849 overlay << lat << nsHemi << ' ' << lon << ewHemi << '\n';
02850 }
02851 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 2733 of file celestiacore.cpp. References _, displayApparentDiameter(), displayDistance(), displayDuration(), distance(), Star::getApparentMagnitude(), Star::getRadius(), PlanetarySystem::getStar(), Star::getTemperature(), astro::kilometersToLightYears(), astro::lightYearsToKilometers(), and sqrt(). Referenced by CelestiaCore::renderOverlay(). 02739 {
02740 double kmDistance = astro::lightYearsToKilometers(distance);
02741
02742 overlay << _("Distance: ");
02743 distance = astro::kilometersToLightYears(kmDistance - body.getRadius());
02744 displayDistance(overlay, distance);
02745 overlay << '\n';
02746
02747 overlay << _("Radius: ");
02748 distance = astro::kilometersToLightYears(body.getRadius());
02749 displayDistance(overlay, distance);
02750 overlay << '\n';
02751
02752 displayApparentDiameter(overlay, body.getRadius(), kmDistance);
02753
02754 if (detail > 1)
02755 {
02756 overlay << _("Day length: ");
02757 displayDuration(overlay, body.getRotationElements().period);
02758 overlay << '\n';
02759
02760 PlanetarySystem* system = body.getSystem();
02761 if (system != NULL)
02762 {
02763 const Star* sun = system->getStar();
02764 if (sun != NULL)
02765 {
02766 double distFromSun = body.getHeliocentricPosition(t).distanceFromOrigin();
02767 float planetTemp = sun->getTemperature() *
02768 (float) (::pow(1.0 - body.getAlbedo(), 0.25) *
02769 sqrt(sun->getRadius() / (2.0 * distFromSun)));
02770 overlay << setprecision(0);
02771 overlay << _("Temperature: ") << planetTemp << " K\n";
02772 overlay << setprecision(3);
02773 }
02774
02775 #if 0
02776 // Code to display apparent magnitude. Disabled because it's not very
02777 // accurate. Too many simplifications are used when computing the amount
02778 // of light reflected from a body.
02779 Point3d bodyPos = body.getHeliocentricPosition(t);
02780 float appMag = body.getApparentMagnitude(*sun,
02781 bodyPos - Point3d(0, 0, 0),
02782 viewVec);
02783 overlay.printf(_("Apparent mag: %.2f\n"), appMag);
02784 #endif
02785 }
02786 }
02787 }
|
|
||||||||||||||||
|
Definition at line 2854 of file celestiacore.cpp. References Body::getName(). Referenced by CelestiaCore::renderOverlay(). 02857 {
02858 switch (sel.getType())
02859 {
02860 case Selection::Type_Body:
02861 overlay << sel.body()->getName(true).c_str();
02862 break;
02863 case Selection::Type_DeepSky:
02864 overlay << univ.getDSOCatalog()->getDSOName(sel.deepsky());
02865 break;
02866 case Selection::Type_Star:
02867 //displayStarName(overlay, *(sel.star()), *univ.getStarCatalog());
02868 overlay << univ.getStarCatalog()->getStarName(*sel.star());
02869 break;
02870 case Selection::Type_Location:
02871 overlay << sel.location()->getName(true).c_str();
02872 break;
02873 default:
02874 break;
02875 }
02876 }
|
|
||||||||||||||||||||||||
|
Definition at line 2650 of file celestiacore.cpp. References _, astro::absToAppMag(), displayApparentDiameter(), displayDistance(), displayDuration(), distance(), SolarSystem::getPlanets(), PlanetarySystem::getSystemSize(), astro::lightYearsToKilometers(), and SigDigitNum(). Referenced by CelestiaCore::renderOverlay(). 02655 {
02656 overlay << _("Distance: ");
02657 displayDistance(overlay, distance);
02658 overlay << '\n';
02659
02660 if (!star.getVisibility())
02661 {
02662 overlay << _("Star system barycenter\n");
02663 return;
02664 }
02665
02666 overlay.printf(_("Abs (app) mag: %.2f (%.2f)\n"),
02667 star.getAbsoluteMagnitude(),
02668 astro::absToAppMag(star.getAbsoluteMagnitude(),
02669 (float) distance));
02670
02671 if (star.getLuminosity() > 1.0e-10f)
02672 overlay << _("Luminosity: ") << SigDigitNum(star.getLuminosity(), 3) << "x Sun\n";
02673 overlay << _("Class: ");
02674 if (star.getSpectralType()[0] == 'Q')
02675 overlay << _("Neutron star");
02676 else if (star.getSpectralType()[0] == 'X')
02677 overlay << _("Black hole");
02678 else
02679 overlay << star.getSpectralType();
02680 overlay << '\n';
02681
02682 displayApparentDiameter(overlay, star.getRadius(),
02683 astro::lightYearsToKilometers(distance));
02684
02685 if (detail > 1)
02686 {
02687 overlay << _("Surface temp: ") << SigDigitNum(star.getTemperature(), 3) << " K\n";
02688 overlay.printf(_("Radius: %.2f Rsun\n"), star.getRadius() / 696000.0f);
02689
02690 overlay << _("Rotation period: ");
02691 float period = star.getRotationElements().period;
02692 displayDuration(overlay, period);
02693 overlay << '\n';
02694
02695 SolarSystem* sys = universe.getSolarSystem(&star);
02696 if (sys != NULL && sys->getPlanets()->getSystemSize() != 0)
02697 overlay << _("Planetary companions present\n");
02698 }
02699 }
|
|
||||||||||||||||
|
Definition at line 3898 of file celestiacore.cpp. References _. Referenced by CelestiaCore::readStars(). 03901 {
03902 if (!filename.empty())
03903 {
03904 ifstream xrefFile(filename.c_str(), ios::in | ios::binary);
03905 if (xrefFile.good())
03906 {
03907 if (!starDB->loadCrossIndex(catalog, xrefFile))
03908 cerr << _("Error reading cross index ") << filename << '\n';
03909 else
03910 clog << _("Loaded cross index ") << filename << '\n';
03911 }
03912 }
03913 }
|
|
||||||||||||
|
Definition at line 967 of file celestiacore.cpp. References console(), ConsolePageRows, and Console::setWindowRow(). Referenced by CelestiaCore::keyDown(). 00968 {
00969 int topRow = con.getWindowRow();
00970 int height = con.getHeight();
00971
00972 if (lines < 0)
00973 {
00974 if (topRow + lines > -height)
00975 console.setWindowRow(topRow + lines);
00976 else
00977 console.setWindowRow(-(height - 1));
00978 }
00979 else
00980 {
00981 if (topRow + lines <= -ConsolePageRows)
00982 console.setWindowRow(topRow + lines);
00983 else
00984 console.setWindowRow(-ConsolePageRows);
00985 }
00986 }
|
|
|
Definition at line 460 of file celestiacore.cpp. References _, radToDeg(), Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z. Referenced by CelestiaCore::charEntered(). 00461 {
00462 Vec3f axis(0.0f, 1.0, 0.0f);
00463 float angle = 0.0f;
00464
00465 if (sel.deepsky() != NULL)
00466 sel.deepsky()->getOrientation().getAxisAngle(axis, angle);
00467 else if (sel.body() != NULL)
00468 sel.body()->getOrientation().getAxisAngle(axis, angle);
00469
00470 cout << sel.getName() << '\n';
00471 cout << _("Orientation: ") << '[' << axis.x << ',' << axis.y << ',' << axis.z << "], " << radToDeg(angle) << '\n';
00472 }
|
|
||||||||||||||||
|
Definition at line 2879 of file celestiacore.cpp. Referenced by CelestiaCore::renderOverlay(). 02880 {
02881 glBegin(GL_LINE_LOOP);
02882 glVertex3f(v->x * width, v->y * height, 0.0f);
02883 glVertex3f(v->x * width, (v->y + v->height) * height - 1, 0.0f);
02884 glVertex3f((v->x + v->width) * width - 1, (v->y + v->height) * height - 1, 0.0f);
02885 glVertex3f((v->x + v->width) * width - 1, v->y * height, 0.0f);
02886 glEnd();
02887 }
|
|
||||||||||||
|
Definition at line 2511 of file celestiacore.cpp. Referenced by displayDistance(), and displayStarInfo(). 02512 {
02513 return FormattedNumber(v, digits,
02514 FormattedNumber::GroupThousands |
02515 FormattedNumber::SignificantDigits);
02516 }
|
|
|
Definition at line 69 of file celestiacore.cpp. Referenced by CelestiaCore::initSimulation(), and CelestiaCore::readFavoritesFile(). 00070 {
00071 cout << s;
00072 }
|
|
|
Definition at line 65 of file celestiacore.cpp. Referenced by CelestiaCore::CelestiaCore(), CelestiaCore::draw(), CelestiaCore::keyDown(), and scrollConsole(). |
|
|
Definition at line 49 of file celestiacore.cpp. Referenced by CelestiaCore::mouseButtonUp(). |
|
|
Definition at line 55 of file celestiacore.cpp. |
|
|
Definition at line 54 of file celestiacore.cpp. Referenced by CelestiaCore::keyDown(). |
|
|
Definition at line 53 of file celestiacore.cpp. |
|
|
Definition at line 62 of file celestiacore.cpp. Referenced by CelestiaCore::initSimulation(), and CelestiaCore::tick(). |
|
|
Definition at line 60 of file celestiacore.cpp. Referenced by CelestiaCore::charEntered(), and CelestiaCore::mouseMove(). |
|
|
Definition at line 58 of file celestiacore.cpp. Referenced by CelestiaCore::charEntered(). |
|
|
Definition at line 61 of file celestiacore.cpp. Referenced by CelestiaCore::charEntered(), and CelestiaCore::mouseMove(). |
|
|
Definition at line 63 of file celestiacore.cpp. Referenced by CelestiaCore::initSimulation(), and CelestiaCore::mouseMove(). |
|
|
Definition at line 84 of file celestiacore.cpp. Referenced by CelestiaCore::renderOverlay(). |
|
|
Definition at line 56 of file celestiacore.cpp. Referenced by CelestiaCore::tick(). |
|
|
Definition at line 57 of file celestiacore.cpp. Referenced by CelestiaCore::tick(). |
|
|
Definition at line 59 of file celestiacore.cpp. Referenced by CelestiaCore::CelestiaCore(), and CelestiaCore::tick(). |
|
|
Definition at line 52 of file celestiacore.cpp. Referenced by CelestiaCore::charEntered(). |
1.4.1