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