3
// Copyright (C) 2003-2009, the Celestia Development Team
4
// Original version by Chris Laurel <claurel@gmail.com>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
#include "deepskyobj.h"
14
#include <fmt/format.h>
16
#include <celastro/astro.h>
17
#include <celmath/intersect.h>
18
#include <celmath/sphere.h>
19
#include <celutil/infourl.h>
22
namespace astro = celestia::astro;
23
namespace math = celestia::math;
25
Eigen::Vector3d DeepSkyObject::getPosition() const
30
void DeepSkyObject::setPosition(const Eigen::Vector3d& p)
35
Eigen::Quaternionf DeepSkyObject::getOrientation() const
40
void DeepSkyObject::setOrientation(const Eigen::Quaternionf& q)
45
void DeepSkyObject::setRadius(float r)
50
float DeepSkyObject::getAbsoluteMagnitude() const
55
void DeepSkyObject::setAbsoluteMagnitude(float _absMag)
60
std::string DeepSkyObject::getDescription() const
65
const std::string& DeepSkyObject::getInfoURL() const
70
void DeepSkyObject::setInfoURL(std::string&& s)
72
infoURL = std::move(s);
76
bool DeepSkyObject::pick(const Eigen::ParametrizedLine<double, 3>& ray,
77
double& distanceToPicker,
78
double& cosAngleToBoundCenter) const
80
return isVisible() && math::testIntersection(ray,
81
math::Sphered(position, static_cast<double>(radius)),
83
cosAngleToBoundCenter);
87
bool DeepSkyObject::load(const AssociativeArray* params, const fs::path& resPath)
90
if (auto pos = params->getLengthVector<double>("Position", astro::KM_PER_LY<double>); pos.has_value())
96
auto distance = params->getLength<double>("Distance", astro::KM_PER_LY<double>).value_or(1.0);
97
auto RA = params->getAngle<double>("RA", astro::DEG_PER_HRA).value_or(0.0);
98
auto dec = params->getAngle<double>("Dec").value_or(0.0);
100
Eigen::Vector3d p = astro::equatorialToCelestialCart(RA, dec, distance);
105
auto axis = params->getVector3<double>("Axis").value_or(Eigen::Vector3d::UnitX());
106
auto angle = params->getAngle<double>("Angle").value_or(0.0);
108
setOrientation(Eigen::Quaternionf(Eigen::AngleAxisf(static_cast<float>(math::degToRad(angle)),
109
axis.cast<float>().normalized())));
111
setRadius(params->getLength<float>("Radius", astro::KM_PER_LY<double>).value_or(1.0f));
113
if (auto absMagValue = params->getNumber<float>("AbsMag"); absMagValue.has_value())
114
setAbsoluteMagnitude(*absMagValue);
116
// TODO: infourl class
117
if (const auto *infoURLValue = params->getString("InfoURL"); infoURLValue != nullptr)
118
setInfoURL(BuildInfoURL(*infoURLValue, resPath));
120
if (auto visibleValue = params->getBoolean("Visible"); visibleValue.has_value())
121
setVisible(*visibleValue);
123
if (auto clickableValue = params->getBoolean("Clickable"); clickableValue.has_value())
124
setClickable(*clickableValue);