- Timestamp:
- May 15, 2008, 10:10:47 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc
r1295 r1302 26 26 */ 27 27 28 /* local coordinate system of space ship :28 /* local coordinate system of space ship at the beginning: 29 29 30 30 y … … 33 33 | / 34 34 |/ 35 35 x +------O 36 36 */ 37 37 … … 42 42 #include "RadarOverlayElement.h" 43 43 44 45 44 namespace orxonox 46 45 { 47 using namespace Ogre;46 using namespace Ogre; 48 47 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 } 52 50 53 RadarOverlayElement::~RadarOverlayElement(){} 51 RadarOverlayElement::~RadarOverlayElement(){ 52 } 54 53 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 } 60 57 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; 88 64 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 } 99 104 } 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.... 106 118 } 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 120 120 } 121 121
Note: See TracChangeset
for help on using the changeset viewer.