/* -*- C++ -*- * Copyright ©2004 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ #include "content_check.h" extern "C" PluginInfo* getmodules(int i) { if(i==0) { PluginInfo_Content* pi = new PluginInfo_Content(); pi->name = "Checked sphere"; pi->author = "Hugo Mills"; pi->copyright = "©2005 Hugo Mills"; pi->version = 0x10000; pi->parser = Content_Check::parse; return pi; } else return NULL; } Content* Content_Check::parse( ConfigLexer* lex, const std::string& type, const std::string& subtype ) { if(type != "check") return NULL; int lon = 2; int lat = 0; ivec3 col1; ivec3 col2; col1[0] = col1[1] = col1[2] = 255; col2[0] = 255; col2[1] = col2[2] = 0; while(!lex->eos()) { if(readkeyedvalue(lex, "longitude-divs", &lon) || readkeyedvalue(lex, "latitude-divs", &lat) || readkeyedvalue(lex, "colour1", &col1[0], &col1[1], &col1[2]) || readkeyedvalue(lex, "colour2", &col2[0], &col2[1], &col2[2]) ) { } else throw(UnknownConfigToken(lex)); } if(lat == 0) lat = lon/2; if(lon == 0) lon = lat*2; if(lat == 0 || lon == 0) { lat = 5; lon = 10; } return new Content_Check(lon, lat, col1, col2); } void Content_Check::plot( Output* bitmap, XfView* viewport, XfMap* projection, XfOrbit* orbit, XfSphere* sphere ) { ivec2 bm_pos; dvec2 map_pos; dvec3 shifted_pos; dvec3 globe_pos; dvec2 latlong; ivec3 colour; for(bm_pos[1] = viewport->bottom(); bm_pos[1] < viewport->top(); bm_pos[1]++) { for(bm_pos[0] = viewport->left(); bm_pos[0] < viewport->right(); bm_pos[0]++) { if(viewport->g(map_pos, bm_pos) && projection->g(shifted_pos, map_pos) && orbit->g(globe_pos, shifted_pos) && sphere->g(latlong, globe_pos)) { int hchk = int(hdivs*(latlong[0]+M_PI)/M_PI/2); int vchk = int(vdivs*(latlong[1]+M_PI_2)/M_PI); if((vchk+hchk) % 2) colour = colour1; else colour = colour2; } else continue; bitmap->setpixel(bm_pos, colour); } } }