• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 5926409083

21 Aug 2023 12:45PM UTC coverage: 11.905% (+0.01%) from 11.891%
5926409083

Pull #3373

github

gzotti
Reduce verbosity a bit.
Pull Request #3373: Fix: unambiguous comet names

264 of 264 new or added lines in 9 files covered. (100.0%)

14845 of 124700 relevant lines covered (11.9%)

23289.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.95
/src/core/modules/Comet.cpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2010 Bogdan Marinov
4
 * Copyright (C) 2014 Georg Zotti (Tails)
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
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
19
 */
20
 
21
#include "Comet.hpp"
22
#include "Orbit.hpp"
23

24
#include "StelApp.hpp"
25
#include "StelCore.hpp"
26
#include "StelPainter.hpp"
27

28
#include "StelTexture.hpp"
29
#include "StelToneReproducer.hpp"
30
#include "StelTranslator.hpp"
31
#include "StelUtils.hpp"
32
#include "StelMovementMgr.hpp"
33
#include "StelModuleMgr.hpp"
34
#include "LandscapeMgr.hpp"
35
#include "StelLocaleMgr.hpp"
36

37
#include <QDebug>
38
#include <QElapsedTimer>
39

40
// for compute tail shape
41
#define COMET_TAIL_SLICES 16u // segments around the perimeter
42
#define COMET_TAIL_STACKS 16u // cuts along the rotational axis
43

44
// These are to avoid having index arrays for each comet when all are equal.
45
bool Comet::createTailIndices=true;
46
bool Comet::createTailTextureCoords=true;
47
StelTextureSP Comet::comaTexture;
48
StelTextureSP Comet::tailTexture;
49
QVector<Vec2f> Comet::tailTexCoordArr; // computed only once for all Comets.
50
QVector<unsigned short> Comet::tailIndices; // computed only once for all Comets.
51

52
Comet::Comet(const QString& englishName,
×
53
             double radius,
54
             double oblateness,
55
             Vec3f halocolor,
56
             float albedo,
57
             float roughness,
58
             float outgas_intensity,
59
             float outgas_falloff,
60
             const QString& atexMapName,
61
             const QString& aobjModelName,
62
             posFuncType coordFunc,
63
             KeplerOrbit* orbitPtr,
64
             OsculatingFunctType *osculatingFunc,
65
             bool acloseOrbit,
66
             bool hidden,
67
             const QString& pTypeStr,
68
             float dustTailWidthFact,
69
             float dustTailLengthFact,
70
             float dustTailBrightnessFact)
×
71
        : Planet (englishName,
72
                  radius,
73
                  oblateness,
74
                  halocolor,
75
                  albedo,
76
                  roughness,
77
                  atexMapName,
78
                  "", // no normalmap.
79
                  "", // no horizon map
80
                  aobjModelName,
81
                  coordFunc,
82
                  orbitPtr,
83
                  osculatingFunc,
84
                  acloseOrbit,
85
                  hidden,
86
                  false, //No atmosphere
87
                  true, //halo
88
                  pTypeStr),
89
          slopeParameter(-10.f), // -10 == uninitialized: used in getVMagnitude()
×
90
          isCometFragment(false),
×
91
          iauDesignation(""),
×
92
          extraDesignations(),
×
93
          extraDesignationsHtml(),
×
94
          discoverer(""),
×
95
          discoveryDate(""),
×
96
          tailFactors(-1., -1.), // mark "invalid"
×
97
          tailActive(false),
×
98
          tailBright(false),
×
99
          deltaJDEtail(15.0*StelCore::JD_MINUTE), // update tail geometry every 15 minutes only
×
100
          lastJDEtail(0.0),
×
101
          dustTailWidthFactor(dustTailWidthFact),
×
102
          dustTailLengthFactor(dustTailLengthFact),
×
103
          dustTailBrightnessFactor(dustTailBrightnessFact),
×
104
          intensityFovScale(1.0f),
×
105
          intensityMinFov(0.001f), // when zooming in further, Coma is no longer visible.
×
106
          intensityMaxFov(0.010f) // when zooming out further, Coma is fully visible (when enabled).
×
107
{
108
        this->outgas_intensity =outgas_intensity;
×
109
        this->outgas_falloff   =outgas_falloff;
×
110

111
        gastailVertexArr.clear();
×
112
        dusttailVertexArr.clear();
×
113
        comaVertexArr.clear();
×
114
        gastailColorArr.clear();
×
115
        dusttailColorArr.clear();
×
116

117
        //TODO: Name processing?
118
}
×
119

120
Comet::~Comet()
×
121
{
122
}
×
123

124
void Comet::setAbsoluteMagnitudeAndSlope(const float magnitude, const float slope)
×
125
{
126
        if ((slope < -2.5f) || (slope > 25.0f))
×
127
        {
128
                // Slope G can become slightly smaller than 0. -10 is mark of invalidity.
129
                qDebug() << "Warning: Suspect slope parameter value" << slope << "for comet" << getEnglishName() << "(rarely exceeding -1...20)";
×
130
                return;
×
131
        }
132
        absoluteMagnitude = magnitude;
×
133
        slopeParameter = slope;
×
134
}
135

136
void Comet::translateName(const StelTranslator &translator)
×
137
{
138
        static const QRegularExpression cometNamePattern("^(.+)[(](.+)[)]\\s*$");
×
139
        QRegularExpressionMatch matchCometName = cometNamePattern.match(englishName);
×
140
        if (matchCometName.hasMatch())
×
141
                nameI18 = QString("%1(%2)").arg(matchCometName.captured(1),translator.qtranslate(matchCometName.captured(2), "comet"));
×
142
        else
143
                nameI18 = translator.qtranslate(englishName, "comet");
×
144
}
×
145

146
QString Comet::getInfoStringName(const StelCore *core, const InfoStringGroup& flags) const
×
147
{
148
        Q_UNUSED(core) Q_UNUSED(flags)
149
        QString str;
×
150
        QTextStream oss(&str);
×
151

152
        oss << "<h2>";
×
153
        oss << getNameI18n(); // UI translation can differ from sky translation
×
154

155
        if (!getExtraDesignations().isEmpty())
×
156
                oss << QString(" - %1").arg(extraDesignationsHtml.join(" - "));
×
157

158
        if (sphereScale != 1.)
×
159
        {
160
                oss.setRealNumberNotation(QTextStream::FixedNotation);
×
161
                oss.setRealNumberPrecision(1);
×
162
                oss << QString::fromUtf8(" (\xC3\x97") << sphereScale << ")";
×
163
        }
164
        oss << "</h2>";
×
165

166
        return str;
×
167
}
×
168

169
QString Comet::getInfoStringAbsoluteMagnitude(const StelCore *core, const InfoStringGroup& flags) const
×
170
{
171
        Q_UNUSED(core)
172
        QString str;
×
173
        QTextStream oss(&str);
×
174
        if (flags&AbsoluteMagnitude)
×
175
        {
176
                //TODO: Make sure absolute magnitude is a sane value
177
                //If the two parameter magnitude system is not used, don't display this
178
                //value. (Using radius/albedo doesn't make any sense for comets.)
179
                // Note that slope parameter can be <0 (down to -2?), so -10 is now used for "uninitialized"
180
                if (slopeParameter >= -9.9f)
×
181
                        oss << QString("%1: %2<br/>").arg(q_("Absolute Magnitude")).arg(absoluteMagnitude, 0, 'f', 2);
×
182
        }
183

184
        return str;
×
185
}
×
186

187
QString Comet::getInfoStringSize(const StelCore *core, const InfoStringGroup &flags) const
×
188
{
189
        // TRANSLATORS: Unit of measure for distance - kilometers
190
        QString km = qc_("km", "distance");
×
191
        // TRANSLATORS: Unit of measure for distance - milliones kilometers
192
        QString Mkm = qc_("M km", "distance");
×
193
        const bool withDecimalDegree = StelApp::getInstance().getFlagShowDecimalDegrees();
×
194
        QString str;
×
195
        QTextStream oss(&str);
×
196

197
        if (flags&Size)
×
198
        {
199
                // Given the very irregular shape, other terminology like "equatorial radius" do not make much sense.
200
                oss << QString("%1: %2 %3<br/>").arg(q_("Core diameter"), QString::number(AU * 2.0 * getEquatorialRadius(), 'f', 1) , qc_("km", "distance"));
×
201
        }
202
        if ((flags&Size) && (tailFactors[0]>0.0f))
×
203
        {
204
                // GZ: Add estimates for coma diameter and tail length.
205
                QString comaEst = q_("Coma diameter (estimate)");
×
206
                const double coma = floor(static_cast<double>(tailFactors[0])*AU/1000.0)*1000.0;
×
207
                const double tail = static_cast<double>(tailFactors[1])*AU;
×
208
                const double distanceKm = AU * getJ2000EquatorialPos(core).norm();
×
209
                // Try to estimate tail length in degrees.
210
                // TODO: Take projection effect into account!
211
                // The estimates here assume that the tail is seen from the side.
212
                QString comaDeg, tailDeg;
×
213
                if (withDecimalDegree)
×
214
                {
215
                        comaDeg = StelUtils::radToDecDegStr(atan(coma/distanceKm),4,false,true);
×
216
                        tailDeg = StelUtils::radToDecDegStr(atan(tail/distanceKm),4,false,true);
×
217
                }
218
                else
219
                {
220
                        comaDeg = StelUtils::radToDmsStr(atan(coma/distanceKm));
×
221
                        tailDeg = StelUtils::radToDmsStr(atan(tail/distanceKm));
×
222
                }
223
                if (coma>1e6)
×
224
                        oss << QString("%1: %2 %3 (%4)<br/>").arg(comaEst, QString::number(coma*1e-6, 'G', 3), Mkm, comaDeg);
×
225
                else
226
                        oss << QString("%1: %2 %3 (%4)<br/>").arg(comaEst, QString::number(coma, 'f', 0), km, comaDeg);
×
227
                oss << QString("%1: %2 %3 (%4)<br/>").arg(q_("Gas tail length (estimate)"), QString::number(tail*1e-6, 'G', 3), Mkm, tailDeg);
×
228
        }
×
229
        return str;
×
230
}
×
231

232
// Nothing interesting?
233
QString Comet::getInfoStringExtra(const StelCore *core, const InfoStringGroup &flags) const
×
234
{
235
        Q_UNUSED(core)
236
        QString str;
×
237
        QTextStream oss(&str);
×
238
        if (flags&Extra)
×
239
        {
240
                if (!discoveryDate.isEmpty())
×
241
                        oss << QString("%1: %2<br/>").arg(q_("Discovered"), getDiscoveryCircumstances());
×
242
        }
243
        return str;
×
244
}
×
245

246
QVariantMap Comet::getInfoMap(const StelCore *core) const
×
247
{
248
        QVariantMap map = Planet::getInfoMap(core);
×
249
        map.insert("tail-length-km", tailFactors[1]*AUf);
×
250
        map.insert("coma-diameter-km", tailFactors[0]*AUf);
×
251

252
        return map;
×
253
}
×
254

255
QString Comet::getDiscoveryCircumstances() const
×
256
{
257
        QString ddate = StelUtils::localeDiscoveryDateString(discoveryDate);
×
258
        if (discoverer.isEmpty())
×
259
                return ddate;
×
260
        else
261
                return QString("%1 (%2)").arg(ddate, discoverer);
×
262
}
×
263

264
double Comet::getSiderealPeriod() const
×
265
{
266
        const double semiMajorAxis=static_cast<KeplerOrbit*>(orbitPtr)->getSemimajorAxis();
×
267
        return ((semiMajorAxis>0) ? KeplerOrbit::calculateSiderealPeriod(semiMajorAxis, 1.0) : 0.);
×
268
}
269

270
float Comet::getVMagnitude(const StelCore* core) const
×
271
{
272
        //If the two parameter system is not used,
273
        //use the default radius/albedo mechanism
274
        if (slopeParameter < -9.0f)
×
275
        {
276
                return Planet::getVMagnitude(core);
×
277
        }
278

279
        //Calculate distances
280
        const Vec3d& observerHeliocentricPosition = core->getObserverHeliocentricEclipticPos();
×
281
        const Vec3d& cometHeliocentricPosition = getHeliocentricEclipticPos();
×
282
        const float cometSunDistance = static_cast<float>(cometHeliocentricPosition.norm());
×
283
        const float observerCometDistance = static_cast<float>((observerHeliocentricPosition - cometHeliocentricPosition).norm());
×
284

285
        //Calculate apparent magnitude
286
        //Sources: http://www.clearskyinstitute.com/xephem/help/xephem.html#mozTocId564354
287
        //(XEphem manual, section 7.1.2.3 "Magnitude models"), also
288
        //http://www.ayton.id.au/gary/Science/Astronomy/Ast_comets.htm#Comet%20facts:
289
        // GZ: Note that Meeus, Astr.Alg.1998 p.231, has m=absoluteMagnitude+5log10(observerCometDistance) + kappa*log10(cometSunDistance)
290
        // with kappa typically 5..15. MPC provides Slope parameter. So we should expect to have slopeParameter (a word only used for minor planets!) for our comets 2..6
291
        return absoluteMagnitude + 5.f * std::log10(observerCometDistance) + 2.5f * slopeParameter * std::log10(cometSunDistance);
×
292
}
293

294
void Comet::update(int deltaTime)
×
295
{
296
        Planet::update(deltaTime);
×
297

298
        //calculate FOV fade value, linear fade between intensityMaxFov and intensityMinFov
299
        const float vfov = static_cast<float>(StelApp::getInstance().getCore()->getMovementMgr()->getCurrentFov());
×
300
        intensityFovScale = qBound(0.25f,(vfov - intensityMinFov) / (intensityMaxFov - intensityMinFov),1.0f);
×
301

302
        // The rest deals with updating tail geometries and brightness
303
        StelCore* core=StelApp::getInstance().getCore();
×
304
        double dateJDE=core->getJDE();
×
305

306
        if (!static_cast<KeplerOrbit*>(orbitPtr)->objectDateGoodEnoughForOrbits(dateJDE)) return; // don't do anything if out of useful date range. This allows having hundreds of comet elements.
×
307

308
        //GZ: I think we can make deltaJDtail adaptive, depending on distance to sun! For some reason though, this leads to a crash!
309
        //deltaJDtail=StelCore::JD_SECOND * qBound(1.0, eclipticPos.length(), 20.0);
310

311
        if (fabs(lastJDEtail-dateJDE)>deltaJDEtail)
×
312
        {
313
                lastJDEtail=dateJDE;
×
314

315
                if (static_cast<KeplerOrbit*>(orbitPtr)->getUpdateTails()){
×
316
                        // Compute lengths and orientations from orbit object, but only if required.
317
                        tailFactors=getComaDiameterAndTailLengthAU();
×
318

319
                        // Note that we use a diameter larger than what the formula returns. A scale factor of 1.2 is ad-hoc/empirical (GZ), but may look better.
320
                        computeComa(1.0f*tailFactors[0]); // TBD: APPARENTLY NO SCALING? REMOVE 1.0 and note above.
×
321

322
                        tailActive = (tailFactors[1] > tailFactors[0]); // Inhibit tails drawing if too short. Would be nice to include geometric projection angle, but this is too costly.
×
323

324
                        if (tailActive)
×
325
                        {
326
                                float gasTailEndRadius=qMax(tailFactors[0], 0.025f*tailFactors[1]) ; // This avoids too slim gas tails for bright comets like Hale-Bopp.
×
327
                                float gasparameter=gasTailEndRadius*gasTailEndRadius/(2.0f*tailFactors[1]); // parabola formula: z=r²/2p, so p=r²/2z
×
328
                                // The dust tail is thicker and usually shorter. The factors can be configured in the elements.
329
                                float dustparameter=gasTailEndRadius*gasTailEndRadius*dustTailWidthFactor*dustTailWidthFactor/(2.0f*dustTailLengthFactor*tailFactors[1]);
×
330

331
                                // Find valid parameters to create paraboloid vertex arrays: dustTail, gasTail.
332
                                computeParabola(gasparameter, gasTailEndRadius, -0.5f*gasparameter, gastailVertexArr,  tailTexCoordArr, tailIndices);
×
333
                                //gastailColorArr.fill(Vec3f(0.3,0.3,0.3), gastailVertexArr.length());
334
                                // Now we make a skewed parabola. Skew factor (xOffset, last arg) is rather ad-hoc/empirical. TBD later: Find physically correct solution.
335
                                computeParabola(dustparameter, dustTailWidthFactor*gasTailEndRadius, -0.5f*dustparameter, dusttailVertexArr, tailTexCoordArr, tailIndices, 25.0f*static_cast<float>(static_cast<KeplerOrbit*>(orbitPtr)->getVelocity().norm()));
×
336
                                //dusttailColorArr.fill(Vec3f(0.3,0.3,0.3), dusttailVertexArr.length());
337

338

339
                                // 2014-08 for 0.13.1 Moved from drawTail() to save lots of computation per frame (There *are* folks downloading all 730 MPC current comet elements...)
340
                                // Find rotation matrix from 0/0/1 to eclipticPosition: crossproduct for axis (normal vector), dotproduct for angle.
341
                                Vec3d eclposNrm=eclipticPos+aberrationPush; eclposNrm.normalize();
×
342
                                gasTailRot=Mat4d::rotation(Vec3d(0.0, 0.0, 1.0)^(eclposNrm), std::acos(Vec3d(0.0, 0.0, 1.0).dot(eclposNrm)) );
×
343

344
                                Vec3d velocity=static_cast<KeplerOrbit*>(orbitPtr)->getVelocity(); // [AU/d]
×
345
                                // This was a try to rotate a straight parabola somewhat away from the antisolar direction.
346
                                //Mat4d dustTailRot=Mat4d::rotation(eclposNrm^(-velocity), 0.15f*std::acos(eclposNrm.dot(-velocity))); // GZ: This scale factor of 0.15 is empirical from photos of Halley and Hale-Bopp.
347
                                // The curved tail is curved towards positive X. We first rotate around the Z axis into a direction opposite of the motion vector, then again the antisolar rotation applies.
348
                                // In addition, we let the dust tail already start with a light tilt.
349
                                dustTailRot=gasTailRot * Mat4d::zrotation(atan2(velocity[1], velocity[0]) + M_PI) * Mat4d::yrotation(5.0*velocity.norm());
×
350

351
                                // Rotate vertex arrays:
352
                                Vec3d* gasVertices= static_cast<Vec3d*>(gastailVertexArr.data());
×
353
                                Vec3d* dustVertices=static_cast<Vec3d*>(dusttailVertexArr.data());
×
354
                                for (unsigned short int i=0; i<COMET_TAIL_SLICES*COMET_TAIL_STACKS+1; ++i)
×
355
                                {
356
                                        gasVertices[i].transfo4d(gasTailRot);
×
357
                                        dustVertices[i].transfo4d(dustTailRot);
×
358
                                }
359
                        }
360
                        static_cast<KeplerOrbit*>(orbitPtr)->setUpdateTails(false); // don't update until position has been recalculated elsewhere
×
361
                }
362
        }
363

364
        // And also update magnitude and tail brightness/extinction here.
365
        const bool withAtmosphere=(core->getSkyDrawer()->getFlagHasAtmosphere());
×
366

367
        StelToneReproducer* eye = core->getToneReproducer();
×
368
        const float lum = core->getSkyDrawer()->surfaceBrightnessToLuminance(getVMagnitude(core)+13.0f); // How to calibrate?
×
369
        // Get the luminance scaled between 0 and 1
370
        float aLum =eye->adaptLuminanceScaled(lum);
×
371

372

373
        // To make comet more apparent in overviews, take field of view into account:
374
        const float fov=core->getProjection(core->getAltAzModelViewTransform())->getFov();
×
375
        if (fov>20)
×
376
                aLum*= (fov/20.0f);
×
377

378
        // Now inhibit tail drawing if still too dim.
379
        if (aLum<0.002f)
×
380
        {
381
                // Far too dim: don't even show tail...
382
                tailBright=false;
×
383
                return;
×
384
        } else
385
                tailBright=true;
×
386

387
        // Separate factors, but avoid overly bright tails. I limit to about 0.7 for overlapping both tails which should not exceed full-white.
388
        float gasMagFactor=qMin(0.9f*aLum, 0.7f);
×
389
        float dustMagFactor=qMin(dustTailBrightnessFactor*aLum, 0.7f);
×
390

391
        // TODO: Maybe make gas color distance dependent? (various typical ingredients outgas at different temperatures...)
392
        Vec3f gasColor(0.15f*gasMagFactor,0.35f*gasMagFactor,0.6f*gasMagFactor); // Orig color 0.15/0.15/0.6.
×
393
        Vec3f dustColor(dustMagFactor, dustMagFactor,0.6f*dustMagFactor);
×
394

395
        if (withAtmosphere)
×
396
        {
397
                Extinction extinction=core->getSkyDrawer()->getExtinction();
×
398

399
                // Not only correct the color values for extinction, but for twilight conditions, also make tail end less visible.
400
                // I consider sky brightness over 1cd/m^2 as reason to shorten tail.
401
                // Below this brightness, the tail brightness loss by this method is insignificant:
402
                // Just counting through the vertices might make a spiral appearance. Maybe even better than stackwise? Let's see...
403
                const float avgAtmLum=GETSTELMODULE(LandscapeMgr)->getAtmosphereAverageLuminance();
×
404
                const float brightnessDecreasePerVertexFromHead=1.0f/(COMET_TAIL_SLICES*COMET_TAIL_STACKS)  * avgAtmLum;
×
405
                float brightnessPerVertexFromHead=1.0f;
×
406

407
                gastailColorArr.clear();
×
408
                dusttailColorArr.clear();
×
409
                for (int i=0; i<gastailVertexArr.size(); ++i)
×
410
                {
411
                        // Gastail extinction:
412
                        Vec3d vertAltAz=core->j2000ToAltAz(gastailVertexArr.at(i), StelCore::RefractionOn);
×
413
                        vertAltAz.normalize();
×
414
                        Q_ASSERT(fabs(vertAltAz.normSquared()-1.0) < 0.001);
×
415
                        float oneMag=0.0f;
×
416
                        extinction.forward(vertAltAz, &oneMag);
×
417
                        float extinctionFactor=std::pow(0.4f, oneMag); // drop of one magnitude: factor 2.5 or 40%
×
418
                        gastailColorArr.append(gasColor*extinctionFactor* brightnessPerVertexFromHead*intensityFovScale);
×
419

420
                        // dusttail extinction:
421
                        vertAltAz=core->j2000ToAltAz(dusttailVertexArr.at(i), StelCore::RefractionOn);
×
422
                        vertAltAz.normalize();
×
423
                        Q_ASSERT(fabs(vertAltAz.normSquared()-1.0) < 0.001);
×
424
                        oneMag=0.0f;
×
425
                        extinction.forward(vertAltAz, &oneMag);
×
426
                        extinctionFactor=std::pow(0.4f, oneMag); // drop of one magnitude: factor 2.5 or 40%
×
427
                        dusttailColorArr.append(dustColor*extinctionFactor * brightnessPerVertexFromHead*intensityFovScale);
×
428

429
                        brightnessPerVertexFromHead-=brightnessDecreasePerVertexFromHead;
×
430
                }
431
        }
432
        else // no atmosphere: set all vertices to same brightness.
433
        {
434
                gastailColorArr.fill(gasColor  *intensityFovScale, gastailVertexArr.length());
×
435
                dusttailColorArr.fill(dustColor*intensityFovScale, dusttailVertexArr.length());
×
436
        }
437
        //qDebug() << "Comet " << getEnglishName() <<  "JDE: " << date << "gasR" << gasColor[0] << " dustR" << dustColor[0];
438
}
439

440

441
// Draw the Comet and all the related infos: name, circle etc... GZ: Taken from Planet.cpp 2013-11-05 and extended
442
void Comet::draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont)
×
443
{
444
        if (hidden)
×
445
                return;
×
446

447
        // Exclude drawing if user set a hard limit magnitude.
448
        if (core->getSkyDrawer()->getFlagPlanetMagnitudeLimit() && (getVMagnitude(core) > core->getSkyDrawer()->getCustomPlanetMagnitudeLimit()))
×
449
                return;
×
450

451
        if (getEnglishName() == core->getCurrentLocation().planetName)
×
452
        { // Maybe even don't do that? E.g., draw tail while riding the comet? Decide later.
453
                return;
×
454
        }
455

456
        // This test seemed necessary for reasonable fps in case too many comet elements are loaded.
457
        // Problematic: Early-out here of course disables the wanted hint circles for dim comets.
458
        // The line makes hints for comets 5 magnitudes below sky limiting magnitude visible.
459
        // If comet is too faint to be seen, don't bother rendering. (Massive speedup if people have hundreds of comet elements!)
460
        if ((getVMagnitude(core)-5.0f) > core->getSkyDrawer()->getLimitMagnitude() && !core->getCurrentLocation().planetName.contains("Observer", Qt::CaseInsensitive))
×
461
        {
462
                return;
×
463
        }
464
        if (!static_cast<KeplerOrbit*>(orbitPtr)->objectDateGoodEnoughForOrbits(core->getJDE())) return; // don't draw at all if out of useful date range. This allows having hundreds of comet elements.
×
465

466
        Mat4d mat = Mat4d::translation(eclipticPos+aberrationPush) * rotLocalToParent;
×
467
        // This removed totally the Planet shaking bug!!!
468
        StelProjector::ModelViewTranformP transfo = core->getHeliocentricEclipticModelViewTransform();
×
469
        transfo->combine(mat);
×
470

471
        // Compute the 2D position and check if in the screen
472
        const StelProjectorP prj = core->getProjection(transfo);
×
473
        const double screenRd = (getAngularRadius(core))*M_PI_180*static_cast<double>(prj->getPixelPerRadAtCenter());
×
474
        const double viewport_left = prj->getViewportPosX();
×
475
        const double viewport_bottom = prj->getViewportPosY();
×
476
        const bool projectionValid=prj->project(Vec3d(0.), screenPos);
×
477
        if (projectionValid
×
478
                && screenPos[1] > viewport_bottom - screenRd
×
479
                && screenPos[1] < viewport_bottom + prj->getViewportHeight()+screenRd
×
480
                && screenPos[0] > viewport_left - screenRd
×
481
                && screenPos[0] < viewport_left + prj->getViewportWidth() + screenRd)
×
482
        {
483
                // Draw the name, and the circle if it's not too close from the body it's turning around
484
                // this prevents name overlapping (ie for jupiter satellites)
485
                float ang_dist = 300.f*static_cast<float>(atan(getEclipticPos().norm()/getEquinoxEquatorialPos(core).norm())/core->getMovementMgr()->getCurrentFov());
×
486
                // if (ang_dist==0.f) ang_dist = 1.f; // if ang_dist == 0, the Planet is sun.. --> GZ: we can remove it.
487

488
                // by putting here, only draw orbit if Comet is visible for clarity
489
                drawOrbit(core);  // TODO - fade in here also...
×
490

491
                labelsFader = (flagLabels && ang_dist>0.25f && maxMagLabels>getVMagnitude(core));
×
492
                drawHints(core, planetNameFont);
×
493

494
                draw3dModel(core,transfo,static_cast<float>(screenRd));
×
495
        }
496
        else
497
                if (!projectionValid && prj.data()->getNameI18() == q_("Orthographic"))
×
498
                        return; // End prematurely. This excludes bad "ghost" comet tail on the wrong hemisphere in ortho projection! Maybe also Fisheye, but it's less problematic.
×
499
        else if (permanentDrawingOrbits) // A special case for demos
×
500
                        drawOrbit(core);
×
501

502

503
        // If comet is too faint to be seen, don't bother rendering. (Massive speedup if people have hundreds of comets!)
504
        // This test moved here so that hints are still drawn.
505
        if ((getVMagnitude(core)-5.0f) > core->getSkyDrawer()->getLimitMagnitude())
×
506
        {
507
                return;
×
508
        }
509

510
        // but tails should also be drawn if comet core is off-screen...
511
        if (tailActive && tailBright)
×
512
        {
513
                drawTail(core,transfo,true);  // gas tail
×
514
                drawTail(core,transfo,false); // dust tail
×
515
        }
516
        //Coma: this is just a fan disk tilted towards the observer;-)
517
        drawComa(core, transfo);
×
518
        return;
×
519
}
×
520

521
void Comet::drawTail(StelCore* core, StelProjector::ModelViewTranformP transfo, bool gas)
×
522
{        
523
        StelPainter sPainter(core->getProjection(transfo));
×
524
        sPainter.setBlending(true, GL_ONE, GL_ONE);
×
525

526
        tailTexture->bind();
×
527

528
        if (gas) {
×
529
                StelVertexArray vaGas(static_cast<const QVector<Vec3d> >(gastailVertexArr), StelVertexArray::Triangles,
×
530
                                      static_cast<const QVector<Vec2f> >(tailTexCoordArr), tailIndices, static_cast<const QVector<Vec3f> >(gastailColorArr));
×
531
                sPainter.drawStelVertexArray(vaGas, true);
×
532

533
        } else {
×
534
                StelVertexArray vaDust(static_cast<const QVector<Vec3d> >(dusttailVertexArr), StelVertexArray::Triangles,
×
535
                                      static_cast<const QVector<Vec2f> >(tailTexCoordArr), tailIndices, static_cast<const QVector<Vec3f> >(dusttailColorArr));
×
536
                sPainter.drawStelVertexArray(vaDust, true);
×
537
        }
×
538
        sPainter.setBlending(false);
×
539
}
×
540

541
void Comet::drawComa(StelCore* core, StelProjector::ModelViewTranformP transfo)
×
542
{
543
        // Find rotation matrix from 0/0/1 to viewdirection! crossproduct for axis (normal vector), dotproduct for angle.
544
        Vec3d eclposNrm=eclipticPos+aberrationPush - core->getObserverHeliocentricEclipticPos()  ; eclposNrm.normalize();
×
545
        Mat4d comarot=Mat4d::rotation(Vec3d(0.0, 0.0, 1.0)^(eclposNrm), std::acos(Vec3d(0.0, 0.0, 1.0).dot(eclposNrm)) );
×
546
        StelProjector::ModelViewTranformP transfo2 = transfo->clone();
×
547
        transfo2->combine(comarot);
×
548
        StelPainter sPainter(core->getProjection(transfo2));
×
549

550
        sPainter.setBlending(true, GL_ONE, GL_ONE);
×
551

552
        StelToneReproducer* eye = core->getToneReproducer();
×
553
        float lum = core->getSkyDrawer()->surfaceBrightnessToLuminance(getVMagnitudeWithExtinction(core)+11.0f); // How to calibrate?
×
554
        // Get the luminance scaled between 0 and 1
555
        const float aLum =eye->adaptLuminanceScaled(lum);
×
556
        const float magFactor=qBound(0.25f*intensityFovScale, aLum*intensityFovScale, 2.0f);
×
557
        comaTexture->bind();
×
558
        sPainter.setColor(0.3f*magFactor,0.7f*magFactor,magFactor);
×
559
        StelVertexArray vaComa(static_cast<const QVector<Vec3d> >(comaVertexArr), StelVertexArray::Triangles, static_cast<const QVector<Vec2f> >(comaTexCoordArr));
×
560
        sPainter.drawStelVertexArray(vaComa, true);
×
561
        sPainter.setBlending(false);
×
562
}
×
563

564
// Formula found at http://www.projectpluto.com/update7b.htm#comet_tail_formula
565
Vec2f Comet::getComaDiameterAndTailLengthAU() const
×
566
{
567
        const float r = static_cast<float>(getHeliocentricEclipticPos().norm());
×
568
        const float mhelio = absoluteMagnitude + slopeParameter * log10(r);
×
569
        const float Do = powf(10.0f, ((-0.0033f*mhelio - 0.07f) * mhelio + 3.25f));
×
570
        const float common = 1.0f - powf(10.0f, (-2.0f*r));
×
571
        const float D = Do * common * (1.0f - powf(10.0f, -r)) * (1000.0f*AU_KMf);
×
572
        const float Lo = powf(10.0f, ((-0.0075f*mhelio - 0.19f) * mhelio + 2.1f));
×
573
        const float L = Lo*(1.0f-powf(10.0f, -4.0f*r)) * common * (1e6f*AU_KMf);
×
574
        return Vec2f(D, L);
×
575
}
576

577
void Comet::computeComa(const float diameter)
×
578
{
579
        StelPainter::computeFanDisk(0.5f*diameter, 3, 3, comaVertexArr, comaTexCoordArr);
×
580
}
×
581

582
//! create parabola shell to represent a tail. Designed for slices=16, stacks=16, but should work with other sizes as well.
583
//! (Maybe slices must be an even number.)
584
// Parabola equation: z=x²/2p.
585
// xOffset for the dust tail, this may introduce a bend. Units are x per sqrt(z).
586
void Comet::computeParabola(const float parameter, const float radius, const float zshift,
×
587
                                                  QVector<Vec3d>& vertexArr, QVector<Vec2f>& texCoordArr,
588
                                                  QVector<unsigned short> &indices, const float xOffset)
589
{
590
        // keep the array and replace contents. However, using replace() is only slightly faster.
591
        if (vertexArr.length() < static_cast<int>(((COMET_TAIL_SLICES*COMET_TAIL_STACKS+1))))
×
592
                vertexArr.resize((COMET_TAIL_SLICES*COMET_TAIL_STACKS+1));
×
593
        if (createTailIndices) indices.clear();
×
594
        if (createTailTextureCoords) texCoordArr.clear();
×
595
        // The parabola has triangular faces with vertices on two circles that are rotated against each other. 
596
        float xa[2*COMET_TAIL_SLICES];
597
        float ya[2*COMET_TAIL_SLICES];
598
        float x, y, z;
599
        
600
        // fill xa, ya with sin/cosines. TBD: make more efficient with index mirroring etc.
601
        float da=M_PIf/COMET_TAIL_SLICES; // full circle/2slices
×
602
        for (unsigned short int i=0; i<2*COMET_TAIL_SLICES; ++i){
×
603
                xa[i]=-sin(i*da);
×
604
                ya[i]=cos(i*da);
×
605
        }
606
        
607
        vertexArr.replace(0, Vec3d(0.0, 0.0, static_cast<double>(zshift)));
×
608
        int vertexArrIndex=1;
×
609
        if (createTailTextureCoords) texCoordArr << Vec2f(0.5f, 0.5f);
×
610
        // define the indices lying on circles, starting at 1: odd rings have 1/slices+1/2slices, even-numbered rings straight 1/slices
611
        // inner ring#1
612
        for (unsigned short int ring=1; ring<=COMET_TAIL_STACKS; ++ring){
×
613
                z=ring*radius/COMET_TAIL_STACKS; z=z*z/(2*parameter) + zshift;
×
614
                const float xShift= xOffset*z*z;
×
615
                for (unsigned short int i=ring & 1; i<2*COMET_TAIL_SLICES; i+=2) { // i.e., ring1 has shifted vertices, ring2 has even ones.
×
616
                        x=xa[i]*radius*ring/COMET_TAIL_STACKS;
×
617
                        y=ya[i]*radius*ring/COMET_TAIL_STACKS;
×
618
                        vertexArr.replace(vertexArrIndex++, Vec3d(static_cast<double>(x+xShift), static_cast<double>(y), static_cast<double>(z)));
×
619
                        if (createTailTextureCoords) texCoordArr << Vec2f(0.5f+ 0.5f*x/radius, 0.5f+0.5f*y/radius);
×
620
                }
621
        }
622
        // now link the faces with indices.
623
        if (createTailIndices)
×
624
        {
625
                for (unsigned short i=1; i<COMET_TAIL_SLICES; ++i) indices << 0 << i << i+1;
×
626
                indices << 0 << COMET_TAIL_SLICES << 1; // close inner fan.
×
627
                // The other slices are a repeating pattern of 2 possibilities. Index @ring always is on the inner ring (slices-agon)
628
                for (unsigned short ring=1; ring<COMET_TAIL_STACKS; ring+=2) { // odd rings
×
629
                        const unsigned short int first=(ring-1)*COMET_TAIL_SLICES+1;
×
630
                        for (unsigned short int i=0; i<COMET_TAIL_SLICES-1; ++i){
×
631
                                indices << first+i << first+COMET_TAIL_SLICES+i << first+COMET_TAIL_SLICES+1+i;
×
632
                                indices << first+i << first+COMET_TAIL_SLICES+1+i << first+1+i;
×
633
                        }
634
                        // closing slice: mesh with other indices...
635
                        indices << ring*COMET_TAIL_SLICES << (ring+1)*COMET_TAIL_SLICES << ring*COMET_TAIL_SLICES+1;
×
636
                        indices << ring*COMET_TAIL_SLICES << ring*COMET_TAIL_SLICES+1 << first;
×
637
                }
638

639
                for (unsigned short int ring=2; ring<COMET_TAIL_STACKS; ring+=2) { // even rings: different sequence.
×
640
                        const unsigned short int first=(ring-1)*COMET_TAIL_SLICES+1;
×
641
                        for (unsigned short int i=0; i<COMET_TAIL_SLICES-1; ++i){
×
642
                                indices << first+i << first+COMET_TAIL_SLICES+i << first+1+i;
×
643
                                indices << first+1+i << first+COMET_TAIL_SLICES+i << first+COMET_TAIL_SLICES+1+i;
×
644
                        }
645
                        // closing slice: mesh with other indices...
646
                        indices << ring*COMET_TAIL_SLICES << (ring+1)*COMET_TAIL_SLICES << first;
×
647
                        indices << first << (ring+1)*COMET_TAIL_SLICES << ring*COMET_TAIL_SLICES+1;
×
648
                }
649
        }
650
        createTailIndices=false;
×
651
        createTailTextureCoords=false;
×
652
}
×
653

654
void Comet::setIAUDesignation(const QString& designation)
×
655
{
656
        static const QRegularExpression periodicDesignationPattern("^(\\d+)P/");
×
657
        static const QRegularExpression periodicCometPattern("^P/([\\w\\s]+)$");
×
658
        QRegularExpressionMatch matchPeriodicNumber = periodicDesignationPattern.match(englishName);
×
659
        QRegularExpressionMatch matchPeriodicComet  = periodicCometPattern.match(designation);
×
660
        if (matchPeriodicNumber.hasMatch() && matchPeriodicComet.hasMatch())
×
661
        {
662
                // combined designation for numbered periodic comets - 1P/1982 U1 or 146P/1984 W1
663
                iauDesignation = QString("%1P/%2").arg(matchPeriodicNumber.captured(1), matchPeriodicComet.captured(1));
×
664
        }
665
        else
666
                iauDesignation = designation;
×
667
}
×
668

669
void Comet::setExtraDesignations(QStringList codes)
×
670
{
671
        extraDesignations = codes;
×
672
        for (const auto& c : codes)
×
673
        {
674
                extraDesignationsHtml << renderDiscoveryDesignationHtml(c);
×
675
        }
676
}
×
677

678
QString Comet::renderDiscoveryDesignationHtml(const QString &plainTextName)
3✔
679
{
680
        static const QRegularExpression discoveryDesignationPattern("^(\\d{4}[a-z]{1})(\\d+)$");
3✔
681
        QRegularExpressionMatch match=discoveryDesignationPattern.match(plainTextName);
3✔
682
        if (match.hasMatch())
3✔
683
        {
684
                QString main = match.captured(1);
2✔
685
                QString suffix = match.captured(2);
2✔
686
                return (QString("%1<sub>%2</sub>").arg(main, suffix));
4✔
687
        }
2✔
688
        else
689
                return plainTextName;
1✔
690
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc