Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/test/src/world_entities/elements/glgui_radar.cc @ 9932

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

orxonox/trunk: OggPlayer retrieves Information about the current Title
The Title Played is relayed to the Hud's Notifier

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 = .01f;
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::setRange(float range)
81  {
82    this->_range = range;
83  }
84
85
86  void GLGuiRadar::setAttenuation(Attenuation attenuation)
87  {
88    this->_attenuation = attenuation;
89  }
90
91
92  void GLGuiRadar::tick(float dt)
93  {
94    _timePassed+=dt;
95
96    if (_timePassed > _updateInterval)
97    {
98      _timePassed = 0 ; //-=_updateInterval;
99      this->updateRadar();
100    }
101
102  }
103
104  void GLGuiRadar::updateRadar()
105  {
106    if (_centerNode == NULL)
107    {
108      for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
109        this->_dotLists[i].positions.clear();
110      return;
111    }
112
113    std::list<WorldEntity*>::const_iterator it;
114    for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
115    {
116      this->_dotLists[i].positions.clear();
117
118      for (it = _dotLists[i].entityList->begin(); it != _dotLists[i].entityList->end(); ++it)
119      {
120        if (_centerNode->distance(*it) < this->_range)
121        {
122          this->_dotLists[i].positions.push_back(Vector2D(((*it)->getAbsCoor().x - _centerNode->getAbsCoor().x) * this->getSizeX2D() ,
123                                                 ((*it)->getAbsCoor().z - _centerNode->getAbsCoor().z) * this->getSizeY2D()  )
124                                                 / (2.0f * _range));
125        }
126
127      }
128
129    }
130  }
131
132
133  void GLGuiRadar::draw() const
134  {
135    this->beginDraw();
136    GLGuiWidget::draw();
137
138    if (likely(this->_centerNode != NULL))
139    {
140      glTranslatef(this->getSizeX2D()/2.0f, this->getSizeY2D()/2.0f, 0);
141      glRotatef((this->_centerNode->getAbsDir().getHeading() - M_PI_2)* 180.0 /M_PI , 0, 0, 1);
142
143      glPointSize(4.0f);
144      for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
145      {
146        glColor4fv(&_dotLists[i].dotColor[0]);
147        for (unsigned int j = 0; j < this->_dotLists[i].positions.size(); ++j)
148        {
149          glBegin(GL_POINTS);
150          glVertex2f(this->_dotLists[i].positions[j].x, this->_dotLists[i].positions[j].y);
151          glEnd();
152        }
153      }
154    }
155    this->endDraw();
156  }
157
158
159  void GLGuiRadar::resize()
160  {
161    GLGuiWidget::resize();
162  }
163
164
165  void GLGuiRadar::showing()
166  {}
167
168  void GLGuiRadar::hiding()
169{}}
Note: See TracBrowser for help on using the repository browser.