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 | * Si Sun |
---|
24 | * |
---|
25 | */ |
---|
26 | #include "OrxonoxStableHeaders.h" |
---|
27 | #include "Map.h" |
---|
28 | |
---|
29 | #include <string> |
---|
30 | #include "util/String.h" |
---|
31 | #include <OgreSceneManager.h> |
---|
32 | #include <OgreSceneNode.h> |
---|
33 | #include <OgreEntity.h> |
---|
34 | #include <OgreNode.h> |
---|
35 | |
---|
36 | |
---|
37 | #include <OgreRenderWindow.h> |
---|
38 | #include <OgreRenderTexture.h> |
---|
39 | #include <OgreTexture.h> |
---|
40 | #include <OgreViewport.h> |
---|
41 | |
---|
42 | #include <OgreMaterialManager.h> |
---|
43 | #include <OgreRoot.h> |
---|
44 | #include <OgreHardwarePixelBuffer.h> |
---|
45 | #include "objects/worldentities/ControllableEntity.h" |
---|
46 | #include "objects/worldentities/CameraPosition.h" |
---|
47 | |
---|
48 | #include <OgreOverlay.h> |
---|
49 | #include <OgreOverlayElement.h> |
---|
50 | #include <OgreOverlayManager.h> |
---|
51 | #include <OgreOverlayContainer.h> |
---|
52 | #include "core/CoreIncludes.h" |
---|
53 | #include "core/ConfigValueIncludes.h" |
---|
54 | #include "core/ConsoleCommand.h" |
---|
55 | #include "objects/Scene.h" |
---|
56 | #include "objects/RadarViewable.h" |
---|
57 | #include "objects/controllers/HumanController.h" |
---|
58 | |
---|
59 | namespace orxonox |
---|
60 | { |
---|
61 | CreateFactory(Map); |
---|
62 | SetConsoleCommand(Map, openMap, true); |
---|
63 | SetConsoleCommand(Map, rotateYaw, true).setAsInputCommand(); |
---|
64 | SetConsoleCommand(Map, rotatePitch, true).setAsInputCommand(); |
---|
65 | |
---|
66 | Map* Map::singletonMap_s = 0; |
---|
67 | |
---|
68 | Map::Map(BaseObject* creator) : OrxonoxOverlay(creator) |
---|
69 | { |
---|
70 | RegisterObject(Map); |
---|
71 | Map::singletonMap_s=this; |
---|
72 | //Getting Scene Manager (Hack) |
---|
73 | ObjectList<Scene>::iterator it = ObjectList<Scene>::begin(); |
---|
74 | this->sManager_ = it->getSceneManager(); |
---|
75 | |
---|
76 | this->mapSceneM_ = Ogre::Root::getSingletonPtr()->createSceneManager( Ogre::ST_GENERIC,"MapScene" ); |
---|
77 | rootNode_ = mapSceneM_->getRootSceneNode(); |
---|
78 | |
---|
79 | //this->sNode_ = new Ogre::SceneNode(sManager_); |
---|
80 | //oManager_ = Ogre::OverlayManager::getSingletonPtr(); |
---|
81 | //overlay_ = oManager_->create("Map"); |
---|
82 | //overlay_ is member of OrxonoxOverlay |
---|
83 | |
---|
84 | //Not Showing the map as default |
---|
85 | //this->isVisible_=false; |
---|
86 | //overlay_->hide(); |
---|
87 | |
---|
88 | |
---|
89 | //TestEntity |
---|
90 | //Ogre::Entity * ent = mapSceneM_->createEntity("ent", "drone.mesh"); |
---|
91 | |
---|
92 | //rootNode_->attachObject( ent ); |
---|
93 | /*sNode_->setPosition(0,0,-50); |
---|
94 | overlay_->add3D(sNode_); |
---|
95 | */ |
---|
96 | |
---|
97 | this->mouseLookSpeed_ = 200; |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | // Alter the camera aspect ratio to match the viewport |
---|
102 | //mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight())); |
---|
103 | mReflectCam_ = mapSceneM_->createCamera("ReflectCam"); |
---|
104 | mReflectCam_->setPosition(200,170, -160); |
---|
105 | mReflectCam_->lookAt(0,0,0); |
---|
106 | mReflectCam_->setAspectRatio(1); |
---|
107 | |
---|
108 | //Create overlay material |
---|
109 | std::string camMat_id = "RttMat"; |
---|
110 | Ogre::MaterialPtr material = this->createRenderCamera(mReflectCam_, camMat_id); |
---|
111 | /* |
---|
112 | Ogre::TexturePtr rttTex = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); |
---|
113 | |
---|
114 | Ogre::RenderTexture *renderTexture = rttTex->getBuffer()->getRenderTarget(); |
---|
115 | |
---|
116 | renderTexture->addViewport(mReflectCam_); |
---|
117 | renderTexture->getViewport(0)->setClearEveryFrame(true); |
---|
118 | renderTexture->getViewport(0)->setBackgroundColour(ColourValue::Black); |
---|
119 | renderTexture->getViewport(0)->setOverlaysEnabled(false); |
---|
120 | |
---|
121 | Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("RttMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
122 | Ogre::Technique *technique = material->createTechnique(); |
---|
123 | technique->createPass(); |
---|
124 | material->getTechnique(0)->getPass(0)->setLightingEnabled(false); |
---|
125 | material->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex"); |
---|
126 | */ |
---|
127 | |
---|
128 | |
---|
129 | // create overlay |
---|
130 | /* |
---|
131 | Ogre::Overlay* pOverlay = Ogre::OverlayManager::getSingleton().create("Overlay1"); |
---|
132 | |
---|
133 | // Create a panel with RenderToTexture texture |
---|
134 | Ogre::OverlayContainer* m_pOverlayPanel = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel","OverlayPanelName%d")); |
---|
135 | m_pOverlayPanel->setMetricsMode(Ogre::GMM_PIXELS); |
---|
136 | m_pOverlayPanel->setPosition(10, 10); |
---|
137 | m_pOverlayPanel->setDimensions(500, 300); |
---|
138 | // Give overlay a texture |
---|
139 | m_pOverlayPanel->setMaterialName(camMat_id); |
---|
140 | pOverlay->add2D(m_pOverlayPanel); |
---|
141 | pOverlay->show(); |
---|
142 | */ |
---|
143 | overlay_ = Ogre::OverlayManager::getSingleton().create("MapOverlay"); |
---|
144 | Ogre::OverlayContainer* m_pOverlayPanel = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel","OverlayPanelName%d")); |
---|
145 | m_pOverlayPanel->setMetricsMode(Ogre::GMM_PIXELS); |
---|
146 | m_pOverlayPanel->setPosition(10, 10); |
---|
147 | m_pOverlayPanel->setDimensions(500, 300); |
---|
148 | // Give overlay a texture |
---|
149 | m_pOverlayPanel->setMaterialName(camMat_id); |
---|
150 | overlay_->add2D(m_pOverlayPanel); |
---|
151 | //Not Showing the map as default |
---|
152 | this->isVisible_=false; |
---|
153 | overlay_->hide(); |
---|
154 | |
---|
155 | //Create plane in map |
---|
156 | Ogre::Entity* plane_ent = this->mapSceneM_->createEntity( "MapPlane", "plane.mesh"); |
---|
157 | Ogre::SceneNode* plane_node = this->mapSceneM_->getRootSceneNode()->createChildSceneNode(); |
---|
158 | |
---|
159 | //Ogre::MaterialPtr plane_mat = Ogre::MaterialManager::getSingleton().create("mapgrid", "General"); |
---|
160 | //plane_mat->getTechnique(0)->getPass(0)->createTextureUnitState("mapgrid.tga"); |
---|
161 | //plane_ent->setMaterialName("mapgrid"); |
---|
162 | plane_ent->setMaterialName("Map/Grid"); |
---|
163 | plane_node->attachObject(plane_ent); |
---|
164 | plane_node->scale(10,1,10); |
---|
165 | //Ogre::Material plane_mat = Ogre::MaterialManager::getSingletonPtr()->getByName("rock"); |
---|
166 | |
---|
167 | |
---|
168 | //ToDo create material script |
---|
169 | Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("Map/Line","General"); |
---|
170 | myManualObjectMaterial->setReceiveShadows(false); |
---|
171 | myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); |
---|
172 | myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(1,1,0,0); |
---|
173 | myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(1,1,0); |
---|
174 | myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1,1,0); |
---|
175 | |
---|
176 | } |
---|
177 | |
---|
178 | Map::~Map() |
---|
179 | { |
---|
180 | singletonMap_s = 0; |
---|
181 | //delete sManager_; |
---|
182 | //delete rootNode_; |
---|
183 | //delete oManager_; |
---|
184 | //delete mReflectCam_; |
---|
185 | //delete mapSceneM_; |
---|
186 | } |
---|
187 | |
---|
188 | Ogre::MaterialPtr Map::createRenderCamera(Ogre::Camera * cam, std::string matName) |
---|
189 | { |
---|
190 | Ogre::TexturePtr rttTex = Ogre::TextureManager::getSingleton().createManual(matName+"_tex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); |
---|
191 | |
---|
192 | Ogre::RenderTexture *renderTexture = rttTex->getBuffer()->getRenderTarget(); |
---|
193 | |
---|
194 | renderTexture->addViewport(cam); |
---|
195 | renderTexture->getViewport(0)->setClearEveryFrame(true); |
---|
196 | renderTexture->getViewport(0)->setBackgroundColour(ColourValue::Black); |
---|
197 | renderTexture->getViewport(0)->setOverlaysEnabled(false); |
---|
198 | |
---|
199 | Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
200 | Ogre::Technique *technique = material->createTechnique(); |
---|
201 | technique->createPass(); |
---|
202 | material->getTechnique(0)->getPass(0)->setLightingEnabled(false); |
---|
203 | material->getTechnique(0)->getPass(0)->createTextureUnitState(matName+"_tex"); |
---|
204 | return material; |
---|
205 | } |
---|
206 | |
---|
207 | void Map::updatePositions() |
---|
208 | { |
---|
209 | |
---|
210 | //Ogre::Entity * ent;// = mapSceneM_->createEntity("ent1", "drone.mesh"); |
---|
211 | for(ObjectList<orxonox::RadarViewable>::iterator it = ObjectList<orxonox::RadarViewable>::begin(); |
---|
212 | it!=ObjectList<orxonox::RadarViewable>::end(); |
---|
213 | it++) |
---|
214 | { |
---|
215 | //COUT(0) << "Radar_Position: " << it->getRVWorldPosition() << std::endl; |
---|
216 | //Ogre::SceneNode node = it->getMapNode(); |
---|
217 | //Ogre::Entity ent = it->getMapEntity(); |
---|
218 | if( !(it->MapNode_) ) |
---|
219 | { |
---|
220 | it->MapNode_ = rootNode_->createChildSceneNode( it->getRVWorldPosition() ); |
---|
221 | //it->MapNode_->translate( it->getRVOrientedVelocity(), Ogre::TS_WORLD ); |
---|
222 | /*if(it->getRadarObjectShape() == RadarViewable::Dot) |
---|
223 | { |
---|
224 | //if( !(it->MapEntity_) )//check wether the entity is already attached |
---|
225 | //{ |
---|
226 | //it->MapEntity_ = this->mapSceneM_->createEntity( getUniqueNumberString(), "drone.mesh"); |
---|
227 | //it->addEntity(); |
---|
228 | //it->MapNode_->attachObject( it->MapEntity_ ); |
---|
229 | //it->MapNode_->attachObject( it->line_ ); |
---|
230 | // } |
---|
231 | }*/ |
---|
232 | it->addMapEntity(); |
---|
233 | } |
---|
234 | |
---|
235 | it->updateMapPosition(); |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | |
---|
240 | |
---|
241 | |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | void Map::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
246 | { |
---|
247 | SUPER(Map, XMLPort, xmlElement, mode); |
---|
248 | } |
---|
249 | |
---|
250 | void Map::changedOwner() |
---|
251 | { |
---|
252 | //COUT(0) << "shipptr" << this->getOwner()->getReverseCamera() << std::endl; |
---|
253 | if(this->getOwner()->getReverseCamera()) |
---|
254 | { |
---|
255 | //COUT(0) << "foo"; |
---|
256 | this->getOwner()->getReverseCamera()->attachCamera(this->mReflectCam_); |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | |
---|
261 | void Map::toggleVisibility() |
---|
262 | { |
---|
263 | if (!(this->isVisible_)) |
---|
264 | { |
---|
265 | this->overlay_->show(); |
---|
266 | this->isVisible_=1; |
---|
267 | //set mouselook when showing map |
---|
268 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && !HumanController::localController_s->controllableEntity_->isInMouseLook()) |
---|
269 | HumanController::localController_s->controllableEntity_->mouseLook(); |
---|
270 | } |
---|
271 | else |
---|
272 | { |
---|
273 | this->overlay_->hide(); |
---|
274 | this->isVisible_=0; |
---|
275 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->isInMouseLook()) |
---|
276 | HumanController::localController_s->controllableEntity_->mouseLook(); |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | //Static function to toggle visibility of the map |
---|
281 | void Map::openMap() |
---|
282 | { |
---|
283 | for(ObjectList<orxonox::Map>::iterator it = ObjectList<orxonox::Map>::begin(); |
---|
284 | it!=ObjectList<orxonox::Map>::end(); |
---|
285 | it++) |
---|
286 | { |
---|
287 | //Map * m = it->getMap(); |
---|
288 | //COUT(0) << it->isVisible_ << std::endl; |
---|
289 | it->toggleVisibility(); |
---|
290 | //it->updatePositions(); |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | void Map::tick(float dt) |
---|
295 | { |
---|
296 | //sNode_->lookAt(Vector3::NEGATIVE_UNIT_Z, Ogre::Node::TS_WORLD, Vector3::NEGATIVE_UNIT_Z); |
---|
297 | if( this->isVisible_ ) |
---|
298 | updatePositions(); |
---|
299 | //mReflectCam_->roll(Degree(1)); |
---|
300 | |
---|
301 | } |
---|
302 | |
---|
303 | void Map::rotateYaw(const Vector2& value) |
---|
304 | { |
---|
305 | //if (this->bMouseLook_) |
---|
306 | //this->mReflectCam_->yaw(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL); |
---|
307 | if(Map::singletonMap_s) |
---|
308 | singletonMap_s->mReflectCam_->setOrientation(singletonMap_s->mReflectCam_->getOrientation() * Quaternion( (Degree)(value.y * singletonMap_s->mouseLookSpeed_) , Vector3::UNIT_Y)); |
---|
309 | } |
---|
310 | |
---|
311 | void Map::rotatePitch(const Vector2& value) |
---|
312 | { |
---|
313 | //if (this->bMouseLook_) |
---|
314 | //this->mReflectCam_->pitch(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL); |
---|
315 | if(Map::singletonMap_s) |
---|
316 | singletonMap_s->mReflectCam_->setOrientation(singletonMap_s->mReflectCam_->getOrientation() * Quaternion( (Degree)(-value.y * singletonMap_s->mouseLookSpeed_) , Vector3::UNIT_X)); |
---|
317 | } |
---|
318 | |
---|
319 | } |
---|