~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to src/hip_star.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Stellarium
3
 
 * Copyright (C) 2002 Fabien Chereau
4
 
 * 
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.
9
 
 * 
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.
14
 
 * 
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.
18
 
 */
19
 
 
20
 
#include "hip_star.h"
21
 
#include "bytes.h"
22
 
#include "stellarium.h"
23
 
#include "navigator.h"
24
 
#include "stellastro.h"
25
 
#include "stel_utility.h"
26
 
#include "s_gui.h"  //circle
27
 
 
28
 
#define RADIUS_STAR 1.
29
 
 
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;
39
 
 
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] = 
43
 
{
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 */
51
 
};
52
 
 
53
 
HipStar::HipStar(void) :
54
 
        HP(0),
55
 
///     HD(0),
56
 
///     SAO(0),
57
 
        doubleStar(false),
58
 
        variableStar(false)
59
 
{
60
 
}
61
 
 
62
 
wstring HipStar::getInfoString(const Navigator * nav) const
63
 
{
64
 
        float tempDE, tempRA;
65
 
        Vec3d equatorial_pos = nav->j2000_to_earth_equ(XYZ);
66
 
        rect_to_sphe(&tempRA,&tempDE,equatorial_pos);
67
 
        wostringstream oss;
68
 
        if (commonNameI18!=L"" || sciName!=L"")
69
 
        {
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")");
74
 
        }
75
 
        else 
76
 
        {
77
 
                if (HP) oss << L"HP " << HP;
78
 
        }
79
 
        if (doubleStar) oss << L" **";
80
 
        oss << endl;
81
 
 
82
 
        oss.setf(ios::fixed);
83
 
        oss.precision(2);
84
 
        oss << _("Magnitude: ") << Mag;
85
 
        if (variableStar) oss << _(" (Variable)");
86
 
        oss << endl;
87
 
        oss << _("RA/DE: ") << StelUtility::printAngleHMS(tempRA) << L"/" << StelUtility::printAngleDMS(tempDE) << endl;
88
 
        // calculate alt az
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;
94
 
 
95
 
        oss << _("Distance: ");
96
 
        if(Distance) oss << Distance; else oss << "-";
97
 
        oss << _(" Light Years") << endl;
98
 
 
99
 
        oss << L"Cat: HP ";
100
 
        if (HP > 0)     oss << HP; else oss << "-";
101
 
 
102
 
        oss << endl;
103
 
 
104
 
        oss << _("Spectral Type: ") << getSpectralType() << endl;
105
 
        oss.precision(2);
106
 
 
107
 
        return oss.str();
108
 
}
109
 
 
110
 
wstring HipStar::getNameI18() const 
111
 
{
112
 
 
113
 
        if (commonNameI18!=L"" || sciName!=L"")
114
 
        {
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; 
119
 
        }
120
 
        else 
121
 
                return L"HP " + StelUtility::intToWstring(HP);
122
 
}
123
 
 
124
 
wstring HipStar::getShortInfoString(const Navigator * nav) const
125
 
{
126
 
        wostringstream oss;
127
 
        
128
 
        oss << getNameI18() << L"  ";
129
 
 
130
 
        oss.setf(ios::fixed);
131
 
        oss.precision(1);
132
 
        oss << _("Magnitude: ") << Mag;
133
 
        if (variableStar) oss << _(" (Variable)");
134
 
 
135
 
        if(Distance) {
136
 
                oss << L"  " << Distance << _(" Light Years");
137
 
        }
138
 
 
139
 
        return oss.str();
140
 
}
141
 
 
142
 
static const char spectral_type[13] = {
143
 
  'O','B','A','F','G','K','M','R','S','N','W','X','?'
144
 
};
145
 
 
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),
158
 
  Vec3f(1.0,  1.0, 1.0)
159
 
};
160
 
 
161
 
char HipStar::getSpectralType(void) const {
162
 
  return spectral_type[type];
163
 
}
164
 
 
165
 
Vec3f HipStar::get_RGB(void) const {
166
 
  return star_colors[type];
167
 
}
168
 
 
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)
173
 
{
174
 
        union { float fl; unsigned int ui; } RA, DE, LY, xRA, xDE, xLY;
175
 
 
176
 
        fread(&xRA.ui,4,1,catalog);
177
 
        LE_TO_CPU_INT32(RA.ui, xRA.ui);
178
 
 
179
 
        fread(&xDE.ui,4,1,catalog);
180
 
        LE_TO_CPU_INT32(DE.ui, xDE.ui);
181
 
 
182
 
        // for debug printing
183
 
        //      float rao = RA.fl;
184
 
        //  float deo = DE.fl;
185
 
     
186
 
    RA.fl*=M_PI/12.;     // Convert from hours to rad
187
 
    DE.fl*=M_PI/180.;    // Convert from deg to rad
188
 
 
189
 
        unsigned short int mag, xmag;
190
 
        fread(&xmag,2,1,catalog);
191
 
        LE_TO_CPU_INT16(mag, xmag);
192
 
 
193
 
        Mag = (5. + mag) / 256.0;
194
 
        if (Mag>250) Mag = Mag - 256;
195
 
 
196
 
        fread(&type,1,1,catalog);
197
 
        if (type > 12) type = 12;
198
 
 
199
 
        // Calc the Cartesian coord with RA and DE
200
 
    sphe_to_rect(RA.fl,DE.fl,XYZ);
201
 
 
202
 
    XYZ*=RADIUS_STAR;
203
 
 
204
 
        // Precomputation of a term used later
205
 
        term1 = expf(-0.92103f*(Mag + 12.12331f)) * 108064.73f;
206
 
 
207
 
        // distance
208
 
        fread(&xLY.ui,4,1,catalog);
209
 
        LE_TO_CPU_INT32(LY.ui, xLY.ui);
210
 
        Distance = LY.fl;
211
 
 
212
 
        if (mag==0 && type==0) return 0;
213
 
 
214
 
        // Hardcoded fix for bad data (because hp catalog isn't in cvs control)
215
 
        if(HP==120412) { mag  = type = 0; return 0; }
216
 
 
217
 
        //      printf("%d\t%d\t%.4f\t%.4f\t%c\n", HP, mag, rao, deo, SpType);
218
 
 
219
 
    return 1;
220
 
 
221
 
}
222
 
 
223
 
void HipStar::draw(const Vec3d &XY)
224
 
{
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;
229
 
        float cmag = 1.f;
230
 
        
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
233
 
    if (rmag<1.2f)
234
 
    {
235
 
        cmag=rmag*rmag/1.44f;
236
 
                if (rmag/star_scale<0.1f || cmag<0.1/star_mag_scale) return;
237
 
        rmag=1.2f;
238
 
    }
239
 
        else
240
 
    {
241
 
                if (rmag>5.f)
242
 
        {
243
 
                rmag=5.f;
244
 
        }
245
 
        }
246
 
 
247
 
    // Calculation of the luminosity
248
 
    // Random coef for star twinkling
249
 
    cmag*=(1.-twinkle_amount*rand()/RAND_MAX);
250
 
 
251
 
        // Global scaling
252
 
        rmag*=star_scale;
253
 
        cmag*=star_mag_scale;
254
 
 
255
 
        glColor3fv(star_colors[type]*cmag);
256
 
 
257
 
        glBlendFunc(GL_ONE, GL_ONE);
258
 
 
259
 
    glBegin(GL_QUADS );
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
264
 
    glEnd();
265
 
}
266
 
 
267
 
void HipStar::draw_point(const Vec3d &XY)
268
 
{
269
 
        float cmag;
270
 
        float rmag;
271
 
 
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;
276
 
 
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;
280
 
 
281
 
        if (rmag/star_scale<0.05f || cmag<0.05/star_mag_scale) return;
282
 
 
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);
288
 
 
289
 
        glBlendFunc(GL_ONE, GL_ONE);
290
 
 
291
 
        // rms - one pixel stars
292
 
        glDisable(GL_TEXTURE_2D);
293
 
        glPointSize(0.1);
294
 
        glBegin(GL_POINTS);
295
 
        glVertex3f(XY[0],XY[1],0);
296
 
        glEnd();
297
 
        glEnable(GL_TEXTURE_2D); // required for star labels to work
298
 
}
299
 
 
300
 
bool HipStar::draw_name(const Vec3d &XY)
301
 
{   
302
 
        wstring starname;
303
 
 
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,
310
 
                          names_brightness);
311
 
        // }
312
 
        //else glColor3fv(label_color);
313
 
 
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);
316
 
        
317
 
        return true;
318
 
}
319
 
 
320
 
 
321
 
 
322
 
 
323
 
 
324
 
 
325
 
 
326
 
 
327
 
 
328
 
 
329
 
 
330
 
 
331
 
 
332
 
 
333
 
/*
334
 
void HipStar::draw_chart(const Vec3d &XY)
335
 
{
336
 
        float r = Mag*-0.81+8.85;
337
 
 
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))));
340
 
 
341
 
        if (r < 2.4) return;
342
 
        
343
 
    glColor3fv(ChartColors[ChartColorIndex]);
344
 
 
345
 
//      glBindTexture (GL_TEXTURE_2D, idcTex);
346
 
        glBegin(GL_QUADS);
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
351
 
    glEnd();
352
 
 
353
 
        glColor3fv(circle_color);
354
 
        glCircle(XY,r);
355
 
        if (variableStar)
356
 
                glCircle(XY,(r-2));
357
 
        else if (doubleStar)
358
 
        {
359
 
                bool lastState = glIsEnabled(GL_TEXTURE_2D);
360
 
 
361
 
                glDisable(GL_TEXTURE_2D);
362
 
                glLineWidth(1.f);
363
 
                        
364
 
                glBegin(GL_LINE_LOOP);
365
 
                        glVertex3f(XY[0] - r - 4, XY[1],0.f);
366
 
                        glVertex3f(XY[0] - r, XY[1],0.f);
367
 
                glEnd();
368
 
                        
369
 
                glBegin(GL_LINE_LOOP);
370
 
                        glVertex3f(XY[0] + r, XY[1],0.f);
371
 
                        glVertex3f(XY[0] + r+4, XY[1],0.f);
372
 
                glEnd();
373
 
                        
374
 
                if (lastState) glEnable(GL_TEXTURE_2D);
375
 
                glLineWidth(1.0f);
376
 
        }
377
 
}
378
 
 
379
 
bool HipStar::readSAO(char *record, float maxmag)
380
 
{
381
 
        int RAh, RAm, DEd, DEm;
382
 
        float RAs, DEs;
383
 
        double DE, RA;
384
 
        int num;
385
 
        
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;
390
 
 
391
 
        sscanf(&record[0],"%d",&SAO);
392
 
        sscanf(&record[11],"%d",&num);
393
 
        if (num > 0) HD = num;
394
 
        
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.;
400
 
 
401
 
        RA*=M_PI/12.;     // Convert from hours to rad
402
 
        DE*=M_PI/180.;    // Convert from deg to rad
403
 
 
404
 
        // Calc the Cartesian coord with RA and DE
405
 
    sphe_to_rect(RA,DE,XYZ);
406
 
        XYZ *= RADIUS_STAR;
407
 
 
408
 
        SpType = record[143];
409
 
        setColor(SpType); // Color depending on the spectral type
410
 
 
411
 
        Distance = 0; // not in file (no parallex)
412
 
 
413
 
        return true;
414
 
}
415
 
 
416
 
bool HipStar::readHP(char *record, float maxmag)
417
 
{
418
 
        int RAh, RAm, DEd, DEm;
419
 
        float RAs, DEs;
420
 
        double DE, RA;
421
 
        int num;
422
 
        float par;
423
 
        
424
 
        sscanf(&record[2],"%d",&HP);
425
 
 
426
 
        // filter the magnitude
427
 
        sscanf(&record[351],"%f",&Mag);
428
 
        if (Mag < -2) Mag = 14;                         // trap -9.99's, sirius = -1.03!
429
 
        if (Mag > maxmag)
430
 
                return false;
431
 
 
432
 
        sscanf(&record[465],"%d",&num);
433
 
        if (num > 0) HD = num;
434
 
 
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.;
440
 
        
441
 
        RA*=M_PI/12.;     // Convert from hours to rad
442
 
        DE*=M_PI/180.;    // Convert from deg to rad
443
 
 
444
 
        // Calc the Cartesian coord with RA and DE
445
 
    sphe_to_rect(RA,DE,XYZ);
446
 
        XYZ *= RADIUS_STAR;
447
 
 
448
 
        SpType = record[516];
449
 
        setColor(SpType); // Color depending on the spectral type
450
 
 
451
 
        // Determine the distance from the parallax
452
 
        sscanf(&record[87],"%f",&par);
453
 
        if (par <= 0.001)
454
 
                Distance = 0;
455
 
        else
456
 
        {
457
 
                Distance = 1.f*3261.64/par;
458
 
                if (Distance < 0) Distance = 0;
459
 
        }
460
 
 
461
 
        return true;
462
 
}
463
 
*/
464
 
 
465