- Timestamp:
- May 20, 2008, 1:38:30 PM (17 years ago)
- Location:
- code/branches/hud3/src/orxonox/hud
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud3/src/orxonox/hud/HUD.cc
r1332 r1335 34 34 #include <OgreEntity.h> 35 35 #include "core/Debug.h" 36 36 #include "objects/SpaceShip.h" 37 37 #include "HUD.h" 38 38 #include "BarOverlayElement.h" … … 46 46 HUD::HUD(int zoom){ 47 47 om = &Ogre::OverlayManager::getSingleton(); 48 48 49 // create Factories 49 50 BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); 50 51 om->addOverlayElementFactory(barOverlayElementFactory); 51 52 52 RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); 53 53 om->addOverlayElementFactory(radarOverlayElementFactory); 54 54 55 55 orxonoxHUD = om->create("Orxonox/HUD"); 56 57 56 container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container")); 58 59 energy Counter = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyCounter"));60 energy Counter->show();61 62 speedo = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedo"));63 speedo ->show();64 57 // create energy bar 58 energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar")); 59 energyBar->show(); 60 // create speedo bar 61 speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar")); 62 speedoBar->show(); 63 // create radar 65 64 radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar")); 66 65 radar->show(); 67 66 67 // set up screen-wide container 68 68 container->show(); 69 69 70 orxonoxHUD->add2D(container); 70 71 orxonoxHUD->show(); … … 74 75 container->setHeight(1.0); 75 76 container->setMetricsMode(Ogre::GMM_RELATIVE); 76 77 energyCounter->init(0.01, 0.95, 0.4, 0.04, container); 78 energyCounter->setValue(1); 79 80 speedo->init(0.01, 0.90, 0.4, 0.04, container); 81 77 energyBar->init(0.01, 0.94, 0.4, 0.04, container); 78 energyBar->setValue(1); 79 speedoBar->init(0.01, 0.90, 0.4, 0.04, container); 82 80 radar->init(0.5, 0.9, 0.2, container); 81 radar->addObject(Vector3(1337.0, 0.0, 0.0)); 83 82 } 84 83 85 84 void HUD::tick(float dt) 86 85 { 87 energy Counter->resize();86 energyBar->resize(); 88 87 89 88 float v = SpaceShip::instance_s->getVelocity().length(); 90 89 float vmax = SpaceShip::instance_s->getMaxSpeed(); 91 speedo ->setValue(v/vmax);92 speedo ->resize();90 speedoBar->setValue(v/vmax); 91 speedoBar->resize(); 93 92 94 93 radar->resize(); -
code/branches/hud3/src/orxonox/hud/HUD.h
r1328 r1335 32 32 #include <string.h> 33 33 #include <OgreOverlayElement.h> 34 #include <OgreTextAreaOverlayElement.h>35 34 #include <OgrePrerequisites.h> 36 35 37 36 #include "OrxonoxPrereqs.h" 38 #include "objects/SpaceShip.h"39 37 #include "core/Tickable.h" 40 38 #include "BarOverlayElement.h" … … 50 48 Ogre::Overlay* orxonoxHUD; 51 49 Ogre::OverlayContainer* container; 52 BarOverlayElement* energy Counter;53 BarOverlayElement* speedo ;50 BarOverlayElement* energyBar; 51 BarOverlayElement* speedoBar; 54 52 RadarOverlayElement* radar; 55 53 -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc
r1329 r1335 53 53 } 54 54 55 void RadarOverlayElement::initialise(){56 PanelOverlayElement::initialise();57 }58 59 55 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){ 60 count_ = 0; 56 om = &Ogre::OverlayManager::getSingleton(); 61 57 dimRel_ = dimRel; 62 58 leftRel_ = leftRel; … … 65 61 66 62 shipPos_ = Vector3(0.0, 0.0, 0.0); 67 targetPos_ = Vector3(1337.0, 0.0, 0.0);68 63 initialDir_ = Vector3(1.0, 0.0, 0.0); 69 64 currentDir_ = initialDir_; … … 74 69 setMaterialName("Orxonox/Radar"); 75 70 resize(); 76 77 om = &Ogre::OverlayManager::getSingleton(); 78 point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point")); 79 point->show(); 80 container->addChild(this); 81 container->addChild(point); 82 point->setMaterialName("Orxonox/RedDot"); 83 point->setDimensions(5,5); 84 point->setMetricsMode(Ogre::GMM_PIXELS); 85 71 72 container_->addChild(this); 86 73 } 87 74 … … 102 89 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_; 103 90 104 radius_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length())); 105 phi_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length())); 106 if((currentDir_.crossProduct(currentOrth_)).dotProduct(targetPos_ - shipPos_) > 0) right_ = true; 107 else right_=false; 91 if(tomato_ == NULL) return; 92 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; 108 100 109 if (right_){ 110 point->setPosition(sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2); 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); 111 104 } 112 105 else { 113 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); 114 108 } 115 109 } 116 110 111 void RadarOverlayElement::addObject(Vector3 pos){ 112 tomato_ = new RadarObject(container_); 113 tomato_->pos_ = pos; 114 } 115 116 //// RadarObject //// 117 118 int RadarObject::count = 0; 119 120 RadarObject::RadarObject(Ogre::OverlayContainer* container){ 121 container_ = container; 122 pos_ = Vector3(0.0, 0.0, 0.0); 123 init(); 124 } 125 126 RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){ 127 container_ = container; 128 pos_ = pos; 129 init(); 130 } 131 132 RadarObject::~RadarObject(){} 133 134 void RadarObject::init(){ 135 om = &Ogre::OverlayManager::getSingleton(); 136 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", 137 "Object"+Ogre::StringConverter::toString(count++))); 138 panel_->setMaterialName("Orxonox/RedDot"); 139 panel_->setDimensions(5,5); 140 panel_->setMetricsMode(Ogre::GMM_PIXELS); 141 panel_->show(); 142 container_->addChild(panel_); 143 } 117 144 } 118 145 119 120 146 /* my local clipboard... 147 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n"; 148 COUT(3) << tomato_->radius_ << " " << tomato_->phi_ << std::endl; 149 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n"; 150 */ -
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 -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.h
r1329 r1335 41 41 namespace orxonox 42 42 { 43 class _OrxonoxExport RadarObject 44 { 45 private: 46 Ogre::OverlayManager* om; // our one and only overlay manager 47 void init(); 48 49 public: 50 RadarObject(Ogre::OverlayContainer* container); 51 RadarObject(Ogre::OverlayContainer* container, Vector3 pos); 52 ~RadarObject(); 53 54 Vector3 pos_; // position in space 55 Ogre::Real radius_, phi_; // position on radar 56 bool right_; 57 Ogre::OverlayContainer* container_; 58 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot 59 60 static int count; 61 }; 62 43 63 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement 44 64 { 45 65 private: 46 Ogre:: PanelOverlayElement* point;66 Ogre::OverlayManager* om; // our one and only overlay manager 47 67 Ogre::OverlayContainer* container_; 48 Ogre::OverlayManager* om; // pointer to the one and only overlay manager49 68 Vector3 initialDir_; // direction of nose 50 Vector3 currentDir_; 69 Vector3 currentDir_; 51 70 Vector3 initialOrth_; // direction of normal 52 71 Vector3 currentOrth_; 53 Vector3 targetPos_; // position of target54 72 Vector3 shipPos_; // position of ship 55 56 Ogre::Real radius_; // radius on the radar 57 Ogre::Real phi_; // angle on the radar 58 bool right_; // checks whether the object is on the right side (since cos is not bijective) 73 74 RadarObject* tomato_; 75 59 76 Ogre::Real leftRel_, topRel_, dimRel_; // relative position/dimension 60 77 int left_, top_, dim_; // absolute position/dimension 61 int windowW_, windowH_; // absolute window dimensions 62 int count_; 78 int windowW_, windowH_; // absolute window dimensions 63 79 64 80 public: 65 81 RadarOverlayElement(const Ogre::String& name); 66 virtual ~RadarOverlayElement(); 67 virtual void initialise(); 82 ~RadarOverlayElement(); 83 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 84 void resize(); 68 85 void update(); 69 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 70 void setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ); 71 int newShip(int X, int Y, int Z); 72 void resize(); 73 void resetShip(int shipID, int Y, int Z); 74 }; 86 void addObject(Vector3 pos); 87 }; 75 88 } 76 89 -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.h~
r1295 r1335 32 32 #include <OgreOverlayElement.h> 33 33 #include <OgrePanelOverlayElement.h> 34 #include <math.h>35 34 #include <util/Math.h> 36 35 #include <string.h> 37 #include <Tickable.h>36 #include "core/Tickable.h" 38 37 #include <OgrePrerequisites.h> 38 #include "objects/SpaceShip.h" 39 39 #include "../OrxonoxPrereqs.h" 40 40 41 41 namespace orxonox 42 42 { 43 class _OrxonoxExport RadarObject 44 { 45 private: 46 Ogre::OverlayManager* om; // our one and only overlay manager 47 48 public: 49 RadarObject(Ogre::OverlayContainer* container); 50 RadarObject(Ogre::OverlayContainer* container, Vector3 pos); 51 ~RadarObject(); 52 53 Vector3 pos_; // position in space 54 Ogre::Real radius_, phi_; // position on radar 55 bool right_; 56 Ogre::OverlayContainer* container_; 57 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot 58 59 static int count; 60 }; 43 61 44 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement, public Tickable45 {46 private:47 48 PanelOverlayElement* point[100];49 50 Vector3 initialDir; //initial direction51 int dirX_, dirY_, dirZ_; //flying direction52 int ortX_, ortY_, ortZ_; //orthogonal direction53 int dX_, dY_, dZ_; //distance between main ship and the object54 int vecX_, vecY_, vecZ_; //vector product dir X ort55 double alpha_; //defines the radius in the radar 56 double beta_; //defines the angle in the radar57 bool right_; //checks whether the object is on the right side (since cos is not bijective)58 59 // static int ID = 0; 62 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement 63 { 64 private: 65 Ogre::OverlayManager* om; // our one and only overlay manager 66 Ogre::OverlayContainer* container_; 67 Vector3 initialDir_; // direction of nose 68 Vector3 currentDir_; 69 Vector3 initialOrth_; // direction of normal 70 Vector3 currentOrth_; 71 Vector3 shipPos_; // position of ship 72 73 RadarObject* tomato_; 74 75 Ogre::Real leftRel_, topRel_, dimRel_; // relative position/dimension 76 int left_, top_, dim_; // absolute position/dimension 77 int windowW_, windowH_; // absolute window dimensions 60 78 61 public: 62 63 RadarOverlayElement(const Ogre::String& name); 64 virtual ~RadarOverlayElement(); 65 virtual void initialise(); 66 67 void initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container); 68 void setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ); 69 void tick(float dt); 70 int newShip(int X, int Y, int Z); 71 72 void resetShip(int shipID, int Y, int Z); 73 }; 74 } 79 public: 80 RadarOverlayElement(const Ogre::String& name); 81 ~RadarOverlayElement(); 82 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 83 void resize(); 84 void update(); 85 void addObject(Vector3 pos); 86 }; 87 } 75 88 76 89 #endif
Note: See TracChangeset
for help on using the changeset viewer.