Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (17 years ago)
Author:
rgrieder
Message:
  • @everyone: Do not create a branch until I've added the svn:eol-style property correctly. Otherwise this would cost me another 4 hours or so when we want to merge back.
  • merged network branch back to trunk
  • I had to omit the changes from last evening concerning the line endings
  • might not work yet because of the line endings
  • @beni: script branch is the only branch still open. you probably will have to apply a patch because of inconsistent new lines
Location:
code/trunk/src/orxonox
Files:
1 deleted
43 edited
6 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/CMakeLists.txt

    r1407 r1502  
    99  hud/RadarOverlayElement.cc
    1010  hud/RadarObject.cc
     11  hud/Navigation.cc
    1112  particle/ParticleInterface.cc
    1213  tolua/tolua_bind.cc
     
    2425  objects/NPC.cc
    2526  objects/Projectile.cc
     27  objects/RotatingProjectile.cc
    2628  objects/Skybox.cc
    2729  objects/SpaceShip.cc
     30  objects/SpaceShipAI.cc
    2831  objects/WorldEntity.cc
    2932
  • code/trunk/src/orxonox/GraphicsEngine.cc

    r1349 r1502  
    4545#include "core/Debug.h"
    4646#include "core/CommandExecutor.h"
    47 
     47#include "core/TclBind.h"
     48#include "console/InGameConsole.h"
     49
     50#include "core/ConsoleCommand.h"
     51#include <OgreSceneManager.h>
     52#include <OgreCompositorManager.h>
     53#include <OgreViewport.h>
    4854
    4955namespace orxonox {
    50 
    5156  /**
    5257    @brief Returns the singleton instance and creates it the first time.
     
    8388    SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    8489    SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
     90
     91    TclBind::getInstance().setDataPath(this->dataPath_);
    8592  }
    8693
     
    137144#endif
    138145
    139 /*    // create a logManager
     146// TODO: LogManager doesn't work on specific systems. The why is unknown yet.
     147#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     148    // create a logManager
    140149    // note: If there's already a logManager, Ogre will complain by a failed assertation.
    141150    // but that shouldn't happen, since this is the first time to create a logManager..
     
    148157      myLog = logger->createLog("ogre.log", true, false, true);
    149158    else
    150           myLog = logger->createLog(this->ogreLogfile_, true, false, false);
     159      myLog = logger->createLog(this->ogreLogfile_, true, false, false);
    151160    CCOUT(4) << "Ogre Log created" << std::endl;
    152161
    153162    myLog->setLogDetail(Ogre::LL_BOREME);
    154     myLog->addListener(this);*/
     163    myLog->addListener(this);
     164#endif
    155165
    156166    // Root will detect that we've already created a Log
    157167    CCOUT(4) << "Creating Ogre Root..." << std::endl;
    158     root_ = new Ogre::Root(plugin_filename);
     168
     169    root_ = new Ogre::Root(plugin_filename, "ogre.cfg", this->ogreLogfile_);
     170
     171#if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32
     172    // tame the ogre ouput so we don't get all the mess in the console
     173    Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
     174    defaultLog->setDebugOutputEnabled(false);
     175    defaultLog->setLogDetail(Ogre::LL_BOREME);
     176    defaultLog->addListener(this);
     177#endif
     178
    159179    CCOUT(4) << "Creating Ogre Root done" << std::endl;
    160180
     
    241261  bool GraphicsEngine::createNewScene()
    242262  {
    243     CCOUT(4) << "Creating new SceneManager" << std::endl;
     263    CCOUT(4) << "Creating new SceneManager..." << std::endl;
    244264    if (scene_)
    245265    {
     
    291311    else
    292312      return 0;
     313  }
     314
     315  /**
     316    @brief Returns the window aspect ratio height/width.
     317    @return The ratio
     318  */
     319  float GraphicsEngine::getWindowAspectRatio() const
     320  {
     321    if (this->renderWindow_)
     322        return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth();
     323    else
     324        return 1.0f;
    293325  }
    294326
     
    345377    int h = rw->getHeight();
    346378    InputManager::setWindowExtents(w, h);
     379    InGameConsole::getInstance().resize();
    347380  }
    348381
     
    365398    CommandExecutor::execute("exit", false);
    366399  }
     400
     401  //HACK!!
     402  /*SetConsoleCommandShortcut(GraphicsEngine, CompositorBloomOn).setAccessLevel(AccessLevel::User);
     403  SetConsoleCommandShortcut(GraphicsEngine, CompositorMotionBlurOn).setAccessLevel(AccessLevel::User);
     404  SetConsoleCommandShortcut(GraphicsEngine, CompositorBloomOff).setAccessLevel(AccessLevel::User);
     405  SetConsoleCommandShortcut(GraphicsEngine, CompositorMotionBlurOff).setAccessLevel(AccessLevel::User);
     406  void GraphicsEngine::CompositorBloomOn()
     407  {
     408    Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     409    Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     410    Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom");
     411    Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Bloom", true);
     412  }
     413  void GraphicsEngine::CompositorBloomOff()
     414  {
     415    Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     416    Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     417    Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Bloom", false);
     418  }
     419
     420  void GraphicsEngine::CompositorMotionBlurOn()
     421  {
     422    Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     423    Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     424    Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur");
     425    Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "MotionBlur", true);
     426  }
     427  void GraphicsEngine::CompositorMotionBlurOff()
     428  {
     429    Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     430    Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     431    Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "MotionBlur", false);
     432  }*/
    367433}
  • code/trunk/src/orxonox/GraphicsEngine.h

    r1293 r1502  
    7272            int getWindowWidth() const;
    7373            int getWindowHeight() const;
     74            float getWindowAspectRatio() const;
     75            float getAverageFPS() const
     76            { if (renderWindow_) return this->renderWindow_->getAverageFPS(); else return 0.0f; }
    7477
    7578            void windowMoved       (Ogre::RenderWindow* rw);
     
    8083            static GraphicsEngine& getSingleton();
    8184            static GraphicsEngine* getSingletonPtr() { return &getSingleton(); }
     85
     86            //HACK!!!
     87            //void static CompositorBloomOn();
     88            //void static CompositorBloomOff();
     89            //void static CompositorMotionBlurOn();
     90            //void static CompositorMotionBlurOff();
     91
    8292
    8393        private:
  • code/trunk/src/orxonox/Main.cc

    r1293 r1502  
    3636#include <exception>
    3737
    38 #include "OrxonoxPlatform.h"
     38#include "util/OrxonoxPlatform.h"
    3939#include "core/SignalHandler.h"
    4040#include "Orxonox.h"
  • code/trunk/src/orxonox/Orxonox.cc

    r1407 r1502  
    5151//#include "util/Sleep.h"
    5252#include "util/ArgReader.h"
    53 #include "util/ExprParser.h"
    5453
    5554// core
     
    5756#include "core/ConsoleCommand.h"
    5857#include "core/Debug.h"
    59 #include "core/Factory.h"
    6058#include "core/Loader.h"
    6159#include "core/Tickable.h"
    62 #include "core/InputBuffer.h"
    6360#include "core/InputManager.h"
    6461#include "core/TclBind.h"
     
    7269
    7370// objects and tools
    74 #include "tools/Timer.h"
    7571#include "hud/HUD.h"
    76 #include "console/InGameConsole.h"
     72#include <Ogre.h>
     73
     74#include "GraphicsEngine.h"
    7775
    7876// FIXME: is this really file scope?
     
    8381namespace orxonox
    8482{
    85   ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None).setKeybindMode(KeybindMode::OnPress);
    86   ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0)
    87     .setAxisParamIndex(0).setIsAxisRelative(false);
    88   ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0);
    89   ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None);
    90   class Testconsole : public InputBufferListener
    91   {
    92     public:
    93       Testconsole(InputBuffer* ib) : ib_(ib) {}
    94       void listen() const
    95       {
    96         std::cout << "> " << this->ib_->get() << std::endl;
    97       }
    98       void execute() const
    99       {
    100         std::cout << ">> " << this->ib_->get() << std::endl;
    101         if (!CommandExecutor::execute(this->ib_->get()))
    102           std::cout << "Error" << std::endl;
    103         this->ib_->clear();
    104       }
    105       void hintandcomplete() const
    106       {
    107         std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl;
    108         this->ib_->set(CommandExecutor::complete(this->ib_->get()));
    109       }
    110       void clear() const
    111       {
    112         this->ib_->clear();
    113       }
    114       void removeLast() const
    115       {
    116         this->ib_->removeLast();
    117       }
    118       void exit() const
    119       {
    120         InputManager::setInputState(InputManager::IS_NORMAL);
    121       }
    122 
    123     private:
    124       InputBuffer* ib_;
    125   };
    126 
    127   class Calculator
    128   {
    129   public:
    130     static float calculate(const std::string& calculation)
    131     {
    132       ExprParser expr(calculation);
    133       if (expr.getSuccess())
    134       {
    135         if (expr.getResult() == 42.0)
    136           std::cout << "Greetings from the restaurant at the end of the universe." << std::endl;
    137         // FIXME: insert modifier to display in full precision
    138         std::cout << "Result is: " << expr.getResult() << std::endl;
    139         if (expr.getRemains() != "")
    140           std::cout << "Warning: Expression could not be parsed to the end! Remains: '"
    141               << expr.getRemains() << "'" << std::endl;
    142         return expr.getResult();
    143       }
    144       else
    145       {
    146         std::cout << "Cannot calculate expression: Parse error" << std::endl;
    147         return 0;
    148       }
    149     }
    150   };
    151   ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None);
     83  SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress);
     84  SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false);
     85  SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0);
    15286
    15387  /**
     
    16599    // turn on frame smoothing by setting a value different from 0
    166100    frameSmoothingTime_(0.0f),
    167     orxonoxConsole_(0),
    168101    orxonoxHUD_(0),
    169102    bAbort_(false),
    170103    timefactor_(1.0f),
    171104    mode_(STANDALONE),
    172     serverIp_("")
     105    serverIp_(""),
     106    serverPort_(NETWORK_PORT)
    173107  {
    174108  }
     
    180114  {
    181115    // keep in mind: the order of deletion is very important!
    182     if (this->orxonoxHUD_)
    183       delete this->orxonoxHUD_;
     116//    if (this->orxonoxHUD_)
     117//      delete this->orxonoxHUD_;
    184118    Loader::close();
    185119    InputManager::destroy();
     
    244178    ar.checkArgument("data", dataPath, false);
    245179    ar.checkArgument("ip", serverIp_, false);
     180    ar.checkArgument("port", serverPort_, false);
    246181    if(ar.errorHandling())
    247182      return false;
     
    251186    else if (mode == "server")
    252187      mode_ = SERVER;
     188    else if (mode == "dedicated")
     189      mode_ = DEDICATED;
    253190    else
    254191    {
     
    265202    // procedure until the GUI is identical
    266203
    267     TclBind::getInstance().setDataPath(dataPath);
    268204    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    269205    Factory::createClassHierarchy();
     
    281217  bool Orxonox::start()
    282218  {
    283     //if (mode == DEDICATED)
    284     // do something else
    285     //else
    286 
    287     if (!ogre_->loadRenderer())    // creates the render window
    288       return false;
    289 
    290     // Calls the InputManager which sets up the input devices.
    291     // The render window width and height are used to set up the mouse movement.
    292     if (!InputManager::initialise(ogre_->getWindowHandle(),
    293           ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true))
    294       return false;
    295 
    296     // TODO: Spread this so that this call only initialises things needed for the GUI
    297     if (!ogre_->initialiseResources())
    298       return false;
    299 
    300     // TOOD: load the GUI here
    301     // set InputManager to GUI mode
    302     InputManager::setInputState(InputManager::IS_GUI);
    303     // TODO: run GUI here
    304 
    305     // The following lines depend very much on the GUI output, so they're probably misplaced here..
    306 
    307     InputManager::setInputState(InputManager::IS_NONE);
    308 
    309     if (!loadPlayground())
    310       return false;
     219    if (mode_ == DEDICATED)
     220    {
     221      // do something else
     222    }
     223    else
     224    { // not dedicated server
     225      if (!ogre_->loadRenderer())    // creates the render window
     226        return false;
     227
     228      // Calls the InputManager which sets up the input devices.
     229      // The render window width and height are used to set up the mouse movement.
     230      if (!InputManager::initialise(ogre_->getWindowHandle(),
     231            ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true))
     232        return false;
     233
     234      // TODO: Spread this so that this call only initialises things needed for the GUI
     235      if (!ogre_->initialiseResources())
     236        return false;
     237
     238      // TOOD: load the GUI here
     239      // set InputManager to GUI mode
     240      InputManager::setInputState(InputManager::IS_GUI);
     241      // TODO: run GUI here
     242
     243      // The following lines depend very much on the GUI output, so they're probably misplaced here..
     244
     245      InputManager::setInputState(InputManager::IS_NONE);
     246
     247      // create Ogre SceneManager
     248      ogre_->createNewScene();
     249
     250      if (!loadPlayground())
     251        return false;
     252    }
    311253
    312254    switch (mode_)
     
    320262        return false;
    321263      break;
     264    case DEDICATED:
     265      if (!serverLoad())
     266        return false;
     267      break;
    322268    default:
    323269      if (!standaloneLoad())
     
    336282  bool Orxonox::loadPlayground()
    337283  {
    338     ogre_->createNewScene();
    339 
    340           // Init audio
     284    // Init audio
    341285    //auMan_ = new audio::AudioManager();
    342286    //auMan_->ambientAdd("a1");
     
    348292    // Load the HUD
    349293    COUT(3) << "Orxonox: Loading HUD..." << std::endl;
    350     orxonoxHUD_ = new HUD(1);
    351 
    352     COUT(3) << "Orxonox: Loading Console..." << std::endl;
    353     InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));
    354     /*
    355     Testconsole* console = new Testconsole(ib);
    356     ib->registerListener(console, &Testconsole::listen, true);
    357     ib->registerListener(console, &Testconsole::execute, '\r', false);
    358     ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);
    359     ib->registerListener(console, &Testconsole::clear, '§', true);
    360     ib->registerListener(console, &Testconsole::removeLast, '\b', true);
    361     ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
    362     */
    363     orxonoxConsole_ = new InGameConsole(ib);
    364     ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);
    365     ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false);
    366     ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true);
    367     ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true);
    368     ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true);
    369     ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);
    370 
     294    orxonoxHUD_ = &HUD::getSingleton();
    371295    return true;
    372296  }
     
    379303    COUT(2) << "Loading level in server mode" << std::endl;
    380304
    381     server_g = new network::Server();
     305    server_g = new network::Server(serverPort_);
    382306
    383307    if (!loadScene())
     
    399323      client_g = network::Client::createSingleton();
    400324    else
    401       client_g = network::Client::createSingleton(serverIp_, NETWORK_PORT);
    402 
    403     client_g->establishConnection();
     325
     326      client_g = network::Client::createSingleton(serverIp_, serverPort_);
     327
     328    if(!client_g->establishConnection())
     329      return false;
    404330    client_g->tick(0);
    405331
     
    427353    Level* startlevel = new Level("levels/sample.oxw");
    428354    Loader::open(startlevel);
    429 
     355   
     356    // HACK: shader stuff for presentation
     357    /*Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     358    mSceneMgr->setAmbientLight(ColourValue(0.4,0.4,0.4));
     359    Ogre::Light* dirlight = mSceneMgr->createLight("Light1");
     360
     361    dirlight->setType(Ogre::Light::LT_DIRECTIONAL);
     362    dirlight->setDirection(Vector3( 0, 1, 5 ));
     363    dirlight->setDiffuseColour(ColourValue(0.6, 0.6, 0.4));
     364    dirlight->setSpecularColour(ColourValue(1.0, 1.0, 1.0));*/
     365   
    430366    return true;
    431367  }
     
    453389    // Contains the times of recently fired events
    454390    // eventTimes[4] is the list for the times required for the fps counter
    455     std::deque<unsigned long> eventTimes[4];
     391    std::deque<unsigned long> eventTimes[3];
    456392    // Clear event times
    457     for (int i = 0; i < 4; ++i)
     393    for (int i = 0; i < 3; ++i)
    458394      eventTimes[i].clear();
    459     // fill the fps time list with zeros
    460     for (int i = 0; i < 50; i++)
    461       eventTimes[3].push_back(0);
    462395
    463396    // use the ogre timer class to measure time.
     
    466399    timer_->reset();
    467400
     401    float renderTime = 0.0f;
     402    float frameTime = 0.0f;
     403    clock_t time = 0;
     404
     405    //Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     406    //Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     407   
     408    //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom");
     409    //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur");
     410
    468411    COUT(3) << "Orxonox: Starting the main loop." << std::endl;
    469           while (!bAbort_)
    470           {
    471                   // Pump messages in all registered RenderWindows
    472       // This calls the WindowEventListener objects.
    473       Ogre::WindowEventUtilities::messagePump();
    474 
     412    while (!bAbort_)
     413    {
    475414      // get current time
    476415      unsigned long now = timer_->getMilliseconds();
    477       eventTimes[3].push_back(now);
    478       eventTimes[3].erase(eventTimes[3].begin());
    479416
    480417      // create an event to pass to the frameStarted method in ogre
     
    482419      evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
    483420      evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]);
     421      frameTime += evt.timeSinceLastFrame;
    484422
    485423      // show the current time in the HUD
    486 //      orxonoxHUD_->setTime((int)now, 0);
    487 //      orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber());
    488       if (eventTimes[3].back() - eventTimes[3].front() != 0)
    489 //        orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front())));
    490 
    491       // Iterate through all Tickables and call their tick(dt) function
     424      // HUD::getSingleton().setTime(now);
     425      if (mode_ != DEDICATED && frameTime > 0.4f)
     426      {
     427        HUD::getSingleton().setRenderTimeRatio(renderTime / frameTime);
     428        frameTime = 0.0f;
     429        renderTime = 0.0f;
     430      }
     431
     432      // Call those objects that need the real time
     433      for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
     434        it->tick((float)evt.timeSinceLastFrame);
     435      // Call the scene objects
    492436      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
    493437        it->tick((float)evt.timeSinceLastFrame * this->timefactor_);
    494       // Iterate through all TickableReals and call their tick(dt) function
    495       for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
    496         it->tick((float)evt.timeSinceLastFrame);
    497       orxonoxConsole_->tick((float)evt.timeSinceLastFrame);
    498438
    499439      // don't forget to call _fireFrameStarted in ogre to make sure
     
    501441      ogreRoot._fireFrameStarted(evt);
    502442
    503       // server still renders at the moment
    504       //if (mode_ != SERVER)
    505       ogreRoot._updateAllRenderTargets(); // only render in non-server mode
    506 
    507443      // get current time
    508444      now = timer_->getMilliseconds();
     445      calculateEventTime(now, eventTimes[2]);
     446
     447      if (mode_ != DEDICATED)
     448      {
     449        // Pump messages in all registered RenderWindows
     450        // This calls the WindowEventListener objects.
     451        Ogre::WindowEventUtilities::messagePump();
     452
     453        // render
     454        ogreRoot._updateAllRenderTargets();
     455      }
     456
     457      // get current time
     458      now = timer_->getMilliseconds();
    509459
    510460      // create an event to pass to the frameEnded method in ogre
    511461      evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
    512       evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[2]);
     462      renderTime += calculateEventTime(now, eventTimes[2]);
    513463
    514464      // again, just to be sure ogre works fine
    515465      ogreRoot._fireFrameEnded(evt);
    516           }
    517 
    518     if(mode_==CLIENT)
     466      //msleep(200);
     467    }
     468
     469    if (mode_ == CLIENT)
    519470      network::Client::getSingleton()->closeConnection();
    520     else if(mode_==SERVER)
     471    else if (mode_ == SERVER)
    521472      server_g->close();
     473
    522474    return true;
    523475  }
     
    560512    return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000);
    561513  }
    562 
    563   /**
    564    * Static function that shows the console in game mode.
    565    */
    566   void Orxonox::activateConsole()
    567   {
    568     // currently, the console shows itself when feeded with input.
    569     InputManager::setInputState(InputManager::IS_CONSOLE);
    570   }
    571514}
  • code/trunk/src/orxonox/Orxonox.h

    r1293 r1502  
    5050    SERVER,
    5151    CLIENT,
    52     STANDALONE
     52    STANDALONE,
     53    DEDICATED
    5354  };
    5455
     
    7071      static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; }
    7172      static inline void exit() { Orxonox::getSingleton()->abortRequest(); }
    72       static inline void activateConsole();
    7373
    7474   private:
     
    9797      // TODO: make this a config-value by creating a config class for orxonox
    9898      float                 frameSmoothingTime_;
    99       InGameConsole*        orxonoxConsole_;
    10099      HUD*                  orxonoxHUD_;
    101100      bool                  bAbort_;        //!< aborts the render loop if true
     
    105104      gameMode              mode_;
    106105      std::string           serverIp_;
     106      int                   serverPort_;
    107107
    108108      static Orxonox *singletonRef_s;
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r1214 r1502  
    3535#define _OrxonoxPrereqs_H__
    3636
    37 #include "OrxonoxPlatform.h"
     37#include "util/OrxonoxPlatform.h"
    3838
    3939//-----------------------------------------------------------------------
     
    7474  class Skybox;
    7575  class SpaceShip;
     76  class SpaceShipAI;
    7677  class WorldEntity;
    7778
     
    9596
    9697  // hud
     98  class BarOverlayElement;
    9799  class HUD;
     100  class Navigation;
     101  class RadarObject;
     102  class RadarOverlayElement;
     103
    98104  //console
    99105  class InGameConsole;
  • code/trunk/src/orxonox/OrxonoxStableHeaders.h

    r1219 r1502  
    3535#define _OrxonoxStableHeaders_H__
    3636
    37 #include "OrxonoxPlatform.h"
     37#include "util/OrxonoxPlatform.h"
    3838
    3939#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     
    109109#include "network/Synchronisable.h"
    110110
    111 #include "OrxonoxPlatform.h"
    112111#include "OrxonoxPrereqs.h"
    113112#include "tools/Timer.h"
  • code/trunk/src/orxonox/console/InGameConsole.cc

    r1362 r1502  
    2323 *      Felix Schulthess
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau
    2626 *
    2727 */
     
    4040#include "core/Debug.h"
    4141#include "core/CoreIncludes.h"
     42#include "core/ConfigValueIncludes.h"
    4243#include "core/ConsoleCommand.h"
    4344#include "core/InputManager.h"
     45#include "util/Math.h"
    4446#include "GraphicsEngine.h"
    4547
    46 #define LINES 20
     48#define LINES 30
     49#define CHAR_WIDTH1 7.78 //34 // fix this please - determine the char-width dynamically
     50#define CHAR_WIDTH2 8.28 // fix this please - determine the char-width dynamically
     51#define CHAR_WIDTH3 7.80 //78 // fix this please - determine the char-width dynamically
    4752
    4853namespace orxonox
    4954{
     55    SetConsoleCommand(InGameConsole, openConsole, true);
     56    SetConsoleCommand(InGameConsole, closeConsole, true);
     57
    5058    using namespace Ogre;
    5159
    52     const float REL_WIDTH = 0.8;
    53     const float REL_HEIGHT = 0.4;
    54     const float BLINK = 0.25;
    55 
    56     InGameConsole::InGameConsole(InputBuffer* ib) :
    57         windowW(0), windowH(0),
    58         scroll(0), scrollTimer(0.0f),
    59         cursor(0.0f),
    60         active(false),
    61         ib_(ib),
    62         om(0),
    63         consoleOverlay(0),
    64         consoleOverlayContainer(0),
    65         consoleOverlayNoise(0),
    66         consoleOverlayBorder(0),
    67         consoleOverlayTextAreas(0)
    68     {
    69         //RegisterObject(InGameConsole);
    70         init();
    71     }
    72 
    73     InGameConsole::~InGameConsole(void){
    74         for(int i=0; i<LINES; i++) delete consoleOverlayTextAreas[i];
    75         delete consoleOverlayTextAreas;
    76     }
    77 
    78     void InGameConsole::listen(){
    79         if(!active) activate();
    80         print(convert2UTF(this->ib_->get()));
    81     }
    82 
    83     void InGameConsole::execute(){     
    84         newline();
    85         if (!CommandExecutor::execute(this->ib_->get())){
    86             print("Error");
    87             newline();
    88         }
    89         this->ib_->clear();
    90     }
    91 
    92     void InGameConsole::hintandcomplete(){
    93         print(CommandExecutor::hint(this->ib_->get()));
    94         newline();
    95         this->ib_->set(CommandExecutor::complete(this->ib_->get()));
    96         print(convert2UTF(this->ib_->get()));
    97     }
    98 
    99     void InGameConsole::clear(){
    100         this->ib_->clear();
    101     }
    102 
    103     void InGameConsole::removeLast(){
    104         this->ib_->removeLast();
    105     }
    106 
    107     void InGameConsole::exit(){
    108         clear();
    109         deactivate();
    110         InputManager::setInputState(InputManager::IS_NORMAL);
    111     }
    112 
    113     /**
    114     @brief called once by constructor
    115     */
    116     void InGameConsole::init(){
     60    float InGameConsole::REL_WIDTH = 0.8;
     61    float InGameConsole::REL_HEIGHT = 0.4;
     62    float InGameConsole::BLINK = 0.5;
     63
     64    /**
     65        @brief Constructor: Creates and initializes the InGameConsole.
     66    */
     67    InGameConsole::InGameConsole() :
     68        om_(0), consoleOverlay_(0), consoleOverlayContainer_(0),
     69        consoleOverlayNoise_(0), consoleOverlayBorder_(0), consoleOverlayTextAreas_(0)
     70    {
     71        RegisterObject(InGameConsole);
     72
     73        this->active_ = false;
     74        this->cursor_ = 0.0;
     75        this->cursorSymbol_ = '|';
     76        this->inputWindowStart_ = 0;
     77        this->numLinesShifted_ = LINES - 1;
     78
     79        this->init();
     80        this->setConfigValues();
     81
     82        Shell::getInstance().addOutputLevel(true);
     83    }
     84
     85    /**
     86        @brief Destructor: Destroys the TextAreas.
     87    */
     88    InGameConsole::~InGameConsole(void)
     89    {
     90        /*for (int i = 0; i < LINES; i++)
     91            if (this->consoleOverlayTextAreas_[i])
     92                om_->destroyOverlayElement(this->consoleOverlayTextAreas_[i]);
     93
     94        if (this->consoleOverlayTextAreas_)
     95            delete[] this->consoleOverlayTextAreas_;*/
     96    }
     97
     98    /**
     99        @brief Returns a reference to the only existing instance of InGameConsole.
     100    */
     101    InGameConsole& InGameConsole::getInstance()
     102    {
     103        static InGameConsole instance;
     104        return instance;
     105    }
     106
     107    /**
     108        @brief Sets the config values, describing the size of the console.
     109    */
     110    void InGameConsole::setConfigValues()
     111    {
     112        SetConfigValue(REL_WIDTH, 0.8);
     113        SetConfigValue(REL_HEIGHT, 0.4);
     114        SetConfigValue(BLINK, 0.5);
     115    }
     116
     117    /**
     118        @brief Called if all output-lines have to be redrawn.
     119    */
     120    void InGameConsole::linesChanged()
     121    {
     122        std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();
     123        int max = 0;
     124        for (int i = 1; i < LINES; ++i)
     125        {
     126            if (it != Shell::getInstance().getEndIterator())
     127            {
     128                ++it;
     129                max = i;
     130            }
     131            else
     132                break;
     133        }
     134
     135        for (int i = LINES - 1; i > max; --i)
     136            this->print("", i, true);
     137
     138        for (int i = max; i >= 1; --i)
     139        {
     140            --it;
     141            this->print(*it, i, true);
     142        }
     143    }
     144
     145    /**
     146        @brief Called if only the last output-line has changed.
     147    */
     148    void InGameConsole::onlyLastLineChanged()
     149    {
     150        if (LINES > 1)
     151            this->print(*Shell::getInstance().getNewestLineIterator(), 1);
     152    }
     153
     154    /**
     155        @brief Called if a new output-line was added.
     156    */
     157    void InGameConsole::lineAdded()
     158    {
     159        this->numLinesShifted_ = 0;
     160        this->shiftLines();
     161        this->onlyLastLineChanged();
     162    }
     163
     164    /**
     165        @brief Called if the text in the input-line has changed.
     166    */
     167    void InGameConsole::inputChanged()
     168    {
     169        if (LINES > 0)
     170            this->print(Shell::getInstance().getInput(), 0);
     171
     172        if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0)
     173            this->inputWindowStart_ = 0;
     174    }
     175
     176    /**
     177        @brief Called if the position of the cursor in the input-line has changed.
     178    */
     179    void InGameConsole::cursorChanged()
     180    {
     181        /*std::string input = Shell::getInstance().getInput();
     182        input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_);
     183        if (LINES > 0)
     184            this->print(input, 0);*/
     185        this->setCursorPosition(Shell::getInstance().getCursorPosition() - inputWindowStart_);
     186    }
     187
     188    /**
     189        @brief Called if the console gets closed.
     190    */
     191    void InGameConsole::exit()
     192    {
     193        this->deactivate();
     194    }
     195
     196    /**
     197        @brief Called once by constructor, initializes the InGameConsole.
     198    */
     199    void InGameConsole::init()
     200    {
    117201        // for the beginning, don't scroll
    118         scroll = 0;
    119         scrollTimer = 0;
    120         cursor = 0;
     202        this->scroll_ = 0;
     203        this->scrollTimer_ = 0;
     204        this->cursor_ = 0;
    121205
    122206        // create overlay and elements
    123         om = &Ogre::OverlayManager::getSingleton();
     207        this->om_ = &Ogre::OverlayManager::getSingleton();
    124208
    125209        // create a container
    126         consoleOverlayContainer = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", "container"));
    127         consoleOverlayContainer->setMetricsMode(Ogre::GMM_RELATIVE);
    128         consoleOverlayContainer->setPosition((1-REL_WIDTH)/2, 0);
    129         consoleOverlayContainer->setDimensions(REL_WIDTH, REL_HEIGHT);
     210        this->consoleOverlayContainer_ = static_cast<OverlayContainer*>(this->om_->createOverlayElement("Panel", "InGameConsoleContainer"));
     211        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
     212        this->consoleOverlayContainer_->setPosition((1 - InGameConsole::REL_WIDTH) / 2, 0);
     213        this->consoleOverlayContainer_->setDimensions(InGameConsole::REL_WIDTH, InGameConsole::REL_HEIGHT);
    130214
    131215        // create BorderPanel
    132         consoleOverlayBorder = static_cast<BorderPanelOverlayElement*>(om->createOverlayElement("BorderPanel", "borderPanel"));
    133         consoleOverlayBorder->setMetricsMode(Ogre::GMM_PIXELS);
    134         consoleOverlayBorder->setMaterialName("ConsoleCenter");
     216        this->consoleOverlayBorder_ = static_cast<BorderPanelOverlayElement*>(this->om_->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
     217        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
     218        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
    135219        // set parameters for border
    136         consoleOverlayBorder->setBorderSize(16, 16, 0, 16);
    137         consoleOverlayBorder->setBorderMaterialName("ConsoleBorder");
    138         consoleOverlayBorder->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
    139         consoleOverlayBorder->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
    140         consoleOverlayBorder->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
    141         consoleOverlayBorder->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
    142         consoleOverlayBorder->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
     220        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
     221        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
     222        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
     223        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
     224        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
     225        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
     226        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
    143227
    144228        // create the text lines
    145         consoleOverlayTextAreas = new TextAreaOverlayElement*[LINES];
    146         for(int i = 0; i<LINES; i++){
    147             consoleOverlayTextAreas[i] = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "textArea"+Ogre::StringConverter::toString(i)));
    148             consoleOverlayTextAreas[i]->setMetricsMode(Ogre::GMM_PIXELS);
    149             consoleOverlayTextAreas[i]->setFontName("Console");
    150             consoleOverlayTextAreas[i]->setCharHeight(20);
    151             consoleOverlayTextAreas[i]->setParameter("colour_top", "0.21 0.69 0.21");
    152             consoleOverlayTextAreas[i]->setLeft(8);
    153             consoleOverlayTextAreas[i]->setCaption("");
     229        this->consoleOverlayTextAreas_ = new TextAreaOverlayElement*[LINES];
     230        for (int i = 0; i < LINES; i++)
     231        {
     232            this->consoleOverlayTextAreas_[i] = static_cast<TextAreaOverlayElement*>(this->om_->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i)));
     233            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
     234            this->consoleOverlayTextAreas_[i]->setFontName("Console");
     235            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
     236            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
     237            this->consoleOverlayTextAreas_[i]->setLeft(8);
     238            this->consoleOverlayTextAreas_[i]->setCaption("");
    154239        }
    155240
    156241        // create noise
    157         consoleOverlayNoise = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "noise"));
    158         consoleOverlayNoise->setMetricsMode(Ogre::GMM_PIXELS);
    159         consoleOverlayNoise->setPosition(5,0);
    160         consoleOverlayNoise->setMaterialName("ConsoleNoise");
    161 
    162         consoleOverlay = om->create("Console");
    163         consoleOverlay->add2D(consoleOverlayContainer);
    164         consoleOverlayContainer->addChild(consoleOverlayBorder);
    165 //comment following line to disable noise
    166         consoleOverlayContainer->addChild(consoleOverlayNoise);
    167         for(int i = 0; i<LINES; i++) consoleOverlayContainer->addChild(consoleOverlayTextAreas[i]);
    168         resize();
     242        this->consoleOverlayNoise_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleNoise"));
     243        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
     244        this->consoleOverlayNoise_->setPosition(5,0);
     245        this->consoleOverlayNoise_->setMaterialName("ConsoleNoise");
     246
     247        // create cursor
     248        this->consoleOverlayCursor_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleCursor"));
     249        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
     250        this->consoleOverlayCursor_->setPosition(5,219);
     251        this->consoleOverlayCursor_->setDimensions(1, 14);
     252        this->consoleOverlayCursor_->setMaterialName("Orxonox/GreenDot");
     253
     254        this->consoleOverlay_ = this->om_->create("InGameConsoleConsole");
     255        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
     256        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
     257        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
     258        //comment following line to disable noise
     259        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
     260        for (int i = 0; i < LINES; i++)
     261            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
     262
     263        this->resize();
    169264
    170265        // move overlay "above" the top edge of the screen
    171266        // we take -1.2 because the border mkes the panel bigger
    172         consoleOverlayContainer->setTop(-1.2*REL_HEIGHT);
     267        this->consoleOverlayContainer_->setTop(-1.2 * InGameConsole::REL_HEIGHT);
    173268        // show overlay
    174         consoleOverlay->show();
    175 
    176         COUT(3) << "Info: InGameConsole initialized" << std::endl;
    177     }
    178 
    179     /**
    180     @brief used to control the actual scrolling and cursor
    181     */
    182     void InGameConsole::tick(float dt){
    183         scrollTimer += dt;
    184         if(scrollTimer >= 0.01){
    185             float top = consoleOverlayContainer->getTop();
    186             scrollTimer = 0;
    187             if(scroll!=0){
     269        this->consoleOverlay_->show();
     270
     271        COUT(4) << "Info: InGameConsole initialized" << std::endl;
     272    }
     273
     274    /**
     275        @brief Resizes the console elements. Call if window size changes.
     276    */
     277    void InGameConsole::resize()
     278    {
     279        this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
     280        this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
     281        this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH);
     282        this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT);
     283        this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10);
     284        this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5);
     285
     286        // now adjust the text lines...
     287        this->desiredTextWidth_ = (int) (this->windowW_ * InGameConsole::REL_WIDTH) - 12;
     288
     289        if (LINES > 0)
     290            this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH3));
     291        else
     292            this->maxCharsPerLine_ = 10;
     293
     294        for (int i = 0; i < LINES; i++)
     295        {
     296            this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_);
     297            this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i);
     298        }
     299
     300        this->linesChanged();
     301    }
     302
     303    /**
     304        @brief Used to control the actual scrolling and the cursor.
     305    */
     306    void InGameConsole::tick(float dt)
     307    {
     308        this->scrollTimer_ += dt;
     309        if (this->scrollTimer_ >= 0.01)
     310        {
     311            float top = this->consoleOverlayContainer_->getTop();
     312            float timePassed = scrollTimer_;
     313            this->scrollTimer_ = 0;
     314            if (this->scroll_ != 0)
     315            {
    188316                // scroll
    189                 top = top + 0.02*scroll;
    190                 consoleOverlayContainer->setTop(top);
     317                top = top + timePassed * this->scroll_;
     318                this->consoleOverlayContainer_->setTop(top);
    191319            }
    192             if(top <= -1.2*REL_HEIGHT){
     320            if (top <= -1.2 * InGameConsole::REL_HEIGHT)
     321            {
    193322                // window has completely scrolled up
    194                 scroll = 0;
    195                 consoleOverlay->hide();
    196                 active = false;
     323                this->scroll_ = 0;
     324                this->consoleOverlay_->hide();
     325                this->active_ = false;
     326                Shell::getInstance().unregisterListener(this);
    197327            }
    198             if(top >= 0){
     328            if (top >= 0)
     329            {
    199330                // window has completely scrolled down
    200                 scroll = 0;
    201                 consoleOverlayContainer->setTop(0);
    202                 active = true;
     331                this->scroll_ = 0;
     332                this->consoleOverlayContainer_->setTop(0);
     333                this->active_ = true;
    203334            }
    204335        }
    205336
    206         cursor += dt;
    207         if(cursor >= 2*BLINK) cursor = 0;
    208         print(convert2UTF(this->ib_->get()));
    209 
    210 // this creates a flickering effect
    211         consoleOverlayNoise->setTiling(1, rand()%5+1);
    212     }
    213 
    214     /**
    215     @brief resizes the console elements. call if window size changes
    216     */
    217     void InGameConsole::resize(){
    218         windowW = GraphicsEngine::getSingleton().getWindowWidth();
    219         windowH = GraphicsEngine::getSingleton().getWindowHeight();
    220         consoleOverlayBorder->setWidth((int) windowW*REL_WIDTH);
    221         consoleOverlayBorder->setHeight((int) windowH*REL_HEIGHT);
    222         consoleOverlayNoise->setWidth((int) windowW*REL_WIDTH - 10);
    223         consoleOverlayNoise->setHeight((int) windowH*REL_HEIGHT - 5);
    224         // now adjust the text lines...
    225         for(int i = 0; i<LINES; i++){
    226             consoleOverlayTextAreas[i]->setWidth(windowW*REL_WIDTH);
    227             consoleOverlayTextAreas[i]->setTop((int)windowH*REL_HEIGHT - 24 - 16*i);
    228         }
    229     }
    230 
    231     /**
    232     @brief shows console
    233     */
    234     void InGameConsole::activate(){
    235         consoleOverlay->show();
     337        this->cursor_ += dt;
     338        if (this->cursor_ >= InGameConsole::BLINK)
     339        {
     340            this->cursor_ = 0;
     341            bShowCursor_ = !bShowCursor_;
     342            if (bShowCursor_)
     343              this->consoleOverlayCursor_->show();
     344            else
     345              this->consoleOverlayCursor_->hide();
     346        }
     347
     348        /*if (this->cursor_ >= 2 * InGameConsole::BLINK)
     349          this->cursor_ = 0;
     350
     351        if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|')
     352        {
     353            this->cursorSymbol_ = ' ';
     354            this->cursorChanged();
     355        }
     356        else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ')
     357        {
     358            this->cursorSymbol_ = '|';
     359            this->cursorChanged();
     360        }*/
     361
     362        // this creates a flickering effect
     363        this->consoleOverlayNoise_->setTiling(1, rand() % 5 + 1);
     364    }
     365
     366    /**
     367        @brief Shows the InGameConsole.
     368    */
     369    void InGameConsole::activate()
     370    {
     371        InputManager::setInputState(InputManager::IS_CONSOLE);
     372        Shell::getInstance().registerListener(this);
     373        this->linesChanged();
     374
     375        this->consoleOverlay_->show();
    236376        // just in case window size has changed...
    237         resize();
     377        this->resize();
    238378        // scroll down
    239         scroll = 1;
     379        this->scroll_ = 1;
    240380        // the rest is done by tick
    241381    }
    242382
    243383    /**
    244     @brief hides console
    245     */
    246     void InGameConsole::deactivate(){
     384    @brief Hides the InGameConsole.
     385    */
     386    void InGameConsole::deactivate()
     387    {
    247388        // scroll up
    248         scroll = -1;
     389        this->scroll_ = -1;
    249390        // the rest is done by tick
    250     }
    251 
    252     /**
    253     @brief prints string to bottom line
    254     @param s string to be printed
    255     */
    256     void InGameConsole::print(Ogre::UTFString s){
    257         if(cursor>BLINK) consoleOverlayTextAreas[0]->setCaption(">" + s);
    258         else consoleOverlayTextAreas[0]->setCaption(">" + s + "_");
    259     }
    260 
    261     /**
    262     @brief shifts all lines up and clears the bottom line
    263     */
    264     void InGameConsole::newline(){
    265         Ogre::UTFString line;
    266         for(int i = LINES-1; i>=1; i--){
    267             line = consoleOverlayTextAreas[i-1]->getCaption();
    268             // don't copy the cursor...
    269             int l = line.length();
    270             if(!line.empty() && line.substr(l-1) == "_") line.erase(l-1);
    271             consoleOverlayTextAreas[i]->setCaption(line);
    272         }
    273         consoleOverlayTextAreas[0]->setCaption(">");
    274     }
    275 
    276     Ogre::UTFString InGameConsole::convert2UTF(std::string s){
     391        InputManager::setInputState(InputManager::IS_NORMAL);
     392    }
     393
     394    /**
     395        @brief Activates the console.
     396    */
     397    void InGameConsole::openConsole()
     398    {
     399        InGameConsole::getInstance().activate();
     400    }
     401
     402    /**
     403        @brief Deactivates the console.
     404    */
     405    void InGameConsole::closeConsole()
     406    {
     407        InGameConsole::getInstance().deactivate();
     408    }
     409
     410    /**
     411        @brief Shifts all output lines one line up
     412    */
     413    void InGameConsole::shiftLines()
     414    {
     415        for (unsigned int i = LINES - 1; i > 1; --i)
     416        {
     417            this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption());
     418            this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop());
     419            this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom());
     420        }
     421    }
     422
     423    void InGameConsole::colourLine(int colourcode, int index)
     424    {
     425        if (colourcode == -1)
     426        {
     427            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.90, 0.90, 0.90, 1.00));
     428            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00));
     429        }
     430        else if (colourcode == 1)
     431        {
     432            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.25, 0.25, 1.00));
     433            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00));
     434        }
     435        else if (colourcode == 2)
     436        {
     437            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.50, 0.20, 1.00));
     438            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00));
     439        }
     440        else if (colourcode == 3)
     441        {
     442            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.50, 0.50, 0.95, 1.00));
     443            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00));
     444        }
     445        else if (colourcode == 4)
     446        {
     447            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.65, 0.48, 0.44, 1.00));
     448            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00));
     449        }
     450        else if (colourcode == 5)
     451        {
     452            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.40, 0.20, 0.40, 1.00));
     453            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00));
     454        }
     455        else
     456        {
     457            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.21, 0.69, 0.21, 1.00));
     458            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00));
     459        }
     460    }
     461
     462    void InGameConsole::setCursorPosition(int pos)
     463    {
     464        static std::string char1 = "bdefgilpqtzCEGIJKNOPQT5[}äü";
     465        static std::string char2 = "Z4";
     466
     467        if (pos > (int)maxCharsPerLine_)
     468          pos = maxCharsPerLine_;
     469        else if (pos < 0)
     470          pos = 0;
     471
     472        float width = 0;
     473        for (int i = 0; i < pos; ++i)
     474        {
     475            if (char1.find(displayedText_[i]) != std::string::npos)
     476                width += CHAR_WIDTH1;
     477            else if (char2.find(displayedText_[i]) != std::string::npos)
     478                width += CHAR_WIDTH2;
     479            else
     480                width += CHAR_WIDTH3;
     481        }
     482        this->consoleOverlayCursor_->setPosition(width + 5, this->windowH_ * InGameConsole::REL_HEIGHT - 20);
     483    }
     484
     485    /**
     486        @brief Prints string to bottom line.
     487        @param s String to be printed
     488    */
     489    void InGameConsole::print(const std::string& text, int index, bool alwaysShift)
     490    {
     491        char level = 0;
     492        if (text.size() > 0)
     493            level = text[0];
     494
     495        std::string output = text;
     496
     497        if (level >= -1 && level <= 5)
     498            output.erase(0, 1);
     499
     500        if (LINES > index)
     501        {
     502            this->colourLine(level, index);
     503
     504            if (index > 0)
     505            {
     506                unsigned int linesUsed = 1;
     507                while (output.size() > this->maxCharsPerLine_)
     508                {
     509                    ++linesUsed;
     510                    this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output.substr(0, this->maxCharsPerLine_)));
     511                    output.erase(0, this->maxCharsPerLine_);
     512                    output.insert(0, 1, ' ');
     513                    if (linesUsed > numLinesShifted_ || alwaysShift)
     514                        this->shiftLines();
     515                    this->colourLine(level, index);
     516                }
     517                this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
     518                this->displayedText_ = output;
     519                this->numLinesShifted_ = linesUsed;
     520            }
     521            else
     522            {
     523                if (output.size() > this->maxCharsPerLine_)
     524                {
     525                    if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_)
     526                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition();
     527                    else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
     528                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1;
     529
     530                    output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
     531                }
     532                else
     533                  this->inputWindowStart_ = 0;
     534                this->displayedText_ = output;
     535                this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
     536            }
     537        }
     538    }
     539
     540    /**
     541        @brief Converts a string into an Ogre::UTFString.
     542        @param s The string to convert
     543        @return The converted string
     544    */
     545    Ogre::UTFString InGameConsole::convert2UTF(std::string s)
     546    {
    277547        Ogre::UTFString utf;
    278         int i;
    279548        Ogre::UTFString::code_point cp;
    280         for (i=0; i<(int)s.size(); ++i){
     549        for (unsigned int i = 0; i < s.size(); ++i)
     550        {
    281551          cp = s[i];
    282552          cp &= 0xFF;
  • code/trunk/src/orxonox/console/InGameConsole.h

    r1214 r1502  
    2323 *      Felix Schulthess
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau
    2626 *
    2727 */
     
    3737
    3838#include "core/Tickable.h"
    39 #include "core/InputBuffer.h"
     39#include "core/Shell.h"
    4040
    4141
    4242namespace orxonox
    4343{
    44     class _OrxonoxExport InGameConsole : public InputBufferListener
     44    class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener
    4545    {
    4646        public:
    47             InGameConsole(InputBuffer* ib);
    48             ~InGameConsole();
    49             void listen();
    50             void execute();
    51             void hintandcomplete();
    52             void clear();
    53             void removeLast();
    54             void exit();
    55             void init();
     47            static InGameConsole& getInstance();
     48
     49            void setConfigValues();
    5650            void tick(float dt);
     51
    5752            void activate();
    5853            void deactivate();
     54            void resize();
     55
     56            static void openConsole();
     57            static void closeConsole();
    5958
    6059        private:
    61             void resize();
    62             void print(Ogre::UTFString s);
    63             void newline();
    64             Ogre::UTFString convert2UTF(std::string s);
     60            InGameConsole();
     61            InGameConsole(const InGameConsole& other);
     62            ~InGameConsole();
    6563
    66             int windowW;
    67             int windowH;
    68             int scroll;
    69             float scrollTimer;
    70             float cursor;
    71             bool active;
    72             InputBuffer* ib_;
    73             Ogre::OverlayManager* om;
    74             Ogre::Overlay* consoleOverlay;
    75             Ogre::OverlayContainer* consoleOverlayContainer;
    76             Ogre::PanelOverlayElement* consoleOverlayNoise;
    77             Ogre::BorderPanelOverlayElement* consoleOverlayBorder;
    78             Ogre::TextAreaOverlayElement** consoleOverlayTextAreas;
     64            virtual void linesChanged();
     65            virtual void onlyLastLineChanged();
     66            virtual void lineAdded();
     67            virtual void inputChanged();
     68            virtual void cursorChanged();
     69            virtual void exit();
     70
     71            void init();
     72            void shiftLines();
     73            void colourLine(int colourcode, int index);
     74            void setCursorPosition(int pos);
     75            void print(const std::string& text, int index, bool alwaysShift = false);
     76            static Ogre::UTFString convert2UTF(std::string s);
     77
     78            static float REL_WIDTH;
     79            static float REL_HEIGHT;
     80            static float BLINK;
     81
     82            int windowW_;
     83            int windowH_;
     84            int desiredTextWidth_;
     85            unsigned int maxCharsPerLine_;
     86            unsigned int numLinesShifted_;
     87            int scroll_;
     88            float scrollTimer_;
     89            float cursor_;
     90            unsigned int inputWindowStart_;
     91            char cursorSymbol_;
     92            bool active_;
     93            bool bShowCursor_;
     94            std::string displayedText_;
     95            Ogre::OverlayManager* om_;
     96            Ogre::Overlay* consoleOverlay_;
     97            Ogre::OverlayContainer* consoleOverlayContainer_;
     98            Ogre::PanelOverlayElement* consoleOverlayNoise_;
     99            Ogre::PanelOverlayElement* consoleOverlayCursor_;
     100            Ogre::BorderPanelOverlayElement* consoleOverlayBorder_;
     101            Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_;
    79102    };
    80103}
  • code/trunk/src/orxonox/hud/BarOverlayElement.cc

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
     29#include "OrxonoxStableHeaders.h"
     30#include "BarOverlayElement.h"
    2831#include <OgreOverlayManager.h>
    29 #include <OgreOverlayElement.h>
    30 #include <OgrePanelOverlayElement.h>
    3132#include "GraphicsEngine.h"
    32 #include "BarOverlayElement.h"
    3333
    3434namespace orxonox
    3535{
    36   using namespace Ogre;
     36    using namespace Ogre;
    3737
    38     BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
     38    BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
    3939        name_ = name;
    4040    }
     
    4242    BarOverlayElement::~BarOverlayElement(){}
    4343
    44     void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
     44    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
    4545        // init some values...
    4646        container_ = container;
    47         om = &Ogre::OverlayManager::getSingleton();
     47        om = &OverlayManager::getSingleton();
    4848        value_ = 0;
    4949        color_ = 2;
     
    5353        topRel_ = topRel;
    5454        dimRel_ = dimRel;
    55        
     55
    5656        // create background...
    5757        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
    5858        background_->show();
    5959        container_->addChild(background_);
    60         background_->setMetricsMode(Ogre::GMM_PIXELS);
     60        background_->setMetricsMode(GMM_PIXELS);
    6161        background_->setMaterialName("Orxonox/BarBackground");
    6262
     
    6565
    6666        show();
    67         setMetricsMode(Ogre::GMM_PIXELS);
     67        setMetricsMode(GMM_PIXELS);
    6868        setMaterialName("Orxonox/Green");
    6969        background_->addChild(this);
     
    126126    }
    127127}
    128 
    129 
  • code/trunk/src/orxonox/hud/BarOverlayElement.h

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
     29#ifndef _BarOverlayElement_H__
     30#define _BarOverlayElement_H__
    2831
    29 #ifndef _BAR_H__
    30 #define _BAR_H__
    31 
    32 #include <OgreOverlayManager.h>
    33 #include <OgreOverlayElement.h>
    34 #include <OgrePanelOverlayElement.h>
     32#include "OrxonoxPrereqs.h"
    3533
    3634#include <OgrePrerequisites.h>
    37 #include "../OrxonoxPrereqs.h"
    38 
    39 
     35#include <OgrePanelOverlayElement.h>
    4036
    4137namespace orxonox
     
    4440  {
    4541    private:
    46         bool autoColor_;                    // whether bar changes color automatically
    47         float value_;                       // progress of bar
    48         int color_;
    49         int left_;
    50         int top_;
    51         int width_;
    52         int height_;
    53         int windowW_, windowH_;
    54         Ogre::Real leftRel_;
    55         Ogre::Real topRel_;
    56         Ogre::Real dimRel_;
    57         Ogre::OverlayManager* om;           // our overlay manager
    58         Ogre::OverlayContainer* container_; // our parent container to attach to
    59         Ogre::OverlayContainer* background_;
    60         Ogre::String name_;
     42      bool autoColor_;                    // whether bar changes color automatically
     43      float value_;                       // progress of bar
     44      int color_;
     45      int left_;
     46      int top_;
     47      int width_;
     48      int height_;
     49      int windowW_, windowH_;
     50      Ogre::Real leftRel_;
     51      Ogre::Real topRel_;
     52      Ogre::Real dimRel_;
     53      Ogre::OverlayManager* om;           // our overlay manager
     54      Ogre::OverlayContainer* container_; // our parent container to attach to
     55      Ogre::OverlayContainer* background_;
     56      Ogre::String name_;
    6157
    6258    public:
    63         bool left2Right;
    64         static const int RED = 0;           // predefined colors
    65         static const int YELLOW = 1;
    66         static const int GREEN = 2;
     59      bool left2Right;
     60      static const int RED = 0;           // predefined colors
     61      static const int YELLOW = 1;
     62      static const int GREEN = 2;
    6763
    68         BarOverlayElement(const Ogre::String& name);
    69         virtual ~BarOverlayElement();
    70         void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
    71         void resize();
    72         void setValue(float value);
    73         void setColor(int color);
    74         float getValue();
    75         int getBarColor();
     64      BarOverlayElement(const Ogre::String& name);
     65      virtual ~BarOverlayElement();
     66      void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
     67      void resize();
     68      void setValue(float value);
     69      void setColor(int color);
     70      float getValue();
     71      int getBarColor();
    7672    };
    7773}
    78 #endif
    79 
    80 
     74#endif /* _BarOverlayElement_H__ */
  • code/trunk/src/orxonox/hud/HUD.cc

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
    27 
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2828
    2929#include "OrxonoxStableHeaders.h"
     30#include "HUD.h"
     31
     32#include <string>
     33#include <set>
    3034#include <OgreOverlay.h>
    3135#include <OgreOverlayContainer.h>
    3236#include <OgreOverlayManager.h>
    33 #include <OgreSceneNode.h>
    34 #include <OgreEntity.h>
    3537#include <OgreStringConverter.h>
     38
    3639#include "core/Debug.h"
     40#include "core/ConsoleCommand.h"
    3741#include "objects/SpaceShip.h"
    38 #include "HUD.h"
     42#include "GraphicsEngine.h"
    3943#include "BarOverlayElement.h"
     44#include "RadarObject.h"
    4045#include "RadarOverlayElement.h"
     46#include "Navigation.h"
    4147#include "OverlayElementFactories.h"
    4248
    4349namespace orxonox
    4450{
     51    SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User);
     52    SetConsoleCommandShortcut(HUD, toggleFPS).setAccessLevel(AccessLevel::User);
     53    SetConsoleCommandShortcut(HUD, toggleRenderTime).setAccessLevel(AccessLevel::User);
     54
    4555    using namespace Ogre;
    4656
    47     HUD::HUD(int zoom){
     57    HUD::HUD(){
    4858        om = &Ogre::OverlayManager::getSingleton();
    49 
    50                 // create Factories
     59        sm = GraphicsEngine::getSingleton().getSceneManager();
     60        showFPS = true;
     61        showRenderTime = true;
     62
     63        // create Factories
    5164        BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
    5265        om->addOverlayElementFactory(barOverlayElementFactory);
     
    5669        orxonoxHUD = om->create("Orxonox/HUD");
    5770        container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
    58         // test
    59         test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123"));
    60         test->show();
    61         test->setMetricsMode(Ogre::GMM_RELATIVE);
    62         test->setDimensions(0.8, 0.8);
    63         test->setPosition(0.02, 0.02);
    64         test->setFontName("Console");
    65         test->setCaption("init");
     71
     72        // creating text to display fps
     73        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
     74        fpsText->show();
     75        fpsText->setMetricsMode(Ogre::GMM_PIXELS);
     76        fpsText->setDimensions(0.001, 0.001);
     77        fpsText->setPosition(10, 10);
     78        fpsText->setFontName("Console");
     79        fpsText->setCharHeight(20);
     80        fpsText->setCaption("init");
     81
     82        // creating text to display render time ratio
     83        rTRText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "rTRText"));
     84        rTRText->show();
     85        rTRText->setMetricsMode(Ogre::GMM_PIXELS);
     86        rTRText->setDimensions(0.001, 0.001);
     87        rTRText->setPosition(10, 30);
     88        rTRText->setFontName("Console");
     89        rTRText->setCharHeight(20);
     90        rTRText->setCaption("init");
    6691
    6792        // create energy bar
     
    75100        radar->show();
    76101
    77                 // set up screen-wide container
     102        // create Navigation
     103        nav = new Navigation(container);
     104
     105        // set up screen-wide container
    78106        container->show();
    79107
     
    85113        container->setHeight(1.0);
    86114        container->setMetricsMode(Ogre::GMM_RELATIVE);
    87         container->addChild(test);
     115        container->addChild(fpsText);
     116        container->addChild(rTRText);
     117
    88118        energyBar->init(0.01, 0.94, 0.4, container);
    89119        energyBar->setValue(1);
     120
    90121        speedoBar->init(0.01, 0.90, 0.4, container);
     122
    91123        radar->init(0.5, 0.9, 0.2, container);
    92         radar->addObject(Vector3(1500.0, 0.0, 100.0));
    93         radar->addObject(Vector3(0.0, 4000.0, 0.0));
    94         radar->addObject(Vector3(0.0, 0.0, 6800.0));
    95         RadarOverlayElement::cycleFocus();
     124        SceneNode* node;
     125        node = sm->getRootSceneNode()->createChildSceneNode("tomato1", Vector3(2000.0, 0.0, 0.0));
     126        addRadarObject(node);
     127        node = sm->getRootSceneNode()->createChildSceneNode("tomato2", Vector3(0.0, 2000.0, 0.0));
     128        addRadarObject(node);
     129        node = sm->getRootSceneNode()->createChildSceneNode("tomato3", Vector3(0.0, 0.0, 2000.0));
     130        addRadarObject(node);
     131        node = sm->getRootSceneNode()->createChildSceneNode("station", Vector3(10000.0,16000.0,0.0));
     132        addRadarObject(node, 3);
     133    }
     134
     135    HUD::~HUD(){
     136        //todo: clean up objects
    96137    }
    97138
    98139    void HUD::tick(float dt)
    99140    {
    100         int d = radar->getDist2Focus()/10;
    101         if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d));
    102         else test->setCaption("");
    103 
    104141        energyBar->resize();
    105142
    106         float v = SpaceShip::instance_s->getVelocity().length();
    107         float vmax = SpaceShip::instance_s->getMaxSpeed();
     143        if(!SpaceShip::getLocalShip())
     144          return;
     145        float v = SpaceShip::getLocalShip()->getVelocity().length();
     146        float vmax = SpaceShip::getLocalShip()->getMaxSpeed();
    108147        speedoBar->setValue(v/vmax);
    109148        speedoBar->resize();
     
    111150        radar->resize();
    112151        radar->update();
    113     }
    114 
    115     HUD::~HUD(void){
     152
     153        nav->update();
     154
     155        setFPS();
     156    }
     157
     158    void HUD::setRenderTimeRatio(float ratio)
     159    {
     160        if(showRenderTime){
     161            rTRText->setCaption("Render time ratio: " + Ogre::StringConverter::toString(ratio));
     162        }
     163        else{
     164            rTRText->setCaption("");
     165            return;
     166        }
     167    }
     168
     169    void HUD::setFPS(){
     170        if(showFPS){
     171            float fps = GraphicsEngine::getSingleton().getAverageFPS();
     172            fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
     173        }
     174        else{
     175            fpsText->setCaption("");
     176            return;
     177        }
     178    }
     179
     180    void HUD::addRadarObject(SceneNode* node, int colour){
     181        RadarObject* obj = new RadarObject(container, node, colour);
     182        roSet.insert(obj);
     183//        // check if this is the first RadarObject to create
     184//        if(firstRadarObject == NULL){
     185//            firstRadarObject = new RadarObject(container, node, colour);
     186//            lastRadarObject = firstRadarObject;
     187//        }
     188//        else{ // if not, append to list
     189//            lastRadarObject->next = new RadarObject(container, node, colour);
     190//            lastRadarObject = lastRadarObject->next;
     191//        }
     192    }
     193
     194    void HUD::removeRadarObject(Ogre::SceneNode* node){
     195      COUT(3) << "blabla" << std::endl;
     196        for(std::set<RadarObject*>::iterator it=roSet.begin(); it!=roSet.end(); it++){
     197            if((*it)->getNode() == node) {
     198                delete (*it);
     199                roSet.erase(it);
     200            }
     201        }
     202    }
     203
     204    /*static*/ HUD& HUD::getSingleton(){
     205        static HUD theInstance;
     206        return theInstance;
     207    }
     208
     209    /*static*/ void HUD::setEnergy(float value){
     210        HUD::getSingleton().energyBar->setValue(value);
     211    }
     212
     213    /*static*/ void HUD::cycleNavigationFocus(){
     214        HUD::getSingleton().nav->cycleFocus();
     215    }
     216
     217    /*static*/ void HUD::toggleFPS(){
     218        HUD::getSingleton().showFPS = !HUD::getSingleton().showFPS;
     219    }
     220
     221    /*static*/ void HUD::toggleRenderTime(){
     222        HUD::getSingleton().showRenderTime = !HUD::getSingleton().showRenderTime;
    116223    }
    117224}
  • code/trunk/src/orxonox/hud/HUD.h

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
    2829
     
    3031#define _HUD_H__
    3132
    32 #include <string.h>
    33 #include <OgreOverlayElement.h>
     33#include "OrxonoxPrereqs.h"
     34
     35#include <OgrePrerequisites.h>
    3436#include <OgreTextAreaOverlayElement.h>
    35 #include <OgrePrerequisites.h>
    36 
    37 #include "OrxonoxPrereqs.h"
     37#include <OgreSceneNode.h>
    3838#include "core/Tickable.h"
    39 #include "BarOverlayElement.h"
    40 #include "RadarOverlayElement.h"
    41 
     39#include "util/Math.h"
    4240
    4341namespace orxonox
     
    4543    class _OrxonoxExport HUD : public Tickable
    4644    {
    47         private:
    48             Ogre::OverlayManager* om;
    49             Ogre::Overlay* orxonoxHUD;
    50             Ogre::OverlayContainer* container;
    51             Ogre::TextAreaOverlayElement* test;
    52             BarOverlayElement* energyBar;
    53             BarOverlayElement* speedoBar;
    54             RadarOverlayElement* radar;
     45      private:
     46        HUD();
     47        HUD(HUD& instance);
     48        ~HUD();
     49        Ogre::OverlayManager* om;
     50        Ogre::SceneManager* sm;
     51        Ogre::Overlay* orxonoxHUD;
     52        Ogre::OverlayContainer* container;
     53        Ogre::TextAreaOverlayElement* fpsText;
     54        Ogre::TextAreaOverlayElement* rTRText;
     55        BarOverlayElement* energyBar;
     56        BarOverlayElement* speedoBar;
     57        RadarOverlayElement* radar;
     58        Navigation* nav;
    5559
    56         public:
    57             HUD(int zoom);
    58             ~HUD();
    59             virtual void tick(float);
     60        bool showFPS;
     61        bool showRenderTime;
    6062
     63      public:
     64        virtual void tick(float);
     65        void addRadarObject(Ogre::SceneNode* node, int colour = 0);
     66        void removeRadarObject(Ogre::SceneNode* node);
     67        void setRenderTimeRatio(float ratio);
     68        void setFPS();
     69
     70        std::set<RadarObject*> roSet;
     71
     72        static HUD* instance_s;
     73        static HUD& getSingleton();
     74        static void setEnergy(float value);
     75        static void cycleNavigationFocus();
     76        static void toggleFPS();
     77        static void toggleRenderTime();
    6178    };
    6279}
    6380
    64 #endif
     81#endif /* _HUD_H__ */
  • code/trunk/src/orxonox/hud/OverlayElementFactories.h

    r1362 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
    28 #ifndef _FACTORIES_H__
    29 #define _FACTORIES_H__
     29#ifndef _OverlayElementFactories_H__
     30#define _OverlayElementFactories_H__
    3031
     32#include "OrxonoxPrereqs.h"
     33
     34#include <OgrePrerequisites.h>
    3135#include <OgreOverlayElement.h>
    32 #include <OgrePrerequisites.h>
    3336#include <OgreOverlayElementFactory.h>
    3437
    3538#include "BarOverlayElement.h"
     39#include "RadarOverlayElement.h"
    3640
    3741namespace orxonox{
    3842    class _OrxonoxExport BarOverlayElementFactory : public Ogre::OverlayElementFactory{
    39         public:
     43      public:
    4044        Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){
    4145            return new BarOverlayElement(instanceName);
     
    4852
    4953    class _OrxonoxExport RadarOverlayElementFactory : public Ogre::OverlayElementFactory{
    50         public:
     54      public:
    5155        Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){
    5256            return new RadarOverlayElement(instanceName);
     
    5963}
    6064
    61 #endif
     65#endif /* _OverlayElementFactories_H__ */
  • code/trunk/src/orxonox/hud/RadarObject.cc

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Felix Schulthess
    23 *   Co-authors:
    24 *      ...
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Felix Schulthess
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
    2728
     29#include "OrxonoxStableHeaders.h"
    2830#include "RadarObject.h"
     31
     32#include <OgreOverlayManager.h>
     33#include <OgreStringConverter.h>
     34#include "GraphicsEngine.h"
    2935
    3036namespace orxonox
     
    3238    using namespace Ogre;
    3339
    34         int RadarObject::count = 0;             // initialize static variable
     40    int RadarObject::count = 0;         // initialize static variable
    3541
    36         RadarObject::RadarObject(Ogre::OverlayContainer* container){
    37                 container_ = container;
    38                 pos_ = Vector3(0.0, 0.0, 0.0);
    39                 init();
    40         }
    41 
    42         RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){
    43                 container_ = container;
    44                 pos_ = pos;
    45                 init();
    46         }
    47 
    48         RadarObject::~RadarObject(){}
    49 
    50         void RadarObject::init(){
    51             next = NULL;
    52                 om = &Ogre::OverlayManager::getSingleton();
    53                 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
    54                         "Object"+Ogre::StringConverter::toString(count)));
    55                 panel_->setMaterialName("Orxonox/RedDot");
    56                 panel_->setDimensions(3,3);
     42    RadarObject::RadarObject(OverlayContainer* container, SceneNode* node, int colour){
     43        container_ = container;
     44        node_ = node;
     45        colour_ = colour;
     46        om = &OverlayManager::getSingleton();
     47        panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
     48            "Object"+StringConverter::toString(count)));
     49        setColour(colour_);
     50        panel_->setDimensions(3,3);
    5751        panel_->setMetricsMode(Ogre::GMM_PIXELS);
    5852        panel_->show();
     
    6054        count++;
    6155        container_->addChild(panel_);
    62         }
     56    }
     57
     58    RadarObject::~RadarObject(){
     59        delete panel_;
     60    }
     61
     62    void RadarObject::setColour(int colour){
     63        switch(colour){
     64        case RED: panel_->setMaterialName("Orxonox/RedDot"); break;
     65        case YELLOW: panel_->setMaterialName("Orxonox/YellowDot"); break;
     66        case GREEN: panel_->setMaterialName("Orxonox/GreenDot"); break;
     67        case BLUE: panel_->setMaterialName("Orxonox/BlueDot"); break;
     68        case WHITE: panel_->setMaterialName("Orxonox/WhiteDot"); break;
     69        default: panel_->setMaterialName("Orxonox/RedDot"); break;
     70        }
     71    }
     72
     73    void RadarObject::resetColour(){
     74        setColour(colour_);
     75    }
     76
     77    Vector3 RadarObject::getPosition(){
     78        return node_->getPosition();
     79    }
     80
     81    SceneNode* RadarObject::getNode(){
     82        return node_;
     83    }
    6384}
    6485
    65 /* my local clipboard...
    66 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    67 COUT(3) << firstRadarObject_->radius_ << "  " << firstRadarObject_->phi_ << std::endl;
    68 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    69 */
  • code/trunk/src/orxonox/hud/RadarObject.h

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      ...
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Felix Schulthess
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
    2728
    28 #ifndef _RADAR2_H__
    29 #define _RADAR2_H__
     29#ifndef _RadarObject_H__
     30#define _RadarObject_H__
    3031
    31 #include <string.h>
    3232#include <OgrePrerequisites.h>
    33 #include <OgreOverlayManager.h>
    34 #include <OgreOverlayElement.h>
     33#include <OgreSceneNode.h>
    3534#include <OgrePanelOverlayElement.h>
    36 #include <OgreStringConverter.h>
    37 
    38 #include <util/Math.h>
    39 #include "../OrxonoxPrereqs.h"
     35#include "OrxonoxPrereqs.h"
     36#include "util/Math.h"
    4037
    4138namespace orxonox
     
    4340    class _OrxonoxExport RadarObject
    4441    {
    45         private:
    46                 Ogre::OverlayManager* om;                               // our one and only overlay manager
    47                 void init();
     42      private:
     43        Ogre::OverlayManager* om;                               // our one and only overlay manager
     44        Ogre::SceneNode* node_;                                 // node of object
     45        int colour_;
    4846
    49         public:
    50                 RadarObject(Ogre::OverlayContainer* container);
    51                 RadarObject(Ogre::OverlayContainer* container, Vector3 pos);
    52                 ~RadarObject();
     47      public:
     48        RadarObject(Ogre::OverlayContainer* container, Ogre::SceneNode* node, int colour = 0);
     49        ~RadarObject();
     50        void setColour(int colour);
     51        void resetColour();
     52        Vector3 getPosition();
     53        Ogre::SceneNode* getNode();
    5354
    54             bool right_;
    55             int index_;                             // index number of object
    56                 Vector3 pos_;                                                   // position in space
    57                         Ogre::Real radius_, phi_;                               // position on radar
    58                         Ogre::OverlayContainer* container_;
    59                         Ogre::PanelOverlayElement* panel_;              // the panel used to show the dot
    60                         RadarObject* next;                      // next pointer of linked list
     55        bool right_;
     56        int index_;                             // index number of object
     57        Ogre::OverlayContainer* container_;
     58        Ogre::PanelOverlayElement* panel_;              // the panel used to show the dot
    6159
    62                 static int count;
    63         };
     60        static int count;
     61        static const int RED = 0;
     62        static const int YELLOW = 1;
     63        static const int GREEN = 2;
     64        static const int BLUE = 3;
     65        static const int WHITE = 99;            // used if object got nav focus
     66  };
    6467}
    6568
    66 #endif
     69#endif /* _RadarObject_H__ */
  • code/trunk/src/orxonox/hud/RadarOverlayElement.cc

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      ...
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
     29#include "OrxonoxStableHeaders.h"
    2830#include "RadarOverlayElement.h"
     31
     32#include <string>
     33#include <OgreOverlayManager.h>
     34#include <OgreStringConverter.h>
     35
     36#include "GraphicsEngine.h"
     37#include "core/Tickable.h"
     38#include "core/ConsoleCommand.h"
     39#include "objects/SpaceShip.h"
     40#include "RadarObject.h"
     41#include "HUD.h"
    2942
    3043namespace orxonox
    3144{
    32     ConsoleCommandShortcut(RadarOverlayElement, cycleFocus, AccessLevel::User);
    33 
    3445    using namespace Ogre;
    3546
    36     RadarOverlayElement* RadarOverlayElement::instance_s = NULL;
    37 
    38     RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
    39         RadarOverlayElement::instance_s = this;
     47    RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){
    4048    }
    4149
     
    4351    }
    4452
    45     void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
     53    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
    4654        // some initial data
    47                 om = &Ogre::OverlayManager::getSingleton();
     55        om = &OverlayManager::getSingleton();
    4856        dimRel_ = dimRel;
    4957        leftRel_ = leftRel;
    5058        topRel_ = topRel;
    5159        container_ = container;
    52         firstRadarObject_ = NULL;
    53         lastRadarObject_ = NULL;
    54         focus_ = NULL;
    5560
    56         // create nav marker ...
    57         navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker"));
    58         navMarker_->setMetricsMode(Ogre::GMM_PIXELS);
    59         navMarker_->setMaterialName("Orxonox/NavMarker");
    60         navMarker_->setDimensions(16,16);
    61         navMarker_->setPosition(0,386);
    62         navMarker_->hide();
    63         container_->addChild(navMarker_);
    64 
    65         // these have to fit the data in the level
    66         shipPos_ = Vector3(0.0, 0.0, 0.0);
    67         initialDir_ = Vector3(1.0, 0.0, 0.0);
    68         currentDir_ = initialDir_;
    69         initialOrth_ = Vector3(0.0, 0.0, 1.0);
    70         currentOrth_ = initialOrth_;
    71         plane = Plane(currentDir_, shipPos_);
    72 
    73         setMetricsMode(Ogre::GMM_PIXELS);
     61        setMetricsMode(GMM_PIXELS);
    7462        setMaterialName("Orxonox/Radar");
    7563        resize();
     
    9078
    9179    void RadarOverlayElement::update() {
    92         shipPos_ = SpaceShip::instance_s->getPosition();
    93         currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
    94                 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
    95         plane = Plane(currentDir_, shipPos_);
    96 
    97         RadarObject* ro = firstRadarObject_;
     80        shipPos_ = SpaceShip::getLocalShip()->getPosition();
     81        currentDir_ = SpaceShip::getLocalShip()->getDir();
     82        currentOrth_ = SpaceShip::getLocalShip()->getOrth();
    9883        // iterate through all RadarObjects
    99                 while(ro != NULL){
    100                     // calc position on radar...
    101             ro->radius_ = calcRadius(ro);
    102             ro->phi_ = calcPhi(ro);
    103             ro->right_ = calcRight(ro);
     84        for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
     85        // calc position on radar...
     86            float radius = calcRadius(shipPos_, currentDir_, currentOrth_, (*it));
     87            float phi = calcPhi(shipPos_, currentDir_, currentOrth_, (*it));
     88            bool right = calcRight(shipPos_, currentDir_, currentOrth_, (*it));
    10489
    10590            // set size to fit distance...
    106             float d = (ro->pos_-shipPos_).length();
    107             if(d<4000) ro->panel_->setDimensions(4,4);
    108             else if(d<8000) ro->panel_->setDimensions(3,3);
    109             else if(d<16000) ro->panel_->setDimensions(2,2);
    110             else ro->panel_->setDimensions(1,1);
     91            float d = ((*it)->getPosition()-shipPos_).length();
     92            if(d<10000) (*it)->panel_->setDimensions(4,4);
     93            else if(d<20000) (*it)->panel_->setDimensions(3,3);
     94            else (*it)->panel_->setDimensions(2,2);
    11195
    112             if (ro->right_){
    113                 ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/
    114                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     96            if (right){
     97                (*it)->panel_->setPosition(sin(phi)*radius/
     98                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    11599            }
    116100            else {
    117                 ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/
    118                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
    119             }
    120             ro = ro->next;
    121                 }
    122                 updateNavMarker();
    123     }
    124 
    125     void RadarOverlayElement::updateNavMarker(){
    126         if(focus_ == NULL) return;
    127         // from the angle we find out where to draw the marker
    128         // and which of the four arrows to take
    129         float r1 = atan((float)(windowW_)/(float)(windowH_));
    130         float phi = focus_->phi_;
    131         if(focus_->right_){
    132             if(phi<r1){
    133                 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);
    134                 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    135             }
    136             else if(phi>3.14-r1){
    137                 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);
    138                 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    139             }
    140             else {
    141                 navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
    142                 navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
    143             }
    144         }
    145         else{
    146             if(phi<r1) {
    147                 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);
    148                 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    149             }
    150             else if(phi>3.14-r1) {
    151                 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);
    152                 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    153             }
    154             else {
    155                 navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
    156                 navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
     101                (*it)->panel_->setPosition(-sin(phi)*radius/
     102                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    157103            }
    158104        }
    159105    }
    160106
    161     void RadarOverlayElement::addObject(Vector3 pos){
    162         if(firstRadarObject_ == NULL){
    163             firstRadarObject_ = new RadarObject(container_, pos);
    164             lastRadarObject_ = firstRadarObject_;
     107    void RadarOverlayElement::listObjects(){
     108        int i = 0;
     109        COUT(3) << "List of RadarObjects:\n";
     110        // iterate through all Radar Objects
     111        for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
     112            COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl;
    165113        }
    166         else{
    167             lastRadarObject_->next = new RadarObject(container_, pos);
    168             lastRadarObject_ = lastRadarObject_->next;
    169         }
    170         }
     114    }
    171115
    172         void RadarOverlayElement::listObjects(){
    173             int i = 0;
    174             RadarObject* ro = firstRadarObject_;
    175             COUT(3) << "List of RadarObjects:\n";
    176             // iterate through all Radar Objects
    177             while(ro != NULL) {
    178                 COUT(3) << i++ << ": " << ro->pos_ << std::endl;
    179                 ro = ro->next;
    180             }
    181         }
     116    float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     117        return(acos((dir.dotProduct(obj->getPosition() - pos))/
     118        ((obj->getPosition() - pos).length()*dir.length())));
     119    }
    182120
    183         float RadarOverlayElement::getDist2Focus(){
    184             if(focus_ == NULL) return(0.0);
    185             return((focus_->pos_-shipPos_).length());
    186         }
     121    float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     122        // project difference vector on our plane...
     123        Vector3 proj = Plane(dir, pos).projectVector(obj->getPosition() - pos);
     124        // ...and find out the angle
     125        return(acos((orth.dotProduct(proj))/
     126              (orth.length()*proj.length())));
     127    }
    187128
    188         float RadarOverlayElement::calcRadius(RadarObject* obj){
    189             return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/
    190                         ((obj->pos_ - shipPos_).length()*currentDir_.length())));
    191         }
    192 
    193         float RadarOverlayElement::calcPhi(RadarObject* obj){
    194             // project difference vector on our plane...
    195             Ogre::Vector3 proj = plane.projectVector(obj->pos_ - shipPos_);
    196             // ...and find out the angle
    197             return(acos((currentOrth_.dotProduct(proj))/
    198             (currentOrth_.length()*proj.length())));
    199         }
    200 
    201         bool RadarOverlayElement::calcRight(RadarObject* obj){
    202             if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0)
    203                 return true;
     129    bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     130        if((dir.crossProduct(orth)).dotProduct(obj->getPosition() - pos) > 0)
     131            return true;
    204132        else return false;
    205         }
    206 
    207         /*static*/void RadarOverlayElement::cycleFocus(){
    208             if(RadarOverlayElement::instance_s == NULL) return;
    209 
    210             if(RadarOverlayElement::instance_s->focus_ == NULL){
    211             RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->firstRadarObject_;
    212             }
    213         else{
    214             RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/RedDot");
    215             RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->focus_->next;
    216         }
    217 
    218         if(RadarOverlayElement::instance_s->focus_ == NULL){
    219             RadarOverlayElement::instance_s->navMarker_->hide();
    220         }
    221         else{
    222             RadarOverlayElement::instance_s->navMarker_->show();
    223             RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/WhiteDot");
    224         }
    225         }
     133    }
    226134}
    227 
    228 /* my local clipboard...
    229 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    230 COUT(3) << firstRadarObject_->radius_ << "  " << firstRadarObject_->phi_ << std::endl;
    231 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    232 */
  • code/trunk/src/orxonox/hud/RadarOverlayElement.h

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      ...
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
    28 #ifndef _RADAR_H__
    29 #define _RADAR_H__
     29#ifndef _RadarOverlayElement_H__
     30#define _RadarOverlayElement_H__
    3031
    31 #include <string.h>
    32 #include <OgreOverlayManager.h>
    33 #include <OgreStringConverter.h>
    34 #include <OgreOverlayElement.h>
     32#include "OrxonoxPrereqs.h"
     33
     34#include <OgrePrerequisites.h>
    3535#include <OgrePanelOverlayElement.h>
    36 #include <OgrePrerequisites.h>
    37 
    38 #include <util/Math.h>
    39 #include <string.h>
    40 #include "core/Tickable.h"
    41 #include "core/ConsoleCommand.h"
    42 #include "objects/SpaceShip.h"
    43 #include "../OrxonoxPrereqs.h"
    44 #include "RadarObject.h"
    45 #include "GraphicsEngine.h"
     36#include "util/Math.h"
    4637
    4738namespace orxonox
     
    4940    class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement
    5041    {
    51         private:
    52             Ogre::OverlayManager* om;               // our one and only overlay manager
    53             Ogre::OverlayContainer* container_;     // pointer to the container we're in
    54             Vector3 initialDir_;                        // direction of nose
    55             Vector3 currentDir_;
    56             Vector3 initialOrth_;                   // direction of normal
    57             Vector3 currentOrth_;
    58             Vector3 shipPos_;                       // position of ship
    59             Ogre::Plane plane;                      // plane perpendicular to dir
     42      private:
     43        Ogre::OverlayManager* om;               // our one and only overlay manager
     44        Ogre::OverlayContainer* container_;     // pointer to the container we're in
     45        Vector3 currentDir_;
     46        Vector3 currentOrth_;
     47        Vector3 shipPos_;                       // position of ship
    6048
    61             Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
    62             int left_, top_, dim_;                  // absolute position/dimension
    63             int windowW_, windowH_;                     // absolute window dimensions
     49        Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
     50        int left_, top_, dim_;                  // absolute position/dimension
     51        int windowW_, windowH_;                   // absolute window dimensions
    6452
    65         public:
    66             RadarOverlayElement(const Ogre::String& name);
    67             ~RadarOverlayElement();
    68             void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
    69                         void resize();
    70             void update();
    71             void updateNavMarker();
    72             void addObject(Vector3 pos);
    73             void listObjects();
    74             float getDist2Focus();
    75             float calcRadius(RadarObject* obj);
    76             float calcPhi(RadarObject* obj);
    77             bool calcRight(RadarObject* obj);
     53      public:
     54        RadarOverlayElement(const Ogre::String& name);
     55        ~RadarOverlayElement();
     56        void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
     57        void resize();
     58        void update();
     59        void listObjects();
    7860
    79             Ogre::PanelOverlayElement* navMarker_;  // marker to help navigating
    80                         RadarObject* firstRadarObject_;         // start of linked list
    81                         RadarObject* lastRadarObject_;          // end of linked list
    82                         RadarObject* focus_;                    // object that is focussed
    83 
    84             static RadarOverlayElement* instance_s;
    85             static void cycleFocus();
    86         };
     61        static float calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
     62        static float calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
     63        static bool calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
     64  };
    8765}
    8866
    89 #endif
     67#endif /* _RadarOverlayElement_H__ */
  • code/trunk/src/orxonox/objects/Ambient.cc

    r1293 r1502  
    4747namespace orxonox
    4848{
    49     ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1));
     49    SetConsoleCommand(Ambient, setAmbientLightTest, false).setDefaultValues(ColourValue(1, 1, 1, 1)).setAccessLevel(AccessLevel::Offline);
    5050
    5151    CreateFactory(Ambient);
     
    6666    bool Ambient::create(){
    6767      GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(ambientLight_);
    68       return true;
     68      return Synchronisable::create();
    6969    }
    7070   
  • code/trunk/src/orxonox/objects/Ambient.h

    r1293 r1502  
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4848            void setAmbientLight(const ColourValue& colour);
    49             bool create();
     49            virtual bool create();
    5050            void registerAllVariables();
    5151
  • code/trunk/src/orxonox/objects/Camera.cc

    r1293 r1502  
    6060  {
    6161    CameraHandler::getInstance()->releaseFocus(this);
     62    GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName());
    6263  }
    6364
     
    7576  void Camera::tick(float dt)
    7677  {
    77     if(this->positionNode_ != NULL) {
     78    if (this->positionNode_ != NULL)
     79    {
    7880      // this stuff here may need some adjustments
    79       Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getPosition();
    80       this->cameraNode_->translate(15*dt*offset);
     81      Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getWorldPosition();
     82      float coeff = 15.0f * dt;
     83      if (coeff > 1.0f)
     84        coeff = 1.0f;
    8185
    82       this->cameraNode_->setOrientation(Quaternion::Slerp(0.7, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false));
     86      this->cameraNode_->translate(coeff * offset);
     87
     88      this->cameraNode_->setOrientation(Quaternion::Slerp(7.0f * dt, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false));
    8389    }
    8490  }
  • code/trunk/src/orxonox/objects/Camera.h

    r1407 r1502  
    5050        void setTargetNode(Ogre::SceneNode* obj);
    5151
     52        Ogre::Camera* cam_;
     53
    5254        void tick(float dt);
    5355        void update();
     
    6365        Ogre::SceneNode* cameraNode_;
    6466        Ogre::Vector3 oldPos;
    65         Ogre::Camera* cam_;
    6667        bool bHasFocus_;
    6768    };
  • code/trunk/src/orxonox/objects/CameraHandler.cc

    r1293 r1502  
    2626 *
    2727 */
     28#include "OrxonoxStableHeaders.h"
     29#include "CameraHandler.h"
     30
    2831#include <OgreSceneManager.h>
    2932#include <OgreRenderWindow.h>
    3033
    31 #include "OrxonoxStableHeaders.h"
    3234#include "core/ObjectList.h"
    33 #include "CameraHandler.h"
    3435#include "Camera.h"
    3536#include "GraphicsEngine.h"
  • code/trunk/src/orxonox/objects/Explosion.cc

    r1293 r1502  
    7979        }
    8080    };
     81   
     82    /*bool Explosion::create(){
     83      if(!WorldEntity::create())
     84        return false;
     85      classID=this->getIdentifier()->getNetworkID();
     86    }*/
    8187
    8288    void Explosion::destroyObject()
  • code/trunk/src/orxonox/objects/Explosion.h

    r1056 r1502  
    4343            virtual ~Explosion();
    4444            void destroyObject();
     45            virtual bool create(){return WorldEntity::create();}
    4546
    4647        private:
  • code/trunk/src/orxonox/objects/Model.cc

    r1293 r1502  
    3434#include "GraphicsEngine.h"
    3535#include "core/XMLPort.h"
     36
     37#include <OgreEntity.h>
     38#include <OgreMesh.h>
     39#include <OgreHardwareVertexBuffer.h>
     40#include <OgreMeshManager.h>
     41
    3642
    3743namespace orxonox
     
    7783        this->mesh_.setMesh(meshSrc_);
    7884        this->attachObject(this->mesh_.getEntity());
     85
     86        //HACK!!
     87        /*if ((this->meshSrc_ == "assff.mesh") || (this->meshSrc_ == "ast1.mesh") || (this->meshSrc_ == "ast2.mesh") || (this->meshSrc_ == "ast3.mesh") || (this->meshSrc_ == "ast4.mesh") ||(this->meshSrc_ == "ast5.mesh") || (this->meshSrc_ == "ast6.mesh"))
     88        {
     89          Ogre::MeshPtr pMesh = this->mesh_.getEntity()->getMesh();
     90          //set Mesh to tangentspace
     91          unsigned short src, dest;
     92          if (!pMesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
     93          {
     94            pMesh->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
     95          }
     96          if ((this->meshSrc_ == "assff.mesh"))
     97          {
     98            (this->mesh_.getEntity())->setMaterialName("Assff/BumpMap");
     99          }
     100          else
     101          {
     102            (this->mesh_.getEntity())->setMaterialName("Asteroid/BumpMap");
     103          }
     104
     105
     106        }*/
    79107        COUT(4) << "Loader (Model.cc): Created model" << std::endl;
    80108      }
  • code/trunk/src/orxonox/objects/Model.h

    r1293 r1502  
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646            void setMesh(const std::string& meshname);
    47             bool create();
     47            virtual bool create();
    4848
    4949        protected:
  • code/trunk/src/orxonox/objects/NPC.cc

    r1293 r1502  
    6767  }
    6868 
    69   bool NPC::create(){
    70     Model::create();
    71     return true;
    72   }
    7369
    7470  /**
  • code/trunk/src/orxonox/objects/NPC.h

    r1293 r1502  
    5353      void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable);
    5454      void registerAllVariables();
    55       bool create();
     55      virtual bool create(){return Model::create();}
    5656
    5757    private:
  • code/trunk/src/orxonox/objects/Projectile.cc

    r1360 r1502  
    3030#include "Projectile.h"
    3131
     32#include <OgreBillboard.h>
     33
    3234#include "core/CoreIncludes.h"
    3335#include "core/Executor.h"
     
    4143{
    4244    CreateFactory(Projectile);
     45
     46    float Projectile::speed_ = 0;
    4347
    4448    Projectile::Projectile(SpaceShip* owner) :
     
    6367
    6468        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    65         this->classID = this->getIdentifier()->getNetworkID(); // TODO: remove this hack
    6669//        COUT(3) << this->classID << std::endl;
    6770    }
     
    9295                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    9396                {
    94                     new Explosion(this);
     97                    Explosion *exp = new Explosion(this);
     98                    exp->create();
    9599                    delete this;
    96100                    return;
     
    104108        delete this;
    105109    }
     110
     111    void Projectile::setColour(const ColourValue& colour)
     112    {
     113        this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
     114    }
    106115}
  • code/trunk/src/orxonox/objects/Projectile.h

    r1056 r1502  
    3535#include "../tools/BillboardSet.h"
    3636#include "../tools/Timer.h"
     37#include "util/Math.h"
    3738
    3839namespace orxonox
     
    4647            void destroyObject();
    4748            virtual void tick(float dt);
     49            virtual bool create(){return WorldEntity::create();}
     50            void setColour(const ColourValue& colour);
     51
     52            static float getSpeed()
     53                { return Projectile::speed_; }
     54
     55        protected:
     56            SpaceShip* owner_;
    4857
    4958        private:
    50             SpaceShip* owner_;
    5159            BillboardSet billboard_;
    52             float speed_;
     60            static float speed_;
    5361            float lifetime_;
    5462            Timer<Projectile> destroyTimer_;
  • code/trunk/src/orxonox/objects/Skybox.cc

    r1293 r1502  
    9090    bool Skybox::create(){
    9191      this->setSkybox(skyboxSrc_);
    92       return true;
     92      return Synchronisable::create();
    9393    }
    9494   
  • code/trunk/src/orxonox/objects/Skybox.h

    r1293 r1502  
    4747            void setSkybox(const std::string& skyboxname);
    4848           
    49             bool create();
     49            virtual bool create();
    5050            void registerAllVariables();
    5151            void setSkyboxSrc(const std::string &src);
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1407 r1502  
    4545#include "particle/ParticleInterface.h"
    4646#include "Projectile.h"
     47#include "RotatingProjectile.h"
    4748#include "core/XMLPort.h"
    4849#include "core/ConsoleCommand.h"
    4950#include "network/Client.h"
     51#include "hud/HUD.h"
    5052
    5153namespace orxonox
    5254{
    53     ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);
    54     ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true);
    55     ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);
    56     ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);
    57     ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false);
     55    SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug);
     56    SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User);
     57    SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     58    SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     59    SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     60    SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     61    SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     62    SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold);
     63    SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug);
     64    SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug);
     65    SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug);
    5866
    5967    CreateFactory(SpaceShip);
     
    6472      Iterator<SpaceShip> it;
    6573      for(it = ObjectList<SpaceShip>::start(); it; ++it){
    66         if((it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ) )
     74        if( (it)->myShip_ )
    6775          return *it;
    6876      }
    6977      return NULL;
    7078    }
    71    
     79
    7280    SpaceShip::SpaceShip() :
    7381      //testvector_(0,0,0),
     
    103111      mouseY_(0.0f),
    104112      emitterRate_(0.0f),
    105       server_(false)
     113      myShip_(false),
     114      teamNr_(0),
     115      health_(100)
    106116    {
    107117        RegisterObject(SpaceShip);
     
    112122        this->setConfigValues();
    113123
     124        initialDir_ = Vector3(1.0, 0.0, 0.0);
     125        currentDir_ = initialDir_;
     126        initialOrth_ = Vector3(0.0, 0.0, 1.0);
     127        currentOrth_ = initialOrth_;
     128
     129        this->camName_ = this->getName() + "CamNode";
    114130
    115131        this->setRotationAxis(1, 0, 0);
     
    127143        if (this->cam_)
    128144          delete this->cam_;
     145        if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL)
     146          //remove the radar object
     147          HUD::getSingleton().removeRadarObject(this->getNode());
    129148    }
    130149
    131150    bool SpaceShip::create(){
     151      if(!myShip_){
     152        if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID())
     153          myShip_=true;
     154        else
     155          HUD::getSingleton().addRadarObject(this->getNode(), 3);
     156      }
    132157      if(Model::create())
    133158        this->init();
     
    153178    void SpaceShip::init()
    154179    {
    155         if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))
    156         {
    157               if (!setMouseEventCallback_)
    158               {
    159                   InputManager::addMouseHandler(this, "SpaceShip");
    160                   //InputManager::enableMouseHandler("SpaceShip");
    161                   setMouseEventCallback_ = true;
    162               }
    163         }
    164 
    165180        // START CREATING THRUSTER
    166181        this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
     
    200215        // END CREATING BLINKING LIGHTS
    201216
    202         // START of testing crosshair
    203         this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
    204         this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
    205 
    206         this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
    207         this->chNearNode_->setInheritScale(false);
    208         this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
    209         this->chFarNode_->setInheritScale(false);
    210 
    211         this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
    212         this->chNearNode_->setScale(0.2, 0.2, 0.2);
    213 
    214         this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
    215         this->chFarNode_->setScale(0.4, 0.4, 0.4);
     217        if (this->isExactlyA(Class(SpaceShip)))
     218        {
     219            // START of testing crosshair
     220            this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
     221            this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
     222
     223            this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
     224            this->chNearNode_->setInheritScale(false);
     225            this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
     226            this->chFarNode_->setInheritScale(false);
     227
     228            this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
     229            this->chNearNode_->setScale(0.2, 0.2, 0.2);
     230
     231            this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
     232            this->chFarNode_->setScale(0.4, 0.4, 0.4);
     233        }
    216234
    217235        createCamera();
     
    237255        CameraHandler::getInstance()->requestFocus(cam_);
    238256
     257    }
     258
     259    Camera* SpaceShip::getCamera(){
     260        return cam_;
    239261    }
    240262
     
    295317        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    296318        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
    297         server_=true; // TODO: this is only a hack
     319        myShip_=true; // TODO: this is only a hack
     320
    298321        SpaceShip::create();
    299         getFocus();
     322        if (this->isExactlyA(Class(SpaceShip)))
     323            getFocus();
    300324    }
    301325
     
    308332    }
    309333
    310     void SpaceShip::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    311     {
    312 /*
    313         this->mouseX += e.state.X.rel;
    314         if (this->bInvertMouse_)
    315             this->mouseY += e.state.Y.rel;
    316         else
    317             this->mouseY -= e.state.Y.rel;
    318 
    319 //        if(mouseX>maxMouseX) maxMouseX = mouseX;
    320 //        if(mouseX<minMouseX) minMouseX = mouseX;
    321 //        cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;
    322 
    323         this->moved = true;
    324 */
    325         if (this->bRMousePressed_)
    326         {
    327             this->camNode_->roll(Degree(-rel.x * 0.10));
    328             this->camNode_->yaw(Degree(rel.y * 0.10));
    329         }
    330         else
    331         {
    332             float minDimension = clippingSize.y;
    333             if (clippingSize.x < minDimension)
    334                 minDimension = clippingSize.x;
    335 
    336             this->mouseX_ += rel.x;
    337             if (this->mouseX_ < -minDimension)
    338                 this->mouseX_ = -minDimension;
    339             if (this->mouseX_ > minDimension)
    340                 this->mouseX_ = minDimension;
    341 
    342             this->mouseY_ += rel.y;
    343             if (this->mouseY_ < -minDimension)
    344                 this->mouseY_ = -minDimension;
    345             if (this->mouseY_ > minDimension)
    346                 this->mouseY_ = minDimension;
    347 
    348             float xRotation = this->mouseX_ / minDimension;
    349             xRotation = xRotation*xRotation * sgn(xRotation);
    350             xRotation *= -this->rotationAcceleration_;
    351             if (xRotation > this->maxRotation_)
    352                 xRotation = this->maxRotation_;
    353             if (xRotation < -this->maxRotation_)
    354                 xRotation = -this->maxRotation_;
    355             this->mouseXRotation_ = Radian(xRotation);
    356 
    357             float yRotation = this->mouseY_ / minDimension;
    358             yRotation = yRotation*yRotation * sgn(yRotation);
    359             yRotation *= this->rotationAcceleration_;
    360             if (yRotation > this->maxRotation_)
    361                 yRotation = this->maxRotation_;
    362             if (yRotation < -this->maxRotation_)
    363                 yRotation = -this->maxRotation_;
    364             this->mouseYRotation_ = Radian(yRotation);
    365         }
    366     }
    367 
    368     void SpaceShip::mouseButtonPressed(MouseButton::Enum id)
    369     {
    370         if (id == MouseButton::Left)
    371             this->bLMousePressed_ = true;
    372         else if (id == MouseButton::Right)
    373             this->bRMousePressed_ = true;
    374     }
    375 
    376     void SpaceShip::mouseButtonReleased(MouseButton::Enum id)
    377     {
    378         if (id == MouseButton::Left)
    379             this->bLMousePressed_ = false;
    380         else if (id == MouseButton::Right)
    381         {
    382             this->bRMousePressed_ = false;
    383             this->camNode_->resetOrientation();
    384         }
    385     }
    386 
    387334    std::string SpaceShip::whereAmI() {
    388335        return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
     
    391338    }
    392339
    393     Vector3 SpaceShip::getSPosition() {
    394         return SpaceShip::getLocalShip()->getPosition();
    395     }
    396 
    397     Quaternion SpaceShip::getSOrientation() {
    398         return SpaceShip::getLocalShip()->getOrientation();
     340    Vector3 SpaceShip::getDir() {
     341        return currentDir_;
     342    }
     343
     344    Vector3 SpaceShip::getOrth(){
     345        return currentOrth_;
    399346    }
    400347
     
    403350    void SpaceShip::tick(float dt)
    404351    {
     352        currentDir_ = getOrientation()*initialDir_;
     353                currentOrth_ = getOrientation()*initialOrth_;
     354
    405355        if (this->cam_)
    406356            this->cam_->tick(dt);
     
    422372        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
    423373        {
    424          
    425             Projectile *p = new Projectile(this);
    426            
     374
     375            Projectile *p;
     376            if (this->isExactlyA(Class(SpaceShip)))
     377                p = new RotatingProjectile(this);
     378            else
     379                p = new Projectile(this);
     380            p->setColour(this->getProjectileColour());
     381            p->create();
     382            if(p->classID==0)
     383              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
     384
    427385            p->setBacksync(true);
    428386            this->timeToReload_ = this->reloadTime_;
     
    495453        }
    496454
    497         if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ )
    498         {
    499           COUT(4) << "steering our ship: " << objectID << std::endl;
    500           if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W))
    501             this->acceleration_.x = this->translationAcceleration_;
    502           else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S))
    503             this->acceleration_.x = -this->translationAcceleration_;
    504           else
    505             this->acceleration_.x = 0;
    506 
    507           if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D))
    508             this->acceleration_.y = -this->translationAcceleration_;
    509           else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A))
    510             this->acceleration_.y = this->translationAcceleration_;
    511           else
    512             this->acceleration_.y = 0;
    513 
    514           if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q))
    515             this->momentum_ = Radian(-this->rotationAccelerationRadian_);
    516           else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E))
    517             this->momentum_ = Radian(this->rotationAccelerationRadian_);
    518           else
    519             this->momentum_ = 0;
    520         }/*else
    521           COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
    522455
    523456        WorldEntity::tick(dt);
     
    533466        else
    534467            this->tt_->setRate(0);
    535     }
    536 
     468
     469        if( myShip_ )
     470        {
     471          COUT(4) << "steering our ship: " << objectID << std::endl;
     472          this->acceleration_.x = 0;
     473          this->acceleration_.y = 0;
     474          this->momentum_ = 0;
     475          this->mouseXRotation_ = Radian(0);
     476          this->mouseYRotation_ = Radian(0);
     477          this->bLMousePressed_ = false;
     478        }/*else
     479          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
     480    }
     481
     482    void SpaceShip::movePitch(float val)
     483    {   getLocalShip()->setMovePitch(val);   }
     484    void SpaceShip::moveYaw(float val)
     485    {   getLocalShip()->setMoveYaw(val);   }
     486    void SpaceShip::moveRoll(float val)
     487    {   getLocalShip()->setMoveRoll(val);   }
     488    void SpaceShip::moveLongitudinal(float val)
     489    {   getLocalShip()->setMoveLongitudinal(val);   }
     490    void SpaceShip::moveLateral(float val)
     491    {   getLocalShip()->setMoveLateral(val);   }
     492    void SpaceShip::fire()
     493    {   getLocalShip()->doFire();   }
     494
     495    void SpaceShip::setMovePitch(float val)
     496    {
     497        val = -val * val * sgn(val) * this->rotationAcceleration_;
     498        if (val > this->maxRotation_)
     499            val = this->maxRotation_;
     500        if (val < -this->maxRotation_)
     501            val = -this->maxRotation_;
     502        this->mouseYRotation_ = Radian(val);
     503    }
     504
     505    void SpaceShip::setMoveYaw(float val)
     506    {
     507        val = -val * val * sgn(val) * this->rotationAcceleration_;
     508        if (val > this->maxRotation_)
     509            val = this->maxRotation_;
     510        if (val < -this->maxRotation_)
     511            val = -this->maxRotation_;
     512        this->mouseXRotation_ = Radian(val);
     513    }
     514
     515    void SpaceShip::setMoveRoll(float val)
     516    {
     517        this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val);
     518        //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl;
     519    }
     520
     521    void SpaceShip::setMoveLongitudinal(float val)
     522    {
     523        this->acceleration_.x = this->translationAcceleration_ * val;
     524    }
     525
     526    void SpaceShip::setMoveLateral(float val)
     527    {
     528        this->acceleration_.y = -this->translationAcceleration_ * val;
     529    }
     530
     531    void SpaceShip::doFire()
     532    {
     533        this->bLMousePressed_ = true;
     534    }
    537535}
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1407 r1502  
    4141namespace orxonox
    4242{
    43     class _OrxonoxExport SpaceShip : public Model, public MouseHandler
     43    class _OrxonoxExport SpaceShip : public Model
    4444    {
    4545        public:
    46          
     46
    4747            static SpaceShip *getLocalShip();
    48            
     48
    4949            SpaceShip();
    5050            ~SpaceShip();
    51             bool create();
     51            virtual bool create();
    5252            void registerAllVariables();
    5353            void init();
     
    6464            void setTransDamp(float value);
    6565            void setRotDamp(float value);
     66            void getFocus();
    6667
    67             void getFocus();
    68             static SpaceShip* instance_s;
    69             static Vector3 getSPosition();
    70             static Quaternion getSOrientation();
    7168            static std::string whereAmI();
    7269            static void setMaxSpeedTest(float value)
    7370                { SpaceShip::instance_s->setMaxSpeed(value); }
    7471
    75             void mouseButtonPressed (MouseButton::Enum id);
    76             void mouseButtonReleased(MouseButton::Enum id);
    77             void mouseButtonHeld    (MouseButton::Enum id) { }
    78             void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    79             void mouseScrolled      (int abs, int rel) { }
     72            static void movePitch(float value);
     73            static void moveYaw(float value);
     74            static void moveRoll(float value);
     75            static void moveLongitudinal(float value);
     76            static void moveLateral(float value);
     77            static void fire();
     78            void setMovePitch(float value);
     79            void setMoveYaw(float value);
     80            void setMoveRoll(float value);
     81            void setMoveLongitudinal(float value);
     82            void setMoveLateral(float value);
     83            void doFire();
    8084
    8185            float getMaxSpeed();
     86            Vector3 getDir();
     87            Vector3 getOrth();
     88            Camera* getCamera();
     89
     90            int getTeamNr() const
     91                { return this->teamNr_; }
     92            int getHealth() const
     93                { return this->health_; }
     94
     95            bool getMyShip(){return myShip_;}
     96
     97        protected:
     98            void setTeamNr(int teamNr)
     99                { this->teamNr_ = teamNr; }
    82100
    83101        private:
    84102            void createCamera();
     103            virtual ColourValue getProjectileColour() const
     104                { return ColourValue(1.0, 1.0, 0.5); }
    85105
    86106            Vector3 testvector_;
     107            Vector3 initialDir_;
     108            Vector3 currentDir_;
     109            Vector3 initialOrth_;
     110            Vector3 currentOrth_;
    87111            bool bInvertYAxis_;
    88112            bool setMouseEventCallback_;
     
    130154
    131155            float emitterRate_;
    132             bool server_;
     156
     157        protected:
     158            bool myShip_;
     159
     160            int teamNr_;
     161            int health_;
     162
     163            static SpaceShip* instance_s;
    133164    };
    134165}
  • code/trunk/src/orxonox/objects/WorldEntity.cc

    r1360 r1502  
    8585            this->rotationRate_ += (dt * this->momentum_);
    8686            this->rotate(this->rotationAxis_, dt * this->rotationRate_);
     87            //COUT(3) << "rotationrate: " << this->rotationRate_.valueDegrees() << " momentum: " << this->momentum_.valueDegrees() << std::endl;
    8788        }
    8889    }
     
    153154      registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3);
    154155      //register acceleration & momentum
    155       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
    156       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
    157       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
    158       registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA);
     156//       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x2);
     157//       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x2);
     158//       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x2);
     159//       registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA, 0x2); // only backsync
    159160    }
    160161
  • code/trunk/src/orxonox/objects/WorldEntity.h

    r1227 r1502  
    5353            virtual void loadParams(TiXmlElement* xmlElem);
    5454            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    55             inline bool create(){ return true; }
     55            virtual inline bool create(){ return Synchronisable::create(); }
    5656
    5757            void attachWorldEntity(WorldEntity* entity);
  • code/trunk/src/orxonox/objects/weapon/AmmunitionDump.h

    r1056 r1502  
    6060
    6161  protected:
    62     inline bool create() { return true; }
     62    inline bool create() { return Synchronisable::create(); }
    6363    void registerAllVariables();
    6464
  • code/trunk/src/orxonox/objects/weapon/BulletManager.h

    r1209 r1502  
    6060
    6161  protected:
    62     inline bool create() { return true; }
     62    inline bool create() { return Synchronisable::create(); }
    6363    void registerAllVariables();
    6464
  • code/trunk/src/orxonox/tools/Mesh.cc

    r1056 r1502  
    4040    unsigned int Mesh::meshCounter_s = 0;
    4141
    42     Mesh::Mesh()
     42    Mesh::Mesh() :
     43      entity_(0)
    4344    {
    44         this->entity_ = 0;
    4545    }
    4646
  • code/trunk/src/orxonox/tools/Timer.cc

    r1293 r1502  
    2727 */
    2828
     29#include <set>
     30
    2931#include "OrxonoxStableHeaders.h"
    3032#include "Timer.h"
     
    3739namespace orxonox
    3840{
    39     ConsoleCommandShortcutExtern(delay, AccessLevel::None);
     41    SetConsoleCommandShortcutExtern(delay);
     42    SetConsoleCommandShortcutExtern(killdelays);
     43
     44    static std::set<StaticTimer*> delaytimerset;
    4045
    4146    /**
     
    4752    {
    4853        StaticTimer *delaytimer = new StaticTimer();
     54        delaytimerset.insert(delaytimer);
     55
    4956        ExecutorStatic* delayexecutor = createExecutor(createFunctor(&executeDelayedCommand));
    5057        delayexecutor->setDefaultValues(delaytimer, command);
     
    6168        CommandExecutor::execute(command);
    6269        delete timer;
     70        delaytimerset.erase(timer);
     71    }
     72
     73    /**
     74        @brief Kills all delayed commands.
     75    */
     76    void killdelays()
     77    {
     78        for (std::set<StaticTimer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it)
     79            delete (*it);
     80
     81        delaytimerset.clear();
    6382    }
    6483
  • code/trunk/src/orxonox/tools/Timer.h

    r1056 r1502  
    6969    class StaticTimer;
    7070    void delay(float delay, const std::string& command);
     71    void killdelays();
    7172    void executeDelayedCommand(StaticTimer* timer, const std::string& command);
    7273
Note: See TracChangeset for help on using the changeset viewer.