celestia/src/celengine/location.cpp

235 lines
5.2 KiB
C++
Raw Permalink Normal View History

2003-06-17 11:40:49 -06:00
// location.cpp
//
// Copyright (C) 2003, Chris Laurel <claurel@shatters.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#include <map>
2003-06-17 11:40:49 -06:00
#include <celengine/location.h>
2003-06-29 10:26:08 -06:00
#include <celengine/body.h>
2018-12-03 09:41:31 -07:00
#include <celengine/selection.h>
2020-02-13 09:21:42 -07:00
#include <celutil/gettext.h>
2003-06-17 11:40:49 -06:00
using namespace Eigen;
2003-06-17 11:40:49 -06:00
using namespace std;
2018-08-04 04:05:25 -06:00
static map<string, Location::FeatureType> FeatureNameToFlag;
static bool featureTableInitialized = false;
struct FeatureNameEntry
{
const char* name;
2018-08-04 04:05:25 -06:00
Location::FeatureType flag;
};
FeatureNameEntry FeatureNames[] =
{
{ "AA", Location::Crater },
{ "AL", Location::Albedo },
{ "AR", Location::Arcus },
{ "AS", Location::Astrum },
2018-11-05 11:08:47 -07:00
{ "CA", Location::Catena },
{ "CB", Location::Cavus },
2018-11-05 11:08:47 -07:00
{ "CH", Location::Chaos },
{ "CM", Location::Chasma },
{ "CO", Location::Colles },
{ "CR", Location::Corona },
{ "DO", Location::Dorsum },
2018-11-05 11:08:47 -07:00
{ "ER", Location::EruptiveCenter },
{ "FA", Location::Facula },
{ "FR", Location::Farrum },
{ "FE", Location::Flexus },
2018-11-05 11:08:47 -07:00
{ "FL", Location::Fluctus },
{ "FM", Location::Flumen },
{ "FO", Location::Fossa },
2018-11-05 11:08:47 -07:00
{ "FR", Location::Farrum },
{ "FT", Location::Fretum },
2018-11-05 11:08:47 -07:00
{ "IN", Location::Insula },
{ "LA", Location::Labes },
{ "LB", Location::Labyrinthus },
{ "LU", Location::Lacuna },
{ "LC", Location::Lacus },
2018-11-05 11:08:47 -07:00
{ "LF", Location::LandingSite },
{ "LG", Location::LargeRinged },
{ "LE", Location::Lenticula },
2018-11-05 11:08:47 -07:00
{ "LI", Location::Linea },
{ "LN", Location::Lingula },
{ "MA", Location::Macula },
2018-11-05 11:08:47 -07:00
{ "ME", Location::Mare },
{ "MN", Location::Mensa },
2018-11-05 11:08:47 -07:00
{ "MO", Location::Mons },
{ "OC", Location::Oceanus },
{ "PA", Location::Palus },
2018-11-05 11:08:47 -07:00
{ "PE", Location::Patera },
{ "PL", Location::Planitia },
{ "PM", Location::Planum },
{ "PU", Location::Plume },
{ "PR", Location::Promontorium },
2018-11-05 11:08:47 -07:00
{ "RE", Location::Regio },
{ "RI", Location::Rima },
{ "RT", Location::Reticulum },
2018-11-05 11:08:47 -07:00
{ "RU", Location::Rupes },
2018-11-08 02:35:44 -07:00
{ "SA", Location::Saxum },
{ "SF", Location::Satellite },
{ "SC", Location::Scopulus },
{ "SE", Location::Serpens },
{ "SI", Location::Sinus },
{ "SU", Location::Sulcus },
2018-11-05 11:08:47 -07:00
{ "TA", Location::Terra },
{ "TE", Location::Tessera },
{ "TH", Location::Tholus },
{ "UN", Location::Undae },
{ "VA", Location::Vallis },
{ "VS", Location::Vastitas },
{ "VI", Location::Virga },
{ "XX", Location::Other },
{ "City", Location::City },
{ "Observatory", Location::Observatory },
{ "Landing Site", Location::LandingSite },
{ "Crater", Location::Crater },
2018-11-11 12:10:37 -07:00
{ "Capital", Location::Capital},
{ "Cosmodrome", Location::Cosmodrome},
{ "Ring", Location::Ring},
{ "RG", Location::Ring},
2018-11-11 12:10:37 -07:00
{ "Historical", Location::Historical},
};
2003-06-17 11:40:49 -06:00
2005-07-19 15:31:04 -06:00
string Location::getName(bool i18n) const
2003-06-17 11:40:49 -06:00
{
2005-07-19 15:31:04 -06:00
if (!i18n || i18nName == "") return name;
return i18nName;
2003-06-17 11:40:49 -06:00
}
void Location::setName(const string& _name)
{
name = _name;
i18nName = D_(_name.c_str());
2005-07-19 15:31:04 -06:00
if (name == i18nName) i18nName = "";
2003-06-17 11:40:49 -06:00
}
Vector3f Location::getPosition() const
2003-06-17 11:40:49 -06:00
{
return position;
}
void Location::setPosition(const Vector3f& _position)
2003-06-17 11:40:49 -06:00
{
position = _position;
}
float Location::getSize() const
{
return size;
}
void Location::setSize(float _size)
{
size = _size;
}
float Location::getImportance() const
{
return importance;
}
void Location::setImportance(float _importance)
{
importance = _importance;
}
const string& Location::getInfoURL() const
2003-06-17 11:40:49 -06:00
{
return infoURL;
2003-06-17 11:40:49 -06:00
}
void Location::setInfoURL(const string&)
2003-06-17 11:40:49 -06:00
{
}
2018-08-04 04:05:25 -06:00
Location::FeatureType Location::getFeatureType() const
2003-06-17 11:40:49 -06:00
{
return featureType;
2003-06-17 11:40:49 -06:00
}
2018-08-04 04:05:25 -06:00
void Location::setFeatureType(Location::FeatureType _featureType)
{
featureType = _featureType;
}
static void initFeatureTypeTable()
{
featureTableInitialized = true;
2004-01-10 22:19:05 -07:00
for (int i = 0; i < (int)(sizeof(FeatureNames) / sizeof(FeatureNames[0])); i++)
{
FeatureNameToFlag[string(FeatureNames[i].name)] = FeatureNames[i].flag;
}
}
2018-08-04 04:05:25 -06:00
Location::FeatureType Location::parseFeatureType(const string& s)
{
if (!featureTableInitialized)
initFeatureTypeTable();
FeatureType flag = FeatureNameToFlag[s];
return flag != (FeatureType) 0 ? flag : Other;
}
2003-06-29 10:26:08 -06:00
Body* Location::getParentBody() const
{
return parent;
}
void Location::setParentBody(Body* _parent)
{
parent = _parent;
}
/*! Get the position of the location relative to its body in
* the J2000 ecliptic coordinate system.
*/
Vector3d Location::getPlanetocentricPosition(double t) const
2003-06-29 10:26:08 -06:00
{
if (parent == nullptr)
return position.cast<double>();
Quaterniond q = parent->getEclipticToBodyFixed(t);
return q.conjugate() * position.cast<double>();
2003-06-29 10:26:08 -06:00
}
Vector3d Location::getHeliocentricPosition(double t) const
2003-06-29 10:26:08 -06:00
{
if (parent == nullptr)
return position.cast<double>();
2003-06-29 10:26:08 -06:00
return parent->getAstrocentricPosition(t) + getPlanetocentricPosition(t);
2003-06-29 10:26:08 -06:00
}
2018-12-03 09:41:31 -07:00
Selection Location::toSelection()
{
// std::cout << "Location::toSelection()\n";
return Selection(this);
}