1 // boundaries.cpp
2 //
3 // Copyright (C) 2002, Chris Laurel <claurel@shatters.net>
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 #include <cassert>
11 #include <celengine/boundaries.h>
12 #include <celengine/astro.h>
13 #include <celengine/gl.h>
14 #include <celengine/vecgl.h>
15
16 using namespace std;
17
18
19 static const float BoundariesDrawDistance = 10000.0f;
20
21
ConstellationBoundaries()22 ConstellationBoundaries::ConstellationBoundaries() :
23 currentChain(NULL)
24 {
25 currentChain = new Chain();
26 currentChain->insert(currentChain->end(), Point3f(0.0f, 0.0f, 0.0f));
27 }
28
~ConstellationBoundaries()29 ConstellationBoundaries::~ConstellationBoundaries()
30 {
31 for (vector<Chain*>::iterator iter = chains.begin();
32 iter != chains.end(); iter++)
33 {
34 delete *iter;
35 }
36
37 delete currentChain;
38 }
39
40
moveto(float ra,float dec)41 void ConstellationBoundaries::moveto(float ra, float dec)
42 {
43 assert(currentChain != NULL);
44
45 Point3f p = astro::equatorialToCelestialCart(ra, dec, BoundariesDrawDistance);
46 if (currentChain->size() > 1)
47 {
48 chains.insert(chains.end(), currentChain);
49 currentChain = new Chain();
50 currentChain->insert(currentChain->end(), p);
51 }
52 else
53 {
54 (*currentChain)[0] = p;
55 }
56 }
57
58
lineto(float ra,float dec)59 void ConstellationBoundaries::lineto(float ra, float dec)
60 {
61 currentChain->insert(currentChain->end(),
62 astro::equatorialToCelestialCart(ra, dec, BoundariesDrawDistance));
63 }
64
65
render()66 void ConstellationBoundaries::render()
67 {
68 for (vector<Chain*>::iterator iter = chains.begin();
69 iter != chains.end(); iter++)
70 {
71 Chain* chain = *iter;
72 glBegin(GL_LINE_STRIP);
73 for (Chain::iterator citer = chain->begin(); citer != chain->end();
74 citer++)
75 {
76 glVertex(*citer);
77 }
78 glEnd();
79 }
80 }
81
82
ReadBoundaries(istream & in)83 ConstellationBoundaries* ReadBoundaries(istream& in)
84 {
85 ConstellationBoundaries* boundaries = new ConstellationBoundaries();
86 string lastCon;
87 int conCount = 0;
88 int ptCount = 0;
89
90 for (;;)
91 {
92 float ra = 0.0f;
93 float dec = 0.0f;
94 in >> ra;
95 if (!in.good())
96 break;
97 in >> dec;
98
99 string pt;
100 string con;
101
102 in >> con;
103 in >> pt;
104 if (!in.good())
105 break;
106
107 if (con != lastCon)
108 {
109 boundaries->moveto(ra, dec);
110 lastCon = con;
111 conCount++;
112 }
113 else
114 {
115 boundaries->lineto(ra, dec);
116 }
117 ptCount++;
118 }
119
120 return boundaries;
121 }
122
123
124