Changeset 1400 for code/trunk/src/orxonox/hud/RadarOverlayElement.cc
- Timestamp:
- May 24, 2008, 12:24:30 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/hud/RadarOverlayElement.cc
r1399 r1400 59 59 container_ = container; 60 60 61 // these have to fit the data in the level62 shipPos_ = Vector3(0.0, 0.0, 0.0);63 initialDir_ = Vector3(1.0, 0.0, 0.0);64 currentDir_ = initialDir_;65 initialOrth_ = Vector3(0.0, 0.0, 1.0);66 currentOrth_ = initialOrth_;67 plane = Plane(currentDir_, shipPos_);68 69 61 setMetricsMode(GMM_PIXELS); 70 62 setMaterialName("Orxonox/Radar"); … … 86 78 87 79 void RadarOverlayElement::update() { 88 shipPos_ = SpaceShip::instance_s->getPosition(); 89 currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; 90 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_; 91 plane = Plane(currentDir_, shipPos_); 80 shipPos_ = SpaceShip::getLocalShip()->getPosition(); 81 currentDir_ = SpaceShip::getLocalShip()->getDir(); 82 currentOrth_ = SpaceShip::getLocalShip()->getOrth(); 92 83 RadarObject* ro = HUD::getSingleton().getFirstRadarObject(); 93 84 // iterate through all RadarObjects 94 85 while(ro != NULL){ 95 86 // calc position on radar... 96 ro->radius_ = calcRadius(ro);97 ro->phi_ = calcPhi(ro);98 ro->right_ = calcRight(ro);87 float radius = calcRadius(shipPos_, currentDir_, currentOrth_, ro); 88 float phi = calcPhi(shipPos_, currentDir_, currentOrth_, ro); 89 bool right = calcRight(shipPos_, currentDir_, currentOrth_, ro); 99 90 100 91 // set size to fit distance... … … 105 96 else ro->panel_->setDimensions(1,1); 106 97 107 if (r o->right_){108 ro->panel_->setPosition(sin( ro->phi_)*ro->radius_/109 3.5*dim_/2+dim_/2+left_-2,-cos( ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);98 if (right){ 99 ro->panel_->setPosition(sin(phi)*radius/ 100 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 110 101 } 111 102 else { 112 ro->panel_->setPosition(-sin( ro->phi_)*ro->radius_/113 3.5*dim_/2+dim_/2+left_-2,-cos( ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);103 ro->panel_->setPosition(-sin(phi)*radius/ 104 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 114 105 } 115 106 ro = ro->next; … … 128 119 } 129 120 130 float RadarOverlayElement::calcRadius( RadarObject* obj){131 return(acos(( currentDir_.dotProduct(obj->pos_ - shipPos_))/132 ((obj->pos_ - shipPos_).length()*currentDir_.length())));121 float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 122 return(acos((dir.dotProduct(obj->pos_ - pos))/ 123 ((obj->pos_ - pos).length()*dir.length()))); 133 124 } 134 125 135 float RadarOverlayElement::calcPhi( RadarObject* obj){126 float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 136 127 // project difference vector on our plane... 137 Vector3 proj = plane.projectVector(obj->pos_ - shipPos_);128 Vector3 proj = Plane(dir, pos).projectVector(obj->pos_ - pos); 138 129 // ...and find out the angle 139 return(acos(( currentOrth_.dotProduct(proj))/140 ( currentOrth_.length()*proj.length())));130 return(acos((orth.dotProduct(proj))/ 131 (orth.length()*proj.length()))); 141 132 } 142 133 143 bool RadarOverlayElement::calcRight( RadarObject* obj){144 if(( currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0)134 bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 135 if((dir.crossProduct(orth)).dotProduct(obj->pos_ - pos) > 0) 145 136 return true; 146 137 else return false;
Note: See TracChangeset
for help on using the changeset viewer.