[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 | |
---|
[8972] | 21 | namespace OrxGui |
---|
[3365] | 22 | { |
---|
[8972] | 23 | /** |
---|
| 24 | * @brief standard constructor |
---|
[8981] | 25 | */ |
---|
[8991] | 26 | GLGuiRadar::GLGuiRadar () |
---|
[8993] | 27 | {} |
---|
[4320] | 28 | |
---|
| 29 | |
---|
[8972] | 30 | /** |
---|
| 31 | * @brief standard deconstructor |
---|
[4320] | 32 | */ |
---|
[8991] | 33 | GLGuiRadar::~GLGuiRadar () |
---|
[8993] | 34 | {} |
---|
| 35 | |
---|
| 36 | void GLGuiRadar::init() |
---|
[8972] | 37 | { |
---|
[8993] | 38 | this->_updateInterval = 1.0f; |
---|
| 39 | this->_timePassed = 0.0f; |
---|
| 40 | this->_range = 100.0f; |
---|
| 41 | this->_centerNode = NULL; |
---|
[8972] | 42 | } |
---|
[8974] | 43 | |
---|
[8993] | 44 | void GLGuiRadar::setCenterNode(const PNode* center) |
---|
| 45 | { |
---|
| 46 | this->_centerNode = center; |
---|
| 47 | } |
---|
[8974] | 48 | |
---|
[8993] | 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; |
---|
[8992] | 54 | |
---|
[8993] | 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 | |
---|
[8992] | 70 | void GLGuiRadar::setAttenuation(Attenuation attenuation) |
---|
| 71 | { |
---|
| 72 | this->_attenuation = attenuation; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | void GLGuiRadar::tick(float dt) |
---|
| 77 | { |
---|
[8993] | 78 | _timePassed+=dt; |
---|
[8992] | 79 | |
---|
[8993] | 80 | if (_timePassed > _updateInterval) |
---|
| 81 | { |
---|
| 82 | _timePassed-=_updateInterval; |
---|
| 83 | this->updateRadar(); |
---|
| 84 | } |
---|
| 85 | |
---|
[8992] | 86 | } |
---|
| 87 | |
---|
[8993] | 88 | void GLGuiRadar::updateRadar() |
---|
[8992] | 89 | { |
---|
[8993] | 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 | } |
---|
[8992] | 96 | |
---|
[8993] | 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(); |
---|
[8992] | 101 | |
---|
[8993] | 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 | } |
---|
[8992] | 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
[8993] | 115 | void GLGuiRadar::draw() const |
---|
| 116 | { |
---|
[8994] | 117 | this->beginDraw(); |
---|
| 118 | GLGuiWidget::draw(); |
---|
| 119 | |
---|
[8993] | 120 | for (unsigned int i = 0; i < this->_dotLists.size(); ++i) |
---|
| 121 | { |
---|
[8994] | 122 | glColor4fv(&_dotLists[i].dotColor[0]); |
---|
[8993] | 123 | for (unsigned int j = 0; j < this->_dotLists[i].positions.size(); ++j) |
---|
| 124 | { |
---|
[8994] | 125 | glBegin(GL_POINTS); |
---|
| 126 | |
---|
| 127 | glVertex2f(this->_dotLists[i].positions[i].x, this->_dotLists[i].positions[i].y); |
---|
| 128 | |
---|
| 129 | glEnd(); |
---|
[8993] | 130 | } |
---|
| 131 | } |
---|
[8994] | 132 | |
---|
| 133 | this->endDraw(); |
---|
[8993] | 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
[8991] | 137 | void GLGuiRadar::resize() |
---|
[8977] | 138 | { |
---|
[8991] | 139 | GLGuiWidget::resize(); |
---|
[8977] | 140 | } |
---|
[8975] | 141 | |
---|
[8974] | 142 | |
---|
[8991] | 143 | void GLGuiRadar::showing() |
---|
[8993] | 144 | {} |
---|
[8974] | 145 | |
---|
[8991] | 146 | void GLGuiRadar::hiding() |
---|
[8993] | 147 | {}} |
---|