Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10561 was 10516, checked in by patrick, 18 years ago

merged playability back to trunk

File size: 3.8 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[8991]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[8991]18#include "glgui_radar.h"
[8993]19#include "world_entity.h"
[1853]20
[8996]21#include "debug.h"
22
[8972]23namespace OrxGui
[3365]24{
[8972]25  /**
26   * @brief standard constructor
[8981]27   */
[8991]28  GLGuiRadar::GLGuiRadar ()
[8996]29  {
30    this->init();
31  }
[4320]32
33
[8972]34  /**
35   * @brief standard deconstructor
[4320]36   */
[8991]37  GLGuiRadar::~GLGuiRadar ()
[8993]38  {}
39
40  void GLGuiRadar::init()
[8972]41  {
[10317]42    this->setBackgroundTexture("textures/gui/gui_radar.png");
[10516]43    this->setBackgroundColor(Color(1.0,1.0,1.0,0.5));
[9001]44
[9019]45    this->_updateInterval = .01f;
[8993]46    this->_timePassed = 0.0f;
47    this->_range = 100.0f;
48    this->_centerNode = NULL;
[8972]49  }
[8974]50
[8993]51  void GLGuiRadar::setCenterNode(const PNode* center)
52  {
53    this->_centerNode = center;
54  }
[8974]55
[8993]56  void GLGuiRadar::addEntityList(const std::list<WorldEntity*>* entityList, const Color& color)
57  {
[9000]58    for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
59      if (_dotLists[i].entityList == entityList)
60        return;
61
[8993]62    GLGuiRadar::DotList dotList;
63    dotList.dotColor = color;
64    dotList.entityList = entityList;
[8992]65
[8993]66    this->_dotLists.push_back(dotList);
67  }
68
69  void GLGuiRadar::removeEntityList(const std::list<WorldEntity*>* entityList)
70  {
71    std::vector<DotList>::iterator it;
72    for (it = this->_dotLists.begin(); it != this->_dotLists.end(); ++it)
73      if ((*it).entityList == entityList)
74      {
75        this->_dotLists.erase(it);
76        break;
77      }
78  }
79
80
[9014]81  void GLGuiRadar::setRange(float range)
82  {
83    this->_range = range;
84  }
85
86
[8992]87  void GLGuiRadar::setAttenuation(Attenuation attenuation)
88  {
89    this->_attenuation = attenuation;
90  }
91
92
93  void GLGuiRadar::tick(float dt)
94  {
[8993]95    _timePassed+=dt;
[8992]96
[9019]97    if (_timePassed > _updateInterval)
[8993]98    {
[8996]99      _timePassed = 0 ; //-=_updateInterval;
[8993]100      this->updateRadar();
101    }
102
[8992]103  }
104
[8993]105  void GLGuiRadar::updateRadar()
[8992]106  {
[8993]107    if (_centerNode == NULL)
108    {
109      for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
110        this->_dotLists[i].positions.clear();
111      return;
112    }
[8992]113
[8993]114    std::list<WorldEntity*>::const_iterator it;
115    for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
116    {
117      this->_dotLists[i].positions.clear();
[8992]118
[8993]119      for (it = _dotLists[i].entityList->begin(); it != _dotLists[i].entityList->end(); ++it)
120      {
121        if (_centerNode->distance(*it) < this->_range)
122        {
[9002]123          this->_dotLists[i].positions.push_back(Vector2D(((*it)->getAbsCoor().x - _centerNode->getAbsCoor().x) * this->getSizeX2D() ,
124                                                 ((*it)->getAbsCoor().z - _centerNode->getAbsCoor().z) * this->getSizeY2D()  )
[10368]125                                                 / (3.0f * _range));
[8993]126        }
127
128      }
129
130    }
[8992]131  }
132
133
[8993]134  void GLGuiRadar::draw() const
135  {
[8994]136    this->beginDraw();
137    GLGuiWidget::draw();
138
[9002]139    if (likely(this->_centerNode != NULL))
[8993]140    {
[9002]141      glTranslatef(this->getSizeX2D()/2.0f, this->getSizeY2D()/2.0f, 0);
142      glRotatef((this->_centerNode->getAbsDir().getHeading() - M_PI_2)* 180.0 /M_PI , 0, 0, 1);
143
[9003]144      glPointSize(4.0f);
[9002]145      for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
[8993]146      {
[9002]147        glColor4fv(&_dotLists[i].dotColor[0]);
148        for (unsigned int j = 0; j < this->_dotLists[i].positions.size(); ++j)
149        {
150          glBegin(GL_POINTS);
151          glVertex2f(this->_dotLists[i].positions[j].x, this->_dotLists[i].positions[j].y);
152          glEnd();
153        }
[8993]154      }
155    }
[8994]156    this->endDraw();
[8993]157  }
158
159
[8991]160  void GLGuiRadar::resize()
[8977]161  {
[8991]162    GLGuiWidget::resize();
[8977]163  }
[8975]164
[8974]165
[8991]166  void GLGuiRadar::showing()
[8993]167  {}
[8974]168
[8991]169  void GLGuiRadar::hiding()
[8993]170{}}
Note: See TracBrowser for help on using the repository browser.