Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1302


Ignore:
Timestamp:
May 15, 2008, 10:10:47 PM (16 years ago)
Author:
FelixSchulthess
Message:

using vectors instead of integers now

Location:
code/branches/hud3/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud3/src/orxonox/hud/HUD.cc

    r1281 r1302  
    3030#include <OgreOverlay.h>
    3131#include <OgreOverlayContainer.h>
    32 #include <OgreOverlayManager.h>ma
     32#include <OgreOverlayManager.h>
    3333#include <OgreSceneNode.h>
    3434#include <OgreEntity.h>
     
    5050
    5151    Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
    52    
     52
    5353    BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
    5454    overlayManager.addOverlayElementFactory(barOverlayElementFactory);
    55    
     55
    5656    SmartBarOverlayElementFactory *smartBarOverlayElementFactory = new SmartBarOverlayElementFactory();
    5757    overlayManager.addOverlayElementFactory(smartBarOverlayElementFactory);
    58    
     58
    5959    RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory();
    6060    overlayManager.addOverlayElementFactory(radarOverlayElementFactory);
    61    
    62     Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD"); 
     61
     62    Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD");
    6363
    6464    Ogre::OverlayContainer* energyCounterPanel = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "Orxonox/HUD/energyCounterPanel"));
    65    
     65
    6666    energyCounter = static_cast<SmartBarOverlayElement*>(overlayManager.createOverlayElement("SmartBar", "energyCounter"));
    6767    energyCounter->show();
    68    
    69    
     68
     69
    7070    radar = static_cast<RadarOverlayElement*>(overlayManager.createOverlayElement("Radar", "radar"));
    7171    radar->show();
    7272
    73    
     73
    7474/*    TextAreaOverlayElement* test = static_cast<TextAreaOverlayElement*>(overlayManager.createOverlayElement("TextArea", "test"));
    75    
     75
    7676    int dirX, dirY, dirZ;      //flying direction
    7777    int ortX, ortY, ortZ;      //orthogonal direction
     
    8181    double beta;               //defines the angle in the radar
    8282    bool right;                //checks whether the object is on the right side (since cos is not bijective)
    83    
     83
    8484    dirX = 1;
    8585    dirY = 0;
    8686    dirZ = 0;
    87    
     87
    8888    ortX = 0;
    8989    ortY = 0;
    9090    ortZ = 1;
    91    
     91
    9292    dX = -2;
    9393    dY = 2;
    9494    dZ = 0;
    95    
     95
    9696    alpha = acos((dirX*dX+dirY*dY+dirZ*dZ)/(sqrt(pow(dX,2)+pow(dY,2)+pow(dZ,2))*sqrt(pow(dirX,2)+pow(dirY,2)+pow(dirZ,2))));
    9797    beta = acos((ortX*dX+ortY*dY+ortZ*dZ)/(sqrt(pow(dX,2)+pow(dY,2)+pow(dZ,2))*sqrt(pow(ortX,2)+pow(ortY,2)+pow(ortZ,2))));
     
    9999    vecY = dirZ*ortX - dirX*ortZ;
    100100    vecZ = dirX*ortY - dirY*ortX;
    101    
     101
    102102    if((vecX*dX+vecY*dY+vecZ*dZ)>0){right=true;}
    103103    else right=false;
    104    
     104
    105105    test->setCaption("hell");
    106106    test->setPosition(10,10);
    107107    test->setDimensions(20,20);
    108108    test->show();
    109     test->setMetricsMode(Ogre::GMM_PIXELS);     
     109    test->setMetricsMode(Ogre::GMM_PIXELS);
    110110    energyCounterPanel->addChild(test);
    111    
     111
    112112    COUT(0)<<alpha<<" "<<beta<<" "<<right<<std::endl;
    113113*/
    114    
     114
    115115    energyCounterPanel->addChild(energyCounter);
    116116    energyCounterPanel->addChild(radar);
    117117    energyCounterPanel->show();
    118    
     118
    119119    orxonoxOverlay->add2D(energyCounterPanel);
    120120    orxonoxOverlay->show();
    121121
    122    
    123    
     122
     123
    124124    // important: don't use SceneManager to create the node! but register the creator scene manager.
    125125/*    ogreNode_ = new Ogre::SceneNode(Orxonox::getSingleton()->getSceneManager(), "hudNoedely");
    126    
     126
    127127    ogreNode_->setPosition(80,-60,-200);
    128128    ogreNode_->setScale(0.4,0.4,0.4);
     
    132132//    orxonoxOverlay->add3D(ogreNode_);
    133133*/
    134    
     134
    135135    energyCounterPanel->setLeft(-50);
    136136    energyCounterPanel->setTop(10);
     
    138138    energyCounterPanel->setHeight(20);
    139139    energyCounterPanel->setHorizontalAlignment(Ogre::GHA_CENTER);
    140     energyCounterPanel->setMetricsMode(Ogre::GMM_PIXELS);       
    141        
     140    energyCounterPanel->setMetricsMode(Ogre::GMM_PIXELS);
     141
    142142    energyCounter->initSmartBarOverlayElement(-100,0,200,20,BarOverlayElement::LEFT);
    143143    energyCounter->reset(80);
    144    
     144
    145145    radar->initRadarOverlayElement(10,10,200,energyCounterPanel);
    146146
    147    
     147
    148148  }
    149149
    150 /*  void HUD::tick(float dt)
     150  void HUD::tick(float dt)
    151151  {
    152     if (this->ogreNode_)
     152      radar->update();
     153    /*if (this->ogreNode_)
    153154    {
    154155      this->ogreNode_->roll(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL);
    155       this->ogreNode_->yaw(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); 
     156      this->ogreNode_->yaw(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL);
    156157      this->ogreNode_->pitch(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL);
    157     }
     158    }*/
    158159  }
    159 */
     160
    160161  HUD::~HUD(void){}
    161 
    162 
    163162
    164163}
  • code/branches/hud3/src/orxonox/hud/HUD.h

    r1281 r1302  
    4444namespace orxonox
    4545{
    46   class _OrxonoxExport HUD// : Tickable
     46  class _OrxonoxExport HUD : Tickable
    4747  {
    4848  private:
     
    5252    ~HUD();
    5353
    54 //    virtual void tick(float);
     54    virtual void tick(float);
    5555
    5656    SmartBarOverlayElement* energyCounter;
    57    
     57
    5858    RadarOverlayElement* radar;
    59 //    Ogre::SceneNode* ogreNode_;
    6059  };
    61 }       
     60}
    6261
    6362#endif
  • code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc

    r1295 r1302  
    2626*/
    2727
    28 /*      local coordinate system of space ship:
     28/*      local coordinate system of space ship at the beginning:
    2929
    3030                        y
     
    3333                        | /
    3434                        |/
    35                x +------O
     35   x +------O
    3636*/
    3737
     
    4242#include "RadarOverlayElement.h"
    4343
    44 
    4544namespace orxonox
    4645{
    47   using namespace Ogre;
     46    using namespace Ogre;
    4847
    49   RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
    50     initialDir = Vector3(0.0, 0.0, 1.0);
    51   }
     48    RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
     49    }
    5250
    53   RadarOverlayElement::~RadarOverlayElement(){}
     51    RadarOverlayElement::~RadarOverlayElement(){
     52    }
    5453
    55   void RadarOverlayElement::initialise(){
    56     PanelOverlayElement::initialise();
    57   }
    58  
    59   void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container){
     54    void RadarOverlayElement::initialise(){
     55        PanelOverlayElement::initialise();
     56    }
    6057
    61     dirX_ = 0;  // direction of travel
    62     dirY_ = 0;
    63     dirZ_ = 1;
    64    
    65     ortX_ = 0;  // normal of ship
    66     ortY_ = 1;
    67     ortZ_ = 0;
    68    
    69     dX_ = 37;
    70     dY_ = 0;
    71     dZ_ = 0;
    72    
    73     alpha_ = acos((dirX_*dX_+dirY_*dY_+dirZ_*dZ_)/(sqrt(pow(dX_,2)+pow(dY_,2)+pow(dZ_,2))*sqrt(pow(dirX_,2)+pow(dirY_,2)+pow(dirZ_,2))));
    74     beta_ = acos((ortX_*dX_+ortY_*dY_+ortZ_*dZ_)/(sqrt(pow(dX_,2)+pow(dY_,2)+pow(dZ_,2))*sqrt(pow(ortX_,2)+pow(ortY_,2)+pow(ortZ_,2))));
    75     vecX_ = dirY_*ortZ_ - dirZ_*ortY_;
    76     vecY_ = dirZ_*ortX_ - dirX_*ortZ_;
    77     vecZ_ = dirX_*ortY_ - dirY_*ortX_;
    78    
    79     if((vecX_*dX_+vecY_*dY_+vecZ_*dZ_)>0){right_=true;}
    80     else right_=false;
    81    
    82     setMetricsMode(Ogre::GMM_PIXELS);
    83     setPosition(left,top);
    84     setDimensions(dim,dim);
    85     setMaterialName("Orxonox/Radar");
    86    
    87     Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
     58    void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container){
     59        dim_ = dim;
     60        left_ = left;
     61        top_ = top;
     62        count_ = 0;
     63        container_ = container;
    8864
    89     PanelOverlayElement* point = static_cast<PanelOverlayElement*>(overlayManager.createOverlayElement("Panel", "point"));
    90     point->show();
    91    
    92     container->addChild(point);
    93    
    94     if (right_){
    95       point->setPosition(sin(beta_)*alpha_/3.5*dim/2+dim/2+left-2,-cos(beta_)*alpha_/3.5*dim/2+dim/2+top-2);
    96       point->setMaterialName("Orxonox/RedPoint");
    97       point->setDimensions(5,5);
    98       point->setMetricsMode(Ogre::GMM_PIXELS);
     65        shipPos_ = Vector3(0.0, 0.0, 0.0);
     66        targetPos_ = Vector3(42.0, 42.0, 0.0);
     67        initialDir_ = Vector3(0.0, 0.0, 1.0);
     68        currentDir_ = initialDir_;
     69        initialOrth_ = Vector3(0.0, 1.0, 0.0);
     70        currentOrth_ = initialOrth_;
     71
     72        alpha_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length()));
     73        beta_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length()));
     74        vec_ = currentDir_.crossProduct(currentOrth_);
     75
     76        if(vec_.dotProduct(targetPos_ - shipPos_) > 0)
     77            right_ = true;
     78        else
     79            right_=false;
     80
     81        setMetricsMode(Ogre::GMM_PIXELS);
     82        setPosition(left,top);
     83        setDimensions(dim_,dim_);
     84        setMaterialName("Orxonox/Radar");
     85
     86        om = &Ogre::OverlayManager::getSingleton();
     87        point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point"));
     88        point->show();
     89        container->addChild(point);
     90
     91        if (right_){
     92            point->setPosition(sin(beta_)*alpha_/3.5*dim_/2+dim_/2+left-2,-cos(beta_)*alpha_/3.5*dim_/2+dim_/2+top-2);
     93            point->setMaterialName("Orxonox/RedPoint");
     94            point->setDimensions(5,5);
     95            point->setMetricsMode(Ogre::GMM_PIXELS);
     96        }
     97
     98        else {
     99            point->setPosition(-sin(beta_)*alpha_/3.5*dim_/2+dim_/2+left-2,-cos(beta_)*alpha_/3.5*dim_/2+dim_/2+top-2);
     100            point->setMaterialName("Orxonox/RedPoint");
     101            point->setDimensions(5,5);
     102            point->setMetricsMode(Ogre::GMM_PIXELS);
     103        }
    99104    }
    100  
    101     else {
    102       point->setPosition(-sin(beta_)*alpha_/3.5*dim/2+dim/2+left-2,-cos(beta_)*alpha_/3.5*dim/2+dim/2+top-2);
    103       point->setMaterialName("Orxonox/RedPoint");
    104       point->setDimensions(5,5);
    105       point->setMetricsMode(Ogre::GMM_PIXELS);
     105
     106//    void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){
     107//        dirX_=dirX;
     108//        dirY_=dirY;
     109//        dirZ_=dirZ;
     110//        ortX_=ortX;
     111//        ortY_=ortY;
     112//        ortZ_=ortZ;
     113//    }
     114
     115    void RadarOverlayElement::update() {
     116        shipPos_ = SpaceShip::instance_s->getPosition();
     117        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; // according to beni....
    106118    }
    107   }
    108    
    109   void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){
    110     dirX_=dirX;
    111     dirY_=dirY;
    112     dirZ_=dirZ;
    113     ortX_=ortX;
    114     ortY_=ortY;
    115     ortZ_=ortZ;
    116   }
    117  
    118  
    119  
     119
    120120}
    121121
  • code/branches/hud3/src/orxonox/hud/RadarOverlayElement.h

    r1295 r1302  
    3232#include <OgreOverlayElement.h>
    3333#include <OgrePanelOverlayElement.h>
    34 #include <math.h>
    3534#include <util/Math.h>
    3635#include <string.h>
    3736#include "core/Tickable.h"
    3837#include <OgrePrerequisites.h>
     38#include "objects/SpaceShip.h"
    3939#include "../OrxonoxPrereqs.h"
    4040
     
    4242{
    4343
    44   class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement, public Tickable
     44  class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement
    4545  {
    4646  private:
    47    
    48     PanelOverlayElement* point[100];
    49    
    50     Vector3 initialDir;         //initial direction
    51     int dirX_, dirY_, dirZ_;    //flying direction
    52     int ortX_, ortY_, ortZ_;    //orthogonal direction
    53     int dX_, dY_, dZ_;          //distance between main ship and the object
    54     int vecX_, vecY_, vecZ_;    //vector product dir X ort
    55     double alpha_;              //defines the radius in the radar
    56     double beta_;               //defines the angle in the radar
    57     bool right_;                //checks whether the object is on the right side (since cos is not bijective)
    58    
    59 //    static int ID = 0;
     47
     48    Ogre::PanelOverlayElement* point;
     49    Ogre::OverlayContainer* container_;
     50    Ogre::OverlayManager* om;       //pointer to the one and only overlay manager
     51    Vector3 initialDir_;                //initial direction of ship
     52    Vector3 currentDir_;            //current direction of ship
     53    Vector3 initialOrth_;
     54    Vector3 currentOrth_;
     55    Vector3 targetPos_;             //position of target
     56    Vector3 shipPos_;               //position of ship
     57    Vector3 vec_;                   //vector product dir X ort
     58    double alpha_;                  //defines the radius in the radar
     59    double beta_;                   //defines the angle in the radar
     60    float left_, top_;
     61    bool right_;                    //checks whether the object is on the right side (since cos is not bijective)
     62    int count_;
     63    int dim_;
    6064
    6165  public:
    62    
     66
    6367    RadarOverlayElement(const Ogre::String& name);
    6468    virtual ~RadarOverlayElement();
    6569    virtual void initialise();
    66 
     70    void update();
    6771    void initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container);
    6872    void setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ);
    69     void tick(float dt);
    7073    int newShip(int X, int Y, int Z);
    71    
     74
    7275    void resetShip(int shipID, int Y, int Z);
    7376  };
    74 }       
     77}
    7578
    7679#endif
  • code/branches/hud3/src/orxonox/objects/SpaceShip.h

    r1295 r1302  
    6464
    6565            void getFocus();
    66 
     66            static SpaceShip* instance_s;
    6767            static Vector3 getSPosition();
    6868            static Quaternion getSOrientation();
     
    8080        private:
    8181            void createCamera();
    82             static SpaceShip* instance_s;
    8382
    8483            Vector3 testvector_;
Note: See TracChangeset for help on using the changeset viewer.