Celestia

Форк
0
/
deepskyobj.cpp 
127 строк · 3.5 Кб
1
// deepskyobj.cpp
2
//
3
// Copyright (C) 2003-2009, the Celestia Development Team
4
// Original version by Chris Laurel <claurel@gmail.com>
5
//
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.
10

11
#include "deepskyobj.h"
12

13
#include <cmath>
14
#include <fmt/format.h>
15

16
#include <celastro/astro.h>
17
#include <celmath/intersect.h>
18
#include <celmath/sphere.h>
19
#include <celutil/infourl.h>
20
#include "hash.h"
21

22
namespace astro = celestia::astro;
23
namespace math = celestia::math;
24

25
Eigen::Vector3d DeepSkyObject::getPosition() const
26
{
27
    return position;
28
}
29

30
void DeepSkyObject::setPosition(const Eigen::Vector3d& p)
31
{
32
    position = p;
33
}
34

35
Eigen::Quaternionf DeepSkyObject::getOrientation() const
36
{
37
    return orientation;
38
}
39

40
void DeepSkyObject::setOrientation(const Eigen::Quaternionf& q)
41
{
42
    orientation = q;
43
}
44

45
void DeepSkyObject::setRadius(float r)
46
{
47
    radius = r;
48
}
49

50
float DeepSkyObject::getAbsoluteMagnitude() const
51
{
52
    return absMag;
53
}
54

55
void DeepSkyObject::setAbsoluteMagnitude(float _absMag)
56
{
57
    absMag = _absMag;
58
}
59

60
std::string DeepSkyObject::getDescription() const
61
{
62
    return "";
63
}
64

65
const std::string& DeepSkyObject::getInfoURL() const
66
{
67
    return infoURL;
68
}
69

70
void DeepSkyObject::setInfoURL(std::string&& s)
71
{
72
    infoURL = std::move(s);
73
}
74

75

76
bool DeepSkyObject::pick(const Eigen::ParametrizedLine<double, 3>& ray,
77
                         double& distanceToPicker,
78
                         double& cosAngleToBoundCenter) const
79
{
80
    return isVisible() && math::testIntersection(ray,
81
                                                 math::Sphered(position, static_cast<double>(radius)),
82
                                                 distanceToPicker,
83
                                                 cosAngleToBoundCenter);
84
}
85

86

87
bool DeepSkyObject::load(const AssociativeArray* params, const fs::path& resPath)
88
{
89
    // Get position
90
    if (auto pos = params->getLengthVector<double>("Position", astro::KM_PER_LY<double>); pos.has_value())
91
    {
92
        setPosition(*pos);
93
    }
94
    else
95
    {
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);
99

100
        Eigen::Vector3d p = astro::equatorialToCelestialCart(RA, dec, distance);
101
        setPosition(p);
102
    }
103

104
    // Get orientation
105
    auto axis = params->getVector3<double>("Axis").value_or(Eigen::Vector3d::UnitX());
106
    auto angle = params->getAngle<double>("Angle").value_or(0.0);
107

108
    setOrientation(Eigen::Quaternionf(Eigen::AngleAxisf(static_cast<float>(math::degToRad(angle)),
109
                                                        axis.cast<float>().normalized())));
110

111
    setRadius(params->getLength<float>("Radius", astro::KM_PER_LY<double>).value_or(1.0f));
112

113
    if (auto absMagValue = params->getNumber<float>("AbsMag"); absMagValue.has_value())
114
        setAbsoluteMagnitude(*absMagValue);
115

116
    // TODO: infourl class
117
    if (const auto *infoURLValue = params->getString("InfoURL"); infoURLValue != nullptr)
118
        setInfoURL(BuildInfoURL(*infoURLValue, resPath));
119

120
    if (auto visibleValue = params->getBoolean("Visible"); visibleValue.has_value())
121
        setVisible(*visibleValue);
122

123
    if (auto clickableValue = params->getBoolean("Clickable"); clickableValue.has_value())
124
        setClickable(*clickableValue);
125

126
    return true;
127
}
128

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.