Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

nicer, better radar

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