Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 16, 2008, 11:27:09 AM (16 years ago)
Author:
FelixSchulthess
Message:

dot on radar moves now, but not continious (nonsatisfying)

File:
1 edited

Legend:

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

    r1295 r1308  
    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_ = 100;
     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, 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     
     72        setMetricsMode(Ogre::GMM_PIXELS);
     73        setPosition(left,top);
     74        setDimensions(dim_,dim_);
     75        setMaterialName("Orxonox/Radar");
     76
     77        om = &Ogre::OverlayManager::getSingleton();
     78        point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point"));
     79        point->show();
     80        container->addChild(point);
     81        point->setMaterialName("Orxonox/RedPoint");
     82        point->setDimensions(5,5);
     83        point->setMetricsMode(Ogre::GMM_PIXELS);
     84
    9985    }
    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);
     86
     87//    void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){
     88//        dirX_=dirX;
     89//        dirY_=dirY;
     90//        dirZ_=dirZ;
     91//        ortX_=ortX;
     92//        ortY_=ortY;
     93//        ortZ_=ortZ;
     94//    }
     95
     96    void RadarOverlayElement::update() {
     97        if(count_++ >= 100) {           // for testing purposes
     98                        count_ = 0;
     99                        COUT(3) << "pos:  " << shipPos_ << std::endl;
     100                        COUT(3) << "dir:  " << currentDir_ << std::endl;
     101                        COUT(3) << "orth: " << currentOrth_ << std::endl << std::endl;         
     102        }
     103        shipPos_ = SpaceShip::instance_s->getPosition();
     104        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
     105                currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
     106               
     107                radius_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length()));
     108        phi_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length()));
     109        vec_ = currentDir_.crossProduct(currentOrth_);
     110        if(vec_.dotProduct(targetPos_ - shipPos_) > 0) right_ = true;
     111        else right_=false;
     112       
     113        if (right_){
     114            point->setPosition(sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);         
     115        }
     116        else {
     117            point->setPosition(-sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);
     118        }
    106119    }
    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  
     120
    120121}
    121122
Note: See TracChangeset for help on using the changeset viewer.