1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
17 | |
---|
18 | #include "glgui_radar.h" |
---|
19 | #include "world_entity.h" |
---|
20 | |
---|
21 | #include "debug.h" |
---|
22 | |
---|
23 | namespace OrxGui |
---|
24 | { |
---|
25 | /** |
---|
26 | * @brief standard constructor |
---|
27 | */ |
---|
28 | GLGuiRadar::GLGuiRadar () |
---|
29 | { |
---|
30 | this->init(); |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | /** |
---|
35 | * @brief standard deconstructor |
---|
36 | */ |
---|
37 | GLGuiRadar::~GLGuiRadar () |
---|
38 | {} |
---|
39 | |
---|
40 | void GLGuiRadar::init() |
---|
41 | { |
---|
42 | this->setBackgroundTexture("textures/gui/gui_radar.png"); |
---|
43 | this->setBackgroundColor(Color(1.0,1.0,1.0,0.5)); |
---|
44 | |
---|
45 | this->_updateInterval = .01f; |
---|
46 | this->_timePassed = 0.0f; |
---|
47 | this->_range = 100.0f; |
---|
48 | this->_centerNode = NULL; |
---|
49 | } |
---|
50 | |
---|
51 | void GLGuiRadar::setCenterNode(const PNode* center) |
---|
52 | { |
---|
53 | this->_centerNode = center; |
---|
54 | } |
---|
55 | |
---|
56 | void GLGuiRadar::addEntityList(const std::list<WorldEntity*>* entityList, const Color& color) |
---|
57 | { |
---|
58 | for (unsigned int i = 0; i < this->_dotLists.size(); ++i) |
---|
59 | if (_dotLists[i].entityList == entityList) |
---|
60 | return; |
---|
61 | |
---|
62 | GLGuiRadar::DotList dotList; |
---|
63 | dotList.dotColor = color; |
---|
64 | dotList.entityList = entityList; |
---|
65 | |
---|
66 | this->_dotLists.push_back(dotList); |
---|
67 | } |
---|
68 | |
---|
69 | void GLGuiRadar::removeEntityList(const std::list<WorldEntity*>* entityList) |
---|
70 | { |
---|
71 | std::vector<DotList>::iterator it; |
---|
72 | for (it = this->_dotLists.begin(); it != this->_dotLists.end(); ++it) |
---|
73 | if ((*it).entityList == entityList) |
---|
74 | { |
---|
75 | this->_dotLists.erase(it); |
---|
76 | break; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | void GLGuiRadar::setRange(float range) |
---|
82 | { |
---|
83 | this->_range = range; |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | void GLGuiRadar::setAttenuation(Attenuation attenuation) |
---|
88 | { |
---|
89 | this->_attenuation = attenuation; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | void GLGuiRadar::tick(float dt) |
---|
94 | { |
---|
95 | _timePassed+=dt; |
---|
96 | |
---|
97 | if (_timePassed > _updateInterval) |
---|
98 | { |
---|
99 | _timePassed = 0 ; //-=_updateInterval; |
---|
100 | this->updateRadar(); |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | void GLGuiRadar::updateRadar() |
---|
106 | { |
---|
107 | if (_centerNode == NULL) |
---|
108 | { |
---|
109 | for (unsigned int i = 0; i < this->_dotLists.size(); ++i) |
---|
110 | this->_dotLists[i].positions.clear(); |
---|
111 | return; |
---|
112 | } |
---|
113 | |
---|
114 | std::list<WorldEntity*>::const_iterator it; |
---|
115 | for (unsigned int i = 0; i < this->_dotLists.size(); ++i) |
---|
116 | { |
---|
117 | this->_dotLists[i].positions.clear(); |
---|
118 | |
---|
119 | for (it = _dotLists[i].entityList->begin(); it != _dotLists[i].entityList->end(); ++it) |
---|
120 | { |
---|
121 | if (_centerNode->distance(*it) < this->_range) |
---|
122 | { |
---|
123 | this->_dotLists[i].positions.push_back(Vector2D(((*it)->getAbsCoor().x - _centerNode->getAbsCoor().x) * this->getSizeX2D() , |
---|
124 | ((*it)->getAbsCoor().z - _centerNode->getAbsCoor().z) * this->getSizeY2D() ) |
---|
125 | / (3.0f * _range)); |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | void GLGuiRadar::draw() const |
---|
135 | { |
---|
136 | this->beginDraw(); |
---|
137 | GLGuiWidget::draw(); |
---|
138 | |
---|
139 | if (likely(this->_centerNode != NULL)) |
---|
140 | { |
---|
141 | glTranslatef(this->getSizeX2D()/2.0f, this->getSizeY2D()/2.0f, 0); |
---|
142 | glRotatef((this->_centerNode->getAbsDir().getHeading() - M_PI_2)* 180.0 /M_PI , 0, 0, 1); |
---|
143 | |
---|
144 | glPointSize(4.0f); |
---|
145 | for (unsigned int i = 0; i < this->_dotLists.size(); ++i) |
---|
146 | { |
---|
147 | glColor4fv(&_dotLists[i].dotColor[0]); |
---|
148 | for (unsigned int j = 0; j < this->_dotLists[i].positions.size(); ++j) |
---|
149 | { |
---|
150 | glBegin(GL_POINTS); |
---|
151 | glVertex2f(this->_dotLists[i].positions[j].x, this->_dotLists[i].positions[j].y); |
---|
152 | glEnd(); |
---|
153 | } |
---|
154 | } |
---|
155 | } |
---|
156 | this->endDraw(); |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | void GLGuiRadar::resize() |
---|
161 | { |
---|
162 | GLGuiWidget::resize(); |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | void GLGuiRadar::showing() |
---|
167 | {} |
---|
168 | |
---|
169 | void GLGuiRadar::hiding() |
---|
170 | {}} |
---|