New planet parameters, core

pull/185/head
Hleb Valoshka 2018-12-10 00:27:38 +03:00
parent 6befa417ff
commit c710412ba7
4 changed files with 160 additions and 33 deletions

View File

@ -75,7 +75,11 @@ void Body::setDefaultProperties()
radius = 1.0f;
semiAxes = Vector3f::Ones();
mass = 0.0f;
albedo = 0.5f;
density = 0.0f;
bondAlbedo = 0.5f;
geomAlbedo = 0.5f;
temperature = 0.0f;
tempDiscrepancy = 0.0f;
geometryOrientation = Quaternionf::Identity();
geometry = InvalidResource;
surface = Surface(Color::White);
@ -278,15 +282,102 @@ void Body::setMass(float _mass)
}
float Body::getDensity() const
{
if (density > 0)
return density;
if (radius == 0 || !isSphere())
return 0;
// assume that we have a spherical body
// @mass unit is mass of Earth
// @astro::EarthMass unit is kg
// @radius unit km
// so we divide density by 1e9 to have kg/m^3
double volume = 4.0 / 3.0 * PI * ::pow(radius, 3);
return (float) mass * astro::EarthMass / 1e9 / volume;
}
void Body::setDensity(float _density)
{
density = _density;
}
float Body::getAlbedo() const
{
return albedo;
return getGeomAlbedo();
}
void Body::setAlbedo(float _albedo)
{
albedo = _albedo;
setGeomAlbedo(_albedo);
}
float Body::getGeomAlbedo() const
{
return geomAlbedo;
}
void Body::setGeomAlbedo(float _geomAlbedo)
{
geomAlbedo = _geomAlbedo;
}
float Body::getBondAlbedo() const
{
return bondAlbedo;
}
void Body::setBondAlbedo(float _bondAlbedo)
{
bondAlbedo = _bondAlbedo;
}
float Body::getTemperature(double time) const
{
if (temperature > 0)
return temperature;
const PlanetarySystem* system = getSystem();
if (system == nullptr)
return 0;
const Star* sun = system->getStar();
if (sun == nullptr)
return 0;
double distFromSun = getAstrocentricPosition(time).norm();
return getTempDiscrepancy() +
sun->getTemperature() *
(float) (::pow(1.0 - getBondAlbedo(), 0.25) *
sqrt(sun->getRadius() / (2.0 * distFromSun)));
}
void Body::setTemperature(float _temperature)
{
temperature = _temperature;
}
float Body::getTempDiscrepancy() const
{
return tempDiscrepancy;
}
void Body::setTempDiscrepancy(float _tempDiscrepancy)
{
tempDiscrepancy = _tempDiscrepancy;
}
@ -674,7 +765,7 @@ float Body::getLuminosity(float sunLuminosity,
// Compute the total energy hitting the planet
double incidentEnergy = satIrradiance * circleArea(radius * 1000);
double reflectedEnergy = incidentEnergy * albedo;
double reflectedEnergy = incidentEnergy * geomAlbedo;
// Compute the luminosity (i.e. power relative to solar power)
return (float) (reflectedEnergy / astro::SOLAR_POWER);

View File

@ -215,8 +215,21 @@ class Body : public CatEntry
float getMass() const;
void setMass(float);
float getAlbedo() const;
void setAlbedo(float);
float getDensity() const;
void setDensity(float);
// Albedo functions and temperature
/* [[deprecated]] */ float getAlbedo() const;
/* [[deprecated]] */ void setAlbedo(float);
float getGeomAlbedo() const;
void setGeomAlbedo(float);
float getBondAlbedo() const;
void setBondAlbedo(float);
float getTemperature(double t = 0) const;
void setTemperature(float);
float getTempDiscrepancy() const;
void setTempDiscrepancy(float);
int getClassification() const;
void setClassification(int);
const std::string& getInfoURL() const;
@ -359,7 +372,12 @@ class Body : public CatEntry
float radius{ 1.0f };
Eigen::Vector3f semiAxes{ Eigen::Vector3f::Ones() };
float mass{ 0.0f };
float albedo{ 0.5f };
float density{ 0.0f };
float geomAlbedo{ 0.5f };
float bondAlbedo{ 0.5f };
float temperature{ 0.0f };
float tempDiscrepancy{ 0.0f };
Eigen::Quaternionf geometryOrientation{ Eigen::Quaternionf::Identity() };
float cullingRadius{ 0.0f };

View File

@ -828,14 +828,37 @@ static Body* CreateBody(const string& name,
body->setInfoURL(infoURL);
}
double albedo = 0.5;
if (planetData->getNumber("Albedo", albedo))
body->setAlbedo((float) albedo);
double t;
if (planetData->getNumber("Albedo", t))
{
fmt::fprintf(cerr, "Deprecated parameter Albedo used in %s definition.\nUse GeomAlbedo instead.", name);
body->setGeomAlbedo((float) t);
}
if (planetData->getNumber("GeomAlbedo", t))
body->setGeomAlbedo((float) t);
if (planetData->getNumber("BondAlbedo", t))
{
if (t >= 0.0 && t <= 1.0)
body->setBondAlbedo((float) t);
else
fmt::fprintf(cerr, "Incorrect BondAlbedo value: %lf", t);
}
if (planetData->getNumber("Temperature", t))
body->setTemperature((float) t);
if (planetData->getNumber("TempDiscrepancy", t))
body->setTempDiscrepancy((float) t);
// TODO - add mass units
double mass = 0.0;
if (planetData->getNumber("Mass", mass))
body->setMass((float) mass);
if (planetData->getNumber("Mass", t))
body->setMass((float) t);
if (planetData->getNumber("Density", t))
body->setDensity((float) t);
Quaternionf orientation = Quaternionf::Identity();
if (planetData->getRotation("Orientation", orientation))
@ -856,7 +879,7 @@ static Body* CreateBody(const string& name,
body->setSurface(surface);
{
string geometry("");
string geometry;
if (planetData->getString("Mesh", geometry))
{
Vector3f geometryCenter(Vector3f::Zero());

View File

@ -3172,30 +3172,25 @@ static void displayPlanetInfo(Overlay& overlay,
if (detail > 1)
{
if (body.getRotationModel(t)->isPeriodic())
{
displayRotationPeriod(overlay, body.getRotationModel(t)->getPeriod());
}
/*
* Equilibrium temperature calculation disabled; it's too simplistic to be very useful,
* it's not a fundamental piece of information like distance or size.
*
PlanetarySystem* system = body.getSystem();
if (system != nullptr)
if (body.getName() != "Earth")
{
const Star* sun = system->getStar();
if (sun != nullptr)
{
double distFromSun = body.getAstrocentricPosition(t).norm();
float planetTemp = sun->getTemperature() *
(float) (::pow(1.0 - body.getAlbedo(), 0.25) *
sqrt(sun->getRadius() / (2.0 * distFromSun)));
fmt::fprintf(overlay,_("Temperature: %.0f K\n"), planetTemp);
}
if (body.getMass() > 0)
fmt::fprintf(overlay, _("Mass: %.2f Me\n"), body.getMass());
}
*/
}
float density = body.getDensity();
if (density > 0)
{
fmt::fprintf(overlay, _("Density: %.2f x 1000 kg/m^3\n"), density / 1000.0);
}
float planetTemp = body.getTemperature(t);
if (planetTemp > 0)
fmt::fprintf(overlay, _("Temperature: %.0f K\n"), planetTemp);
}
}