Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (16 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.