- Timestamp:
- May 24, 2008, 1:39:05 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/orxonox/hud/RadarOverlayElement.cc
r1384 r1406 22 22 * Yuning Chai 23 23 * Co-authors: 24 * ...24 * Felix Schulthess 25 25 * 26 26 */ … … 29 29 #include "RadarOverlayElement.h" 30 30 31 #include <string.h> 32 #include <OgreOverlayManager.h> 33 #include <OgreStringConverter.h> 34 #include <OgrePanelOverlayElement.h> 35 36 #include "GraphicsEngine.h" 37 #include "core/Tickable.h" 38 #include "core/ConsoleCommand.h" 39 #include "objects/SpaceShip.h" 40 #include "HUD.h" 41 31 42 namespace orxonox 32 43 { 33 ConsoleCommandShortcut(RadarOverlayElement, cycleFocus, AccessLevel::User);34 44 35 45 using namespace Ogre; 36 46 37 RadarOverlayElement* RadarOverlayElement::instance_s = NULL; 38 39 RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ 40 RadarOverlayElement::instance_s = this; 47 RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){ 41 48 } 42 49 … … 44 51 } 45 52 46 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, O gre::OverlayContainer* container){53 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 47 54 // some initial data 48 om = &O gre::OverlayManager::getSingleton();55 om = &OverlayManager::getSingleton(); 49 56 dimRel_ = dimRel; 50 57 leftRel_ = leftRel; 51 58 topRel_ = topRel; 52 59 container_ = container; 53 firstRadarObject_ = NULL;54 lastRadarObject_ = NULL;55 focus_ = NULL;56 60 57 // create nav marker ... 58 navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker")); 59 navMarker_->setMetricsMode(Ogre::GMM_PIXELS); 60 navMarker_->setMaterialName("Orxonox/NavMarker"); 61 navMarker_->setDimensions(16,16); 62 navMarker_->setPosition(0,386); 63 navMarker_->hide(); 64 container_->addChild(navMarker_); 65 66 // these have to fit the data in the level 67 shipPos_ = Vector3(0.0, 0.0, 0.0); 68 initialDir_ = Vector3(1.0, 0.0, 0.0); 69 currentDir_ = initialDir_; 70 initialOrth_ = Vector3(0.0, 0.0, 1.0); 71 currentOrth_ = initialOrth_; 72 plane = Plane(currentDir_, shipPos_); 73 74 setMetricsMode(Ogre::GMM_PIXELS); 61 setMetricsMode(GMM_PIXELS); 75 62 setMaterialName("Orxonox/Radar"); 76 63 resize(); … … 91 78 92 79 void RadarOverlayElement::update() { 80 <<<<<<< .working 93 81 shipPos_ = SpaceShip::getLocalShip()->getPosition(); 94 82 currentDir_ = SpaceShip::getLocalShip()->getOrientation()*initialDir_; // according to beni.... … … 97 85 98 86 RadarObject* ro = firstRadarObject_; 87 ======= 88 shipPos_ = SpaceShip::getLocalShip()->getPosition(); 89 currentDir_ = SpaceShip::getLocalShip()->getDir(); 90 currentOrth_ = SpaceShip::getLocalShip()->getOrth(); 91 RadarObject* ro = HUD::getSingleton().getFirstRadarObject(); 92 >>>>>>> .merge-right.r1401 99 93 // iterate through all RadarObjects 100 94 while(ro != NULL){ 101 95 // calc position on radar... 102 ro->radius_ = calcRadius(ro);103 ro->phi_ = calcPhi(ro);104 ro->right_ = calcRight(ro);96 float radius = calcRadius(shipPos_, currentDir_, currentOrth_, ro); 97 float phi = calcPhi(shipPos_, currentDir_, currentOrth_, ro); 98 bool right = calcRight(shipPos_, currentDir_, currentOrth_, ro); 105 99 106 100 // set size to fit distance... … … 111 105 else ro->panel_->setDimensions(1,1); 112 106 113 if (r o->right_){114 ro->panel_->setPosition(sin( ro->phi_)*ro->radius_/115 3.5*dim_/2+dim_/2+left_-2,-cos( ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);107 if (right){ 108 ro->panel_->setPosition(sin(phi)*radius/ 109 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 116 110 } 117 111 else { 118 ro->panel_->setPosition(-sin( ro->phi_)*ro->radius_/119 3.5*dim_/2+dim_/2+left_-2,-cos( ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);112 ro->panel_->setPosition(-sin(phi)*radius/ 113 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 120 114 } 121 115 ro = ro->next; 122 116 } 123 updateNavMarker();124 117 } 125 126 void RadarOverlayElement::updateNavMarker(){127 if(focus_ == NULL) return;128 // from the angle we find out where to draw the marker129 // and which of the four arrows to take130 float r1 = atan((float)(windowW_)/(float)(windowH_));131 float phi = focus_->phi_;132 if(focus_->right_){133 if(phi<r1){134 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);135 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);136 }137 else if(phi>3.14-r1){138 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);139 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);140 }141 else {142 navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);143 navMarker_->setUV(0.5, 0.5, 1.0, 1.0);144 }145 }146 else{147 if(phi<r1) {148 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);149 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);150 }151 else if(phi>3.14-r1) {152 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);153 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);154 }155 else {156 navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);157 navMarker_->setUV(0.0, 0.0, 0.5, 0.5);158 }159 }160 }161 162 void RadarOverlayElement::addObject(Vector3 pos){163 if(firstRadarObject_ == NULL){164 firstRadarObject_ = new RadarObject(container_, pos);165 lastRadarObject_ = firstRadarObject_;166 }167 else{168 lastRadarObject_->next = new RadarObject(container_, pos);169 lastRadarObject_ = lastRadarObject_->next;170 }171 }172 118 173 119 void RadarOverlayElement::listObjects(){ 174 120 int i = 0; 175 RadarObject* ro = firstRadarObject_;121 RadarObject* ro = HUD::getSingleton().getFirstRadarObject(); 176 122 COUT(3) << "List of RadarObjects:\n"; 177 123 // iterate through all Radar Objects … … 182 128 } 183 129 184 float RadarOverlayElement:: getDist2Focus(){185 if(focus_ == NULL) return(0.0);186 return((focus_->pos_-shipPos_).length());130 float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 131 return(acos((dir.dotProduct(obj->pos_ - pos))/ 132 ((obj->pos_ - pos).length()*dir.length()))); 187 133 } 188 134 189 float RadarOverlayElement::calcRadius(RadarObject* obj){ 190 return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/ 191 ((obj->pos_ - shipPos_).length()*currentDir_.length()))); 135 float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 136 // project difference vector on our plane... 137 Vector3 proj = Plane(dir, pos).projectVector(obj->pos_ - pos); 138 // ...and find out the angle 139 return(acos((orth.dotProduct(proj))/ 140 (orth.length()*proj.length()))); 192 141 } 193 142 194 float RadarOverlayElement::calcPhi(RadarObject* obj){ 195 // project difference vector on our plane... 196 Ogre::Vector3 proj = plane.projectVector(obj->pos_ - shipPos_); 197 // ...and find out the angle 198 return(acos((currentOrth_.dotProduct(proj))/ 199 (currentOrth_.length()*proj.length()))); 200 } 201 202 bool RadarOverlayElement::calcRight(RadarObject* obj){ 203 if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0) 143 bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 144 if((dir.crossProduct(orth)).dotProduct(obj->pos_ - pos) > 0) 204 145 return true; 205 146 else return false; 206 147 } 207 208 /*static*/void RadarOverlayElement::cycleFocus(){209 if(RadarOverlayElement::instance_s == NULL) return;210 211 if(RadarOverlayElement::instance_s->focus_ == NULL){212 RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->firstRadarObject_;213 }214 else{215 RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/RedDot");216 RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->focus_->next;217 }218 219 if(RadarOverlayElement::instance_s->focus_ == NULL){220 RadarOverlayElement::instance_s->navMarker_->hide();221 }222 else{223 RadarOverlayElement::instance_s->navMarker_->show();224 RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/WhiteDot");225 }226 }227 148 } 228 229 /* my local clipboard...230 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";231 COUT(3) << firstRadarObject_->radius_ << " " << firstRadarObject_->phi_ << std::endl;232 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";233 */
Note: See TracChangeset
for help on using the changeset viewer.