00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <cassert>
00011 #include <celengine/boundaries.h>
00012 #include <celengine/astro.h>
00013 #include <celengine/gl.h>
00014 #include <celengine/vecgl.h>
00015
00016 using namespace std;
00017
00018
00019 ConstellationBoundaries::ConstellationBoundaries() :
00020 currentChain(NULL)
00021 {
00022 currentChain = new Chain();
00023 currentChain->insert(currentChain->end(), Point3f(0.0f, 0.0f, 0.0f));
00024 }
00025
00026 ConstellationBoundaries::~ConstellationBoundaries()
00027 {
00028 for (vector<Chain*>::iterator iter = chains.begin();
00029 iter != chains.end(); iter++)
00030 {
00031 delete *iter;
00032 }
00033
00034 delete currentChain;
00035 }
00036
00037
00038 void ConstellationBoundaries::moveto(float ra, float dec)
00039 {
00040 assert(currentChain != NULL);
00041
00042 Point3f p = astro::equatorialToCelestialCart(ra, dec, 10.0f);
00043 if (currentChain->size() > 1)
00044 {
00045 chains.insert(chains.end(), currentChain);
00046 currentChain = new Chain();
00047 currentChain->insert(currentChain->end(), p);
00048 }
00049 else
00050 {
00051 (*currentChain)[0] = p;
00052 }
00053 }
00054
00055
00056 void ConstellationBoundaries::lineto(float ra, float dec)
00057 {
00058 currentChain->insert(currentChain->end(),
00059 astro::equatorialToCelestialCart(ra, dec, 10.0f));
00060 }
00061
00062
00063 void ConstellationBoundaries::render()
00064 {
00065 for (vector<Chain*>::iterator iter = chains.begin();
00066 iter != chains.end(); iter++)
00067 {
00068 Chain* chain = *iter;
00069 glBegin(GL_LINE_STRIP);
00070 for (Chain::iterator citer = chain->begin(); citer != chain->end();
00071 citer++)
00072 {
00073 glVertex(*citer);
00074 }
00075 glEnd();
00076 }
00077 }
00078
00079
00080 ConstellationBoundaries* ReadBoundaries(istream& in)
00081 {
00082 ConstellationBoundaries* boundaries = new ConstellationBoundaries();
00083 string lastCon;
00084 int conCount = 0;
00085 int ptCount = 0;
00086
00087 for (;;)
00088 {
00089 float ra = 0.0f;
00090 float dec = 0.0f;
00091 in >> ra;
00092 if (!in.good())
00093 break;
00094 in >> dec;
00095
00096 string pt;
00097 string con;
00098
00099 in >> con;
00100 in >> pt;
00101 if (!in.good())
00102 break;
00103
00104 if (con != lastCon)
00105 {
00106 boundaries->moveto(ra, dec);
00107 lastCon = con;
00108 conCount++;
00109 }
00110 else
00111 {
00112 boundaries->lineto(ra, dec);
00113 }
00114 ptCount++;
00115 }
00116
00117 return boundaries;
00118 }
00119
00120