/* client/rader.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include "core/core.h" #include "client/radar.h" #include "client/video.h" #include "render/draw.h" #include "render/render.h" namespace client { void Radar::draw() { using namespace render; if (!core::localcontrol()) return; const float width = (float) video::width/4; const float height = (float) video::height/4; const float margin = 16; const float xscale = 128; const float yscale = xscale * height / width; const float left = video::width - margin - width; const float top = video::height -margin - height; gl::disable(GL_TEXTURE_2D); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); //glEnableClientState(GL_COLOR_ARRAY); // draw the transparent radar background gl::color(0.0f, 0.0f, 0.0f, 0.2f); gl::begin(gl::Quads); gl::vertex(left, top, 0.0f); gl::vertex(left + width, top, 0.0f); gl::vertex(left + width, top + height, 0.0f); gl::vertex(left, top + height, 0.0f); gl::end(); math::Vector3f center(core::localcontrol()->location()); gl::begin(gl::Points); std::map::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { core::Entity *entity = (*it).second; math::Vector3f position(entity->state()->location() - center); if ((position.x > -yscale) && (position.x < yscale) && (position.y > -xscale) && (position.y < xscale)) { float x = left + width/2 - position.y / xscale * width/2; float y = top + height/2 - position.x / xscale * width/2; if (entity->type() == core::Entity::Globe) { gl::end(); gl::push(); gl::translate(x, y, 0); float r = entity->radius() / xscale * width/2; draw_sphere(entity->color(), r); gl::pop(); gl::begin(gl::Points); } else { gl::color(entity->color()); gl::vertex(x , y , 0); } } } gl::end(); gl::enable(GL_TEXTURE_2D); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); //glDisableClientState(GL_COLOR_ARRAY); } }