Changeset 1629 for code/branches/input/src/orxonox
- Timestamp:
- Jun 27, 2008, 8:07:29 AM (17 years ago)
- Location:
- code/branches/input/src/orxonox
- Files:
-
- 6 deleted
- 30 edited
- 44 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/orxonox/CMakeLists.txt
r1535 r1629 3 3 Main.cc 4 4 Orxonox.cc 5 Radar.cc 6 RadarListener.cc 7 RadarViewable.cc 5 8 Settings.cc 6 9 7 console/InGameConsole.cc 8 hud/HUD.cc 9 hud/BarOverlayElement.cc 10 hud/RadarOverlayElement.cc 11 hud/RadarObject.cc 12 hud/Navigation.cc 13 particle/ParticleInterface.cc 10 overlays/OrxonoxOverlay.cc 11 overlays/OverlayGroup.cc 12 overlays/OverlayText.cc 13 14 overlays/console/InGameConsole.cc 15 16 overlays/debug/DebugFPSText.cc 17 overlays/debug/DebugRTRText.cc 18 19 overlays/hud/HUDBar.cc 20 overlays/hud/HUDNavigation.cc 21 overlays/hud/HUDRadar.cc 22 overlays/hud/HUDSpeedBar.cc 23 14 24 tolua/tolua_bind.cc 15 25 … … 17 27 tools/Light.cc 18 28 tools/Mesh.cc 29 tools/ParticleInterface.cc 30 tools/TextureGenerator.cc 19 31 tools/Timer.cc 32 tools/WindowEventListener.cc 20 33 21 34 objects/Ambient.cc 35 objects/Backlight.cc 22 36 objects/Camera.cc 23 37 objects/CameraHandler.cc 24 objects/Explosion.cc25 38 objects/Model.cc 26 39 objects/NPC.cc 27 objects/Projectile.cc 28 objects/RotatingProjectile.cc 40 objects/ParticleSpawner.cc 29 41 objects/Skybox.cc 30 42 objects/SpaceShip.cc … … 33 45 objects/WorldEntity.cc 34 46 35 # objects/weapon/AmmunitionDump.cc 36 # objects/weapon/BarrelGun.cc 37 # objects/weapon/BaseWeapon.cc 38 # objects/weapon/Bullet.cc 39 # objects/weapon/BulletManager.cc 40 # objects/weapon/WeaponStation.cc 47 objects/Projectile.cc 48 objects/BillboardProjectile.cc 49 objects/RotatingProjectile.cc 50 objects/ParticleProjectile.cc 41 51 ) 42 52 43 53 GET_TARGET_PROPERTY(TOLUA_EXE tolua LOCATION) 44 54 ADD_CUSTOM_COMMAND( 45 OUTPUT tolua/tolua_bind.cc tolua/tolua_bind.h55 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc 46 56 COMMAND ${TOLUA_EXE} -n orxonox -o ../../src/orxonox/tolua/tolua_bind.cc -H ../../src/orxonox/tolua/tolua_bind.h ../../src/orxonox/tolua/tolua.pkg 47 57 DEPENDS tolua … … 75 85 tinyxml 76 86 tolualib 77 ois 87 ois_orxonox 78 88 util 79 89 core -
code/branches/input/src/orxonox/GraphicsEngine.cc
r1538 r1629 50 50 #include "core/CommandExecutor.h" 51 51 #include "core/ConsoleCommand.h" 52 #include "core/input/InputManager.h" 53 54 #include "console/InGameConsole.h" 52 53 #include "overlays/console/InGameConsole.h" 54 #include "overlays/OverlayGroup.h" 55 #include "tools/ParticleInterface.h" 55 56 #include "Settings.h" 56 57 58 namespace orxonox { 57 #include "tools/WindowEventListener.h" 58 59 60 namespace orxonox 61 { 59 62 /** 60 63 @brief Returns the singleton instance and creates it the first time. … … 76 79 { 77 80 RegisterObject(GraphicsEngine); 81 82 this->detailLevelParticle_ = 0; 78 83 79 84 this->setConfigValues(); … … 91 96 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 92 97 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 98 99 unsigned int old = this->detailLevelParticle_; 100 SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high"); 101 102 if (this->detailLevelParticle_ != old) 103 for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) 104 it->detailLevelChanged(this->detailLevelParticle_); 93 105 } 94 106 … … 424 436 425 437 /** 426 * Window has resized.438 * Window has moved. 427 439 * @param rw The render window it occured in 428 440 */ 429 441 void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw) 430 442 { 431 // note: this doesn't change the window extents 443 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 444 it->windowMoved(); 432 445 } 433 446 … … 440 453 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw) 441 454 { 442 // change the mouse clipping size for absolute mouse movements 443 int w = rw->getWidth(); 444 int h = rw->getHeight(); 445 InputManager::setWindowExtents(w, h); 446 InGameConsole::getInstance().resize(); 447 } 448 449 /** 450 * Window has resized. 455 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 456 it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight()); 457 } 458 459 /** 460 * Window has changed Focus. 451 461 * @param rw The render window it occured in 452 462 */ 453 463 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw) 454 464 { 455 // note: this doesn't change the window extents 456 } 457 458 /** 459 * Window has resized. 465 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 466 it->windowFocusChanged(); 467 } 468 469 /** 470 * Window was closed. 460 471 * @param rw The render window it occured in 461 472 */ 462 473 void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw) 463 474 { 464 // using CommandExecutor in order to avoid depending on Orxonox class.475 // using CommandExecutor in order to avoid depending on Orxonox.h. 465 476 CommandExecutor::execute("exit", false); 466 477 } -
code/branches/input/src/orxonox/GraphicsEngine.h
r1535 r1629 47 47 48 48 49 namespace orxonox {50 49 namespace orxonox 50 { 51 51 /** 52 52 @brief Graphics engine manager class … … 72 72 int getWindowHeight() const; 73 73 float getWindowAspectRatio() const; 74 float getAverageFPS() const 75 { if (renderWindow_) return this->renderWindow_->getAverageFPS(); else return 0.0f; } 74 float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; } 75 float getAverageTickTime() const { return this->avgTickTime_; } 76 void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; } 77 void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; } 78 79 void setWindowActivity(bool activity) 80 { if (this->renderWindow_) this->renderWindow_->setActive(activity); } 76 81 77 82 void windowMoved (Ogre::RenderWindow* rw); … … 79 84 void windowFocusChanged(Ogre::RenderWindow* rw); 80 85 void windowClosed (Ogre::RenderWindow* rw); 86 87 inline unsigned int getDetailLevelParticle() const 88 { return this->detailLevelParticle_; } 81 89 82 90 static GraphicsEngine& getSingleton(); … … 94 102 bool, const std::string&); 95 103 96 Ogre::Root* root_; //!< Ogre's root 97 Ogre::SceneManager* scene_; //!< scene manager of the game 98 Ogre::RenderWindow* renderWindow_; //!< the current render window 99 std::string resourceFile_; //!< resources file name 100 std::string ogreConfigFile_; //!< ogre config file name 101 std::string ogrePluginsFile_; //!< ogre plugins file name 102 std::string ogreLogFile_; //!< log file name for Ogre log messages 103 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL 104 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 105 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 104 Ogre::Root* root_; //!< Ogre's root 105 Ogre::SceneManager* scene_; //!< scene manager of the game 106 Ogre::RenderWindow* renderWindow_; //!< the current render window 107 std::string resourceFile_; //!< resources file name 108 std::string ogreConfigFile_; //!< ogre config file name 109 std::string ogrePluginsFile_; //!< ogre plugins file name 110 std::string ogreLogFile_; //!< log file name for Ogre log messages 111 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL 112 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 113 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 114 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 115 float avgTickTime_; //!< time in ms to tick() one frame 116 float avgFramesPerSecond_; //!< number of frames processed in one second 106 117 }; 107 118 } -
code/branches/input/src/orxonox/Orxonox.cc
r1535 r1629 69 69 70 70 // objects and tools 71 #include "hud/HUD.h" 71 #include "overlays/OverlayGroup.h" 72 #include "overlays/console/InGameConsole.h" 72 73 #include "objects/Tickable.h" 74 #include "objects/Backlight.h" 75 #include "tools/ParticleInterface.h" 73 76 74 77 #include "GraphicsEngine.h" 75 78 #include "Settings.h" 76 77 // FIXME: is this really file scope? 79 #include "Radar.h" 80 78 81 // globals for the server or client 79 network::Client *client_g = 0;80 network::Server *server_g = 0;82 static network::Client *client_g = 0; 83 static network::Server *server_g = 0; 81 84 82 85 namespace orxonox … … 94 97 * Create a new instance of Orxonox. Avoid doing any actual work here. 95 98 */ 96 Orxonox::Orxonox() :97 ogre_(0),98 //auMan_(0),99 timer_(0),100 // turn on frame smoothing by setting a value different from 0101 frameSmoothingTime_(0.0f),102 orxonoxHUD_(0),103 bAbort_(false),104 timefactor_(1.0f),105 mode_(STANDALONE),106 serverIp_(""),107 serverPort_(NETWORK_PORT)99 Orxonox::Orxonox() 100 : ogre_(0) 101 , startLevel_(0) 102 , hud_(0) 103 , radar_(0) 104 //, auMan_(0) 105 , timer_(0) 106 , bAbort_(false) 107 , timefactor_(1.0f) 108 , mode_(STANDALONE) 109 , serverIp_("") 110 , serverPort_(NETWORK_PORT) 108 111 { 109 112 } … … 115 118 { 116 119 // keep in mind: the order of deletion is very important! 117 // if (this->orxonoxHUD_) 118 // delete this->orxonoxHUD_; 120 Loader::unload(startLevel_); 121 if (this->startLevel_) 122 delete this->startLevel_; 123 124 Loader::unload(hud_); 125 if (this->hud_) 126 delete this->hud_; 127 128 if (this->radar_) 129 delete this->radar_; 130 119 131 Loader::close(); 120 InputManager::destroy();121 132 //if (this->auMan_) 122 133 // delete this->auMan_; 134 InGameConsole::getInstance().destroy(); 123 135 if (this->timer_) 124 136 delete this->timer_; 137 InputManager::destroy(); 125 138 GraphicsEngine::getSingleton().destroy(); 126 139 … … 159 172 delete singletonRef_s; 160 173 singletonRef_s = 0; 174 } 175 176 /** 177 @brief Changes the speed of Orxonox 178 */ 179 void Orxonox::setTimeFactor(float factor) 180 { 181 float change = factor / Orxonox::getSingleton()->getTimeFactor(); 182 Orxonox::getSingleton()->timefactor_ = factor; 183 for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) 184 it->setSpeedFactor(it->getSpeedFactor() * change); 185 186 for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it) 187 it->setTimeFactor(Orxonox::getSingleton()->getTimeFactor()); 161 188 } 162 189 … … 251 278 return false; 252 279 280 // TODO: Spread this so that this call only initialises things needed for the Console 281 if (!ogre_->initialiseResources()) 282 return false; 283 284 // Load the InGameConsole 285 InGameConsole::getInstance().initialise(); 286 253 287 // Calls the InputManager which sets up the input devices. 254 288 // The render window width and height are used to set up the mouse movement. … … 257 291 return false; 258 292 259 // TODO: Spread this so that this call only initialises things needed for the GUI260 if (!ogre_->initialiseResources())261 return false;262 263 293 // TOOD: load the GUI here 264 294 // set InputManager to GUI mode … … 303 333 /** 304 334 * Loads everything in the scene except for the actual objects. 305 * This includes HUD, Console..335 * This includes HUD, audio.. 306 336 */ 307 337 bool Orxonox::loadPlayground() … … 316 346 317 347 // Load the HUD 318 COUT(3) << "Orxonox: Loading HUD..." << std::endl; 319 orxonoxHUD_ = &HUD::getSingleton(); 348 COUT(3) << "Orxonox: Loading HUD" << std::endl; 349 hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); 350 Loader::load(hud_); 351 352 // Start the Radar 353 this->radar_ = new Radar(); 354 320 355 return true; 321 356 } … … 326 361 bool Orxonox::serverLoad() 327 362 { 328 COUT( 2) << "Loading level in server mode" << std::endl;363 COUT(0) << "Loading level in server mode" << std::endl; 329 364 330 365 //server_g = new network::Server(serverPort_); … … 344 379 bool Orxonox::clientLoad() 345 380 { 346 COUT( 2) << "Loading level in client mode" << std::endl;\381 COUT(0) << "Loading level in client mode" << std::endl;\ 347 382 348 383 if (serverIp_.compare("") == 0) … … 364 399 bool Orxonox::standaloneLoad() 365 400 { 366 COUT( 2) << "Loading level in standalone mode" << std::endl;401 COUT(0) << "Loading level in standalone mode" << std::endl; 367 402 368 403 if (!loadScene()) … … 377 412 bool Orxonox::loadScene() 378 413 { 379 Level* startlevel= new Level("levels/sample.oxw");380 Loader::open(start level);381 414 startLevel_ = new Level("levels/sample.oxw"); 415 Loader::open(startLevel_); 416 382 417 return true; 383 418 } … … 403 438 404 439 405 // Contains the times of recently fired events406 // eventTimes[4] is the list for the times required for the fps counter407 std::deque<unsigned long> eventTimes[3];408 // Clear event times409 for (int i = 0; i < 3; ++i)410 eventTimes[i].clear();411 412 440 // use the ogre timer class to measure time. 413 441 if (!timer_) 414 442 timer_ = new Ogre::Timer(); 443 444 unsigned long frameCount = 0; 445 446 // TODO: this would very well fit into a configValue 447 const unsigned long refreshTime = 200000; 448 unsigned long refreshStartTime = 0; 449 unsigned long tickTime = 0; 450 unsigned long oldFrameCount = 0; 451 452 unsigned long timeBeforeTick = 0; 453 unsigned long timeBeforeTickOld = 0; 454 unsigned long timeAfterTick = 0; 455 456 COUT(3) << "Orxonox: Starting the main loop." << std::endl; 457 415 458 timer_->reset(); 416 417 float renderTime = 0.0f;418 float frameTime = 0.0f;419 clock_t time = 0;420 421 //Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();422 //Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();423 424 //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom");425 //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur");426 427 COUT(3) << "Orxonox: Starting the main loop." << std::endl;428 459 while (!bAbort_) 429 460 { 430 461 // get current time 431 unsigned long now = timer_->getMilliseconds(); 432 433 // create an event to pass to the frameStarted method in ogre 434 Ogre::FrameEvent evt; 435 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 436 evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]); 437 frameTime += evt.timeSinceLastFrame; 438 439 // show the current time in the HUD 440 // HUD::getSingleton().setTime(now); 441 if (mode_ != DEDICATED && frameTime > 0.4f) 442 { 443 HUD::getSingleton().setRenderTimeRatio(renderTime / frameTime); 444 frameTime = 0.0f; 445 renderTime = 0.0f; 446 } 447 448 // tick the core 449 Core::tick((float)evt.timeSinceLastFrame); 462 timeBeforeTickOld = timeBeforeTick; 463 timeBeforeTick = timer_->getMicroseconds(); 464 float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; 465 466 467 // tick the core (needs real time for input and tcl thread management) 468 Core::tick(dt); 469 450 470 // Call those objects that need the real time 451 471 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) 452 it->tick( (float)evt.timeSinceLastFrame);472 it->tick(dt); 453 473 // Call the scene objects 454 474 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 455 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 456 //AudioManager::tick(); 475 it->tick(dt * this->timefactor_); 476 477 // call server/client with normal dt 457 478 if (client_g) 458 client_g->tick( (float)evt.timeSinceLastFrame);479 client_g->tick(dt * this->timefactor_); 459 480 if (server_g) 460 server_g->tick((float)evt.timeSinceLastFrame); 481 server_g->tick(dt * this->timefactor_); 482 483 484 // get current time once again 485 timeAfterTick = timer_->getMicroseconds(); 486 487 tickTime += timeAfterTick - timeBeforeTick; 488 if (timeAfterTick > refreshStartTime + refreshTime) 489 { 490 GraphicsEngine::getSingleton().setAverageTickTime( 491 (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 492 GraphicsEngine::getSingleton().setAverageFramesPerSecond( 493 (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0); 494 oldFrameCount = frameCount; 495 tickTime = 0; 496 refreshStartTime = timeAfterTick; 497 } 498 461 499 462 500 // don't forget to call _fireFrameStarted in ogre to make sure 463 501 // everything goes smoothly 502 Ogre::FrameEvent evt; 503 evt.timeSinceLastFrame = dt; 504 evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway 464 505 ogreRoot._fireFrameStarted(evt); 465 466 // get current time467 now = timer_->getMilliseconds();468 calculateEventTime(now, eventTimes[2]);469 506 470 507 if (mode_ != DEDICATED) … … 473 510 // This calls the WindowEventListener objects. 474 511 Ogre::WindowEventUtilities::messagePump(); 512 // make sure the window stays active even when not focused 513 // (probably only necessary on windows) 514 GraphicsEngine::getSingleton().setWindowActivity(true); 475 515 476 516 // render … … 478 518 } 479 519 480 // get current time481 now = timer_->getMilliseconds();482 483 // create an event to pass to the frameEnded method in ogre484 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);485 renderTime += calculateEventTime(now, eventTimes[2]);486 487 520 // again, just to be sure ogre works fine 488 ogreRoot._fireFrameEnded(evt); 489 //msleep(200); 521 ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 522 523 ++frameCount; 490 524 } 491 525 … … 497 531 return true; 498 532 } 499 500 /**501 Method for calculating the average time between recently fired events.502 Code directly taken from OgreRoot.cc503 @param now The current time in ms.504 @param type The type of event to be considered.505 */506 float Orxonox::calculateEventTime(unsigned long now, std::deque<unsigned long> ×)507 {508 // Calculate the average time passed between events of the given type509 // during the last frameSmoothingTime_ seconds.510 511 times.push_back(now);512 513 if(times.size() == 1)514 return 0;515 516 // Times up to frameSmoothingTime_ seconds old should be kept517 unsigned long discardThreshold = (unsigned long)(frameSmoothingTime_ * 1000.0f);518 519 // Find the oldest time to keep520 std::deque<unsigned long>::iterator it = times.begin();521 // We need at least two times522 std::deque<unsigned long>::iterator end = times.end() - 2;523 524 while(it != end)525 {526 if (now - *it > discardThreshold)527 ++it;528 else529 break;530 }531 532 // Remove old times533 times.erase(times.begin(), it);534 535 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000);536 }537 533 } -
code/branches/input/src/orxonox/Orxonox.h
r1535 r1629 62 62 63 63 void abortRequest(); 64 //inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };65 64 66 65 static Orxonox* getSingleton(); 67 66 static void destroySingleton(); 68 67 69 static inline void slomo(float factor) { Orxonox:: getSingleton()->timefactor_ = factor; }70 static inline void setTimeFactor(float factor = 1.0) { Orxonox::getSingleton()->timefactor_ = factor; }68 static inline void slomo(float factor) { Orxonox::setTimeFactor(factor); } 69 static void setTimeFactor(float factor = 1.0); 71 70 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; } 72 71 static inline void exit() { Orxonox::getSingleton()->abortRequest(); } … … 93 92 private: 94 93 GraphicsEngine* ogre_; //!< our dearest graphics engine <3 94 Level* startLevel_; //!< current hard coded default level 95 Level* hud_; //!< 'level' object fo the HUD 96 Radar* radar_; //!< represents the Radar (not the HUD part) 95 97 //audio::AudioManager* auMan_; //!< audio manager 96 98 Ogre::Timer* timer_; //!< Main loop timer 97 // TODO: make this a config-value by creating a config class for orxonox98 float frameSmoothingTime_;99 HUD* orxonoxHUD_;100 99 bool bAbort_; //!< aborts the render loop if true 101 100 float timefactor_; //!< A factor to change the gamespeed -
code/branches/input/src/orxonox/OrxonoxPrereqs.h
r1505 r1629 60 60 //----------------------------------------------------------------------- 61 61 62 namespace orxonox { 63 class GraphicsEngine; 64 class Orxonox; 62 namespace orxonox 63 { 64 namespace LODParticle 65 { 66 enum LOD 67 { 68 off = 0, 69 low = 1, 70 normal = 2, 71 high = 3 72 }; 73 } 65 74 66 // objects 67 class Ambient; 68 class Camera; 69 class Explosion; 70 class Fighter; 71 class Model; 72 class NPC; 73 class Projectile; 74 class Skybox; 75 class SpaceShip; 76 class SpaceShipAI; 77 class WorldEntity; 75 class GraphicsEngine; 76 class Orxonox; 78 77 79 class AmmunitionDump; 80 class Bullet; 81 class BulletManager; 82 class BaseWeapon; 83 class BarrelGun; 84 class WeaponStation; 78 class RadarViewable; 79 class Radar; 80 class RadarListener; 85 81 86 // tools 87 class BillboardSet; 88 class Light; 89 class Mesh; 90 template <class T> 91 class Timer; 92 class TimerBase; 82 // objects 83 class Ambient; 84 class Backlight; 85 class Camera; 86 class Fighter; 87 class Model; 88 class NPC; 89 class ParticleSpawner; 90 class Skybox; 91 class SpaceShip; 92 class SpaceShipAI; 93 class WorldEntity; 93 94 94 // particle 95 class ParticleInterface; 95 class Projectile; 96 class BillboardProjectile; 97 class RotatingProjectile; 98 class ParticleProjectile; 96 99 97 // hud 98 class BarOverlayElement; 99 class HUD; 100 class Navigation; 101 class RadarObject; 102 class RadarOverlayElement; 100 // tools 101 class BillboardSet; 102 class Light; 103 class Mesh; 104 class ParticleInterface; 105 template <class T> 106 class Timer; 103 107 104 //console 105 class InGameConsole; 108 // overlays 109 class BarColour; 110 class DebugFPSText; 111 class DebugRTRText; 112 class HUDBar; 113 class HUDNavigation; 114 class HUDRadar; 115 class HUDSpeedBar; 116 class InGameConsole; 117 class OrxonoxOverlay; 118 class OverlayGroup; 119 class OverlayText; 106 120 } 107 121 122 namespace Ogre 123 { 124 // some got forgotten in OgrePrerequisites 125 class BorderPanelOverlayElement; 126 class PanelOverlayElement; 127 class TextAreaOverlayElement; 128 } 108 129 109 130 #endif /* _OrxonoxPrereqs_H__ */ -
code/branches/input/src/orxonox/OrxonoxStableHeaders.h
r1543 r1629 37 37 #include "util/OrxonoxPlatform.h" 38 38 39 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 39 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && 0 40 40 41 41 // including std headers here is useless since they're already precompiled … … 112 112 #include "network/Synchronisable.h" 113 113 114 #include "tools/Mesh.h"115 #include "tools/Timer.h"116 #include "objects/Model.h"117 #include "objects/Tickable.h"118 #include "objects/WorldEntity.h"114 //#include "tools/Mesh.h" 115 //#include "tools/Timer.h" 116 //#include "objects/Model.h" 117 //#include "objects/Tickable.h" 118 //#include "objects/WorldEntity.h" 119 119 120 120 #endif /* Compiler MSVC */ -
code/branches/input/src/orxonox/objects/Ambient.cc
r1505 r1629 73 73 74 74 } 75 76 void Ambient:: loadParams(TiXmlElement* xmlElem)75 76 void Ambient::setAmbientLight(const ColourValue& colour) 77 77 { 78 if (xmlElem->Attribute("colourvalue")) 79 { 80 SubString colourvalues(xmlElem->Attribute("colourvalue"), ','); 81 82 float r, g, b; 83 convertValue<std::string, float>(&r, colourvalues[0]); 84 convertValue<std::string, float>(&g, colourvalues[1]); 85 convertValue<std::string, float>(&b, colourvalues[2]); 86 87 this->setAmbientLight(ColourValue(r, g, b)); 88 89 COUT(4) << "Loader: Set ambient light: "<<r<<" " << g << " " << b << std::endl << std::endl; 90 } 91 } 92 93 void Ambient::setAmbientLight(const ColourValue& colour) 94 { 95 GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour); 78 GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour); 96 79 ambientLight_=colour; 97 }80 } 98 81 99 82 /** -
code/branches/input/src/orxonox/objects/Ambient.h
r1505 r1629 44 44 virtual ~Ambient(); 45 45 46 void loadParams(TiXmlElement* xmlElem);47 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 47 void setAmbientLight(const ColourValue& colour); -
code/branches/input/src/orxonox/objects/Model.cc
r1511 r1629 53 53 Model::~Model() 54 54 { 55 if (this->isInitialized() && (this->meshSrc_ != "") && (this->meshSrc_.size() > 0)) 56 this->detachObject(this->mesh_.getEntity()); 55 57 } 56 58 57 59 /** 58 60 @brief XML loading and saving. 59 @p 60 aram xmlelement The XML-element 61 @param xmlelement The XML-element 61 62 @param loading Loading (true) or saving (false) 62 63 @return The XML-element … … 94 95 registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING); 95 96 } 97 98 void Model::changedVisibility() 99 { 100 WorldEntity::changedVisibility(); 101 if (this->isInitialized()) 102 this->mesh_.setVisible(this->isVisible()); 103 } 96 104 } -
code/branches/input/src/orxonox/objects/Model.h
r1505 r1629 44 44 virtual ~Model(); 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 virtual void changedVisibility(); 46 47 void setMesh(const std::string& meshname); 47 48 virtual bool create(); -
code/branches/input/src/orxonox/objects/NPC.cc
r1505 r1629 45 45 NPC::~NPC() 46 46 { 47 }48 49 void NPC::loadParams(TiXmlElement* xmlElem)50 {51 Model::loadParams(xmlElem);52 47 } 53 48 -
code/branches/input/src/orxonox/objects/NPC.h
r1505 r1629 48 48 NPC(); 49 49 virtual ~NPC(); 50 virtual void loadParams(TiXmlElement* xmlElem);51 50 void tick(float dt); 52 51 void update(); -
code/branches/input/src/orxonox/objects/Projectile.cc
r1505 r1629 35 35 #include "core/Executor.h" 36 36 #include "core/ConfigValueIncludes.h" 37 #include "tools/ParticleInterface.h" 37 38 38 #include "SpaceShip .h"39 #include " Explosion.h"39 #include "SpaceShipAI.h" 40 #include "ParticleSpawner.h" 40 41 #include "Model.h" 41 42 42 43 namespace orxonox 43 44 { 44 CreateFactory(Projectile);45 float Projectile::speed_ = 5000; 45 46 46 float Projectile::speed_ = 0; 47 48 Projectile::Projectile(SpaceShip* owner) : 49 owner_(owner) 47 Projectile::Projectile(SpaceShip* owner) : owner_(owner) 50 48 { 51 49 RegisterObject(Projectile); 52 50 53 51 this->setConfigValues(); 54 55 this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); 56 this->attachObject(this->billboard_.getBillboardSet()); 57 this->scale(0.5); 52 this->explosionTemplateName_ = "Orxonox/explosion3"; 53 this->smokeTemplateName_ = "Orxonox/smoke4"; 58 54 59 55 if (this->owner_) … … 63 59 this->setPosition(this->owner_->getPosition()); 64 60 this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL); 65 this->setVelocity( Vector3(1, 0, 0) * this->speed_);61 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 66 62 } 67 63 68 64 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 69 // COUT(3) << this->classID << std::endl;70 65 } 71 66 … … 76 71 void Projectile::setConfigValues() 77 72 { 78 SetConfigValue(lifetime_, 10.0).description("The time in seconds a projectile stays alive"); 79 SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second"); 73 SetConfigValue(damage_, 15.0).description("The damage caused by the projectile"); 74 SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive"); 75 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second"); 80 76 81 this->setVelocity(Vector3(1, 0, 0) * this->speed_); 77 if(this->owner_) 78 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 82 79 } 83 80 … … 85 82 { 86 83 WorldEntity::tick(dt); 84 85 if (!this->isActive()) 86 return; 87 87 88 88 float radius; … … 95 95 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius)) 96 96 { 97 Explosion *exp = new Explosion(this); 98 exp->create(); 97 // hit 98 if (it->isA(Class(SpaceShipAI))) 99 ((SpaceShipAI*)(*it))->damage(this->damage_); 100 ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0); 101 explosion->setPosition(this->getPosition()); 102 explosion->create(); 103 ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0); 104 smoke->setPosition(this->getPosition()); 105 // smoke->getParticleInterface()->setSpeedFactor(3.0); 106 smoke->create(); 99 107 delete this; 100 108 return; … … 108 116 delete this; 109 117 } 110 111 void Projectile::setColour(const ColourValue& colour)112 {113 this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);114 }115 118 } -
code/branches/input/src/orxonox/objects/Projectile.h
r1505 r1629 33 33 34 34 #include "WorldEntity.h" 35 #include "../tools/BillboardSet.h" 36 #include "../tools/Timer.h" 37 #include "util/Math.h" 35 #include "tools/Timer.h" 38 36 39 37 namespace orxonox … … 42 40 { 43 41 public: 44 Projectile(SpaceShip* owner = 0);45 42 virtual ~Projectile(); 46 43 void setConfigValues(); 47 44 void destroyObject(); 48 45 virtual void tick(float dt); 49 virtual bool create(){return WorldEntity::create();}50 void setColour(const ColourValue& colour);51 46 52 47 static float getSpeed() … … 54 49 55 50 protected: 51 Projectile(SpaceShip* owner = 0); 56 52 SpaceShip* owner_; 57 53 58 54 private: 59 BillboardSet billboard_; 55 std::string explosionTemplateName_; 56 std::string smokeTemplateName_; 60 57 static float speed_; 61 58 float lifetime_; 59 float damage_; 62 60 Timer<Projectile> destroyTimer_; 63 61 }; -
code/branches/input/src/orxonox/objects/RotatingProjectile.cc
r1505 r1629 37 37 CreateFactory(RotatingProjectile); 38 38 39 RotatingProjectile::RotatingProjectile(SpaceShip* owner) : Projectile(owner)39 RotatingProjectile::RotatingProjectile(SpaceShip* owner) : BillboardProjectile(owner) 40 40 { 41 41 RegisterObject(RotatingProjectile); … … 73 73 void RotatingProjectile::tick(float dt) 74 74 { 75 this->time_ += dt; 75 if (this->isActive()) 76 { 77 this->time_ += dt; 76 78 77 this->rotatingNode1_->setPosition(0, 50 * sin(this->time_ * 20), 50 * cos(this->time_ * 20)); 78 this->rotatingNode2_->setPosition(0, -50 * sin(this->time_ * 20), -50 * cos(this->time_ * 20)); 79 this->rotatingNode1_->setPosition(0, 50 * sin(this->time_ * 20), 50 * cos(this->time_ * 20)); 80 this->rotatingNode2_->setPosition(0, -50 * sin(this->time_ * 20), -50 * cos(this->time_ * 20)); 81 } 79 82 80 83 Projectile::tick(dt); 81 84 } 85 86 void RotatingProjectile::changedVisibility() 87 { 88 BillboardProjectile::changedVisibility(); 89 this->rotatingBillboard1_.setVisible(this->isVisible()); 90 this->rotatingBillboard2_.setVisible(this->isVisible()); 91 } 82 92 } -
code/branches/input/src/orxonox/objects/RotatingProjectile.h
r1505 r1629 2 2 #define _RotatingProjectile_H__ 3 3 4 #include " ../OrxonoxPrereqs.h"4 #include "OrxonoxPrereqs.h" 5 5 #include "util/Math.h" 6 #include " Projectile.h"6 #include "BillboardProjectile.h" 7 7 8 8 namespace orxonox 9 9 { 10 class _OrxonoxExport RotatingProjectile : public Projectile/*, public network::Synchronisable*/10 class _OrxonoxExport RotatingProjectile : public BillboardProjectile 11 11 { 12 12 public: … … 15 15 void setConfigValues(); 16 16 virtual void tick(float dt); 17 virtual bool create(){return Projectile::create();}17 virtual void changedVisibility(); 18 18 19 19 private: -
code/branches/input/src/orxonox/objects/Skybox.cc
r1505 r1629 54 54 } 55 55 56 void Skybox:: loadParams(TiXmlElement* xmlElem)56 void Skybox::setSkybox(const std::string& skyboxname) 57 57 { 58 if (xmlElem->Attribute("src")) 59 { 60 skyboxSrc_ = xmlElem->Attribute("src"); 61 this->create(); 58 GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(true, skyboxname); 59 } 62 60 63 COUT(4) << "Loader: Set skybox: "<< skyboxSrc_ << std::endl << std::endl; 64 } 65 } 61 void Skybox::setSkyboxSrc(const std::string& src) 62 { 63 this->skyboxSrc_ = src; 64 } 66 65 67 void Skybox::setSkybox(const std::string& skyboxname)68 {69 GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(true, skyboxname);70 }71 72 void Skybox::setSkyboxSrc(const std::string& src){73 skyboxSrc_ = src;74 }75 76 66 /** 77 67 @brief XML loading and saving. … … 87 77 create(); 88 78 } 89 90 bool Skybox::create(){ 91 this->setSkybox(skyboxSrc_); 92 return Synchronisable::create(); 79 80 bool Skybox::create() 81 { 82 this->setSkybox(this->skyboxSrc_); 83 return Synchronisable::create(); 93 84 } 94 95 void Skybox::registerAllVariables(){ 96 registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING); 85 86 void Skybox::registerAllVariables() 87 { 88 registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING); 97 89 } 98 90 91 void Skybox::changedVisibility() 92 { 93 BaseObject::changedVisibility(); 94 GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(this->isVisible(), this->skyboxSrc_); 95 } 99 96 } -
code/branches/input/src/orxonox/objects/Skybox.h
r1505 r1629 43 43 virtual ~Skybox(); 44 44 45 void loadParams(TiXmlElement* xmlElem);46 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 virtual void changedVisibility(); 47 47 void setSkybox(const std::string& skyboxname); 48 48 49 49 virtual bool create(); 50 50 void registerAllVariables(); -
code/branches/input/src/orxonox/objects/SpaceShip.cc
r1535 r1629 35 35 #include <OgreSceneNode.h> 36 36 37 #include "CameraHandler.h"38 37 #include "util/Convert.h" 39 38 #include "util/Math.h" 39 40 40 #include "core/CoreIncludes.h" 41 41 #include "core/ConfigValueIncludes.h" 42 42 #include "core/Debug.h" 43 #include "GraphicsEngine.h"44 #include "core/input/InputManager.h"45 #include "particle/ParticleInterface.h"46 #include "Projectile.h"47 #include "RotatingProjectile.h"48 43 #include "core/XMLPort.h" 49 44 #include "core/ConsoleCommand.h" 45 50 46 #include "network/Client.h" 51 #include "hud/HUD.h" 47 48 #include "tools/ParticleInterface.h" 49 50 #include "GraphicsEngine.h" 51 #include "RotatingProjectile.h" 52 #include "ParticleProjectile.h" 53 #include "ParticleSpawner.h" 54 #include "Backlight.h" 55 #include "CameraHandler.h" 52 56 53 57 namespace orxonox … … 69 73 SpaceShip* SpaceShip::instance_s; 70 74 71 75 72 76 SpaceShip *SpaceShip::getLocalShip(){ 73 77 Iterator<SpaceShip> it; … … 79 83 } 80 84 81 SpaceShip::SpaceShip() : 82 //testvector_(0,0,0), 83 //bInvertYAxis_(false), 84 setMouseEventCallback_(false), 85 bLMousePressed_(false), 86 bRMousePressed_(false), 87 camNode_(0), 88 cam_(0), 89 camName_("CamNode"), 90 tt_(0), 91 redNode_(0), 92 greenNode_(0), 93 blinkTime_(0.0f), 94 chNearNode_(0), 95 chFarNode_(0), 96 timeToReload_(0.0f), 97 //reloadTime_(0.0f), 98 maxSideAndBackSpeed_(0.0f), 99 maxSpeed_(0.0f), 100 maxRotation_(0.0f), 101 translationAcceleration_(0.0f), 102 rotationAcceleration_(0.0f), 103 translationDamping_(0.0f), 104 rotationDamping_(0.0f), 105 maxRotationRadian_(0), 106 rotationAccelerationRadian_(0), 107 rotationDampingRadian_(0), 108 zeroRadian_(0), 109 mouseXRotation_(0), 110 mouseYRotation_(0), 111 mouseX_(0.0f), 112 mouseY_(0.0f), 113 emitterRate_(0.0f), 114 myShip_(false), 115 teamNr_(0), 116 health_(100) 85 SpaceShip::SpaceShip() 117 86 { 118 87 RegisterObject(SpaceShip); 119 this->registerAllVariables();120 121 SpaceShip::instance_s = this;122 123 this->setConfigValues();124 125 initialDir_ = Vector3(1.0, 0.0, 0.0);126 currentDir_ = initialDir_;127 initialOrth_ = Vector3(0.0, 0.0, 1.0);128 currentOrth_ = initialOrth_;129 130 this->camName_ = this->getName() + "CamNode";131 88 132 89 this->setRotationAxis(1, 0, 0); 133 90 this->setStatic(false); 134 91 135 COUT(3) << "Info: SpaceShip was loaded" << std::endl; 92 this->zeroRadian_ = 0; 93 this->maxSideAndBackSpeed_ = 0; 94 this->maxSpeed_ = 0; 95 this->maxRotation_ = 0; 96 this->translationAcceleration_ = 0; 97 this->rotationAcceleration_ = 0; 98 this->translationDamping_ = 0; 99 this->rotationDamping_ = 0; 100 this->maxRotationRadian_ = 0; 101 this->rotationAccelerationRadian_ = 0; 102 this->rotationDampingRadian_ = 0; 103 104 this->cam_ = 0; 105 this->tt1_ = 0; 106 this->tt2_ = 0; 107 this->smoke_ = 0; 108 this->fire_ = 0; 109 110 this->backlight_ = 0; 111 112 this->redNode_ = 0; 113 this->greenNode_ = 0; 114 this->blinkTime_ = 0; 115 116 this->timeToReload_ = 0; 117 118 this->bLMousePressed_ = false; 119 this->bRMousePressed_ = false; 120 this->mouseXRotation_ = 0; 121 this->mouseYRotation_ = 0; 122 this->myShip_ = false; 123 124 this->registerAllVariables(); 125 126 SpaceShip::instance_s = this; 127 128 this->setConfigValues(); 129 130 this->initialDir_ = Vector3(1.0, 0.0, 0.0); 131 this->currentDir_ = initialDir_; 132 this->initialOrth_ = Vector3(0.0, 0.0, 1.0); 133 this->currentOrth_ = initialOrth_; 134 135 this->camName_ = this->getName() + "CamNode"; 136 137 this->teamNr_ = 0; 138 this->health_ = 100; 139 140 this->radarObject_ = static_cast<WorldEntity*>(this); 136 141 } 137 142 138 143 SpaceShip::~SpaceShip() 139 144 { 140 if (this->tt_) 141 delete this->tt_; 142 if(setMouseEventCallback_) 143 InputManager::removeMouseHandler("SpaceShip"); 144 if (this->cam_) 145 delete this->cam_; 146 if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL) 147 //remove the radar object 148 HUD::getSingleton().removeRadarObject(this->getNode()); 145 if (this->isInitialized()) 146 { 147 if (this->tt1_) 148 delete this->tt1_; 149 if (this->tt2_) 150 delete this->tt2_; 151 152 if (this->smoke_) 153 this->smoke_->destroy(); 154 if (this->fire_) 155 this->fire_->destroy(); 156 157 if (this->backlight_) 158 delete this->backlight_; 159 160 if (this->cam_) 161 delete this->cam_; 162 } 149 163 } 150 164 … … 154 168 myShip_=true; 155 169 else 156 HUD::getSingleton().addRadarObject(this->getNode(), 3);170 this->setRadarObjectColour(this->getProjectileColour()); 157 171 } 158 172 if(Model::create()) … … 179 193 void SpaceShip::init() 180 194 { 181 // START CREATING THRUSTER 182 this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); 183 this->tt_->getParticleSystem()->setParameter("local_space","true"); 184 this->tt_->newEmitter(); 185 /* 186 this->tt_->setDirection(Vector3(0,0,1)); 187 this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15)); 188 this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15)); 189 */ 190 this->tt_->setDirection(Vector3(-1,0,0)); 191 this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1)); 192 this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1)); 193 this->tt_->setVelocity(50); 194 195 emitterRate_ = tt_->getRate(); 196 197 Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2"); 198 node2->setInheritScale(false); 199 tt_->addToSceneNode(node2); 200 // END CREATING THRUSTER 195 // START CREATING THRUSTERS 196 this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low); 197 this->tt1_->createNewEmitter(); 198 this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir()); 199 this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1)); 200 this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1)); 201 this->tt1_->setSpeedFactor(3.0); 202 203 Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a"); 204 node2a->setInheritScale(false); 205 node2a->setScale(1, 1, 1); 206 tt1_->addToSceneNode(node2a); 207 208 this->tt2_ = new ParticleInterface("Orxonox/thruster2", LODParticle::normal); 209 this->tt2_->createNewEmitter(); 210 this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0)); 211 this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2)); 212 this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2)); 213 214 Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b"); 215 node2b->setInheritScale(false); 216 node2b->setScale(0.5, 0.5, 0.5); 217 tt2_->addToSceneNode(node2b); 218 219 this->leftThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, -10, -0.5)); 220 this->rightThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, 10, -0.5)); 221 222 Ogre::SceneNode* node2c = this->getNode()->createChildSceneNode(this->getName() + "particle2c"); 223 node2c->setInheritScale(false); 224 node2c->setScale(2, 2, 2); 225 node2c->attachObject(this->leftThrusterFlare_.getBillboardSet()); 226 node2c->attachObject(this->rightThrusterFlare_.getBillboardSet()); 227 // END CREATING THRUSTERS 201 228 202 229 // START CREATING BLINKING LIGHTS … … 216 243 // END CREATING BLINKING LIGHTS 217 244 245 // START CREATING ADDITIONAL EFFECTS 246 this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 247 this->attachObject(this->backlight_); 248 this->backlight_->setPosition(-2.35, 0, 0.2); 249 this->backlight_->setColour(this->getProjectileColour()); 250 251 this->smoke_ = new ParticleSpawner(); 252 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 253 this->attachObject(this->smoke_); 254 255 this->fire_ = new ParticleSpawner(); 256 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 257 this->attachObject(this->fire_); 258 // END CREATING ADDITIONAL EFFECTS 259 218 260 if (this->isExactlyA(Class(SpaceShip))) 219 261 { … … 232 274 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 233 275 this->chFarNode_->setScale(0.4, 0.4, 0.4); 276 // END of testing crosshair 234 277 } 235 278 236 279 createCamera(); 237 // END of testing crosshair238 280 } 239 281 … … 245 287 } 246 288 289 void SpaceShip::changedVisibility() 290 { 291 Model::changedVisibility(); 292 293 this->tt1_->setEnabled(this->isVisible()); 294 this->tt2_->setEnabled(this->isVisible()); 295 this->redBillboard_.setVisible(this->isVisible()); 296 this->greenBillboard_.setVisible(this->isVisible()); 297 this->crosshairNear_.setVisible(this->isVisible()); 298 this->crosshairFar_.setVisible(this->isVisible()); 299 this->rightThrusterFlare_.setVisible(this->isVisible()); 300 this->leftThrusterFlare_.setVisible(this->isVisible()); 301 this->smoke_->setVisible(this->isVisible()); 302 this->fire_->setVisible(this->isVisible()); 303 this->backlight_->setVisible(this->isVisible()); 304 } 305 306 void SpaceShip::changedActivity() 307 { 308 Model::changedActivity(); 309 310 this->tt1_->setEnabled(this->isVisible()); 311 this->tt2_->setEnabled(this->isVisible()); 312 this->redBillboard_.setVisible(this->isVisible()); 313 this->greenBillboard_.setVisible(this->isVisible()); 314 this->crosshairNear_.setVisible(this->isVisible()); 315 this->crosshairFar_.setVisible(this->isVisible()); 316 this->rightThrusterFlare_.setVisible(this->isVisible()); 317 this->leftThrusterFlare_.setVisible(this->isVisible()); 318 } 319 247 320 void SpaceShip::setCamera(const std::string& camera) 248 321 { 322 myShip_=true; // TODO: this is only a hack 249 323 camName_=camera; 250 324 // change camera attributes here, if you want to ;) … … 266 340 this->camNode_ = this->getNode()->createChildSceneNode(camName_); 267 341 COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; 268 this->camNode_->setPosition(Vector3(- 50,0,10));342 this->camNode_->setPosition(Vector3(-25,0,5)); 269 343 // Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); 270 344 // Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); … … 277 351 Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); 278 352 Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0)); 279 camNode_->setOrientation(q2*q1);353 this->camNode_->setOrientation(q2*q1); 280 354 if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ 281 355 this->setBacksync(true); 282 356 CameraHandler::getInstance()->requestFocus(cam_); 283 357 } 284 285 358 } 286 359 … … 318 391 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 319 392 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 320 myShip_=true; // TODO: this is only a hack321 393 322 394 SpaceShip::create(); … … 325 397 } 326 398 327 int sgn(float x)328 {329 if (x >= 0)330 return 1;331 else332 return -1;333 }334 335 399 std::string SpaceShip::whereAmI() { 336 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) 337 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) 338 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); 339 } 340 341 Vector3 SpaceShip::getDir() { 342 return currentDir_; 343 } 344 345 Vector3 SpaceShip::getOrth(){ 346 return currentOrth_; 347 } 348 349 float SpaceShip::getMaxSpeed() { return maxSpeed_; } 400 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) 401 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) 402 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); 403 } 350 404 351 405 void SpaceShip::tick(float dt) 352 406 { 407 if (!this->isActive()) 408 return; 409 353 410 currentDir_ = getOrientation()*initialDir_; 354 411 currentOrth_ = getOrientation()*initialOrth_; 355 412 356 413 if (this->cam_) 357 414 this->cam_->tick(dt); 415 416 if (this->smoke_) 417 this->smoke_->setVisible(this->isVisible() && this->health_ < 40); 418 if (this->fire_) 419 this->fire_->setVisible(this->isVisible() && this->health_ < 20); 420 421 if (this->backlight_) 422 { // (there's already fire || we're to slow || we're moving backwards ) 423 if (this->health_ < 20 || this->getVelocity().squaredLength() < 150*150 || this->getVelocity().dotProduct(this->getInitialDir()) < 0) 424 this->backlight_->setActive(false); 425 else 426 this->backlight_->setActive(true); 427 } 358 428 359 429 if (this->redNode_ && this->greenNode_) … … 374 444 { 375 445 376 Projectile *p; 377 if (this->isExactlyA(Class(SpaceShip))) 378 p = new RotatingProjectile(this); 379 else 380 p = new Projectile(this); 381 p->setColour(this->getProjectileColour()); 382 p->create(); 383 if(p->classID==0) 446 BillboardProjectile* projectile = new ParticleProjectile(this); 447 projectile->setColour(this->getProjectileColour()); 448 projectile->create(); 449 if (projectile->classID == 0) 450 { 384 451 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output 385 386 p->setBacksync(true); 452 } 453 454 projectile->setBacksync(true); 387 455 this->timeToReload_ = this->reloadTime_; 388 456 } … … 464 532 465 533 if (this->acceleration_.x > 0) 466 this->tt_->setRate(emitterRate_); 534 { 535 this->tt1_->setEnabled(true); 536 this->tt2_->setEnabled(true); 537 } 467 538 else 468 this->tt_->setRate(0); 469 470 if( myShip_ ) 471 { 472 COUT(5) << "steering our ship: " << objectID << std::endl; 473 this->acceleration_.x = 0; 474 this->acceleration_.y = 0; 475 this->momentum_ = 0; 476 this->mouseXRotation_ = Radian(0); 477 this->mouseYRotation_ = Radian(0); 478 this->bLMousePressed_ = false; 479 }/*else 480 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 539 { 540 this->tt1_->setEnabled(false); 541 this->tt2_->setEnabled(false); 542 } 543 544 COUT(5) << "steering our ship: " << objectID << std::endl; 545 this->acceleration_.x = 0; 546 this->acceleration_.y = 0; 547 this->momentum_ = 0; 548 this->mouseXRotation_ = Radian(0); 549 this->mouseYRotation_ = Radian(0); 550 this->bLMousePressed_ = false; 481 551 } 482 552 -
code/branches/input/src/orxonox/objects/SpaceShip.h
r1535 r1629 36 36 #include "Camera.h" 37 37 #include "Model.h" 38 #include "RadarViewable.h" 38 39 #include "tools/BillboardSet.h" 39 40 40 41 namespace orxonox 41 42 { 42 class _OrxonoxExport SpaceShip : public Model 43 class _OrxonoxExport SpaceShip : public Model, public RadarViewable 43 44 { 44 45 public: 45 46 47 46 static SpaceShip *getLocalShip(); 48 47 … … 55 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 56 55 virtual void tick(float dt); 56 virtual void changedVisibility(); 57 virtual void changedActivity(); 57 58 58 59 void setCamera(const std::string& camera = ""); … … 65 66 void setRotDamp(float value); 66 67 void getFocus(); 68 69 inline float getMaxSpeed() const 70 { return this->maxSpeed_; } 71 inline float getMaxSideAndBackSpeed() const 72 { return this->maxSideAndBackSpeed_; } 73 inline float getMaxRotation() const 74 { return this->maxRotation_; } 75 inline float getTransAcc() const 76 { return this->translationAcceleration_; } 77 inline float getRotAcc() const 78 { return this->rotationAcceleration_; } 79 inline float getTransDamp() const 80 { return this->translationDamping_; } 81 inline float getRotDamp() const 82 { return this->rotationDamping_; } 67 83 68 84 static std::string whereAmI(); … … 83 99 void doFire(); 84 100 85 float getMaxSpeed(); 86 Vector3 getDir(); 87 Vector3 getOrth(); 101 inline const Vector3& getDir() const 102 { return this->currentDir_; } 103 inline const Vector3& getInitialDir() const 104 { return this->initialDir_; } 105 inline const Vector3& getOrth() const 106 { return this->currentOrth_; } 107 inline const Vector3& getInitialOrth() const 108 { return this->initialOrth_; } 109 88 110 Camera* getCamera(); 89 111 90 112 int getTeamNr() const 91 113 { return this->teamNr_; } 92 int getHealth() const114 float getHealth() const 93 115 { return this->health_; } 94 116 … … 110 132 Vector3 currentOrth_; 111 133 bool bInvertYAxis_; 112 bool setMouseEventCallback_;113 134 bool bLMousePressed_; 114 135 bool bRMousePressed_; … … 118 139 std::string camName_; 119 140 141 ParticleInterface* tt1_; 142 ParticleInterface* tt2_; 143 BillboardSet leftThrusterFlare_; 144 BillboardSet rightThrusterFlare_; 120 145 121 ParticleInterface* tt_;146 Backlight* backlight_; 122 147 123 148 BillboardSet redBillboard_; … … 126 151 Ogre::SceneNode* greenNode_; 127 152 float blinkTime_; 153 154 ParticleSpawner* smoke_; 155 ParticleSpawner* fire_; 128 156 129 157 BillboardSet crosshairNear_; … … 153 181 float mouseY_; 154 182 155 float emitterRate_;156 157 183 protected: 158 184 bool myShip_; 159 185 160 186 int teamNr_; 161 int health_;187 float health_; 162 188 163 189 static SpaceShip* instance_s; -
code/branches/input/src/orxonox/objects/SpaceShipAI.cc
r1505 r1629 32 32 #include <OgreMath.h> 33 33 #include "Projectile.h" 34 #include "ParticleSpawner.h" 34 35 #include "core/CoreIncludes.h" 35 36 #include "core/Iterator.h" … … 37 38 #include "core/ConsoleCommand.h" 38 39 #include "core/XMLPort.h" 40 #include "tools/ParticleInterface.h" 39 41 40 42 #define ACTION_INTERVAL 1.0f … … 51 53 RegisterObject(SpaceShipAI); 52 54 53 this->alive_ = true;54 this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000)));55 55 this->target_ = 0; 56 56 this->bShooting_ = 0; … … 70 70 } 71 71 72 SpaceShipAI::~SpaceShipAI() 73 { 74 for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ++it) 75 it->shipDied(this); 76 } 77 72 78 void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode) 73 79 { 74 80 SpaceShip::XMLPort(xmlelement, mode); 75 myShip_=true;76 81 77 82 this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action))); … … 85 90 newenemy->setMesh("assff.mesh"); 86 91 // newenemy->setPosition(0, 0, 0); 92 newenemy->setPosition(Vector3(rnd(-3000, 3000), rnd(-3000, 3000), rnd(-3000, 3000))); 87 93 newenemy->setScale(10); 88 94 newenemy->setMaxSpeed(500); … … 95 101 Element xmlelement; 96 102 newenemy->XMLPort(xmlelement, XMLPort::LoadObject); 103 104 ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", LODParticle::normal, 2.0, 0, 0, newenemy->getOrth()); 105 spawneffect->setPosition(newenemy->getPosition() - newenemy->getOrth() * 50); 106 spawneffect->create(); 97 107 } 98 108 } … … 103 113 for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ) 104 114 { 105 delete *(it++); 106 ++i; 115 (it++)->kill(); 107 116 if (num && i >= num) 108 117 break; … … 122 131 // search enemy 123 132 random = rnd(maxrand); 124 //std::cout << "search enemy: " << random << std::endl; 125 if (random < 20 && (!this->target_)) 126 { 133 if (random < 15 && (!this->target_)) 127 134 this->searchNewTarget(); 128 }129 135 130 136 // forget enemy 131 137 random = rnd(maxrand); 132 //std::cout << "forget enemy: " << random << std::endl;133 138 if (random < 5 && (this->target_)) 134 {135 139 this->forgetTarget(); 136 }137 140 138 141 // next enemy 139 142 random = rnd(maxrand); 140 //std::cout << "next enemy: " << random << std::endl;141 143 if (random < 10 && (this->target_)) 142 {143 144 this->searchNewTarget(); 144 }145 145 146 146 // fly somewhere 147 147 random = rnd(maxrand); 148 //std::cout << "fly somewhere: " << random << std::endl; 149 if (random < 40 && (!this->bHasTargetPosition_ && !this->target_)) 150 { 148 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 151 149 this->searchNewTargetPosition(); 152 }153 150 154 151 // stop flying 155 152 random = rnd(maxrand); 156 //std::cout << "stop flying: " << random << std::endl;157 153 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 158 {159 154 this->bHasTargetPosition_ = false; 160 }161 155 162 156 // fly somewhere else 163 157 random = rnd(maxrand); 164 //std::cout << "fly somewhere else: " << random << std::endl;165 158 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 166 {167 159 this->searchNewTargetPosition(); 168 }169 160 170 161 // shoot 171 162 random = rnd(maxrand); 172 //std::cout << "shoot: " << random << std::endl;173 163 if (random < 75 && (this->target_ && !this->bShooting_)) 174 {175 164 this->bShooting_ = true; 176 }177 165 178 166 // stop shooting 179 167 random = rnd(maxrand); 180 //std::cout << "stop shooting: " << random << std::endl;181 168 if (random < 25 && (this->bShooting_)) 182 {183 169 this->bShooting_ = false; 184 } 170 } 171 172 void SpaceShipAI::damage(float damage) 173 { 174 this->health_ -= damage; 175 if (this->health_ <= 0) 176 { 177 this->kill(); 178 SpaceShipAI::createEnemy(1); 179 } 180 } 181 182 void SpaceShipAI::kill() 183 { 184 ParticleSpawner* explosion = new ParticleSpawner("Orxonox/BigExplosion1part1", LODParticle::low, 3.0); 185 explosion->setPosition(this->getPosition()); 186 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 187 explosion->setScale(4); 188 explosion->create(); 189 190 explosion = new ParticleSpawner("Orxonox/BigExplosion1part2", LODParticle::normal, 3.0); 191 explosion->setPosition(this->getPosition()); 192 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 193 explosion->setScale(4); 194 explosion->create(); 195 explosion = new ParticleSpawner("Orxonox/BigExplosion1part2", LODParticle::high, 3.0); 196 explosion->setPosition(this->getPosition()); 197 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 198 explosion->setScale(4); 199 explosion->create(); 200 201 Vector3 ringdirection = Vector3(rnd(), rnd(), rnd()); 202 ringdirection.normalise(); 203 explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::normal, 3.0, 0.5, 0, ringdirection); 204 explosion->setPosition(this->getPosition()); 205 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 206 explosion->setScale(4); 207 explosion->create(); 208 explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::high, 3.0, 0.5, 0, ringdirection); 209 explosion->setPosition(this->getPosition()); 210 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 211 explosion->setScale(4); 212 explosion->create(); 213 214 delete this; 185 215 } 186 216 187 217 void SpaceShipAI::tick(float dt) 188 218 { 219 if (!this->isActive()) 220 return; 221 189 222 if (this->target_) 190 223 this->aimAtTarget(); … … 193 226 this->moveToTargetPosition(dt); 194 227 195 if (this->bShooting_ && this->isCloseAtTarget(2 000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f))228 if (this->bShooting_ && this->isCloseAtTarget(2500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0)) 196 229 this->doFire(); 197 230 … … 201 234 void SpaceShipAI::moveToTargetPosition(float dt) 202 235 { 203 static Radian RadianZERO(0); 204 205 // float dotprod = (this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(this->targetPosition_ - this->getPosition()); 206 Quaternion rotation = (this->getOrientation() * Ogre::Vector3::UNIT_X).getRotationTo(this->targetPosition_ - this->getPosition()); 207 /* 208 std::cout << "scalprod: " << dotprod << std::endl; 209 std::cout << "dist: " << this->targetPosition_ - this->getPosition() << std::endl; 210 std::cout << "yaw: " << rotation.getYaw().valueRadians() << std::endl; 211 std::cout << "pitch: " << rotation.getPitch().valueRadians() << std::endl; 212 std::cout << "roll: " << rotation.getRoll().valueRadians() << std::endl; 213 */ 214 this->setMoveYaw(-rotation.getRoll().valueRadians()); 215 this->setMovePitch(rotation.getYaw().valueRadians()); 216 217 if ((this->targetPosition_ - this->getPosition()).length() > 100) 218 { 219 this->setMoveLongitudinal(1); 220 } 221 236 Vector2 coord = get2DViewdirection(this->getPosition(), this->getDir(), this->getOrth(), this->targetPosition_); 237 238 float distance = (this->targetPosition_ - this->getPosition()).length(); 239 if (this->target_ || distance > 50) 240 { 241 // Multiply with 0.8 to make them a bit slower 242 this->setMoveYaw(0.8 * sgn(coord.x) * coord.x*coord.x); 243 this->setMovePitch(0.8 * sgn(coord.y) * coord.y*coord.y); 244 } 245 246 if (this->target_ && distance < 1000 && this->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 247 this->setMoveLongitudinal(-0.5); // They don't brake with full power to give the player a chance 248 else if (!this->target_ && distance <= this->getVelocity().length() / (2 * this->getTransAcc())) 249 this->setMoveLongitudinal(-1.0); 250 else 251 this->setMoveLongitudinal(0.8); 222 252 } 223 253 … … 241 271 Vector3 distanceNew = it->getPosition() - this->getPosition(); 242 272 if (!this->target_ || it->getPosition().squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * Ogre::Math::PI)) 243 < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)) )273 < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)) + rnd(-250, 250)) 244 274 { 245 275 this->target_ = (*it); … … 248 278 } 249 279 } 250 }280 } 251 281 252 282 void SpaceShipAI::forgetTarget() … … 260 290 if (!this->target_) 261 291 return; 262 /* 263 Vector3 enemymovement = this->target_->getVelocity(); 264 Vector3 distance_normalised = this->target_->getPosition() - this->getPosition(); 265 distance_normalised.normalise(); 266 267 float scalarprod = enemymovement.dotProduct(distance_normalised); 268 float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength(); 269 if (aimoffset < 0) 270 { 271 this->bHasTargetPosition_ = false; 272 return; 273 } 274 aimoffset = -scalarprod + sqrt(aimoffset); 275 this->targetPosition_ = enemymovement + distance_normalised * aimoffset; 276 this->bHasTargetPosition_ = true; 277 278 std::cout << "targetpos: " << this->targetPosition_ << std::endl; 279 */ 280 this->targetPosition_ = this->target_->getPosition(); 281 this->bHasTargetPosition_ = true; 292 293 this->targetPosition_ = getPredictedPosition(this->getPosition(), Projectile::getSpeed(), this->target_->getPosition(), this->target_->getOrientation() * this->target_->getVelocity()); 294 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 282 295 } 283 296 284 297 bool SpaceShipAI::isCloseAtTarget(float distance) 285 298 { 286 return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance); 299 if (!this->target_) 300 return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance); 301 else 302 return (this->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance); 287 303 } 288 304 289 305 bool SpaceShipAI::isLookingAtTarget(float angle) 290 306 { 291 return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle)); 307 return (getAngle(this->getPosition(), this->getDir(), this->targetPosition_) < angle); 308 } 309 310 void SpaceShipAI::shipDied(SpaceShipAI* ship) 311 { 312 if (ship == this->target_) 313 { 314 this->forgetTarget(); 315 this->searchNewTargetPosition(); 316 } 292 317 } 293 318 } -
code/branches/input/src/orxonox/objects/SpaceShipAI.h
r1505 r1629 44 44 public: 45 45 SpaceShipAI(); 46 virtual ~SpaceShipAI(); 47 46 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 49 static void createEnemy(int num); 48 50 static void killEnemies(int num); 51 void shipDied(SpaceShipAI* ship); 52 void damage(float damage); 53 void kill(); 49 54 50 55 private: … … 64 69 Timer<SpaceShipAI> actionTimer_; 65 70 66 bool alive_;67 71 bool bHasTargetPosition_; 68 72 Vector3 targetPosition_; -
code/branches/input/src/orxonox/objects/WorldEntity.cc
r1505 r1629 45 45 unsigned int WorldEntity::worldEntityCounter_s = 0; 46 46 47 WorldEntity::WorldEntity() : 48 velocity_ (0, 0, 0), 49 acceleration_(0, 0, 0), 50 rotationAxis_(0, 1, 0), 51 rotationRate_(0), 52 momentum_ (0), 53 node_ (0), 54 bStatic_ (true) 47 WorldEntity::WorldEntity() 55 48 { 56 49 RegisterObject(WorldEntity); … … 58 51 if (GraphicsEngine::getSingleton().getSceneManager()) 59 52 { 60 std::ostringstream name;61 name << (WorldEntity::worldEntityCounter_s++);62 this->setName("WorldEntity" + name.str());63 this->node_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());53 std::ostringstream name; 54 name << (WorldEntity::worldEntityCounter_s++); 55 this->setName("WorldEntity" + name.str()); 56 this->node_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName()); 64 57 65 registerAllVariables();58 registerAllVariables(); 66 59 } 60 else 61 { 62 this->node_ = 0; 63 } 64 65 this->bStatic_ = true; 66 this->velocity_ = Vector3(0, 0, 0); 67 this->acceleration_ = Vector3(0, 0, 0); 68 this->rotationAxis_ = Vector3(0, 1, 0); 69 this->rotationRate_ = 0; 70 this->momentum_ = 0; 67 71 } 68 72 69 73 70 74 WorldEntity::~WorldEntity() 71 75 { 72 // just to make sure we clean out all scene nodes 73 if(this->getNode()) 74 this->getNode()->removeAndDestroyAllChildren(); 76 if (this->isInitialized()) 77 { 78 this->getNode()->removeAndDestroyAllChildren(); 79 GraphicsEngine::getSingleton().getSceneManager()->destroySceneNode(this->getName()); 80 } 75 81 } 76 82 77 83 void WorldEntity::tick(float dt) 78 84 { 79 if (!this->bStatic_ )85 if (!this->bStatic_ && this->isActive()) 80 86 { 81 87 // COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl; … … 89 95 } 90 96 91 void WorldEntity::loadParams(TiXmlElement* xmlElem)92 {93 94 BaseObject::loadParams(xmlElem);95 create();96 }97 98 97 99 98 void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll) … … 122 121 123 122 XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true); 124 123 125 124 WorldEntity::create(); 126 125 } … … 129 128 void WorldEntity::registerAllVariables() 130 129 { 130 // register inheritec variables from BaseObject 131 registerVar( (void*) &(this->bActive_), sizeof(this->bActive_), network::DATA, 0x3); 132 registerVar( (void*) &(this->bVisible_), sizeof(this->bVisible_), network::DATA, 0x3); 131 133 // register coordinates 132 134 registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3); … … 163 165 { 164 166 this->attachedWorldEntities_.push_back(entity); 167 this->attachObject(entity); 165 168 } 166 169 … … 172 175 return 0; 173 176 } 177 178 void WorldEntity::attachObject(const WorldEntity& obj) const 179 { 180 GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeChild(obj.getNode()); 181 this->getNode()->addChild(obj.getNode()); 182 } 183 184 void WorldEntity::attachObject(WorldEntity* obj) const 185 { 186 GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeChild(obj->getNode()); 187 this->getNode()->addChild(obj->getNode()); 188 } 174 189 } -
code/branches/input/src/orxonox/objects/WorldEntity.h
r1535 r1629 51 51 52 52 virtual void tick(float dt); 53 virtual void loadParams(TiXmlElement* xmlElem);54 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 54 virtual inline bool create(){ return Synchronisable::create(); } … … 58 57 const WorldEntity* getAttachedWorldEntity(unsigned int index) const; 59 58 60 inline Ogre::SceneNode* getNode() 59 inline Ogre::SceneNode* getNode() const 61 60 { return this->node_; } 62 61 … … 74 73 inline const Vector3& getPosition() const 75 74 { return this->node_->getPosition(); } 76 77 inline void translate(const Vector3 &d, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) 75 inline const Vector3& getWorldPosition() const 76 { return this->node_->getWorldPosition(); } 77 78 inline void translate(const Vector3& d, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) 78 79 { this->node_->translate(d, relativeTo); } 79 80 inline void translate(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) 80 81 { this->node_->translate(x, y, z, relativeTo); } 81 inline void translate(const Matrix3 &axes, const Vector3 &move, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)82 inline void translate(const Matrix3& axes, const Vector3& move, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) 82 83 { this->node_->translate(axes, move, relativeTo); } 83 inline void translate(const Matrix3 &axes, Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)84 inline void translate(const Matrix3& axes, Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) 84 85 { this->node_->translate(axes, x, y, z, relativeTo); } 85 86 86 inline void yaw(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)87 inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL) 87 88 { this->node_->yaw(angle, relativeTo); } 88 inline void pitch(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)89 inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL) 89 90 { this->node_->pitch(angle, relativeTo); } 90 inline void roll(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)91 inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL) 91 92 { this->node_->roll(angle, relativeTo); } 92 93 void setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll); 93 94 94 inline void setYaw(const Degree &angle)95 inline void setYaw(const Degree& angle) 95 96 { this->node_->yaw(angle, Ogre::Node::TS_LOCAL); } 96 inline void setPitch(const Degree &angle)97 inline void setPitch(const Degree& angle) 97 98 { this->node_->pitch(angle, Ogre::Node::TS_LOCAL); } 98 inline void setRoll(const Degree &angle)99 inline void setRoll(const Degree& angle) 99 100 { this->node_->roll(angle, Ogre::Node::TS_LOCAL); } 100 101 101 102 inline const Ogre::Quaternion& getOrientation() 102 103 { return this->node_->getOrientation(); } 104 inline const Ogre::Quaternion& getWorldOrientation() 105 { return this->node_->getWorldOrientation(); } 103 106 inline void setOrientation(const Ogre::Quaternion& quat) 104 107 { this->node_->setOrientation(quat); } 105 inline void rotate(const Vector3 &axis, const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)108 inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL) 106 109 { this->node_->rotate(axis, angle, relativeTo); } 107 110 inline void setDirectionLoader(Real x, Real y, Real z) 108 111 { this->setDirection(x, y, z); } 109 inline void setDirection(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)112 inline void setDirection(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector=Vector3::NEGATIVE_UNIT_Z) 110 113 { this->node_->setDirection(x, y, z, relativeTo, localDirectionVector); } 111 inline void setDirection(const Vector3 &vec, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)114 inline void setDirection(const Vector3& vec, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector=Vector3::NEGATIVE_UNIT_Z) 112 115 { this->node_->setDirection(vec, relativeTo, localDirectionVector); } 113 inline void lookAt(const Vector3 &targetPoint, Ogre::Node::TransformSpace relativeTo, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)116 inline void lookAt(const Vector3& targetPoint, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector=Vector3::NEGATIVE_UNIT_Z) 114 117 { this->node_->lookAt(targetPoint, relativeTo, localDirectionVector); } 115 118 116 inline void setScale(const Vector3 &scale)119 inline void setScale(const Vector3& scale) 117 120 { this->node_->setScale(scale); } 118 121 inline void setScale(Real x, Real y, Real z) … … 124 127 inline const Vector3& getScale(void) const 125 128 { return this->node_->getScale(); } 126 inline void scale(const Vector3 &scale)129 inline void scale(const Vector3& scale) 127 130 { this->node_->scale(scale); } 128 131 inline void scale(Real x, Real y, Real z) … … 131 134 { this->node_->scale(scale, scale, scale); } 132 135 133 inline void attachObject(Ogre::MovableObject *obj) 136 void attachObject(const WorldEntity& obj) const; 137 void attachObject(WorldEntity* obj) const; 138 inline void attachObject(Ogre::MovableObject* obj) const 134 139 { this->node_->attachObject(obj); } 135 inline void attachObject(Mesh &mesh)140 inline void attachObject(Mesh& mesh) const 136 141 { this->node_->attachObject(mesh.getEntity()); } 137 inline void detachObject(Ogre::MovableObject *obj)142 inline void detachObject(Ogre::MovableObject* obj) const 138 143 { this->node_->detachObject(obj); } 139 inline void detachAllObjects() 144 inline void detachAllObjects() const 140 145 { this->node_->detachAllObjects(); } 141 146 … … 179 184 inline void setStatic(bool bStatic) 180 185 { this->bStatic_ = bStatic; } 181 inline bool isStatic() 186 inline bool isStatic() const 182 187 { return this->bStatic_; } 183 188 -
code/branches/input/src/orxonox/tools/BillboardSet.cc
r1505 r1629 46 46 } 47 47 48 void BillboardSet::setBillboardSet(const std::string& file, const ColourValue& colour, int count, const Vector3& position) 48 void BillboardSet::setBillboardSet(const std::string& file, int count) 49 { 50 std::ostringstream name; 51 name << (BillboardSet::billboardSetCounter_s++); 52 this->billboardSet_ = GraphicsEngine::getSingleton().getSceneManager()->createBillboardSet("Billboard" + name.str(), count); 53 this->billboardSet_->createBillboard(Vector3::ZERO); 54 this->billboardSet_->setMaterialName(file); 55 } 56 57 void BillboardSet::setBillboardSet(const std::string& file, const ColourValue& colour, int count) 58 { 59 std::ostringstream name; 60 name << (BillboardSet::billboardSetCounter_s++); 61 this->billboardSet_ = GraphicsEngine::getSingleton().getSceneManager()->createBillboardSet("Billboard" + name.str(), count); 62 this->billboardSet_->createBillboard(Vector3::ZERO, colour); 63 this->billboardSet_->setMaterialName(file); 64 } 65 66 void BillboardSet::setBillboardSet(const std::string& file, const Vector3& position, int count) 67 { 68 std::ostringstream name; 69 name << (BillboardSet::billboardSetCounter_s++); 70 this->billboardSet_ = GraphicsEngine::getSingleton().getSceneManager()->createBillboardSet("Billboard" + name.str(), count); 71 this->billboardSet_->createBillboard(position); 72 this->billboardSet_->setMaterialName(file); 73 } 74 75 void BillboardSet::setBillboardSet(const std::string& file, const ColourValue& colour, const Vector3& position, int count) 49 76 { 50 77 std::ostringstream name; -
code/branches/input/src/orxonox/tools/BillboardSet.h
r1505 r1629 33 33 34 34 #include <string> 35 #include <OgreBillboardSet.h> 35 36 36 #include <OgreBillboardSet.h>37 37 #include "util/Math.h" 38 38 … … 44 44 BillboardSet(); 45 45 ~BillboardSet(); 46 void setBillboardSet(const std::string& file, const ColourValue& colour = ColourValue(1.0, 1.0, 1.0), int count = 1, const Vector3& position = Vector3::ZERO); 46 void setBillboardSet(const std::string& file, int count = 1); 47 void setBillboardSet(const std::string& file, const ColourValue& colour, int count = 1); 48 void setBillboardSet(const std::string& file, const Vector3& position, int count = 1); 49 void setBillboardSet(const std::string& file, const ColourValue& colour, const Vector3& position, int count = 1); 47 50 48 51 inline Ogre::BillboardSet* getBillboardSet() … … 51 54 inline const std::string& getName() const 52 55 { return this->billboardSet_->getName(); } 56 57 inline void setVisible(bool visible) 58 { this->billboardSet_->setVisible(visible); } 59 inline bool getVisible() const 60 { return this->billboardSet_->getVisible(); } 53 61 54 62 private: -
code/branches/input/src/orxonox/tools/Mesh.h
r1505 r1629 51 51 { return this->entity_->getName(); } 52 52 53 inline void setVisible(bool visible) 54 { if (this->entity_) this->entity_->setVisible(visible); } 55 inline bool getVisible() const 56 { if (this->entity_) return this->entity_->getVisible(); else return false; } 57 53 58 private: 54 59 static unsigned int meshCounter_s; -
code/branches/input/src/orxonox/tools/Timer.cc
r1505 r1629 102 102 TimerBase::~TimerBase() 103 103 { 104 if (this->executor_) 105 delete this->executor_; 104 this->deleteExecutor(); 106 105 } 107 106 … … 112 111 { 113 112 (*this->executor_)(); 113 } 114 115 /** 116 @brief Deletes the executor. 117 */ 118 void TimerBase::deleteExecutor() 119 { 120 if (this->executor_) 121 delete this->executor_; 114 122 } 115 123 -
code/branches/input/src/orxonox/tools/Timer.h
r1535 r1629 78 78 79 79 void run() const; 80 void deleteExecutor(); 80 81 81 82 /** @brief Starts the Timer: Function-call after 'interval' seconds. */ … … 94 95 inline bool isActive() const 95 96 { return this->bActive_; } 97 /** @brief Returns the remaining time until the Timer calls the function. @return The remaining time */ 98 inline float getRemainingTime() const 99 { return this->time_; } 96 100 /** @brief Gives the Timer some extra time. @param time The amount of extra time in seconds */ 97 101 inline void addTime(float time) … … 149 153 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor) 150 154 { 155 this->deleteExecutor(); 156 151 157 this->interval_ = interval; 152 158 this->bLoop_ = bLoop; … … 185 191 void setTimer(float interval, bool bLoop, ExecutorStatic* executor) 186 192 { 193 this->deleteExecutor(); 194 187 195 this->interval_ = interval; 188 196 this->bLoop_ = bLoop;
Note: See TracChangeset
for help on using the changeset viewer.