Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 27, 2008, 8:07:29 AM (17 years ago)
Author:
rgrieder
Message:

updated input branch

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  
    33  Main.cc
    44  Orxonox.cc
     5  Radar.cc
     6  RadarListener.cc
     7  RadarViewable.cc
    58  Settings.cc
    69
    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
    1424  tolua/tolua_bind.cc
    1525
     
    1727  tools/Light.cc
    1828  tools/Mesh.cc
     29  tools/ParticleInterface.cc
     30  tools/TextureGenerator.cc
    1931  tools/Timer.cc
     32  tools/WindowEventListener.cc
    2033
    2134  objects/Ambient.cc
     35  objects/Backlight.cc
    2236  objects/Camera.cc
    2337  objects/CameraHandler.cc
    24   objects/Explosion.cc
    2538  objects/Model.cc
    2639  objects/NPC.cc
    27   objects/Projectile.cc
    28   objects/RotatingProjectile.cc
     40  objects/ParticleSpawner.cc
    2941  objects/Skybox.cc
    3042  objects/SpaceShip.cc
     
    3345  objects/WorldEntity.cc
    3446
    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
    4151)
    4252
    4353GET_TARGET_PROPERTY(TOLUA_EXE tolua LOCATION)
    4454ADD_CUSTOM_COMMAND(
    45   OUTPUT tolua/tolua_bind.cc tolua/tolua_bind.h
     55  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc
    4656  COMMAND ${TOLUA_EXE} -n orxonox -o ../../src/orxonox/tolua/tolua_bind.cc -H ../../src/orxonox/tolua/tolua_bind.h ../../src/orxonox/tolua/tolua.pkg
    4757  DEPENDS tolua
     
    7585  tinyxml
    7686  tolualib
    77   ois
     87  ois_orxonox
    7888  util
    7989  core
  • code/branches/input/src/orxonox/GraphicsEngine.cc

    r1538 r1629  
    5050#include "core/CommandExecutor.h"
    5151#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"
    5556#include "Settings.h"
    56 
    57 
    58 namespace orxonox {
     57#include "tools/WindowEventListener.h"
     58
     59
     60namespace orxonox
     61{
    5962  /**
    6063    @brief Returns the singleton instance and creates it the first time.
     
    7679  {
    7780    RegisterObject(GraphicsEngine);
     81
     82    this->detailLevelParticle_ = 0;
    7883
    7984    this->setConfigValues();
     
    9196    SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    9297    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_);
    93105  }
    94106
     
    424436
    425437  /**
    426   * Window has resized.
     438  * Window has moved.
    427439  * @param rw The render window it occured in
    428440  */
    429441  void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw)
    430442  {
    431     // note: this doesn't change the window extents
     443    for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)
     444      it->windowMoved();
    432445  }
    433446
     
    440453  void GraphicsEngine::windowResized(Ogre::RenderWindow *rw)
    441454  {
    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.
    451461  * @param rw The render window it occured in
    452462  */
    453463  void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw)
    454464  {
    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.
    460471  * @param rw The render window it occured in
    461472  */
    462473  void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw)
    463474  {
    464     // using CommandExecutor in order to avoid depending on Orxonox class.
     475    // using CommandExecutor in order to avoid depending on Orxonox.h.
    465476    CommandExecutor::execute("exit", false);
    466477  }
  • code/branches/input/src/orxonox/GraphicsEngine.h

    r1535 r1629  
    4747
    4848
    49 namespace orxonox {
    50 
     49namespace orxonox
     50{
    5151    /**
    5252    @brief Graphics engine manager class
     
    7272            int getWindowHeight() const;
    7373            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); }
    7681
    7782            void windowMoved       (Ogre::RenderWindow* rw);
     
    7984            void windowFocusChanged(Ogre::RenderWindow* rw);
    8085            void windowClosed      (Ogre::RenderWindow* rw);
     86
     87            inline unsigned int getDetailLevelParticle() const
     88              { return this->detailLevelParticle_; }
    8189
    8290            static GraphicsEngine& getSingleton();
     
    94102                             bool, const std::string&);
    95103
    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
    106117    };
    107118}
  • code/branches/input/src/orxonox/Orxonox.cc

    r1535 r1629  
    6969
    7070// objects and tools
    71 #include "hud/HUD.h"
     71#include "overlays/OverlayGroup.h"
     72#include "overlays/console/InGameConsole.h"
    7273#include "objects/Tickable.h"
     74#include "objects/Backlight.h"
     75#include "tools/ParticleInterface.h"
    7376
    7477#include "GraphicsEngine.h"
    7578#include "Settings.h"
    76 
    77 // FIXME: is this really file scope?
     79#include "Radar.h"
     80
    7881// globals for the server or client
    79 network::Client *client_g = 0;
    80 network::Server *server_g = 0;
     82static network::Client *client_g = 0;
     83static network::Server *server_g = 0;
    8184
    8285namespace orxonox
     
    9497   * Create a new instance of Orxonox. Avoid doing any actual work here.
    9598   */
    96   Orxonox::Orxonox() :
    97     ogre_(0),
    98     //auMan_(0),
    99     timer_(0),
    100     // turn on frame smoothing by setting a value different from 0
    101     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)
    108111  {
    109112  }
     
    115118  {
    116119    // 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
    119131    Loader::close();
    120     InputManager::destroy();
    121132    //if (this->auMan_)
    122133    //  delete this->auMan_;
     134    InGameConsole::getInstance().destroy();
    123135    if (this->timer_)
    124136      delete this->timer_;
     137    InputManager::destroy();
    125138    GraphicsEngine::getSingleton().destroy();
    126139
     
    159172      delete singletonRef_s;
    160173    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());
    161188  }
    162189
     
    251278        return false;
    252279
     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
    253287      // Calls the InputManager which sets up the input devices.
    254288      // The render window width and height are used to set up the mouse movement.
     
    257291        return false;
    258292
    259       // TODO: Spread this so that this call only initialises things needed for the GUI
    260       if (!ogre_->initialiseResources())
    261         return false;
    262 
    263293      // TOOD: load the GUI here
    264294      // set InputManager to GUI mode
     
    303333  /**
    304334   * Loads everything in the scene except for the actual objects.
    305    * This includes HUD, Console..
     335   * This includes HUD, audio..
    306336   */
    307337  bool Orxonox::loadPlayground()
     
    316346
    317347    // 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
    320355    return true;
    321356  }
     
    326361  bool Orxonox::serverLoad()
    327362  {
    328     COUT(2) << "Loading level in server mode" << std::endl;
     363    COUT(0) << "Loading level in server mode" << std::endl;
    329364
    330365    //server_g = new network::Server(serverPort_);
     
    344379  bool Orxonox::clientLoad()
    345380  {
    346     COUT(2) << "Loading level in client mode" << std::endl;\
     381    COUT(0) << "Loading level in client mode" << std::endl;\
    347382
    348383    if (serverIp_.compare("") == 0)
     
    364399  bool Orxonox::standaloneLoad()
    365400  {
    366     COUT(2) << "Loading level in standalone mode" << std::endl;
     401    COUT(0) << "Loading level in standalone mode" << std::endl;
    367402
    368403    if (!loadScene())
     
    377412  bool Orxonox::loadScene()
    378413  {
    379     Level* startlevel = new Level("levels/sample.oxw");
    380     Loader::open(startlevel);
    381    
     414    startLevel_ = new Level("levels/sample.oxw");
     415    Loader::open(startLevel_);
     416
    382417    return true;
    383418  }
     
    403438
    404439
    405     // Contains the times of recently fired events
    406     // eventTimes[4] is the list for the times required for the fps counter
    407     std::deque<unsigned long> eventTimes[3];
    408     // Clear event times
    409     for (int i = 0; i < 3; ++i)
    410       eventTimes[i].clear();
    411 
    412440    // use the ogre timer class to measure time.
    413441    if (!timer_)
    414442      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
    415458    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;
    428459    while (!bAbort_)
    429460    {
    430461      // 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
    450470      // Call those objects that need the real time
    451471      for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
    452         it->tick((float)evt.timeSinceLastFrame);
     472        it->tick(dt);
    453473      // Call the scene objects
    454474      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
    457478      if (client_g)
    458         client_g->tick((float)evt.timeSinceLastFrame);
     479        client_g->tick(dt * this->timefactor_);
    459480      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
    461499
    462500      // don't forget to call _fireFrameStarted in ogre to make sure
    463501      // everything goes smoothly
     502      Ogre::FrameEvent evt;
     503      evt.timeSinceLastFrame = dt;
     504      evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
    464505      ogreRoot._fireFrameStarted(evt);
    465 
    466       // get current time
    467       now = timer_->getMilliseconds();
    468       calculateEventTime(now, eventTimes[2]);
    469506
    470507      if (mode_ != DEDICATED)
     
    473510        // This calls the WindowEventListener objects.
    474511        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);
    475515
    476516        // render
     
    478518      }
    479519
    480       // get current time
    481       now = timer_->getMilliseconds();
    482 
    483       // create an event to pass to the frameEnded method in ogre
    484       evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
    485       renderTime += calculateEventTime(now, eventTimes[2]);
    486 
    487520      // 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;
    490524    }
    491525
     
    497531    return true;
    498532  }
    499 
    500   /**
    501     Method for calculating the average time between recently fired events.
    502     Code directly taken from OgreRoot.cc
    503     @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> &times)
    507   {
    508     // Calculate the average time passed between events of the given type
    509     // 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 kept
    517     unsigned long discardThreshold = (unsigned long)(frameSmoothingTime_ * 1000.0f);
    518 
    519     // Find the oldest time to keep
    520     std::deque<unsigned long>::iterator it  = times.begin();
    521     // We need at least two times
    522     std::deque<unsigned long>::iterator end = times.end() - 2;
    523 
    524     while(it != end)
    525     {
    526       if (now - *it > discardThreshold)
    527         ++it;
    528       else
    529         break;
    530     }
    531 
    532     // Remove old times
    533     times.erase(times.begin(), it);
    534 
    535     return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000);
    536   }
    537533}
  • code/branches/input/src/orxonox/Orxonox.h

    r1535 r1629  
    6262
    6363      void abortRequest();
    64       //inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
    6564
    6665      static Orxonox* getSingleton();
    6766      static void destroySingleton();
    6867
    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);
    7170      static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; }
    7271      static inline void exit() { Orxonox::getSingleton()->abortRequest(); }
     
    9392    private:
    9493      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)
    9597      //audio::AudioManager*  auMan_;         //!< audio manager
    9698      Ogre::Timer*          timer_;         //!< Main loop timer
    97       // TODO: make this a config-value by creating a config class for orxonox
    98       float                 frameSmoothingTime_;
    99       HUD*                  orxonoxHUD_;
    10099      bool                  bAbort_;        //!< aborts the render loop if true
    101100      float                 timefactor_;    //!< A factor to change the gamespeed
  • code/branches/input/src/orxonox/OrxonoxPrereqs.h

    r1505 r1629  
    6060//-----------------------------------------------------------------------
    6161
    62 namespace orxonox {
    63   class GraphicsEngine;
    64   class Orxonox;
     62namespace orxonox
     63{
     64    namespace LODParticle
     65    {
     66        enum LOD
     67        {
     68            off = 0,
     69            low = 1,
     70            normal = 2,
     71            high = 3
     72        };
     73    }
    6574
    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;
    7877
    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;
    8581
    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;
    9394
    94   // particle
    95   class ParticleInterface;
     95    class Projectile;
     96    class BillboardProjectile;
     97    class RotatingProjectile;
     98    class ParticleProjectile;
    9699
    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;
    103107
    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;
    106120}
    107121
     122namespace Ogre
     123{
     124    // some got forgotten in OgrePrerequisites
     125    class BorderPanelOverlayElement;
     126    class PanelOverlayElement;
     127    class TextAreaOverlayElement;
     128}
    108129
    109130#endif /* _OrxonoxPrereqs_H__ */
  • code/branches/input/src/orxonox/OrxonoxStableHeaders.h

    r1543 r1629  
    3737#include "util/OrxonoxPlatform.h"
    3838
    39 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     39#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && 0
    4040
    4141// including std headers here is useless since they're already precompiled
     
    112112#include "network/Synchronisable.h"
    113113
    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"
    119119
    120120#endif /* Compiler MSVC */
  • code/branches/input/src/orxonox/objects/Ambient.cc

    r1505 r1629  
    7373     
    7474    }
    75    
    76     void Ambient::loadParams(TiXmlElement* xmlElem)
     75
     76    void Ambient::setAmbientLight(const ColourValue& colour)
    7777    {
    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);
    9679      ambientLight_=colour;     
    97    }
     80    }
    9881
    9982    /**
  • code/branches/input/src/orxonox/objects/Ambient.h

    r1505 r1629  
    4444            virtual ~Ambient();
    4545
    46             void loadParams(TiXmlElement* xmlElem);
    4746            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4847            void setAmbientLight(const ColourValue& colour);
  • code/branches/input/src/orxonox/objects/Model.cc

    r1511 r1629  
    5353    Model::~Model()
    5454    {
     55        if (this->isInitialized() && (this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
     56            this->detachObject(this->mesh_.getEntity());
    5557    }
    5658
    5759    /**
    5860        @brief XML loading and saving.
    59     @p
    60     aram xmlelement The XML-element
     61        @param xmlelement The XML-element
    6162        @param loading Loading (true) or saving (false)
    6263        @return The XML-element
     
    9495      registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING);
    9596    }
     97
     98    void Model::changedVisibility()
     99    {
     100        WorldEntity::changedVisibility();
     101        if (this->isInitialized())
     102            this->mesh_.setVisible(this->isVisible());
     103    }
    96104}
  • code/branches/input/src/orxonox/objects/Model.h

    r1505 r1629  
    4444            virtual ~Model();
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void changedVisibility();
    4647            void setMesh(const std::string& meshname);
    4748            virtual bool create();
  • code/branches/input/src/orxonox/objects/NPC.cc

    r1505 r1629  
    4545  NPC::~NPC()
    4646  {
    47   }
    48 
    49   void NPC::loadParams(TiXmlElement* xmlElem)
    50   {
    51     Model::loadParams(xmlElem);
    5247  }
    5348
  • code/branches/input/src/orxonox/objects/NPC.h

    r1505 r1629  
    4848      NPC();
    4949      virtual ~NPC();
    50       virtual void loadParams(TiXmlElement* xmlElem);
    5150      void tick(float dt);
    5251      void update();
  • code/branches/input/src/orxonox/objects/Projectile.cc

    r1505 r1629  
    3535#include "core/Executor.h"
    3636#include "core/ConfigValueIncludes.h"
     37#include "tools/ParticleInterface.h"
    3738
    38 #include "SpaceShip.h"
    39 #include "Explosion.h"
     39#include "SpaceShipAI.h"
     40#include "ParticleSpawner.h"
    4041#include "Model.h"
    4142
    4243namespace orxonox
    4344{
    44     CreateFactory(Projectile);
     45    float Projectile::speed_ = 5000;
    4546
    46     float Projectile::speed_ = 0;
    47 
    48     Projectile::Projectile(SpaceShip* owner) :
    49       owner_(owner)
     47    Projectile::Projectile(SpaceShip* owner) : owner_(owner)
    5048    {
    5149        RegisterObject(Projectile);
    5250
    5351        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";
    5854
    5955        if (this->owner_)
     
    6359            this->setPosition(this->owner_->getPosition());
    6460            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_);
    6662        }
    6763
    6864        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    69 //        COUT(3) << this->classID << std::endl;
    7065    }
    7166
     
    7671    void Projectile::setConfigValues()
    7772    {
    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");
    8076
    81         this->setVelocity(Vector3(1, 0, 0) * this->speed_);
     77        if(this->owner_)
     78          this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    8279    }
    8380
     
    8582    {
    8683        WorldEntity::tick(dt);
     84
     85        if (!this->isActive())
     86            return;
    8787
    8888        float radius;
     
    9595                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    9696                {
    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();
    99107                    delete this;
    100108                    return;
     
    108116        delete this;
    109117    }
    110 
    111     void Projectile::setColour(const ColourValue& colour)
    112     {
    113         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
    114     }
    115118}
  • code/branches/input/src/orxonox/objects/Projectile.h

    r1505 r1629  
    3333
    3434#include "WorldEntity.h"
    35 #include "../tools/BillboardSet.h"
    36 #include "../tools/Timer.h"
    37 #include "util/Math.h"
     35#include "tools/Timer.h"
    3836
    3937namespace orxonox
     
    4240    {
    4341        public:
    44             Projectile(SpaceShip* owner = 0);
    4542            virtual ~Projectile();
    4643            void setConfigValues();
    4744            void destroyObject();
    4845            virtual void tick(float dt);
    49             virtual bool create(){return WorldEntity::create();}
    50             void setColour(const ColourValue& colour);
    5146
    5247            static float getSpeed()
     
    5449
    5550        protected:
     51            Projectile(SpaceShip* owner = 0);
    5652            SpaceShip* owner_;
    5753
    5854        private:
    59             BillboardSet billboard_;
     55            std::string explosionTemplateName_;
     56            std::string smokeTemplateName_;
    6057            static float speed_;
    6158            float lifetime_;
     59            float damage_;
    6260            Timer<Projectile> destroyTimer_;
    6361    };
  • code/branches/input/src/orxonox/objects/RotatingProjectile.cc

    r1505 r1629  
    3737    CreateFactory(RotatingProjectile);
    3838
    39     RotatingProjectile::RotatingProjectile(SpaceShip* owner) : Projectile(owner)
     39    RotatingProjectile::RotatingProjectile(SpaceShip* owner) : BillboardProjectile(owner)
    4040    {
    4141        RegisterObject(RotatingProjectile);
     
    7373    void RotatingProjectile::tick(float dt)
    7474    {
    75         this->time_ += dt;
     75        if (this->isActive())
     76        {
     77            this->time_ += dt;
    7678
    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        }
    7982
    8083        Projectile::tick(dt);
    8184    }
     85
     86    void RotatingProjectile::changedVisibility()
     87    {
     88        BillboardProjectile::changedVisibility();
     89        this->rotatingBillboard1_.setVisible(this->isVisible());
     90        this->rotatingBillboard2_.setVisible(this->isVisible());
     91    }
    8292}
  • code/branches/input/src/orxonox/objects/RotatingProjectile.h

    r1505 r1629  
    22#define _RotatingProjectile_H__
    33
    4 #include "../OrxonoxPrereqs.h"
     4#include "OrxonoxPrereqs.h"
    55#include "util/Math.h"
    6 #include "Projectile.h"
     6#include "BillboardProjectile.h"
    77
    88namespace orxonox
    99{
    10     class _OrxonoxExport RotatingProjectile : public Projectile/*, public network::Synchronisable*/
     10    class _OrxonoxExport RotatingProjectile : public BillboardProjectile
    1111    {
    1212        public:
     
    1515            void setConfigValues();
    1616            virtual void tick(float dt);
    17             virtual bool create(){return Projectile::create();}
     17            virtual void changedVisibility();
    1818
    1919        private:
  • code/branches/input/src/orxonox/objects/Skybox.cc

    r1505 r1629  
    5454    }
    5555
    56     void Skybox::loadParams(TiXmlElement* xmlElem)
     56    void Skybox::setSkybox(const std::string& skyboxname)
    5757    {
    58         if (xmlElem->Attribute("src"))
    59         {
    60                 skyboxSrc_ = xmlElem->Attribute("src");
    61         this->create();
     58        GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(true, skyboxname);
     59    }
    6260
    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    }
    6665
    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    
    7666    /**
    7767        @brief XML loading and saving.
     
    8777        create();
    8878    }
    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();
    9384    }
    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);
    9789    }
    98    
     90
     91    void Skybox::changedVisibility()
     92    {
     93        BaseObject::changedVisibility();
     94        GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(this->isVisible(), this->skyboxSrc_);
     95    }
    9996}
  • code/branches/input/src/orxonox/objects/Skybox.h

    r1505 r1629  
    4343            virtual ~Skybox();
    4444
    45             void loadParams(TiXmlElement* xmlElem);
    4645            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void changedVisibility();
    4747            void setSkybox(const std::string& skyboxname);
    48            
     48
    4949            virtual bool create();
    5050            void registerAllVariables();
  • code/branches/input/src/orxonox/objects/SpaceShip.cc

    r1535 r1629  
    3535#include <OgreSceneNode.h>
    3636
    37 #include "CameraHandler.h"
    3837#include "util/Convert.h"
    3938#include "util/Math.h"
     39
    4040#include "core/CoreIncludes.h"
    4141#include "core/ConfigValueIncludes.h"
    4242#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"
    4843#include "core/XMLPort.h"
    4944#include "core/ConsoleCommand.h"
     45
    5046#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"
    5256
    5357namespace orxonox
     
    6973    SpaceShip* SpaceShip::instance_s;
    7074
    71    
     75
    7276    SpaceShip *SpaceShip::getLocalShip(){
    7377      Iterator<SpaceShip> it;
     
    7983    }
    8084
    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()
    11786    {
    11887        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";
    13188
    13289        this->setRotationAxis(1, 0, 0);
    13390        this->setStatic(false);
    13491
    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);
    136141    }
    137142
    138143    SpaceShip::~SpaceShip()
    139144    {
    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        }
    149163    }
    150164
     
    154168          myShip_=true;
    155169        else
    156           HUD::getSingleton().addRadarObject(this->getNode(), 3);
     170          this->setRadarObjectColour(this->getProjectileColour());
    157171      }
    158172      if(Model::create())
     
    179193    void SpaceShip::init()
    180194    {
    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
    201228
    202229        // START CREATING BLINKING LIGHTS
     
    216243        // END CREATING BLINKING LIGHTS
    217244
     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
    218260        if (this->isExactlyA(Class(SpaceShip)))
    219261        {
     
    232274            this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
    233275            this->chFarNode_->setScale(0.4, 0.4, 0.4);
     276            // END of testing crosshair
    234277        }
    235278
    236279        createCamera();
    237         // END of testing crosshair
    238280    }
    239281
     
    245287    }
    246288
     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
    247320    void SpaceShip::setCamera(const std::string& camera)
    248321    {
     322      myShip_=true; // TODO: this is only a hack
    249323      camName_=camera;
    250324      // change camera attributes here, if you want to ;)
     
    266340      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
    267341      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));
    269343//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    270344//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
     
    277351      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    278352      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0));
    279       camNode_->setOrientation(q2*q1);
     353      this->camNode_->setOrientation(q2*q1);
    280354      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){
    281355        this->setBacksync(true);
    282356        CameraHandler::getInstance()->requestFocus(cam_);
    283357      }
    284 
    285358    }
    286359
     
    318391        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    319392        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
    320         myShip_=true; // TODO: this is only a hack
    321393
    322394        SpaceShip::create();
     
    325397    }
    326398
    327     int sgn(float x)
    328     {
    329         if (x >= 0)
    330             return 1;
    331         else
    332             return -1;
    333     }
    334 
    335399    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    }
    350404
    351405    void SpaceShip::tick(float dt)
    352406    {
     407        if (!this->isActive())
     408            return;
     409
    353410        currentDir_ = getOrientation()*initialDir_;
    354                 currentOrth_ = getOrientation()*initialOrth_;
     411        currentOrth_ = getOrientation()*initialOrth_;
    355412
    356413        if (this->cam_)
    357414            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        }
    358428
    359429        if (this->redNode_ && this->greenNode_)
     
    374444        {
    375445
    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            {
    384451              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
    385 
    386             p->setBacksync(true);
     452            }
     453
     454            projectile->setBacksync(true);
    387455            this->timeToReload_ = this->reloadTime_;
    388456        }
     
    464532
    465533        if (this->acceleration_.x > 0)
    466             this->tt_->setRate(emitterRate_);
     534        {
     535            this->tt1_->setEnabled(true);
     536            this->tt2_->setEnabled(true);
     537        }
    467538        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;
    481551    }
    482552
  • code/branches/input/src/orxonox/objects/SpaceShip.h

    r1535 r1629  
    3636#include "Camera.h"
    3737#include "Model.h"
     38#include "RadarViewable.h"
    3839#include "tools/BillboardSet.h"
    3940
    4041namespace orxonox
    4142{
    42     class _OrxonoxExport SpaceShip : public Model
     43    class _OrxonoxExport SpaceShip : public Model, public RadarViewable
    4344    {
    4445        public:
    45          
    46 
    4746            static SpaceShip *getLocalShip();
    4847
     
    5554            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5655            virtual void tick(float dt);
     56            virtual void changedVisibility();
     57            virtual void changedActivity();
    5758
    5859            void setCamera(const std::string& camera = "");
     
    6566            void setRotDamp(float value);
    6667            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_; }
    6783
    6884            static std::string whereAmI();
     
    8399            void doFire();
    84100
    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
    88110            Camera* getCamera();
    89111
    90112            int getTeamNr() const
    91113                { return this->teamNr_; }
    92             int getHealth() const
     114            float getHealth() const
    93115                { return this->health_; }
    94116
     
    110132            Vector3 currentOrth_;
    111133            bool bInvertYAxis_;
    112             bool setMouseEventCallback_;
    113134            bool bLMousePressed_;
    114135            bool bRMousePressed_;
     
    118139            std::string camName_;
    119140
     141            ParticleInterface* tt1_;
     142            ParticleInterface* tt2_;
     143            BillboardSet leftThrusterFlare_;
     144            BillboardSet rightThrusterFlare_;
    120145
    121             ParticleInterface* tt_;
     146            Backlight* backlight_;
    122147
    123148            BillboardSet redBillboard_;
     
    126151            Ogre::SceneNode* greenNode_;
    127152            float blinkTime_;
     153
     154            ParticleSpawner* smoke_;
     155            ParticleSpawner* fire_;
    128156
    129157            BillboardSet crosshairNear_;
     
    153181            float mouseY_;
    154182
    155             float emitterRate_;
    156 
    157183        protected:
    158184            bool myShip_;
    159185
    160186            int teamNr_;
    161             int health_;
     187            float health_;
    162188
    163189            static SpaceShip* instance_s;
  • code/branches/input/src/orxonox/objects/SpaceShipAI.cc

    r1505 r1629  
    3232#include <OgreMath.h>
    3333#include "Projectile.h"
     34#include "ParticleSpawner.h"
    3435#include "core/CoreIncludes.h"
    3536#include "core/Iterator.h"
     
    3738#include "core/ConsoleCommand.h"
    3839#include "core/XMLPort.h"
     40#include "tools/ParticleInterface.h"
    3941
    4042#define ACTION_INTERVAL 1.0f
     
    5153        RegisterObject(SpaceShipAI);
    5254
    53         this->alive_ = true;
    54         this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000)));
    5555        this->target_ = 0;
    5656        this->bShooting_ = 0;
     
    7070    }
    7171
     72    SpaceShipAI::~SpaceShipAI()
     73    {
     74        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ++it)
     75            it->shipDied(this);
     76    }
     77
    7278    void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7379    {
    7480        SpaceShip::XMLPort(xmlelement, mode);
    75         myShip_=true;
    7681
    7782        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action)));
     
    8590            newenemy->setMesh("assff.mesh");
    8691//            newenemy->setPosition(0, 0, 0);
     92            newenemy->setPosition(Vector3(rnd(-3000, 3000), rnd(-3000, 3000), rnd(-3000, 3000)));
    8793            newenemy->setScale(10);
    8894            newenemy->setMaxSpeed(500);
     
    95101            Element xmlelement;
    96102            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();
    97107        }
    98108    }
     
    103113        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; )
    104114        {
    105             delete *(it++);
    106             ++i;
     115            (it++)->kill();
    107116            if (num && i >= num)
    108117                break;
     
    122131        // search enemy
    123132        random = rnd(maxrand);
    124 //std::cout << "search enemy: " << random << std::endl;
    125         if (random < 20 && (!this->target_))
    126         {
     133        if (random < 15 && (!this->target_))
    127134            this->searchNewTarget();
    128         }
    129135
    130136        // forget enemy
    131137        random = rnd(maxrand);
    132 //std::cout << "forget enemy: " << random << std::endl;
    133138        if (random < 5 && (this->target_))
    134         {
    135139            this->forgetTarget();
    136         }
    137140
    138141        // next enemy
    139142        random = rnd(maxrand);
    140 //std::cout << "next enemy: " << random << std::endl;
    141143        if (random < 10 && (this->target_))
    142         {
    143144            this->searchNewTarget();
    144         }
    145145
    146146        // fly somewhere
    147147        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_))
    151149            this->searchNewTargetPosition();
    152         }
    153150
    154151        // stop flying
    155152        random = rnd(maxrand);
    156 //std::cout << "stop flying: " << random << std::endl;
    157153        if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    158         {
    159154            this->bHasTargetPosition_ = false;
    160         }
    161155
    162156        // fly somewhere else
    163157        random = rnd(maxrand);
    164 //std::cout << "fly somewhere else: " << random << std::endl;
    165158        if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    166         {
    167159            this->searchNewTargetPosition();
    168         }
    169160
    170161        // shoot
    171162        random = rnd(maxrand);
    172 //std::cout << "shoot: " << random << std::endl;
    173163        if (random < 75 && (this->target_ && !this->bShooting_))
    174         {
    175164            this->bShooting_ = true;
    176         }
    177165
    178166        // stop shooting
    179167        random = rnd(maxrand);
    180 //std::cout << "stop shooting: " << random << std::endl;
    181168        if (random < 25 && (this->bShooting_))
    182         {
    183169            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;
    185215    }
    186216
    187217    void SpaceShipAI::tick(float dt)
    188218    {
     219        if (!this->isActive())
     220            return;
     221
    189222        if (this->target_)
    190223            this->aimAtTarget();
     
    193226            this->moveToTargetPosition(dt);
    194227
    195         if (this->bShooting_ && this->isCloseAtTarget(2000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f))
     228        if (this->bShooting_ && this->isCloseAtTarget(2500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
    196229            this->doFire();
    197230
     
    201234    void SpaceShipAI::moveToTargetPosition(float dt)
    202235    {
    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);
    222252    }
    223253
     
    241271                Vector3 distanceNew = it->getPosition() - this->getPosition();
    242272                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))
    244274                {
    245275                    this->target_ = (*it);
     
    248278            }
    249279        }
    250    }
     280    }
    251281
    252282    void SpaceShipAI::forgetTarget()
     
    260290        if (!this->target_)
    261291            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);
    282295    }
    283296
    284297    bool SpaceShipAI::isCloseAtTarget(float distance)
    285298    {
    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);
    287303    }
    288304
    289305    bool SpaceShipAI::isLookingAtTarget(float angle)
    290306    {
    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        }
    292317    }
    293318}
  • code/branches/input/src/orxonox/objects/SpaceShipAI.h

    r1505 r1629  
    4444        public:
    4545            SpaceShipAI();
     46            virtual ~SpaceShipAI();
     47
    4648            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4749            static void createEnemy(int num);
    4850            static void killEnemies(int num);
     51            void shipDied(SpaceShipAI* ship);
     52            void damage(float damage);
     53            void kill();
    4954
    5055        private:
     
    6469            Timer<SpaceShipAI> actionTimer_;
    6570
    66             bool alive_;
    6771            bool bHasTargetPosition_;
    6872            Vector3 targetPosition_;
  • code/branches/input/src/orxonox/objects/WorldEntity.cc

    r1505 r1629  
    4545    unsigned int WorldEntity::worldEntityCounter_s = 0;
    4646
    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()
    5548    {
    5649        RegisterObject(WorldEntity);
     
    5851        if (GraphicsEngine::getSingleton().getSceneManager())
    5952        {
    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());
    6457
    65           registerAllVariables();
     58            registerAllVariables();
    6659        }
     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;
    6771    }
    68    
     72
    6973
    7074    WorldEntity::~WorldEntity()
    7175    {
    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        }
    7581    }
    7682
    7783    void WorldEntity::tick(float dt)
    7884    {
    79         if (!this->bStatic_)
     85        if (!this->bStatic_ && this->isActive())
    8086        {
    8187//             COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl;
     
    8995    }
    9096
    91     void WorldEntity::loadParams(TiXmlElement* xmlElem)
    92     {
    93 
    94         BaseObject::loadParams(xmlElem);
    95         create();
    96     }
    97    
    9897
    9998    void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
     
    122121
    123122        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
    124        
     123
    125124        WorldEntity::create();
    126125    }
     
    129128    void WorldEntity::registerAllVariables()
    130129    {
     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);
    131133      // register coordinates
    132134      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3);
     
    163165    {
    164166        this->attachedWorldEntities_.push_back(entity);
     167        this->attachObject(entity);
    165168    }
    166169
     
    172175            return 0;
    173176    }
     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    }
    174189}
  • code/branches/input/src/orxonox/objects/WorldEntity.h

    r1535 r1629  
    5151
    5252            virtual void tick(float dt);
    53             virtual void loadParams(TiXmlElement* xmlElem);
    5453            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5554            virtual inline bool create(){ return Synchronisable::create(); }
     
    5857            const WorldEntity* getAttachedWorldEntity(unsigned int index) const;
    5958
    60             inline Ogre::SceneNode* getNode()
     59            inline Ogre::SceneNode* getNode() const
    6160                { return this->node_; }
    6261
     
    7473            inline const Vector3& getPosition() const
    7574                { 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)
    7879                { this->node_->translate(d, relativeTo); }
    7980            inline void translate(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    8081                { 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)
    8283                { 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)
    8485                { this->node_->translate(axes, x, y, z, relativeTo); }
    8586
    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)
    8788                { 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)
    8990                { 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)
    9192                { this->node_->roll(angle, relativeTo); }
    9293            void setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll);
    9394
    94             inline void setYaw(const Degree &angle)
     95            inline void setYaw(const Degree& angle)
    9596                { this->node_->yaw(angle, Ogre::Node::TS_LOCAL); }
    96             inline void setPitch(const Degree &angle)
     97            inline void setPitch(const Degree& angle)
    9798                { this->node_->pitch(angle, Ogre::Node::TS_LOCAL); }
    98             inline void setRoll(const Degree &angle)
     99            inline void setRoll(const Degree& angle)
    99100                { this->node_->roll(angle, Ogre::Node::TS_LOCAL); }
    100101
    101102            inline const Ogre::Quaternion& getOrientation()
    102103              { return this->node_->getOrientation(); }
     104            inline const Ogre::Quaternion& getWorldOrientation()
     105              { return this->node_->getWorldOrientation(); }
    103106            inline void setOrientation(const Ogre::Quaternion& quat)
    104107              { 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)
    106109              { this->node_->rotate(axis, angle, relativeTo); }
    107110            inline void setDirectionLoader(Real x, Real y, Real z)
    108111              { 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)
    110113              { 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)
    112115              { 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)
    114117              { this->node_->lookAt(targetPoint, relativeTo, localDirectionVector); }
    115118
    116             inline void setScale(const Vector3 &scale)
     119            inline void setScale(const Vector3& scale)
    117120              { this->node_->setScale(scale); }
    118121            inline void setScale(Real x, Real y, Real z)
     
    124127            inline const Vector3& getScale(void) const
    125128              { return this->node_->getScale(); }
    126             inline void scale(const Vector3 &scale)
     129            inline void scale(const Vector3& scale)
    127130              { this->node_->scale(scale); }
    128131            inline void scale(Real x, Real y, Real z)
     
    131134              { this->node_->scale(scale, scale, scale); }
    132135
    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
    134139              { this->node_->attachObject(obj); }
    135             inline void attachObject(Mesh &mesh)
     140            inline void attachObject(Mesh& mesh) const
    136141              { this->node_->attachObject(mesh.getEntity()); }
    137             inline void detachObject(Ogre::MovableObject *obj)
     142            inline void detachObject(Ogre::MovableObject* obj) const
    138143              { this->node_->detachObject(obj); }
    139             inline void detachAllObjects()
     144            inline void detachAllObjects() const
    140145              { this->node_->detachAllObjects(); }
    141146
     
    179184            inline void setStatic(bool bStatic)
    180185                { this->bStatic_ = bStatic; }
    181             inline bool isStatic()
     186            inline bool isStatic() const
    182187                { return this->bStatic_; }
    183188
  • code/branches/input/src/orxonox/tools/BillboardSet.cc

    r1505 r1629  
    4646    }
    4747
    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)
    4976    {
    5077        std::ostringstream name;
  • code/branches/input/src/orxonox/tools/BillboardSet.h

    r1505 r1629  
    3333
    3434#include <string>
     35#include <OgreBillboardSet.h>
    3536
    36 #include <OgreBillboardSet.h>
    3737#include "util/Math.h"
    3838
     
    4444            BillboardSet();
    4545            ~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);
    4750
    4851            inline Ogre::BillboardSet* getBillboardSet()
     
    5154            inline const std::string& getName() const
    5255                { 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(); }
    5361
    5462        private:
  • code/branches/input/src/orxonox/tools/Mesh.h

    r1505 r1629  
    5151                { return this->entity_->getName(); }
    5252
     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
    5358        private:
    5459            static unsigned int meshCounter_s;
  • code/branches/input/src/orxonox/tools/Timer.cc

    r1505 r1629  
    102102    TimerBase::~TimerBase()
    103103    {
    104       if (this->executor_)
    105           delete this->executor_;
     104        this->deleteExecutor();
    106105    }
    107106
     
    112111    {
    113112        (*this->executor_)();
     113    }
     114
     115    /**
     116        @brief Deletes the executor.
     117    */
     118    void TimerBase::deleteExecutor()
     119    {
     120      if (this->executor_)
     121          delete this->executor_;
    114122    }
    115123
  • code/branches/input/src/orxonox/tools/Timer.h

    r1535 r1629  
    7878
    7979            void run() const;
     80            void deleteExecutor();
    8081
    8182            /** @brief Starts the Timer: Function-call after 'interval' seconds. */
     
    9495            inline bool isActive() const
    9596                { 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_; }
    96100            /** @brief Gives the Timer some extra time. @param time The amount of extra time in seconds */
    97101            inline void addTime(float time)
     
    149153            void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor)
    150154            {
     155                this->deleteExecutor();
     156
    151157                this->interval_ = interval;
    152158                this->bLoop_ = bLoop;
     
    185191            void setTimer(float interval, bool bLoop, ExecutorStatic* executor)
    186192            {
     193                this->deleteExecutor();
     194
    187195                this->interval_ = interval;
    188196                this->bLoop_ = bLoop;
Note: See TracChangeset for help on using the changeset viewer.