3
* Copyright (C) 2002 Fabien Chereau
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include "stellarium.h"
23
#include "navigator.h"
24
#include "stellastro.h"
25
#include "stel_utility.h"
26
#include "s_gui.h" //circle
28
#define RADIUS_STAR 1.
30
// Init Static variables
31
float HipStar::twinkle_amount = 10.f;
32
float HipStar::star_scale = 10.f;
33
float HipStar::star_mag_scale = 10.f;
34
float HipStar::names_brightness = 1.f;
35
ToneReproductor* HipStar::eye = NULL;
36
Projector* HipStar::proj = NULL;
37
bool HipStar::gravity_label = false;
38
s_font *HipStar::starFont = NULL;
40
Vec3f HipStar::circle_color = Vec3f(0.f,0.f,0.f);
41
Vec3f HipStar::label_color = Vec3f(.8f,.8f,.8f);
42
Vec3f HipStar::ChartColors[20] =
44
Vec3f(0.25,0.60,1.00) /* A+*/, Vec3f(0.73,0.13,0.59) /* B+*/, Vec3f(1.00,0.50,0.00) /* C-*/,
45
Vec3f(0.00,0.00,0.00) /* Dx*/, Vec3f(0.00,0.00,0.00) /* Ex*/, Vec3f(0.15,0.85,0.00) /* F+*/,
46
Vec3f(1.00,1.00,0.25) /* G+*/, Vec3f(0.00,0.00,0.00) /* Hx*/, Vec3f(0.00,0.00,0.00) /* Ix*/,
47
Vec3f(0.00,0.00,0.00) /* Jx*/, Vec3f(1.00,0.65,0.25) /* K+*/, Vec3f(0.00,0.00,0.00) /* Lx*/,
48
Vec3f(1.00,0.00,0.00) /* M */, Vec3f(1.00,0.00,0.00) /* N+*/, Vec3f(0.73,0.13,0.59) /* O+*/,
49
Vec3f(0.00,0.00,0.00) /* Px*/, Vec3f(0.00,0.00,0.00) /* Qx*/, Vec3f(1.00,0.00,0.00) /* R+*/,
50
Vec3f(0.00,0.00,0.00) /* S+*/, Vec3f(0.50,0.50,0.50) /* Defualt */
53
HipStar::HipStar(void) :
62
wstring HipStar::getInfoString(const Navigator * nav) const
65
Vec3d equatorial_pos = nav->j2000_to_earth_equ(XYZ);
66
rect_to_sphe(&tempRA,&tempDE,equatorial_pos);
68
if (commonNameI18!=L"" || sciName!=L"")
70
oss << commonNameI18 << wstring(commonNameI18 == L"" ? L"" : L" ");
71
if (commonNameI18!=L"" && sciName!=L"") oss << wstring(L"(");
72
oss << wstring(sciName==L"" ? L"" : sciName);
73
if (commonNameI18!=L"" && sciName!=L"") oss << wstring(L")");
77
if (HP) oss << L"HP " << HP;
79
if (doubleStar) oss << L" **";
84
oss << _("Magnitude: ") << Mag;
85
if (variableStar) oss << _(" (Variable)");
87
oss << _("RA/DE: ") << StelUtility::printAngleHMS(tempRA) << L"/" << StelUtility::printAngleDMS(tempDE) << endl;
89
Vec3d local_pos = nav->earth_equ_to_local(equatorial_pos);
90
rect_to_sphe(&tempRA,&tempDE,local_pos);
91
tempRA = 3*M_PI - tempRA; // N is zero, E is 90 degrees
92
if(tempRA > M_PI*2) tempRA -= M_PI*2;
93
oss << _("Az/Alt: ") << StelUtility::printAngleDMS(tempRA) << L"/" << StelUtility::printAngleDMS(tempDE) << endl;
95
oss << _("Distance: ");
96
if(Distance) oss << Distance; else oss << "-";
97
oss << _(" Light Years") << endl;
100
if (HP > 0) oss << HP; else oss << "-";
104
oss << _("Spectral Type: ") << getSpectralType() << endl;
110
wstring HipStar::getNameI18() const
113
if (commonNameI18!=L"" || sciName!=L"")
115
// TODO: ISSUE Sci name shouldn't show with other cultures
116
// Tie to culture or make option? Rob
117
if (commonNameI18 == L"") return L""; // return sciName;
118
else return commonNameI18;
121
return L"HP " + StelUtility::intToWstring(HP);
124
wstring HipStar::getShortInfoString(const Navigator * nav) const
128
oss << getNameI18() << L" ";
130
oss.setf(ios::fixed);
132
oss << _("Magnitude: ") << Mag;
133
if (variableStar) oss << _(" (Variable)");
136
oss << L" " << Distance << _(" Light Years");
142
static const char spectral_type[13] = {
143
'O','B','A','F','G','K','M','R','S','N','W','X','?'
146
static Vec3f star_colors[12] = {
147
Vec3f(0.8 /1.3, 1.0 /1.3, 1.3 /1.3),
148
Vec3f(0.9 /1.2, 1.0 /1.2, 1.2 /1.2),
149
Vec3f(0.95/1.15, 1.0 /1.15,1.15/1.15),
150
Vec3f(1.05/1.05, 1.0 /1.05,1.05/1.05),
151
Vec3f(1.3 /1.3, 1.0 /1.3, 0.9 /1.3),
152
Vec3f(1.15/1.15, 0.95/1.15,0.8 /1.15),
153
Vec3f(1.15/1.15, 0.85/1.15,0.8 /1.15),
154
Vec3f(1.3 /1.3, 0.85/1.3, 0.6 /1.3),
155
Vec3f(1.5 /1.5, 0.8 /1.5, 0.2 /1.5),
156
Vec3f(1.5 /1.5, 0.8 /1.5, 0.2 /1.5),
157
Vec3f(1.5 /1.5, 0.8 /1.5, 0.2 /1.5),
161
char HipStar::getSpectralType(void) const {
162
return spectral_type[type];
165
Vec3f HipStar::get_RGB(void) const {
166
return star_colors[type];
169
// Read datas in binary catalog and compute x,y,z;
170
// The aliasing bug on some architecture has been fixed by Rainer Canavan on 26/11/2003
171
// Really ? -- JB, 20060607
172
int HipStar::read(FILE * catalog)
174
union { float fl; unsigned int ui; } RA, DE, LY, xRA, xDE, xLY;
176
fread(&xRA.ui,4,1,catalog);
177
LE_TO_CPU_INT32(RA.ui, xRA.ui);
179
fread(&xDE.ui,4,1,catalog);
180
LE_TO_CPU_INT32(DE.ui, xDE.ui);
182
// for debug printing
183
// float rao = RA.fl;
184
// float deo = DE.fl;
186
RA.fl*=M_PI/12.; // Convert from hours to rad
187
DE.fl*=M_PI/180.; // Convert from deg to rad
189
unsigned short int mag, xmag;
190
fread(&xmag,2,1,catalog);
191
LE_TO_CPU_INT16(mag, xmag);
193
Mag = (5. + mag) / 256.0;
194
if (Mag>250) Mag = Mag - 256;
196
fread(&type,1,1,catalog);
197
if (type > 12) type = 12;
199
// Calc the Cartesian coord with RA and DE
200
sphe_to_rect(RA.fl,DE.fl,XYZ);
204
// Precomputation of a term used later
205
term1 = expf(-0.92103f*(Mag + 12.12331f)) * 108064.73f;
208
fread(&xLY.ui,4,1,catalog);
209
LE_TO_CPU_INT32(LY.ui, xLY.ui);
212
if (mag==0 && type==0) return 0;
214
// Hardcoded fix for bad data (because hp catalog isn't in cvs control)
215
if(HP==120412) { mag = type = 0; return 0; }
217
// printf("%d\t%d\t%.4f\t%.4f\t%c\n", HP, mag, rao, deo, SpType);
223
void HipStar::draw(const Vec3d &XY)
225
// Compute the equivalent star luminance for a 5 arc min circle and convert it
226
// in function of the eye adaptation
227
float rmag = eye->adapt_luminance(term1)
228
* powf(proj->get_fov(),-0.85f) * 70.f;
231
// if size of star is too small (blink) we put its size to 1.2 --> no more blink
232
// And we compensate the difference of brighteness with cmag
235
cmag=rmag*rmag/1.44f;
236
if (rmag/star_scale<0.1f || cmag<0.1/star_mag_scale) return;
247
// Calculation of the luminosity
248
// Random coef for star twinkling
249
cmag*=(1.-twinkle_amount*rand()/RAND_MAX);
253
cmag*=star_mag_scale;
255
glColor3fv(star_colors[type]*cmag);
257
glBlendFunc(GL_ONE, GL_ONE);
260
glTexCoord2i(0,0); glVertex2f(XY[0]-rmag,XY[1]-rmag); // Bottom left
261
glTexCoord2i(1,0); glVertex2f(XY[0]+rmag,XY[1]-rmag); // Bottom right
262
glTexCoord2i(1,1); glVertex2f(XY[0]+rmag,XY[1]+rmag); // Top right
263
glTexCoord2i(0,1); glVertex2f(XY[0]-rmag,XY[1]+rmag); // Top left
267
void HipStar::draw_point(const Vec3d &XY)
272
// Compute the equivalent star luminance for a 5 arc min circle and convert it
273
// in function of the eye adaptation
274
rmag = eye->adapt_luminance(term1);
275
rmag = rmag*powf(proj->get_fov(),-0.85f)*50.f;
277
// if size of star is too small (blink) we put its size to 1.2 --> no more blink
278
// And we compensate the difference of brighteness with cmag
279
cmag = rmag * rmag / 1.44f;
281
if (rmag/star_scale<0.05f || cmag<0.05/star_mag_scale) return;
283
// Calculation of the luminosity
284
// Random coef for star twinkling
285
cmag*=(1.-twinkle_amount*rand()/RAND_MAX);
286
cmag*=star_mag_scale;
287
glColor3fv(star_colors[type]*cmag);
289
glBlendFunc(GL_ONE, GL_ONE);
291
// rms - one pixel stars
292
glDisable(GL_TEXTURE_2D);
295
glVertex3f(XY[0],XY[1],0);
297
glEnable(GL_TEXTURE_2D); // required for star labels to work
300
bool HipStar::draw_name(const Vec3d &XY)
304
starname = getNameI18();
305
if (starname==L"") return false;
306
// if (draw_mode == DM_NORMAL) {
307
glColor4f(star_colors[type][0]*0.75,
308
star_colors[type][1]*0.75,
309
star_colors[type][2]*0.75,
312
//else glColor3fv(label_color);
314
proj->getFlagGravityLabels() ? proj->print_gravity180(starFont, XY[0],XY[1], starname, 1, 6, -4) :
315
starFont->print(XY[0]+6,XY[1]-4, starname);
334
void HipStar::draw_chart(const Vec3d &XY)
336
float r = Mag*-0.81+8.85;
338
// multiplier = 1 at fov = 35, and 1/2 at fov=180
339
r = r *((.5-1)/(180-35)*proj->get_fov()+(1-35*((.5-1)/(180-35))));
343
glColor3fv(ChartColors[ChartColorIndex]);
345
// glBindTexture (GL_TEXTURE_2D, idcTex);
347
glTexCoord2i(0,0); glVertex2f(XY[0]-r,XY[1]-r); // Bottom left
348
glTexCoord2i(1,0); glVertex2f(XY[0]+r,XY[1]-r); // Bottom right
349
glTexCoord2i(1,1); glVertex2f(XY[0]+r,XY[1]+r); // Top right
350
glTexCoord2i(0,1); glVertex2f(XY[0]-r,XY[1]+r); // Top left
353
glColor3fv(circle_color);
359
bool lastState = glIsEnabled(GL_TEXTURE_2D);
361
glDisable(GL_TEXTURE_2D);
364
glBegin(GL_LINE_LOOP);
365
glVertex3f(XY[0] - r - 4, XY[1],0.f);
366
glVertex3f(XY[0] - r, XY[1],0.f);
369
glBegin(GL_LINE_LOOP);
370
glVertex3f(XY[0] + r, XY[1],0.f);
371
glVertex3f(XY[0] + r+4, XY[1],0.f);
374
if (lastState) glEnable(GL_TEXTURE_2D);
379
bool HipStar::readSAO(char *record, float maxmag)
381
int RAh, RAm, DEd, DEm;
386
// filter the magnitude
387
sscanf(&record[103],"%f",&Mag);
388
if (Mag < -1) Mag = 14; // trap -9.99's
389
if (Mag > maxmag) return false;
391
sscanf(&record[0],"%d",&SAO);
392
sscanf(&record[11],"%d",&num);
393
if (num > 0) HD = num;
395
sscanf(&record[37],"%d %d %f",&RAh, &RAm, &RAs);
396
sscanf(&record[52],"%d %d %f",&DEd, &DEm, &DEs);
397
RA = (double)RAh+(float)RAm/60.+(float)RAs/3600.;
398
DE = (double)DEd+(float)DEm/60.+(float)DEs/3600.;
399
if (record[51] == '-') DE *= -1.;
401
RA*=M_PI/12.; // Convert from hours to rad
402
DE*=M_PI/180.; // Convert from deg to rad
404
// Calc the Cartesian coord with RA and DE
405
sphe_to_rect(RA,DE,XYZ);
408
SpType = record[143];
409
setColor(SpType); // Color depending on the spectral type
411
Distance = 0; // not in file (no parallex)
416
bool HipStar::readHP(char *record, float maxmag)
418
int RAh, RAm, DEd, DEm;
424
sscanf(&record[2],"%d",&HP);
426
// filter the magnitude
427
sscanf(&record[351],"%f",&Mag);
428
if (Mag < -2) Mag = 14; // trap -9.99's, sirius = -1.03!
432
sscanf(&record[465],"%d",&num);
433
if (num > 0) HD = num;
435
sscanf(&record[14],"%d %d %f",&RAh, &RAm, &RAs);
436
sscanf(&record[28],"%d %d %f",&DEd, &DEm, &DEs);
437
RA = (double)RAh+(float)RAm/60.+(float)RAs/3600.;
438
DE = (double)DEd+(float)DEm/60.+(float)DEs/3600.;
439
if (record[27] == '-') DE *= -1.;
441
RA*=M_PI/12.; // Convert from hours to rad
442
DE*=M_PI/180.; // Convert from deg to rad
444
// Calc the Cartesian coord with RA and DE
445
sphe_to_rect(RA,DE,XYZ);
448
SpType = record[516];
449
setColor(SpType); // Color depending on the spectral type
451
// Determine the distance from the parallax
452
sscanf(&record[87],"%f",&par);
457
Distance = 1.f*3261.64/par;
458
if (Distance < 0) Distance = 0;