/* $Id$
-This file is part of the MSP Märklin suite
-Copyright © 2010 Mikkosoft Productions, Mikko Rasa
+This file is part of R²C²
+Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <algorithm>
#include <cmath>
#include <msp/fs/path.h>
+#include <msp/gl/immediate.h>
#include <msp/gl/matrix.h>
#include <msp/gl/texture.h>
#include <msp/io/print.h>
using namespace std;
using namespace Msp;
-namespace Marklin {
+namespace R2C2 {
Overlay3D::Overlay3D(const Graphics::Window &w, const GL::Camera &c, const GL::Font &f):
window(w),
{
for(map<string, GL::Mesh *>::iterator i=graphics.begin(); i!=graphics.end(); ++i)
delete i->second;
+ for(map<const Object3D *, Icon *>::iterator i=icons.begin(); i!=icons.end(); ++i)
+ delete i->second;
}
-void Overlay3D::set_label(const Track3D &track, const string &label)
+void Overlay3D::set_label(const Object3D &track, const string &label)
{
get_icon(track).label = label;
update_icon(get_icon(track));
}
-void Overlay3D::add_graphic(const Track3D &track, const string &grf_name)
+void Overlay3D::add_graphic(const Object3D &track, const string &grf_name)
{
const GL::Mesh *grf = get_graphic(grf_name);
if(!grf)
update_icon(icon);
}
-void Overlay3D::remove_graphic(const Track3D &track, const string &grf_name)
+void Overlay3D::remove_graphic(const Object3D &track, const string &grf_name)
{
const GL::Mesh *grf = get_graphic(grf_name);
Icon &icon = get_icon(track);
update_icon(icon);
}
-void Overlay3D::clear_graphics(const Track3D &track)
+void Overlay3D::clear_graphics(const Object3D &track)
{
get_icon(track).graphics.clear();
update_icon(get_icon(track));
}
-void Overlay3D::clear(const Track3D &track)
+void Overlay3D::clear(const Object3D &track)
{
- map<const Track3D *, Icon *>::iterator i = icons.find(&track);
+ map<const Object3D *, Icon *>::iterator i = icons.find(&track);
if(i!=icons.end())
{
delete i->second;
float spacing = round(size*1.1)/size;
float baseline = round((0.5-font.get_ascent()*0.5-font.get_descent()*0.5)*size)/size;
- for(map<const Track3D *, Icon *>::const_iterator i=icons.begin(); i!=icons.end(); ++i)
+ for(map<const Object3D *, Icon *>::const_iterator i=icons.begin(); i!=icons.end(); ++i)
{
- const Icon &icon = *i->second;
+ if(!i->first->is_visible())
+ continue;
- const Point &pos = i->first->get_track().get_position();
- Point minp;
- Point maxp;
- i->first->get_type().get_bounds(0, minp, maxp);
- float rot = i->first->get_track().get_rotation();
- float c = cos(rot);
- float s = sin(rot);
+ const Icon &icon = *i->second;
- GL::Vector3 p((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, 0);
- p = GL::Vector3(pos.x+c*p.x-s*p.y, pos.y+s*p.x+c*p.y, pos.z+0.02);
- p = camera.project(p);
+ Vector node = i->first->get_node();
+ GL::Vector3 p = camera.project(GL::Vector3(node.x, node.y, node.z));
GL::PushMatrix push_mat;
p.x = int(p.x*0.5*window.get_width()-icon.width*size/2);
}
GL::translate(0, baseline, 0);
- font.draw_string(icon.label);
+ GL::Immediate imm((GL::TEXCOORD2, GL::COLOR4_UBYTE, GL::VERTEX2));
+ imm.color(0.0f, 1.0f, 0.0f);
+ font.draw_string(icon.label, imm);
GL::Texture::unbind();
}
GL::pop_matrix();
GL::matrix_mode(GL::MODELVIEW);
GL::pop_matrix();
+
+ glColor3f(1.0, 1.0, 1.0);
}
}
-Overlay3D::Icon &Overlay3D::get_icon(const Track3D &track)
+Overlay3D::Icon &Overlay3D::get_icon(const Object3D &track)
{
Icon *&icon = icons[&track];
if(!icon)
background((GL::COLOR4_UBYTE, GL::VERTEX2))
{ }
-} // namespace Marklin
+} // namespace R2C2