Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

compiling radar

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