| [74] | 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * |
|---|
| 4 | * |
|---|
| 5 | * License notice: |
|---|
| 6 | * |
|---|
| [462] | 7 | * This program is free software; you can redistribute it and/or |
|---|
| 8 | * modify it under the terms of the GNU General Public License |
|---|
| 9 | * as published by the Free Software Foundation; either version 2 |
|---|
| 10 | * of the License, or (at your option) any later version. |
|---|
| [74] | 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| [462] | 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| [74] | 20 | * |
|---|
| 21 | * Author: |
|---|
| 22 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
|---|
| 23 | * Co-authors: |
|---|
| 24 | * ... |
|---|
| 25 | * |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| [142] | 28 | /** |
|---|
| 29 | @file orxonox.cc |
|---|
| [462] | 30 | @brief Orxonox Main Class |
|---|
| [142] | 31 | */ |
|---|
| 32 | |
|---|
| [462] | 33 | #include "orxonox.h" |
|---|
| 34 | #include "graphicsEngine.h" |
|---|
| 35 | |
|---|
| [379] | 36 | //#include <Ogre.h> |
|---|
| 37 | // 40% speed up: (instead of Ogre.h) |
|---|
| 38 | #include <OgreSceneNode.h> |
|---|
| 39 | #include <OgreSceneManager.h> |
|---|
| 40 | #include <OgreRoot.h> |
|---|
| 41 | #include <OgreFrameListener.h> |
|---|
| 42 | #include <OgreConfigFile.h> |
|---|
| 43 | #include <OgreTextureManager.h> |
|---|
| 44 | #include <OgreEntity.h> |
|---|
| 45 | #include <OgreRenderWindow.h> |
|---|
| 46 | |
|---|
| [137] | 47 | #include <OIS/OIS.h> |
|---|
| [346] | 48 | //#include <CEGUI/CEGUI.h> |
|---|
| 49 | //#include <OgreCEGUIRenderer.h> |
|---|
| [74] | 50 | |
|---|
| [164] | 51 | #include <string> |
|---|
| 52 | #include <iostream> |
|---|
| 53 | |
|---|
| [496] | 54 | #include "objects/Tickable.h" |
|---|
| 55 | #include "objects/Timer.h" |
|---|
| [542] | 56 | #include "core/ArgReader.h" |
|---|
| [496] | 57 | #include "core/Factory.h" |
|---|
| [568] | 58 | #include "core/Debug.h" |
|---|
| [496] | 59 | |
|---|
| [462] | 60 | #include "../loader/LevelLoader.h" |
|---|
| 61 | #include "../audio/AudioManager.h" |
|---|
| [164] | 62 | |
|---|
| [337] | 63 | #include "spaceship_steering.h" |
|---|
| [164] | 64 | |
|---|
| [535] | 65 | #include "particle/ParticleInterface.h" |
|---|
| [337] | 66 | |
|---|
| [588] | 67 | #include "hud/HUD.h" |
|---|
| 68 | |
|---|
| [459] | 69 | //network stuff |
|---|
| [462] | 70 | #include "../network/Server.h" |
|---|
| 71 | #include "../network/Client.h" |
|---|
| [473] | 72 | #include "../network/NetworkFrameListener.h" |
|---|
| [588] | 73 | |
|---|
| 74 | #ifdef WIN32 |
|---|
| 75 | #include <windows.h> |
|---|
| 76 | #define usleep(x) Sleep((x)/1000) |
|---|
| 77 | #else |
|---|
| 78 | #include <unistd.h> |
|---|
| [576] | 79 | #endif |
|---|
| [459] | 80 | |
|---|
| [337] | 81 | namespace orxonox |
|---|
| 82 | { |
|---|
| [462] | 83 | using namespace Ogre; |
|---|
| [74] | 84 | |
|---|
| [462] | 85 | // put this in seperate Class or solve the problem in another fashion |
|---|
| 86 | class OrxListener : public FrameListener, public OIS::MouseListener |
|---|
| 87 | { |
|---|
| 88 | public: |
|---|
| [519] | 89 | OrxListener(OIS::Keyboard *keyboard, OIS::Mouse *mouse, audio::AudioManager* auMan, SpaceshipSteering* steering) |
|---|
| [462] | 90 | : mKeyboard(keyboard), mMouse(mouse) |
|---|
| 91 | { |
|---|
| [530] | 92 | |
|---|
| 93 | |
|---|
| 94 | |
|---|
| [462] | 95 | speed = 250; |
|---|
| 96 | loop = 100; |
|---|
| 97 | rotate = 10; |
|---|
| 98 | mouseX = 0; |
|---|
| 99 | mouseY = 0; |
|---|
| 100 | maxMouseX = 0; |
|---|
| 101 | minMouseX = 0; |
|---|
| [337] | 102 | moved = false; |
|---|
| [530] | 103 | |
|---|
| [519] | 104 | steering_ = steering; |
|---|
| 105 | |
|---|
| 106 | steering_->brakeRotate(rotate*10); |
|---|
| 107 | steering_->brakeLoop(loop); |
|---|
| 108 | |
|---|
| [530] | 109 | |
|---|
| [462] | 110 | mMouse->setEventCallback(this); |
|---|
| 111 | auMan_ = auMan; |
|---|
| [265] | 112 | } |
|---|
| [462] | 113 | bool frameStarted(const FrameEvent& evt) |
|---|
| 114 | { |
|---|
| [135] | 115 | |
|---|
| [462] | 116 | auMan_->update(); |
|---|
| [74] | 117 | |
|---|
| [462] | 118 | mKeyboard->capture(); |
|---|
| 119 | mMouse->capture(); |
|---|
| 120 | if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) |
|---|
| [519] | 121 | steering_->moveForward(speed); |
|---|
| [462] | 122 | else |
|---|
| [519] | 123 | steering_->moveForward(0); |
|---|
| [462] | 124 | if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) |
|---|
| [519] | 125 | steering_->brakeForward(speed); |
|---|
| [462] | 126 | else |
|---|
| [519] | 127 | steering_->brakeForward(speed/10); |
|---|
| [462] | 128 | if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) |
|---|
| [519] | 129 | steering_->loopRight(loop); |
|---|
| [462] | 130 | else |
|---|
| [519] | 131 | steering_->loopRight(0); |
|---|
| [462] | 132 | if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) |
|---|
| [519] | 133 | steering_->loopLeft(loop); |
|---|
| [462] | 134 | else |
|---|
| [519] | 135 | steering_->loopLeft(0); |
|---|
| [337] | 136 | |
|---|
| [462] | 137 | if(moved) { |
|---|
| [512] | 138 | if (mouseY<=0) |
|---|
| [519] | 139 | steering_->rotateUp(-mouseY*rotate); |
|---|
| [462] | 140 | if (mouseY>0) |
|---|
| [519] | 141 | steering_->rotateDown(mouseY*rotate); |
|---|
| [462] | 142 | if (mouseX>0) |
|---|
| [519] | 143 | steering_->rotateRight(mouseX*rotate); |
|---|
| [512] | 144 | if (mouseX<=0) |
|---|
| [519] | 145 | steering_->rotateLeft(-mouseX*rotate); |
|---|
| [512] | 146 | mouseY = 0; |
|---|
| 147 | mouseX = 0; |
|---|
| [462] | 148 | moved = false; |
|---|
| 149 | } |
|---|
| 150 | else { |
|---|
| [519] | 151 | steering_->rotateUp(0); |
|---|
| 152 | steering_->rotateDown(0); |
|---|
| 153 | steering_->rotateRight(0); |
|---|
| 154 | steering_->rotateLeft(0); |
|---|
| [462] | 155 | } |
|---|
| [337] | 156 | |
|---|
| [519] | 157 | steering_->tick(evt.timeSinceLastFrame); |
|---|
| [530] | 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| [462] | 161 | // scenemanager->spacehip->tick(evt.timesincelastframe); |
|---|
| [542] | 162 | //if(mKeyboard->isKeyDown(OIS::KC_ESCAPE)) |
|---|
| 163 | //cout << "maximal MouseX: " << maxMouseX << "\tminMouseX: " << minMouseX << endl; |
|---|
| [565] | 164 | usleep(10); |
|---|
| [462] | 165 | return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); |
|---|
| 166 | } |
|---|
| [337] | 167 | |
|---|
| [462] | 168 | bool mouseMoved(const OIS::MouseEvent &e) |
|---|
| [265] | 169 | { |
|---|
| [511] | 170 | mouseX += e.state.X.rel; |
|---|
| 171 | mouseY += e.state.Y.rel; |
|---|
| [462] | 172 | if(mouseX>maxMouseX) maxMouseX = mouseX; |
|---|
| 173 | if(mouseX<minMouseX) minMouseX = mouseX; |
|---|
| [542] | 174 | //cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl; |
|---|
| [462] | 175 | moved = true; |
|---|
| 176 | return true; |
|---|
| [265] | 177 | } |
|---|
| [74] | 178 | |
|---|
| [462] | 179 | bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } |
|---|
| 180 | bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } |
|---|
| [137] | 181 | |
|---|
| [265] | 182 | private: |
|---|
| [462] | 183 | float speed; |
|---|
| 184 | float rotate; |
|---|
| 185 | float loop; |
|---|
| 186 | float mouseY; |
|---|
| 187 | float mouseX; |
|---|
| 188 | float maxMouseX; |
|---|
| 189 | float minMouseX; |
|---|
| 190 | bool moved; |
|---|
| [265] | 191 | OIS::Keyboard *mKeyboard; |
|---|
| 192 | OIS::Mouse *mMouse; |
|---|
| [462] | 193 | audio::AudioManager* auMan_; |
|---|
| [519] | 194 | SpaceshipSteering* steering_; |
|---|
| [462] | 195 | }; |
|---|
| 196 | // init static singleton reference of Orxonox |
|---|
| 197 | Orxonox* Orxonox::singletonRef_ = NULL; |
|---|
| [137] | 198 | |
|---|
| [462] | 199 | /** |
|---|
| 200 | * create a new instance of Orxonox |
|---|
| 201 | */ |
|---|
| 202 | Orxonox::Orxonox() |
|---|
| 203 | { |
|---|
| 204 | ogre_ = new GraphicsEngine(); |
|---|
| [546] | 205 | dataPath_ = ""; |
|---|
| [462] | 206 | } |
|---|
| [74] | 207 | |
|---|
| [462] | 208 | /** |
|---|
| 209 | * destruct Orxonox |
|---|
| 210 | */ |
|---|
| 211 | Orxonox::~Orxonox() |
|---|
| 212 | { |
|---|
| 213 | // nothing to delete as for now |
|---|
| 214 | } |
|---|
| [265] | 215 | |
|---|
| [462] | 216 | /** |
|---|
| 217 | * initialization of Orxonox object |
|---|
| 218 | * @param argc argument counter |
|---|
| 219 | * @param argv list of arguments |
|---|
| 220 | * @param path path to config (in home dir or something) |
|---|
| 221 | */ |
|---|
| 222 | void Orxonox::init(int argc, char **argv, std::string path) |
|---|
| 223 | { |
|---|
| 224 | //TODO: find config file (assuming executable directory) |
|---|
| 225 | //TODO: read config file |
|---|
| 226 | //TODO: give config file to Ogre |
|---|
| [568] | 227 | std::string mode; |
|---|
| 228 | if(argc>=2) |
|---|
| 229 | mode = std::string(argv[1]); |
|---|
| 230 | else |
|---|
| 231 | mode = ""; |
|---|
| [542] | 232 | ArgReader ar = ArgReader(argc, argv); |
|---|
| 233 | ar.checkArgument("mode", mode, false); |
|---|
| [546] | 234 | ar.checkArgument("data", this->dataPath_, false); |
|---|
| [542] | 235 | if(ar.errorHandling()) die(); |
|---|
| [534] | 236 | |
|---|
| [542] | 237 | if(mode == std::string("server")) |
|---|
| [462] | 238 | { |
|---|
| 239 | serverInit(path); |
|---|
| [568] | 240 | mode = SERVER; |
|---|
| [462] | 241 | } |
|---|
| [542] | 242 | else if(mode == std::string("client")) |
|---|
| [462] | 243 | { |
|---|
| 244 | clientInit(path); |
|---|
| [568] | 245 | mode = CLIENT; |
|---|
| [534] | 246 | } |
|---|
| [542] | 247 | else if(mode == std::string("presentation")) |
|---|
| [531] | 248 | { |
|---|
| [568] | 249 | serverInit(path); |
|---|
| 250 | mode = PRESENTATION; |
|---|
| [534] | 251 | } |
|---|
| [568] | 252 | else{ |
|---|
| 253 | standaloneInit(path); |
|---|
| 254 | mode = STANDALONE; |
|---|
| 255 | } |
|---|
| [462] | 256 | } |
|---|
| [263] | 257 | |
|---|
| [462] | 258 | /** |
|---|
| 259 | * start modules |
|---|
| 260 | */ |
|---|
| 261 | void Orxonox::start() |
|---|
| 262 | { |
|---|
| 263 | //TODO: start modules |
|---|
| [534] | 264 | ogre_->startRender(); |
|---|
| [462] | 265 | //TODO: run engine |
|---|
| [534] | 266 | createScene(); |
|---|
| 267 | setupScene(); |
|---|
| 268 | setupInputSystem(); |
|---|
| 269 | createFrameListener(); |
|---|
| 270 | Factory::createClassHierarchy(); |
|---|
| [568] | 271 | switch(mode_){ |
|---|
| 272 | case PRESENTATION: |
|---|
| 273 | server_g->open(); |
|---|
| 274 | break; |
|---|
| 275 | case SERVER: |
|---|
| 276 | case CLIENT: |
|---|
| 277 | case STANDALONE: |
|---|
| 278 | default: |
|---|
| 279 | break; |
|---|
| 280 | } |
|---|
| [534] | 281 | startRenderLoop(); |
|---|
| [462] | 282 | } |
|---|
| [74] | 283 | |
|---|
| [462] | 284 | /** |
|---|
| 285 | * @return singleton object |
|---|
| 286 | */ |
|---|
| 287 | Orxonox* Orxonox::getSingleton() |
|---|
| 288 | { |
|---|
| 289 | if (!singletonRef_) |
|---|
| 290 | singletonRef_ = new Orxonox(); |
|---|
| 291 | return singletonRef_; |
|---|
| 292 | } |
|---|
| [74] | 293 | |
|---|
| [462] | 294 | /** |
|---|
| 295 | * error kills orxonox |
|---|
| 296 | */ |
|---|
| 297 | void Orxonox::die(/* some error code */) |
|---|
| 298 | { |
|---|
| 299 | //TODO: destroy and destruct everything and print nice error msg |
|---|
| [542] | 300 | delete this; |
|---|
| [462] | 301 | } |
|---|
| [74] | 302 | |
|---|
| [568] | 303 | void Orxonox::standaloneInit(std::string path) |
|---|
| [462] | 304 | { |
|---|
| 305 | ogre_->setConfigPath(path); |
|---|
| 306 | ogre_->setup(); |
|---|
| [473] | 307 | root_ = ogre_->getRoot(); |
|---|
| [534] | 308 | if(!ogre_->load()) die(/* unable to load */); |
|---|
| [473] | 309 | |
|---|
| [534] | 310 | //defineResources(); |
|---|
| 311 | //setupRenderSystem(); |
|---|
| 312 | //createRenderWindow(); |
|---|
| 313 | //initializeResourceGroups(); |
|---|
| 314 | /*createScene(); |
|---|
| [473] | 315 | setupScene(); |
|---|
| 316 | setupInputSystem(); |
|---|
| 317 | createFrameListener(); |
|---|
| [496] | 318 | Factory::createClassHierarchy(); |
|---|
| [534] | 319 | startRenderLoop();*/ |
|---|
| [462] | 320 | } |
|---|
| [534] | 321 | |
|---|
| [531] | 322 | void Orxonox::playableServer(std::string path) |
|---|
| 323 | { |
|---|
| 324 | ogre_->setConfigPath(path); |
|---|
| 325 | ogre_->setup(); |
|---|
| 326 | root_ = ogre_->getRoot(); |
|---|
| 327 | defineResources(); |
|---|
| 328 | setupRenderSystem(); |
|---|
| 329 | createRenderWindow(); |
|---|
| 330 | initializeResourceGroups(); |
|---|
| 331 | createScene(); |
|---|
| 332 | setupScene(); |
|---|
| 333 | setupInputSystem(); |
|---|
| 334 | Factory::createClassHierarchy(); |
|---|
| 335 | createFrameListener(); |
|---|
| 336 | try{ |
|---|
| [534] | 337 | server_g = new network::Server(); // add port and bindadress |
|---|
| 338 | server_g->open(); // open server and create listener thread |
|---|
| 339 | if(ogre_ && ogre_->getRoot()) |
|---|
| 340 | ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); // adds a framelistener for the server |
|---|
| [560] | 341 | COUT(3) << "Info: network framelistener added" << std::endl; |
|---|
| [534] | 342 | } |
|---|
| [531] | 343 | catch(exception &e) |
|---|
| 344 | { |
|---|
| [560] | 345 | COUT(1) << "Error: There was a problem initialising the server :(" << std::endl; |
|---|
| [531] | 346 | } |
|---|
| 347 | startRenderLoop(); |
|---|
| 348 | } |
|---|
| [576] | 349 | |
|---|
| [568] | 350 | void Orxonox::standalone(){ |
|---|
| [576] | 351 | |
|---|
| 352 | |
|---|
| 353 | |
|---|
| [568] | 354 | } |
|---|
| [74] | 355 | |
|---|
| [462] | 356 | void Orxonox::serverInit(std::string path) |
|---|
| 357 | { |
|---|
| 358 | ogre_->setConfigPath(path); |
|---|
| 359 | ogre_->setup(); |
|---|
| [473] | 360 | server_g = new network::Server(); // add some settings if wanted |
|---|
| [462] | 361 | if(!ogre_->load()) die(/* unable to load */); |
|---|
| [568] | 362 | // add network framelistener |
|---|
| [505] | 363 | ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); |
|---|
| [462] | 364 | } |
|---|
| [164] | 365 | |
|---|
| [462] | 366 | void Orxonox::clientInit(std::string path) |
|---|
| 367 | { |
|---|
| 368 | ogre_->setConfigPath(path); |
|---|
| 369 | ogre_->setup(); |
|---|
| [473] | 370 | client_g = new network::Client(); // address here |
|---|
| [462] | 371 | if(!ogre_->load()) die(/* unable to load */); |
|---|
| [505] | 372 | ogre_->getRoot()->addFrameListener(new network::ClientFrameListener()); |
|---|
| [462] | 373 | } |
|---|
| [258] | 374 | |
|---|
| [473] | 375 | void Orxonox::defineResources() |
|---|
| 376 | { |
|---|
| 377 | Ogre::String secName, typeName, archName; |
|---|
| 378 | Ogre::ConfigFile cf; |
|---|
| 379 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
|---|
| 380 | cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); |
|---|
| 381 | #else |
|---|
| [546] | 382 | cf.load(dataPath_ + "resources.cfg"); |
|---|
| [473] | 383 | #endif |
|---|
| 384 | |
|---|
| 385 | Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
|---|
| 386 | while (seci.hasMoreElements()) |
|---|
| 387 | { |
|---|
| 388 | secName = seci.peekNextKey(); |
|---|
| 389 | Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
|---|
| 390 | Ogre::ConfigFile::SettingsMultiMap::iterator i; |
|---|
| 391 | for (i = settings->begin(); i != settings->end(); ++i) |
|---|
| 392 | { |
|---|
| 393 | typeName = i->first; |
|---|
| 394 | archName = i->second; |
|---|
| 395 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
|---|
| 396 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); |
|---|
| 397 | #else |
|---|
| 398 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); |
|---|
| 399 | #endif |
|---|
| 400 | } |
|---|
| 401 | } |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | void Orxonox::setupRenderSystem() |
|---|
| 405 | { |
|---|
| [588] | 406 | if (!root_->restoreConfig() && !root_->showConfigDialog()) |
|---|
| [473] | 407 | throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | void Orxonox::createRenderWindow() |
|---|
| 411 | { |
|---|
| 412 | root_->initialise(true, "OrxonoxV2"); |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | void Orxonox::initializeResourceGroups() |
|---|
| 416 | { |
|---|
| 417 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
|---|
| 418 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| [537] | 421 | /** |
|---|
| 422 | * |
|---|
| 423 | * @param |
|---|
| 424 | */ |
|---|
| [462] | 425 | void Orxonox::createScene(void) |
|---|
| 426 | { |
|---|
| [480] | 427 | // Init audio |
|---|
| [462] | 428 | auMan_ = new audio::AudioManager(); |
|---|
| [487] | 429 | |
|---|
| [480] | 430 | // load this file from config |
|---|
| 431 | loader_ = new loader::LevelLoader("sample.oxw"); |
|---|
| 432 | loader_->loadLevel(); |
|---|
| [337] | 433 | |
|---|
| [588] | 434 | Overlay* hudOverlay = OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); |
|---|
| 435 | hud::HUD* orxonoxHud; |
|---|
| 436 | orxonoxHud = new hud::HUD(); |
|---|
| 437 | orxonoxHud->setEnergyValue(20); |
|---|
| 438 | orxonoxHud->setEnergyDistr(20,20,60); |
|---|
| 439 | hudOverlay->show(); |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | /* |
|---|
| 443 | auMan_->ambientAdd("a1"); |
|---|
| 444 | auMan_->ambientAdd("a2"); |
|---|
| 445 | auMan_->ambientAdd("a3"); |
|---|
| 446 | //auMan->ambientAdd("ambient1"); |
|---|
| 447 | auMan_->ambientStart();*/ |
|---|
| [462] | 448 | } |
|---|
| [337] | 449 | |
|---|
| 450 | |
|---|
| [537] | 451 | /** |
|---|
| 452 | * |
|---|
| 453 | */ |
|---|
| [462] | 454 | void Orxonox::setupScene() |
|---|
| 455 | { |
|---|
| 456 | SceneManager *mgr = ogre_->getSceneManager(); |
|---|
| [512] | 457 | |
|---|
| [515] | 458 | |
|---|
| [525] | 459 | SceneNode* node = (SceneNode*)mgr->getRootSceneNode()->getChild("OgreHeadNode"); |
|---|
| [541] | 460 | // SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode", Vector3(0,0,0)); |
|---|
| [515] | 461 | |
|---|
| [337] | 462 | |
|---|
| [525] | 463 | steering_ = new SpaceshipSteering(500, 200, 200, 200); |
|---|
| 464 | steering_->addNode(node); |
|---|
| [74] | 465 | |
|---|
| [584] | 466 | /* |
|---|
| [537] | 467 | particle::ParticleInterface *e = new particle::ParticleInterface(mgr,"engine","Orxonox/strahl"); |
|---|
| [535] | 468 | e->particleSystem_->setParameter("local_space","true"); |
|---|
| [537] | 469 | e->setPositionOfEmitter(0, Vector3(0,-10,200)); |
|---|
| 470 | e->setDirection(Vector3(0,0,-1)); |
|---|
| 471 | e->addToSceneNode(node); |
|---|
| [584] | 472 | */ |
|---|
| [535] | 473 | |
|---|
| [537] | 474 | particle::ParticleInterface *w = new particle::ParticleInterface(mgr,"schuss","Orxonox/schuss"); |
|---|
| 475 | w->particleSystem_->setParameter("local_space","true"); |
|---|
| 476 | w->newEmitter(); |
|---|
| 477 | w->setDirection(Vector3(0,0,1)); |
|---|
| 478 | w->setPositionOfEmitter(0, Vector3(10,10,0)); |
|---|
| 479 | w->setPositionOfEmitter(1, Vector3(-10,10,0)); |
|---|
| 480 | w->addToSceneNode(node); |
|---|
| [584] | 481 | |
|---|
| 482 | particle::ParticleInterface *tt = new particle::ParticleInterface(mgr,"thrusters","Orxonox/treibwerk"); |
|---|
| 483 | tt->particleSystem_->setParameter("local_space","true"); |
|---|
| 484 | tt->newEmitter(); |
|---|
| 485 | tt->setDirection(Vector3(0,0,1)); |
|---|
| 486 | tt->setPositionOfEmitter(0, Vector3(15,0,-60)); |
|---|
| 487 | tt->setPositionOfEmitter(1, Vector3(-15,0,-60)); |
|---|
| 488 | tt->addToSceneNode(node); |
|---|
| 489 | |
|---|
| 490 | |
|---|
| [462] | 491 | } |
|---|
| [137] | 492 | |
|---|
| 493 | |
|---|
| [462] | 494 | void Orxonox::setupInputSystem() |
|---|
| 495 | { |
|---|
| 496 | size_t windowHnd = 0; |
|---|
| 497 | std::ostringstream windowHndStr; |
|---|
| 498 | OIS::ParamList pl; |
|---|
| 499 | Ogre::RenderWindow *win = ogre_->getRoot()->getAutoCreatedWindow(); |
|---|
| [137] | 500 | |
|---|
| [462] | 501 | win->getCustomAttribute("WINDOW", &windowHnd); |
|---|
| 502 | windowHndStr << windowHnd; |
|---|
| 503 | pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); |
|---|
| 504 | inputManager_ = OIS::InputManager::createInputSystem(pl); |
|---|
| [265] | 505 | |
|---|
| [462] | 506 | try |
|---|
| [337] | 507 | { |
|---|
| [462] | 508 | keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, false)); |
|---|
| 509 | mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, true)); |
|---|
| [337] | 510 | } |
|---|
| [462] | 511 | catch (const OIS::Exception &e) |
|---|
| [459] | 512 | { |
|---|
| [462] | 513 | throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); |
|---|
| [459] | 514 | } |
|---|
| [462] | 515 | } |
|---|
| [137] | 516 | |
|---|
| [462] | 517 | // we actually want to do this differently... |
|---|
| 518 | void Orxonox::createFrameListener() |
|---|
| [137] | 519 | { |
|---|
| [496] | 520 | TickFrameListener* TickFL = new TickFrameListener(); |
|---|
| 521 | ogre_->getRoot()->addFrameListener(TickFL); |
|---|
| 522 | |
|---|
| 523 | TimerFrameListener* TimerFL = new TimerFrameListener(); |
|---|
| 524 | ogre_->getRoot()->addFrameListener(TimerFL); |
|---|
| 525 | |
|---|
| [519] | 526 | frameListener_ = new OrxListener(keyboard_, mouse_, auMan_, steering_); |
|---|
| [462] | 527 | ogre_->getRoot()->addFrameListener(frameListener_); |
|---|
| [137] | 528 | } |
|---|
| [462] | 529 | |
|---|
| 530 | void Orxonox::startRenderLoop() |
|---|
| [137] | 531 | { |
|---|
| [511] | 532 | // this is a hack!!! |
|---|
| 533 | // the call to reset the mouse clipping size should probably be somewhere |
|---|
| 534 | // else, however this works for the moment. |
|---|
| [523] | 535 | unsigned int width, height, depth; |
|---|
| 536 | int left, top; |
|---|
| 537 | ogre_->getRoot()->getAutoCreatedWindow()->getMetrics(width, height, depth, left, top); |
|---|
| [511] | 538 | |
|---|
| [523] | 539 | const OIS::MouseState &ms = mouse_->getMouseState(); |
|---|
| 540 | ms.width = width; |
|---|
| 541 | ms.height = height; |
|---|
| [511] | 542 | |
|---|
| [462] | 543 | ogre_->getRoot()->startRendering(); |
|---|
| [74] | 544 | } |
|---|
| 545 | } |
|---|