[1818] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "RadarViewable.h" |
---|
[2662] | 30 | |
---|
[3280] | 31 | #include "util/StringUtils.h" |
---|
[1818] | 32 | #include "core/CoreIncludes.h" |
---|
[6961] | 33 | #include "core/GameMode.h" |
---|
[5738] | 34 | #include "worldentities/WorldEntity.h" |
---|
| 35 | #include "Radar.h" |
---|
[5929] | 36 | #include "Scene.h" |
---|
[1818] | 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
| 40 | /** |
---|
| 41 | @brief Constructor. |
---|
| 42 | */ |
---|
[6942] | 43 | RadarViewable::RadarViewable(BaseObject* creator) |
---|
| 44 | : isHumanShip_(false) |
---|
[6417] | 45 | , bVisibility_(true) |
---|
[6942] | 46 | , bInitialized_(false) |
---|
| 47 | , creator_(creator) |
---|
[3089] | 48 | , radarObjectCamouflage_(0.0f) |
---|
[2662] | 49 | , radarObjectShape_(Dot) |
---|
[1818] | 50 | , radarObjectDescription_("staticObject") |
---|
| 51 | { |
---|
| 52 | RegisterRootObject(RadarViewable); |
---|
[3064] | 53 | |
---|
[3089] | 54 | this->uniqueId_=getUniqueNumberString(); |
---|
[6961] | 55 | if( GameMode::showsGraphics() ) |
---|
| 56 | { |
---|
| 57 | this->radar_ = this->creator_->getScene()->getRadar(); |
---|
| 58 | this->radar_->addRadarObject(this); |
---|
| 59 | } |
---|
[6942] | 60 | this->bInitialized_ = true; |
---|
[1818] | 61 | } |
---|
| 62 | |
---|
[3089] | 63 | |
---|
| 64 | RadarViewable::~RadarViewable() |
---|
| 65 | { |
---|
[6961] | 66 | |
---|
[6942] | 67 | if( this->bInitialized_ ) |
---|
[6961] | 68 | { |
---|
| 69 | if( GameMode::showsGraphics() ) |
---|
| 70 | { |
---|
| 71 | this->radar_->removeRadarObject(this); |
---|
| 72 | } |
---|
| 73 | } |
---|
[3089] | 74 | } |
---|
| 75 | |
---|
[6942] | 76 | // void RadarViewable::setRadarObjectDescription(const std::string& str) |
---|
| 77 | // { |
---|
| 78 | // Radar* radar = this->getWorldEntity()->getScene()->getRadar(); |
---|
| 79 | // if (radar) |
---|
| 80 | // this->radarObjectShape_ = radar->addObjectDescription(str); |
---|
| 81 | // else |
---|
| 82 | // { |
---|
| 83 | // CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl; |
---|
| 84 | // } |
---|
| 85 | // this->radarObjectDescription_ = str; |
---|
| 86 | // } |
---|
[3089] | 87 | |
---|
[2662] | 88 | const Vector3& RadarViewable::getRVWorldPosition() const |
---|
[1818] | 89 | { |
---|
[2662] | 90 | const WorldEntity* object = this->getWorldEntity(); |
---|
| 91 | validate(object); |
---|
| 92 | return object->getWorldPosition(); |
---|
[1818] | 93 | } |
---|
| 94 | |
---|
[2662] | 95 | Vector3 RadarViewable::getRVOrientedVelocity() const |
---|
[1818] | 96 | { |
---|
[2662] | 97 | const WorldEntity* object = this->getWorldEntity(); |
---|
| 98 | validate(object); |
---|
| 99 | return object->getWorldOrientation() * object->getVelocity(); |
---|
[1818] | 100 | } |
---|
[3182] | 101 | |
---|
| 102 | void RadarViewable::validate(const WorldEntity* object) const |
---|
| 103 | { |
---|
| 104 | if (!object) |
---|
| 105 | { |
---|
[6417] | 106 | COUT(1) << "Assertion: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl; |
---|
[3182] | 107 | assert(0); |
---|
| 108 | } |
---|
| 109 | } |
---|
[6942] | 110 | |
---|
| 111 | void RadarViewable::settingsChanged() |
---|
| 112 | { |
---|
[6961] | 113 | if( GameMode::showsGraphics() ) |
---|
| 114 | { |
---|
| 115 | this->radar_->radarObjectChanged(this); |
---|
| 116 | } |
---|
[6942] | 117 | } |
---|
[1818] | 118 | } |
---|