Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/elements/glgui_radar.cc @ 8999

Last change on this file since 8999 was 8999, checked in by bensch, 18 years ago

radar: much better sizeing

File size: 3.2 KB
Line 
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
23namespace 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->_updateInterval = 1.0f;
43    this->_timePassed = 0.0f;
44    this->_range = 100.0f;
45    this->_centerNode = NULL;
46  }
47
48  void GLGuiRadar::setCenterNode(const PNode* center)
49  {
50    this->_centerNode = center;
51  }
52
53  void GLGuiRadar::addEntityList(const std::list<WorldEntity*>* entityList, const Color& color)
54  {
55    GLGuiRadar::DotList dotList;
56    dotList.dotColor = color;
57    dotList.entityList = entityList;
58
59    this->_dotLists.push_back(dotList);
60  }
61
62  void GLGuiRadar::removeEntityList(const std::list<WorldEntity*>* entityList)
63  {
64    std::vector<DotList>::iterator it;
65    for (it = this->_dotLists.begin(); it != this->_dotLists.end(); ++it)
66      if ((*it).entityList == entityList)
67      {
68        this->_dotLists.erase(it);
69        break;
70      }
71  }
72
73
74  void GLGuiRadar::setAttenuation(Attenuation attenuation)
75  {
76    this->_attenuation = attenuation;
77  }
78
79
80  void GLGuiRadar::tick(float dt)
81  {
82    _timePassed+=dt;
83
84    //if (_timePassed > _updateInterval)
85    {
86      _timePassed = 0 ; //-=_updateInterval;
87      this->updateRadar();
88    }
89
90  }
91
92  void GLGuiRadar::updateRadar()
93  {
94    if (_centerNode == NULL)
95    {
96      for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
97        this->_dotLists[i].positions.clear();
98      return;
99    }
100
101    std::list<WorldEntity*>::const_iterator it;
102    for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
103    {
104      this->_dotLists[i].positions.clear();
105
106      for (it = _dotLists[i].entityList->begin(); it != _dotLists[i].entityList->end(); ++it)
107      {
108        if (_centerNode->distance(*it) < this->_range)
109        {
110          this->_dotLists[i].positions.push_back(Vector2D(this->getSizeX2D() / 2.0f, this->getSizeY2D() / 2.0f) + Vector2D(_centerNode->getAbsCoor().x - (*it)->getAbsCoor().x, _centerNode->getAbsCoor().z - (*it)->getAbsCoor().z)* (this->getSizeX2D() / 2.0f /_range));
111        }
112
113      }
114
115    }
116  }
117
118
119  void GLGuiRadar::draw() const
120  {
121    this->beginDraw();
122    GLGuiWidget::draw();
123
124    glPointSize(2.0f);
125    for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
126    {
127      glColor4fv(&_dotLists[i].dotColor[0]);
128      for (unsigned int j = 0; j < this->_dotLists[i].positions.size(); ++j)
129      {
130        glBegin(GL_POINTS);
131        glVertex2f(this->_dotLists[i].positions[j].x, this->_dotLists[i].positions[j].y);
132        glEnd();
133      }
134    }
135
136    this->endDraw();
137  }
138
139
140  void GLGuiRadar::resize()
141  {
142    GLGuiWidget::resize();
143  }
144
145
146  void GLGuiRadar::showing()
147  {}
148
149  void GLGuiRadar::hiding()
150{}}
Note: See TracBrowser for help on using the repository browser.