[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 | |
---|
[3130] | 31 | #include <OgreSceneManager.h> |
---|
[3157] | 32 | #include <OgreSceneNode.h> |
---|
| 33 | #include <OgreEntity.h> |
---|
| 34 | |
---|
| 35 | #include "util/String.h" |
---|
[1818] | 36 | #include "core/CoreIncludes.h" |
---|
[3174] | 37 | #include "tools/DynamicLines.h" |
---|
[2662] | 38 | #include "objects/worldentities/WorldEntity.h" |
---|
| 39 | #include "objects/Radar.h" |
---|
[3089] | 40 | #include "overlays/map/Map.h" |
---|
[1818] | 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | /** |
---|
| 45 | @brief Constructor. |
---|
| 46 | */ |
---|
| 47 | RadarViewable::RadarViewable() |
---|
[3089] | 48 | : MapNode_(NULL) |
---|
| 49 | , MapEntity_(NULL) |
---|
| 50 | , line_(NULL) |
---|
| 51 | , LineNode_(NULL) |
---|
| 52 | , radarObjectCamouflage_(0.0f) |
---|
[2662] | 53 | , radarObjectShape_(Dot) |
---|
[1818] | 54 | , radarObjectDescription_("staticObject") |
---|
| 55 | { |
---|
| 56 | RegisterRootObject(RadarViewable); |
---|
[3064] | 57 | |
---|
| 58 | this->bVisibility_ = true; |
---|
[3089] | 59 | this->isHumanShip_ = false; |
---|
| 60 | |
---|
| 61 | this->uniqueId_=getUniqueNumberString(); |
---|
| 62 | /* |
---|
| 63 | if(Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr()) |
---|
| 64 | { |
---|
| 65 | this->addEntity(); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | */ |
---|
[1818] | 69 | } |
---|
| 70 | |
---|
[3089] | 71 | |
---|
| 72 | RadarViewable::~RadarViewable() |
---|
| 73 | { |
---|
[3101] | 74 | if (this->isHumanShip_ && MapNode_) |
---|
| 75 | MapNode_->removeAllChildren(); |
---|
| 76 | |
---|
[3089] | 77 | if (MapNode_) |
---|
| 78 | delete MapNode_; |
---|
| 79 | |
---|
| 80 | if (MapEntity_) |
---|
| 81 | delete MapEntity_; |
---|
| 82 | |
---|
| 83 | if (line_) |
---|
| 84 | delete line_; |
---|
| 85 | |
---|
| 86 | if (LineNode_) |
---|
| 87 | delete LineNode_; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void RadarViewable::addMapEntity() |
---|
| 91 | { //TODO Check shape and add accordantly |
---|
| 92 | if( this->MapNode_ && !this->MapEntity_ && Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr() ) |
---|
| 93 | { |
---|
| 94 | COUT(0) << "Adding " << this->uniqueId_ << " to Map.\n"; |
---|
| 95 | this->MapEntity_ = Map::getSingletonPtr()->getMapSceneManagerPtr()->createEntity( this->uniqueId_, "drone.mesh"); |
---|
| 96 | /*this->line_ = Map::getSingletonPtr()->getMapSceneManagerPtr()->createManualObject(this->uniqueId_ + "_l"); |
---|
| 97 | this->line_->begin("Map/line_", Ogre::RenderOperation::OT_LINE_STRIP); |
---|
| 98 | //line_->position(0, -it->getRVWorldPosition().y, 0); |
---|
| 99 | //this->line_->position(0, -20, 0); |
---|
| 100 | this->line_->position(0, 0, -10); //Front Arrow |
---|
| 101 | this->line_->position(0, 0, 0); |
---|
| 102 | |
---|
| 103 | this->line_->end(); */ |
---|
[3130] | 104 | this->line_ = new Ogre::DynamicLines(Ogre::RenderOperation::OT_LINE_LIST); |
---|
[3089] | 105 | this->line_->addPoint( Vector3(0,0,0) ); |
---|
| 106 | this->line_->addPoint( Vector3(0,0,0) ); |
---|
| 107 | |
---|
| 108 | this->MapNode_->attachObject( this->MapEntity_ ); |
---|
| 109 | |
---|
| 110 | this->LineNode_ = this->MapNode_->createChildSceneNode(); |
---|
| 111 | this->LineNode_->attachObject( this->line_ ); |
---|
| 112 | } |
---|
| 113 | else |
---|
| 114 | { |
---|
| 115 | COUT(0) << "Unable to load " << this->uniqueId_ << " to Map.\n"; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | void RadarViewable::updateMapPosition() |
---|
| 120 | { |
---|
| 121 | if( this->MapNode_ ) |
---|
| 122 | { |
---|
| 123 | this->MapNode_->setPosition( this->getRVWorldPosition() ); |
---|
| 124 | this->MapNode_->translate( this->getRVOrientedVelocity(), (Ogre::Node::TransformSpace)3 ); |
---|
| 125 | this->MapNode_->setOrientation( this->getWorldEntity()->getOrientation() ); |
---|
| 126 | //Vector3 v = this->getRVWorldPosition(); |
---|
| 127 | //this->line_->setPoint(1, Vector3(0,v.y,0) ); |
---|
[3192] | 128 | this->line_->setPoint(1, Vector3( 0, static_cast<float>(static_cast<int>( -Map::getSingletonPtr()->movablePlane_->getDistance( this->getRVWorldPosition() ) ) ) ,0 )); |
---|
[3089] | 129 | this->line_->update(); |
---|
| 130 | if( Map::getSingletonPtr()->playerShipNode_ ) |
---|
| 131 | this->LineNode_->setDirection( Map::getSingletonPtr()->playerShipNode_->getLocalAxes().GetColumn(1) ,Ogre::Node::TS_WORLD,Vector3::UNIT_Y); |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
[1818] | 135 | void RadarViewable::setRadarObjectDescription(const std::string& str) |
---|
| 136 | { |
---|
| 137 | Radar* radar = Radar::getInstancePtr(); |
---|
| 138 | if (radar) |
---|
[2662] | 139 | this->radarObjectShape_ = radar->addObjectDescription(str); |
---|
[1818] | 140 | else |
---|
| 141 | { |
---|
| 142 | CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl; |
---|
| 143 | } |
---|
| 144 | this->radarObjectDescription_ = str; |
---|
| 145 | } |
---|
| 146 | |
---|
[2662] | 147 | const Vector3& RadarViewable::getRVWorldPosition() const |
---|
[1818] | 148 | { |
---|
[2662] | 149 | const WorldEntity* object = this->getWorldEntity(); |
---|
| 150 | validate(object); |
---|
| 151 | return object->getWorldPosition(); |
---|
[1818] | 152 | } |
---|
| 153 | |
---|
[2662] | 154 | Vector3 RadarViewable::getRVOrientedVelocity() const |
---|
[1818] | 155 | { |
---|
[2662] | 156 | const WorldEntity* object = this->getWorldEntity(); |
---|
| 157 | validate(object); |
---|
| 158 | return object->getWorldOrientation() * object->getVelocity(); |
---|
[1818] | 159 | } |
---|
[3182] | 160 | |
---|
| 161 | void RadarViewable::validate(const WorldEntity* object) const |
---|
| 162 | { |
---|
| 163 | if (!object) |
---|
| 164 | { |
---|
| 165 | COUT(1) << "Assertation: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl; |
---|
| 166 | assert(0); |
---|
| 167 | } |
---|
| 168 | } |
---|
[1818] | 169 | } |
---|