Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9019 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
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  {
[9001]42    this->setBackgroundTexture("gui_radar.png");
43
[9019]44    this->_updateInterval = .01f;
[8993]45    this->_timePassed = 0.0f;
46    this->_range = 100.0f;
47    this->_centerNode = NULL;
[8972]48  }
[8974]49
[8993]50  void GLGuiRadar::setCenterNode(const PNode* center)
51  {
52    this->_centerNode = center;
53  }
[8974]54
[8993]55  void GLGuiRadar::addEntityList(const std::list<WorldEntity*>* entityList, const Color& color)
56  {
[9000]57    for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
58      if (_dotLists[i].entityList == entityList)
59        return;
60
[8993]61    GLGuiRadar::DotList dotList;
62    dotList.dotColor = color;
63    dotList.entityList = entityList;
[8992]64
[8993]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
[9014]80  void GLGuiRadar::setRange(float range)
81  {
82    this->_range = range;
83  }
84
85
[8992]86  void GLGuiRadar::setAttenuation(Attenuation attenuation)
87  {
88    this->_attenuation = attenuation;
89  }
90
91
92  void GLGuiRadar::tick(float dt)
93  {
[8993]94    _timePassed+=dt;
[8992]95
[9019]96    if (_timePassed > _updateInterval)
[8993]97    {
[8996]98      _timePassed = 0 ; //-=_updateInterval;
[8993]99      this->updateRadar();
100    }
101
[8992]102  }
103
[8993]104  void GLGuiRadar::updateRadar()
[8992]105  {
[8993]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    }
[8992]112
[8993]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();
[8992]117
[8993]118      for (it = _dotLists[i].entityList->begin(); it != _dotLists[i].entityList->end(); ++it)
119      {
120        if (_centerNode->distance(*it) < this->_range)
121        {
[9002]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));
[8993]125        }
126
127      }
128
129    }
[8992]130  }
131
132
[8993]133  void GLGuiRadar::draw() const
134  {
[8994]135    this->beginDraw();
136    GLGuiWidget::draw();
137
[9002]138    if (likely(this->_centerNode != NULL))
[8993]139    {
[9002]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
[9003]143      glPointSize(4.0f);
[9002]144      for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
[8993]145      {
[9002]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        }
[8993]153      }
154    }
[8994]155    this->endDraw();
[8993]156  }
157
158
[8991]159  void GLGuiRadar::resize()
[8977]160  {
[8991]161    GLGuiWidget::resize();
[8977]162  }
[8975]163
[8974]164
[8991]165  void GLGuiRadar::showing()
[8993]166  {}
[8974]167
[8991]168  void GLGuiRadar::hiding()
[8993]169{}}
Note: See TracBrowser for help on using the repository browser.