Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: redirect everything to see into the dof of the _centerNode

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