/* -*- 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_latlongmarks.h" extern "C" PluginInfo* getmodules(int i) { if(i==0) { PluginInfo_Content* pi = new PluginInfo_Content(); pi->name = "Lat/Long grid marks"; pi->author = "Hugo Mills"; pi->copyright = "©2005 Hugo Mills"; pi->version = 0x10000; pi->parser = Content_LatLongMarks::parse; return pi; } else return NULL; } Content* Content_LatLongMarks::parse( ConfigLexer* lex, const std::string& type, const std::string& subtype ) { if(type != "latlongmarks") return NULL; int longd = 0; int latd = 0; int longdm = 1; int latdm = 1; bool scale = false; ivec3 col1(255); while(!lex->eos()) { if(readkeyedvalue(lex, "longitude-divs", &longd) || readkeyedvalue(lex, "latitude-divs", &latd) || readkeyedvalue(lex, "longitude-minor-divs", &longdm) || readkeyedvalue(lex, "latitude-minor-divs", &latdm) || readbooleanvalue(lex, "scale-long-divs", &scale) || readkeyedvalue(lex, "colour", &col1[0], &col1[1], &col1[2]) ) { } else throw(UnknownConfigToken(lex)); } if(latd == 0) latd = longd/2; if(longd == 0) longd = latd*2; if(longdm == 1) longdm = latdm; if(latdm == 1) latdm = longdm; return new Content_LatLongMarks(longd, longdm, latd, latdm, scale, col1); } void Content_LatLongMarks::plot( Output* bitmap, XfView* viewport, XfMap* projection, XfOrbit* orbit, XfSphere* sphere ) { dvec2 latlong; dvec3 globe_pos; dvec3 shifted_pos; dvec2 map_pos; ivec2 vp_pos; // Draw lines of longitude for(latlong[1] = -M_PI_2; latlong[1] < M_PI_2; latlong[1] += M_PI/latmajors) { double increment = 2*M_PI/(lonmajors*lonminors); if(scale) { increment = 2*M_PI / ( lonmajors* (int(double( lonminors*cos(latlong[1]) ) ) ) ); } for(latlong[0] = -M_PI; latlong[0] < M_PI; latlong[0] += increment) { if(sphere->f(globe_pos, latlong) && orbit->f(shifted_pos, globe_pos) && projection->f(map_pos, shifted_pos) && viewport->f(vp_pos, map_pos)) { bitmap->setpixel(vp_pos, colour); } else { // Do nothing, and move on to the next point } } } for(latlong[0] = -M_PI; latlong[0] < M_PI; latlong[0] += 2*M_PI/lonmajors) { for(latlong[1] = -M_PI_2; latlong[1] < M_PI_2; latlong[1] += M_PI/(latmajors*latminors)) { if(sphere->f(globe_pos, latlong) && orbit->f(shifted_pos, globe_pos) && projection->f(map_pos, shifted_pos) && viewport->f(vp_pos, map_pos)) { bitmap->setpixel(vp_pos, colour); } else { // Do nothing, and move on to the next point } } } }