1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*
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<unsigned int, core::Entity *>::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);
}
}
|