Changeset 1564 for code/trunk/src/orxonox/hud/RadarOverlayElement.cc
- Timestamp:
- Jun 8, 2008, 5:46:52 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/hud/RadarOverlayElement.cc
r1535 r1564 34 34 #include <OgreStringConverter.h> 35 35 36 #include "GraphicsEngine.h"37 36 #include "core/ConsoleCommand.h" 38 37 #include "objects/Tickable.h" 39 38 #include "objects/SpaceShip.h" 39 #include "util/Math.h" 40 41 #include "GraphicsEngine.h" 40 42 #include "RadarObject.h" 41 43 #include "HUD.h" … … 53 55 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 54 56 // some initial data 55 om = &OverlayManager::getSingleton();56 57 dimRel_ = dimRel; 57 58 leftRel_ = leftRel; 58 59 topRel_ = topRel; 59 container_ = container;60 60 61 61 setMetricsMode(GMM_PIXELS); … … 63 63 resize(); 64 64 65 container _->addChild(this);65 container->addChild(this); 66 66 } 67 67 68 68 void RadarOverlayElement::resize() { 69 69 // if window is resized, we must adapt these... 70 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 71 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 72 dim_ = (int) (dimRel_*windowH_); 73 left_ = (int) (leftRel_*windowW_-dim_/2); 74 top_ = (int) (topRel_*windowH_-dim_/2); 70 dim_ = (int) (dimRel_*GraphicsEngine::getSingleton().getWindowHeight()); 71 left_ = (int) (leftRel_*GraphicsEngine::getSingleton().getWindowWidth()-dim_/2); 72 top_ = (int) (topRel_*GraphicsEngine::getSingleton().getWindowHeight()-dim_/2); 75 73 setPosition(left_, top_); 76 74 setDimensions(dim_,dim_); … … 78 76 79 77 void RadarOverlayElement::update() { 80 shipPos_ = SpaceShip::getLocalShip()->getPosition();81 currentDir_ = SpaceShip::getLocalShip()->getDir();82 currentOrth_ = SpaceShip::getLocalShip()->getOrth();83 78 // iterate through all RadarObjects 84 for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){ 85 // calc position on radar... 86 float radius = calcRadius(shipPos_, currentDir_, currentOrth_, (*it)); 87 float phi = calcPhi(shipPos_, currentDir_, currentOrth_, (*it)); 88 bool right = calcRight(shipPos_, currentDir_, currentOrth_, (*it)); 79 for(std::list<RadarObject*>::iterator it=HUD::getSingleton().getRadarObjects().begin(); it!=HUD::getSingleton().getRadarObjects().end(); it++) 80 { 81 // calc position on radar... 82 // set size to fit distance... 83 float distance = ((*it)->getPosition() - SpaceShip::getLocalShip()->getPosition()).length(); 84 if (distance > 20000) (*it)->getPanel()->setDimensions(1, 1); 85 else if (distance > 10000) (*it)->getPanel()->setDimensions(2, 2); 86 else if (distance > 5000) (*it)->getPanel()->setDimensions(3, 3); 87 else if (distance > 2500) (*it)->getPanel()->setDimensions(4, 4); 88 else if (distance > 1000) (*it)->getPanel()->setDimensions(5, 5); 89 else (*it)->getPanel()->setDimensions(6,6); 89 90 90 // set size to fit distance... 91 float d = ((*it)->getPosition()-shipPos_).length(); 92 if(d<10000) (*it)->panel_->setDimensions(4,4); 93 else if(d<20000) (*it)->panel_->setDimensions(3,3); 94 else (*it)->panel_->setDimensions(2,2); 95 96 if (right){ 97 (*it)->panel_->setPosition(sin(phi)*radius/ 98 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 99 } 100 else { 101 (*it)->panel_->setPosition(-sin(phi)*radius/ 102 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 103 } 91 Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), (*it)->getPosition()); 92 coord = coord * Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture 93 float dimfactor = dim_ / 2.0; 94 (*it)->getPanel()->setPosition((1 + coord.x) * dimfactor + left_ - 2, 95 (1 - coord.y) * dimfactor + top_ - 2); 104 96 } 105 97 } 106 98 107 void RadarOverlayElement::listObjects() {99 void RadarOverlayElement::listObjects() const { 108 100 int i = 0; 109 101 COUT(3) << "List of RadarObjects:\n"; 110 102 // iterate through all Radar Objects 111 for(std:: set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){103 for(std::list<RadarObject*>::const_iterator it=HUD::getSingleton().getRadarObjects().begin(); it!=HUD::getSingleton().getRadarObjects().end(); ++it){ 112 104 COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl; 113 105 } 114 106 } 115 116 float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){117 return(acos((dir.dotProduct(obj->getPosition() - pos))/118 ((obj->getPosition() - pos).length()*dir.length())));119 }120 121 float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){122 // project difference vector on our plane...123 Vector3 proj = Plane(dir, pos).projectVector(obj->getPosition() - pos);124 // ...and find out the angle125 return(acos((orth.dotProduct(proj))/126 (orth.length()*proj.length())));127 }128 129 bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){130 if((dir.crossProduct(orth)).dotProduct(obj->getPosition() - pos) > 0)131 return true;132 else return false;133 }134 107 }
Note: See TracChangeset
for help on using the changeset viewer.