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