- Timestamp:
- May 20, 2008, 1:38:30 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc~
r1308 r1335 41 41 #include <OgreStringConverter.h> 42 42 #include "RadarOverlayElement.h" 43 #include "GraphicsEngine.h" 43 44 44 45 namespace orxonox … … 52 53 } 53 54 54 void RadarOverlayElement::initialise(){ 55 PanelOverlayElement::initialise(); 56 } 57 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; 55 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){ 56 om = &Ogre::OverlayManager::getSingleton(); 57 dimRel_ = dimRel; 58 leftRel_ = leftRel; 59 topRel_ = topRel; 63 60 container_ = container; 64 61 65 62 shipPos_ = Vector3(0.0, 0.0, 0.0); 66 targetPos_ = Vector3(42.0, 0.0, 0.0);67 63 initialDir_ = Vector3(1.0, 0.0, 0.0); 68 64 currentDir_ = initialDir_; 69 65 initialOrth_ = Vector3(0.0, 0.0, 1.0); 70 66 currentOrth_ = initialOrth_; 71 67 72 68 setMetricsMode(Ogre::GMM_PIXELS); 73 setPosition(left,top);74 setDimensions(dim_,dim_);75 69 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 70 resize(); 71 72 container_->addChild(this); 85 73 } 86 74 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 // } 75 void RadarOverlayElement::resize() { 76 // if window is resized, we must adapt these... 77 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 78 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 79 dim_ = dimRel_*windowH_; 80 left_ = leftRel_*windowW_-dim_/2; 81 top_ = topRel_*windowH_-dim_/2; 82 setPosition(left_, top_); 83 setDimensions(dim_,dim_); 84 } 95 85 96 86 void RadarOverlayElement::update() { 97 if(count_++ >= 100) { // for testing purposes98 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 87 shipPos_ = SpaceShip::instance_s->getPosition(); 104 88 currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; // according to beni.... 105 89 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_; 90 91 if(tomato_ == NULL) return; 106 92 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); 93 tomato_->radius_ = acos((currentDir_.dotProduct(tomato_->pos_ - shipPos_))/ 94 ((tomato_->pos_ - shipPos_).length()*currentDir_.length())); 95 tomato_->phi_ = acos((currentOrth_.dotProduct(tomato_->pos_ - shipPos_))/ 96 ((tomato_->pos_ - shipPos_).length()*currentOrth_.length())); 97 if((currentDir_.crossProduct(currentOrth_)).dotProduct(tomato_->pos_ - shipPos_) > 0) 98 tomato_->right_ = true; 99 else tomato_->right_=false; 100 101 if (tomato_->right_){ 102 tomato_->panel_->setPosition(sin(tomato_->phi_)*tomato_->radius_/ 103 3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2); 115 104 } 116 105 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); 106 tomato_->panel_->setPosition(-sin(tomato_->phi_)*tomato_->radius_/ 107 3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2); 118 108 } 109 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n"; 110 COUT(3) << tomato_->radius_ << " " << tomato_->phi_ << std::endl; 111 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n"; 119 112 } 120 113 114 void RadarOverlayElement::addObject(Vector3 pos){ 115 tomato_ = new RadarObject(container_); 116 tomato_->pos_ = pos; 117 } 118 119 //// RadarObject //// 120 121 int RadarObject::count = 0; 122 123 RadarObject::RadarObject(Ogre::OverlayContainer* container){ 124 container_ = container; 125 pos_ = Vector3(0.0, 0.0, 0.0); 126 init(); 127 } 128 129 RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){ 130 container_ = container; 131 pos_ = pos; 132 init(); 133 } 134 135 RadarObject::~RadarObject(){} 136 137 void RadarObject::init(){ 138 om = &Ogre::OverlayManager::getSingleton(); 139 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", 140 "Object"+Ogre::StringConverter::toString(count++))); 141 panel_->setMaterialName("Orxonox/RedDot"); 142 panel_->setDimensions(5,5); 143 panel_->setMetricsMode(Ogre::GMM_PIXELS); 144 panel_->show(); 145 container_->addChild(panel_); 146 } 121 147 } 122 148
Note: See TracChangeset
for help on using the changeset viewer.