[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: |
---|
[601] | 89 | OrxListener(OIS::Keyboard *keyboard, OIS::Mouse *mouse, audio::AudioManager* auMan, SpaceshipSteering* steering, gameMode mode) |
---|
[462] | 90 | : mKeyboard(keyboard), mMouse(mouse) |
---|
| 91 | { |
---|
[530] | 92 | |
---|
| 93 | |
---|
[601] | 94 | mode_=mode; |
---|
[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; |
---|
[604] | 164 | if(mode_==PRESENTATION){ |
---|
[601] | 165 | server_g->tick(evt.timeSinceLastFrame); |
---|
[604] | 166 | std::cout << "tick server" << std::endl; |
---|
| 167 | } |
---|
[565] | 168 | usleep(10); |
---|
[462] | 169 | return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); |
---|
| 170 | } |
---|
[337] | 171 | |
---|
[462] | 172 | bool mouseMoved(const OIS::MouseEvent &e) |
---|
[265] | 173 | { |
---|
[511] | 174 | mouseX += e.state.X.rel; |
---|
| 175 | mouseY += e.state.Y.rel; |
---|
[462] | 176 | if(mouseX>maxMouseX) maxMouseX = mouseX; |
---|
| 177 | if(mouseX<minMouseX) minMouseX = mouseX; |
---|
[542] | 178 | //cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl; |
---|
[462] | 179 | moved = true; |
---|
| 180 | return true; |
---|
[265] | 181 | } |
---|
[74] | 182 | |
---|
[462] | 183 | bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } |
---|
| 184 | bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } |
---|
[137] | 185 | |
---|
[265] | 186 | private: |
---|
[601] | 187 | gameMode mode_; |
---|
[462] | 188 | float speed; |
---|
| 189 | float rotate; |
---|
| 190 | float loop; |
---|
| 191 | float mouseY; |
---|
| 192 | float mouseX; |
---|
| 193 | float maxMouseX; |
---|
| 194 | float minMouseX; |
---|
| 195 | bool moved; |
---|
[265] | 196 | OIS::Keyboard *mKeyboard; |
---|
| 197 | OIS::Mouse *mMouse; |
---|
[462] | 198 | audio::AudioManager* auMan_; |
---|
[519] | 199 | SpaceshipSteering* steering_; |
---|
[462] | 200 | }; |
---|
| 201 | // init static singleton reference of Orxonox |
---|
| 202 | Orxonox* Orxonox::singletonRef_ = NULL; |
---|
[137] | 203 | |
---|
[462] | 204 | /** |
---|
| 205 | * create a new instance of Orxonox |
---|
| 206 | */ |
---|
| 207 | Orxonox::Orxonox() |
---|
| 208 | { |
---|
| 209 | ogre_ = new GraphicsEngine(); |
---|
[546] | 210 | dataPath_ = ""; |
---|
[462] | 211 | } |
---|
[74] | 212 | |
---|
[462] | 213 | /** |
---|
| 214 | * destruct Orxonox |
---|
| 215 | */ |
---|
| 216 | Orxonox::~Orxonox() |
---|
| 217 | { |
---|
| 218 | // nothing to delete as for now |
---|
| 219 | } |
---|
[265] | 220 | |
---|
[462] | 221 | /** |
---|
| 222 | * initialization of Orxonox object |
---|
| 223 | * @param argc argument counter |
---|
| 224 | * @param argv list of arguments |
---|
| 225 | * @param path path to config (in home dir or something) |
---|
| 226 | */ |
---|
| 227 | void Orxonox::init(int argc, char **argv, std::string path) |
---|
| 228 | { |
---|
| 229 | //TODO: find config file (assuming executable directory) |
---|
| 230 | //TODO: read config file |
---|
| 231 | //TODO: give config file to Ogre |
---|
[568] | 232 | std::string mode; |
---|
[599] | 233 | // if(argc>=2) |
---|
| 234 | // mode = std::string(argv[1]); |
---|
| 235 | // else |
---|
| 236 | // mode = ""; |
---|
[542] | 237 | ArgReader ar = ArgReader(argc, argv); |
---|
| 238 | ar.checkArgument("mode", mode, false); |
---|
[546] | 239 | ar.checkArgument("data", this->dataPath_, false); |
---|
[599] | 240 | ar.checkArgument("ip", serverIp_, false); |
---|
[542] | 241 | if(ar.errorHandling()) die(); |
---|
[534] | 242 | |
---|
[542] | 243 | if(mode == std::string("server")) |
---|
[462] | 244 | { |
---|
| 245 | serverInit(path); |
---|
[599] | 246 | mode_ = SERVER; |
---|
[462] | 247 | } |
---|
[542] | 248 | else if(mode == std::string("client")) |
---|
[462] | 249 | { |
---|
| 250 | clientInit(path); |
---|
[599] | 251 | mode_ = CLIENT; |
---|
[534] | 252 | } |
---|
[542] | 253 | else if(mode == std::string("presentation")) |
---|
[531] | 254 | { |
---|
[568] | 255 | serverInit(path); |
---|
[599] | 256 | mode_ = PRESENTATION; |
---|
[534] | 257 | } |
---|
[568] | 258 | else{ |
---|
| 259 | standaloneInit(path); |
---|
[599] | 260 | mode_ = STANDALONE; |
---|
[568] | 261 | } |
---|
[462] | 262 | } |
---|
[263] | 263 | |
---|
[462] | 264 | /** |
---|
| 265 | * start modules |
---|
| 266 | */ |
---|
| 267 | void Orxonox::start() |
---|
| 268 | { |
---|
| 269 | //TODO: start modules |
---|
[534] | 270 | ogre_->startRender(); |
---|
[462] | 271 | //TODO: run engine |
---|
[534] | 272 | createScene(); |
---|
| 273 | setupScene(); |
---|
| 274 | setupInputSystem(); |
---|
[599] | 275 | if(mode_!=CLIENT){ // remove this in future ---- presentation hack |
---|
| 276 | } |
---|
| 277 | else |
---|
| 278 | std::cout << "client here" << std::endl; |
---|
[534] | 279 | createFrameListener(); |
---|
| 280 | Factory::createClassHierarchy(); |
---|
[568] | 281 | switch(mode_){ |
---|
| 282 | case PRESENTATION: |
---|
[601] | 283 | //ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); |
---|
| 284 | //std::cout << "could not add framelistener" << std::endl; |
---|
[568] | 285 | server_g->open(); |
---|
| 286 | break; |
---|
[599] | 287 | case CLIENT: |
---|
| 288 | client_g->establishConnection(); |
---|
| 289 | break; |
---|
[568] | 290 | case SERVER: |
---|
| 291 | case STANDALONE: |
---|
| 292 | default: |
---|
| 293 | break; |
---|
| 294 | } |
---|
[534] | 295 | startRenderLoop(); |
---|
[462] | 296 | } |
---|
[74] | 297 | |
---|
[462] | 298 | /** |
---|
| 299 | * @return singleton object |
---|
| 300 | */ |
---|
| 301 | Orxonox* Orxonox::getSingleton() |
---|
| 302 | { |
---|
| 303 | if (!singletonRef_) |
---|
| 304 | singletonRef_ = new Orxonox(); |
---|
| 305 | return singletonRef_; |
---|
| 306 | } |
---|
[74] | 307 | |
---|
[462] | 308 | /** |
---|
| 309 | * error kills orxonox |
---|
| 310 | */ |
---|
| 311 | void Orxonox::die(/* some error code */) |
---|
| 312 | { |
---|
| 313 | //TODO: destroy and destruct everything and print nice error msg |
---|
[542] | 314 | delete this; |
---|
[462] | 315 | } |
---|
[74] | 316 | |
---|
[568] | 317 | void Orxonox::standaloneInit(std::string path) |
---|
[462] | 318 | { |
---|
| 319 | ogre_->setConfigPath(path); |
---|
| 320 | ogre_->setup(); |
---|
[473] | 321 | root_ = ogre_->getRoot(); |
---|
[534] | 322 | if(!ogre_->load()) die(/* unable to load */); |
---|
[473] | 323 | |
---|
[534] | 324 | //defineResources(); |
---|
| 325 | //setupRenderSystem(); |
---|
| 326 | //createRenderWindow(); |
---|
| 327 | //initializeResourceGroups(); |
---|
| 328 | /*createScene(); |
---|
[473] | 329 | setupScene(); |
---|
| 330 | setupInputSystem(); |
---|
| 331 | createFrameListener(); |
---|
[496] | 332 | Factory::createClassHierarchy(); |
---|
[534] | 333 | startRenderLoop();*/ |
---|
[462] | 334 | } |
---|
[534] | 335 | |
---|
[531] | 336 | void Orxonox::playableServer(std::string path) |
---|
| 337 | { |
---|
| 338 | ogre_->setConfigPath(path); |
---|
| 339 | ogre_->setup(); |
---|
| 340 | root_ = ogre_->getRoot(); |
---|
| 341 | defineResources(); |
---|
| 342 | setupRenderSystem(); |
---|
| 343 | createRenderWindow(); |
---|
| 344 | initializeResourceGroups(); |
---|
| 345 | createScene(); |
---|
| 346 | setupScene(); |
---|
| 347 | setupInputSystem(); |
---|
| 348 | Factory::createClassHierarchy(); |
---|
| 349 | createFrameListener(); |
---|
| 350 | try{ |
---|
[534] | 351 | server_g = new network::Server(); // add port and bindadress |
---|
| 352 | server_g->open(); // open server and create listener thread |
---|
| 353 | if(ogre_ && ogre_->getRoot()) |
---|
| 354 | ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); // adds a framelistener for the server |
---|
[560] | 355 | COUT(3) << "Info: network framelistener added" << std::endl; |
---|
[534] | 356 | } |
---|
[531] | 357 | catch(exception &e) |
---|
| 358 | { |
---|
[560] | 359 | COUT(1) << "Error: There was a problem initialising the server :(" << std::endl; |
---|
[531] | 360 | } |
---|
| 361 | startRenderLoop(); |
---|
| 362 | } |
---|
[576] | 363 | |
---|
[568] | 364 | void Orxonox::standalone(){ |
---|
[576] | 365 | |
---|
| 366 | |
---|
| 367 | |
---|
[568] | 368 | } |
---|
[74] | 369 | |
---|
[462] | 370 | void Orxonox::serverInit(std::string path) |
---|
| 371 | { |
---|
[599] | 372 | COUT(2) << "initialising server" << std::endl; |
---|
[462] | 373 | ogre_->setConfigPath(path); |
---|
| 374 | ogre_->setup(); |
---|
[473] | 375 | server_g = new network::Server(); // add some settings if wanted |
---|
[462] | 376 | if(!ogre_->load()) die(/* unable to load */); |
---|
[568] | 377 | // add network framelistener |
---|
[462] | 378 | } |
---|
[164] | 379 | |
---|
[462] | 380 | void Orxonox::clientInit(std::string path) |
---|
| 381 | { |
---|
[599] | 382 | COUT(2) << "initialising client" << std::endl; |
---|
[462] | 383 | ogre_->setConfigPath(path); |
---|
| 384 | ogre_->setup(); |
---|
[599] | 385 | if(serverIp_.compare("")==0) |
---|
| 386 | client_g = new network::Client(); |
---|
| 387 | else |
---|
| 388 | client_g = new network::Client(serverIp_, 55556); |
---|
[462] | 389 | if(!ogre_->load()) die(/* unable to load */); |
---|
[505] | 390 | ogre_->getRoot()->addFrameListener(new network::ClientFrameListener()); |
---|
[462] | 391 | } |
---|
[258] | 392 | |
---|
[473] | 393 | void Orxonox::defineResources() |
---|
| 394 | { |
---|
| 395 | Ogre::String secName, typeName, archName; |
---|
| 396 | Ogre::ConfigFile cf; |
---|
| 397 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 398 | cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); |
---|
| 399 | #else |
---|
[546] | 400 | cf.load(dataPath_ + "resources.cfg"); |
---|
[473] | 401 | #endif |
---|
| 402 | |
---|
| 403 | Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
---|
| 404 | while (seci.hasMoreElements()) |
---|
| 405 | { |
---|
| 406 | secName = seci.peekNextKey(); |
---|
| 407 | Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
---|
| 408 | Ogre::ConfigFile::SettingsMultiMap::iterator i; |
---|
| 409 | for (i = settings->begin(); i != settings->end(); ++i) |
---|
| 410 | { |
---|
| 411 | typeName = i->first; |
---|
| 412 | archName = i->second; |
---|
| 413 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 414 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); |
---|
| 415 | #else |
---|
| 416 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); |
---|
| 417 | #endif |
---|
| 418 | } |
---|
| 419 | } |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | void Orxonox::setupRenderSystem() |
---|
| 423 | { |
---|
[588] | 424 | if (!root_->restoreConfig() && !root_->showConfigDialog()) |
---|
[473] | 425 | throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | void Orxonox::createRenderWindow() |
---|
| 429 | { |
---|
| 430 | root_->initialise(true, "OrxonoxV2"); |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | void Orxonox::initializeResourceGroups() |
---|
| 434 | { |
---|
| 435 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
| 436 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
| 437 | } |
---|
| 438 | |
---|
[537] | 439 | /** |
---|
| 440 | * |
---|
| 441 | * @param |
---|
| 442 | */ |
---|
[462] | 443 | void Orxonox::createScene(void) |
---|
| 444 | { |
---|
[480] | 445 | // Init audio |
---|
[462] | 446 | auMan_ = new audio::AudioManager(); |
---|
[487] | 447 | |
---|
[480] | 448 | // load this file from config |
---|
| 449 | loader_ = new loader::LevelLoader("sample.oxw"); |
---|
| 450 | loader_->loadLevel(); |
---|
[337] | 451 | |
---|
[588] | 452 | Overlay* hudOverlay = OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); |
---|
| 453 | hud::HUD* orxonoxHud; |
---|
| 454 | orxonoxHud = new hud::HUD(); |
---|
| 455 | orxonoxHud->setEnergyValue(20); |
---|
| 456 | orxonoxHud->setEnergyDistr(20,20,60); |
---|
| 457 | hudOverlay->show(); |
---|
| 458 | |
---|
| 459 | |
---|
| 460 | /* |
---|
| 461 | auMan_->ambientAdd("a1"); |
---|
| 462 | auMan_->ambientAdd("a2"); |
---|
| 463 | auMan_->ambientAdd("a3"); |
---|
| 464 | //auMan->ambientAdd("ambient1"); |
---|
| 465 | auMan_->ambientStart();*/ |
---|
[462] | 466 | } |
---|
[337] | 467 | |
---|
| 468 | |
---|
[537] | 469 | /** |
---|
| 470 | * |
---|
| 471 | */ |
---|
[462] | 472 | void Orxonox::setupScene() |
---|
| 473 | { |
---|
| 474 | SceneManager *mgr = ogre_->getSceneManager(); |
---|
[512] | 475 | |
---|
[515] | 476 | |
---|
[525] | 477 | SceneNode* node = (SceneNode*)mgr->getRootSceneNode()->getChild("OgreHeadNode"); |
---|
[541] | 478 | // SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode", Vector3(0,0,0)); |
---|
[515] | 479 | |
---|
[337] | 480 | |
---|
[525] | 481 | steering_ = new SpaceshipSteering(500, 200, 200, 200); |
---|
| 482 | steering_->addNode(node); |
---|
[74] | 483 | |
---|
[584] | 484 | /* |
---|
[537] | 485 | particle::ParticleInterface *e = new particle::ParticleInterface(mgr,"engine","Orxonox/strahl"); |
---|
[535] | 486 | e->particleSystem_->setParameter("local_space","true"); |
---|
[592] | 487 | e->setPositionOfEmitter(0, Vector3(0,-10,0)); |
---|
[537] | 488 | e->setDirection(Vector3(0,0,-1)); |
---|
| 489 | e->addToSceneNode(node); |
---|
[584] | 490 | */ |
---|
[535] | 491 | |
---|
[537] | 492 | particle::ParticleInterface *w = new particle::ParticleInterface(mgr,"schuss","Orxonox/schuss"); |
---|
| 493 | w->particleSystem_->setParameter("local_space","true"); |
---|
| 494 | w->newEmitter(); |
---|
| 495 | w->setDirection(Vector3(0,0,1)); |
---|
| 496 | w->setPositionOfEmitter(0, Vector3(10,10,0)); |
---|
| 497 | w->setPositionOfEmitter(1, Vector3(-10,10,0)); |
---|
| 498 | w->addToSceneNode(node); |
---|
[584] | 499 | |
---|
[592] | 500 | particle::ParticleInterface *tt = new particle::ParticleInterface(mgr,"twinthruster","Orxonox/engineglow"); |
---|
[584] | 501 | tt->particleSystem_->setParameter("local_space","true"); |
---|
| 502 | tt->newEmitter(); |
---|
[592] | 503 | tt->setDirection(Vector3(0,0,-1)); |
---|
| 504 | tt->setPositionOfEmitter(0, Vector3(20,-1,-15)); |
---|
| 505 | tt->setPositionOfEmitter(1, Vector3(-20,-1,-15)); |
---|
[584] | 506 | tt->addToSceneNode(node); |
---|
| 507 | |
---|
[462] | 508 | } |
---|
[137] | 509 | |
---|
| 510 | |
---|
[462] | 511 | void Orxonox::setupInputSystem() |
---|
| 512 | { |
---|
| 513 | size_t windowHnd = 0; |
---|
| 514 | std::ostringstream windowHndStr; |
---|
| 515 | OIS::ParamList pl; |
---|
| 516 | Ogre::RenderWindow *win = ogre_->getRoot()->getAutoCreatedWindow(); |
---|
[137] | 517 | |
---|
[462] | 518 | win->getCustomAttribute("WINDOW", &windowHnd); |
---|
| 519 | windowHndStr << windowHnd; |
---|
| 520 | pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); |
---|
| 521 | inputManager_ = OIS::InputManager::createInputSystem(pl); |
---|
[265] | 522 | |
---|
[462] | 523 | try |
---|
[337] | 524 | { |
---|
[462] | 525 | keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, false)); |
---|
| 526 | mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, true)); |
---|
[337] | 527 | } |
---|
[462] | 528 | catch (const OIS::Exception &e) |
---|
[459] | 529 | { |
---|
[462] | 530 | throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); |
---|
[459] | 531 | } |
---|
[462] | 532 | } |
---|
[137] | 533 | |
---|
[462] | 534 | // we actually want to do this differently... |
---|
| 535 | void Orxonox::createFrameListener() |
---|
[137] | 536 | { |
---|
[496] | 537 | TickFrameListener* TickFL = new TickFrameListener(); |
---|
| 538 | ogre_->getRoot()->addFrameListener(TickFL); |
---|
| 539 | |
---|
| 540 | TimerFrameListener* TimerFL = new TimerFrameListener(); |
---|
| 541 | ogre_->getRoot()->addFrameListener(TimerFL); |
---|
| 542 | |
---|
[599] | 543 | //if(mode_!=CLIENT) // just a hack ------- remove this in future |
---|
[601] | 544 | frameListener_ = new OrxListener(keyboard_, mouse_, auMan_, steering_, mode_); |
---|
[462] | 545 | ogre_->getRoot()->addFrameListener(frameListener_); |
---|
[137] | 546 | } |
---|
[462] | 547 | |
---|
| 548 | void Orxonox::startRenderLoop() |
---|
[137] | 549 | { |
---|
[511] | 550 | // this is a hack!!! |
---|
| 551 | // the call to reset the mouse clipping size should probably be somewhere |
---|
| 552 | // else, however this works for the moment. |
---|
[523] | 553 | unsigned int width, height, depth; |
---|
| 554 | int left, top; |
---|
| 555 | ogre_->getRoot()->getAutoCreatedWindow()->getMetrics(width, height, depth, left, top); |
---|
[511] | 556 | |
---|
[599] | 557 | if(mode_!=CLIENT){ |
---|
| 558 | const OIS::MouseState &ms = mouse_->getMouseState(); |
---|
| 559 | ms.width = width; |
---|
| 560 | ms.height = height; |
---|
| 561 | } |
---|
[462] | 562 | ogre_->getRoot()->startRendering(); |
---|
[74] | 563 | } |
---|
| 564 | } |
---|