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