Changeset 1302
- Timestamp:
- May 15, 2008, 10:10:47 PM (17 years ago)
- Location:
- code/branches/hud3/src/orxonox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud3/src/orxonox/hud/HUD.cc
r1281 r1302 30 30 #include <OgreOverlay.h> 31 31 #include <OgreOverlayContainer.h> 32 #include <OgreOverlayManager.h> ma32 #include <OgreOverlayManager.h> 33 33 #include <OgreSceneNode.h> 34 34 #include <OgreEntity.h> … … 50 50 51 51 Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); 52 52 53 53 BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); 54 54 overlayManager.addOverlayElementFactory(barOverlayElementFactory); 55 55 56 56 SmartBarOverlayElementFactory *smartBarOverlayElementFactory = new SmartBarOverlayElementFactory(); 57 57 overlayManager.addOverlayElementFactory(smartBarOverlayElementFactory); 58 58 59 59 RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); 60 60 overlayManager.addOverlayElementFactory(radarOverlayElementFactory); 61 62 Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD"); 61 62 Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD"); 63 63 64 64 Ogre::OverlayContainer* energyCounterPanel = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "Orxonox/HUD/energyCounterPanel")); 65 65 66 66 energyCounter = static_cast<SmartBarOverlayElement*>(overlayManager.createOverlayElement("SmartBar", "energyCounter")); 67 67 energyCounter->show(); 68 69 68 69 70 70 radar = static_cast<RadarOverlayElement*>(overlayManager.createOverlayElement("Radar", "radar")); 71 71 radar->show(); 72 72 73 73 74 74 /* TextAreaOverlayElement* test = static_cast<TextAreaOverlayElement*>(overlayManager.createOverlayElement("TextArea", "test")); 75 75 76 76 int dirX, dirY, dirZ; //flying direction 77 77 int ortX, ortY, ortZ; //orthogonal direction … … 81 81 double beta; //defines the angle in the radar 82 82 bool right; //checks whether the object is on the right side (since cos is not bijective) 83 83 84 84 dirX = 1; 85 85 dirY = 0; 86 86 dirZ = 0; 87 87 88 88 ortX = 0; 89 89 ortY = 0; 90 90 ortZ = 1; 91 91 92 92 dX = -2; 93 93 dY = 2; 94 94 dZ = 0; 95 95 96 96 alpha = acos((dirX*dX+dirY*dY+dirZ*dZ)/(sqrt(pow(dX,2)+pow(dY,2)+pow(dZ,2))*sqrt(pow(dirX,2)+pow(dirY,2)+pow(dirZ,2)))); 97 97 beta = acos((ortX*dX+ortY*dY+ortZ*dZ)/(sqrt(pow(dX,2)+pow(dY,2)+pow(dZ,2))*sqrt(pow(ortX,2)+pow(ortY,2)+pow(ortZ,2)))); … … 99 99 vecY = dirZ*ortX - dirX*ortZ; 100 100 vecZ = dirX*ortY - dirY*ortX; 101 101 102 102 if((vecX*dX+vecY*dY+vecZ*dZ)>0){right=true;} 103 103 else right=false; 104 104 105 105 test->setCaption("hell"); 106 106 test->setPosition(10,10); 107 107 test->setDimensions(20,20); 108 108 test->show(); 109 test->setMetricsMode(Ogre::GMM_PIXELS); 109 test->setMetricsMode(Ogre::GMM_PIXELS); 110 110 energyCounterPanel->addChild(test); 111 111 112 112 COUT(0)<<alpha<<" "<<beta<<" "<<right<<std::endl; 113 113 */ 114 114 115 115 energyCounterPanel->addChild(energyCounter); 116 116 energyCounterPanel->addChild(radar); 117 117 energyCounterPanel->show(); 118 118 119 119 orxonoxOverlay->add2D(energyCounterPanel); 120 120 orxonoxOverlay->show(); 121 121 122 123 122 123 124 124 // important: don't use SceneManager to create the node! but register the creator scene manager. 125 125 /* ogreNode_ = new Ogre::SceneNode(Orxonox::getSingleton()->getSceneManager(), "hudNoedely"); 126 126 127 127 ogreNode_->setPosition(80,-60,-200); 128 128 ogreNode_->setScale(0.4,0.4,0.4); … … 132 132 // orxonoxOverlay->add3D(ogreNode_); 133 133 */ 134 134 135 135 energyCounterPanel->setLeft(-50); 136 136 energyCounterPanel->setTop(10); … … 138 138 energyCounterPanel->setHeight(20); 139 139 energyCounterPanel->setHorizontalAlignment(Ogre::GHA_CENTER); 140 energyCounterPanel->setMetricsMode(Ogre::GMM_PIXELS); 141 140 energyCounterPanel->setMetricsMode(Ogre::GMM_PIXELS); 141 142 142 energyCounter->initSmartBarOverlayElement(-100,0,200,20,BarOverlayElement::LEFT); 143 143 energyCounter->reset(80); 144 144 145 145 radar->initRadarOverlayElement(10,10,200,energyCounterPanel); 146 146 147 147 148 148 } 149 149 150 /*void HUD::tick(float dt)150 void HUD::tick(float dt) 151 151 { 152 if (this->ogreNode_) 152 radar->update(); 153 /*if (this->ogreNode_) 153 154 { 154 155 this->ogreNode_->roll(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); 155 this->ogreNode_->yaw(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); 156 this->ogreNode_->yaw(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); 156 157 this->ogreNode_->pitch(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); 157 } 158 }*/ 158 159 } 159 */ 160 160 161 HUD::~HUD(void){} 161 162 163 162 164 163 } -
code/branches/hud3/src/orxonox/hud/HUD.h
r1281 r1302 44 44 namespace orxonox 45 45 { 46 class _OrxonoxExport HUD //: Tickable46 class _OrxonoxExport HUD : Tickable 47 47 { 48 48 private: … … 52 52 ~HUD(); 53 53 54 //virtual void tick(float);54 virtual void tick(float); 55 55 56 56 SmartBarOverlayElement* energyCounter; 57 57 58 58 RadarOverlayElement* radar; 59 // Ogre::SceneNode* ogreNode_;60 59 }; 61 } 60 } 62 61 63 62 #endif -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc
r1295 r1302 26 26 */ 27 27 28 /* local coordinate system of space ship :28 /* local coordinate system of space ship at the beginning: 29 29 30 30 y … … 33 33 | / 34 34 |/ 35 35 x +------O 36 36 */ 37 37 … … 42 42 #include "RadarOverlayElement.h" 43 43 44 45 44 namespace orxonox 46 45 { 47 using namespace Ogre;46 using namespace Ogre; 48 47 49 RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ 50 initialDir = Vector3(0.0, 0.0, 1.0); 51 } 48 RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ 49 } 52 50 53 RadarOverlayElement::~RadarOverlayElement(){} 51 RadarOverlayElement::~RadarOverlayElement(){ 52 } 54 53 55 void RadarOverlayElement::initialise(){ 56 PanelOverlayElement::initialise(); 57 } 58 59 void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container){ 54 void RadarOverlayElement::initialise(){ 55 PanelOverlayElement::initialise(); 56 } 60 57 61 dirX_ = 0; // direction of travel 62 dirY_ = 0; 63 dirZ_ = 1; 64 65 ortX_ = 0; // normal of ship 66 ortY_ = 1; 67 ortZ_ = 0; 68 69 dX_ = 37; 70 dY_ = 0; 71 dZ_ = 0; 72 73 alpha_ = acos((dirX_*dX_+dirY_*dY_+dirZ_*dZ_)/(sqrt(pow(dX_,2)+pow(dY_,2)+pow(dZ_,2))*sqrt(pow(dirX_,2)+pow(dirY_,2)+pow(dirZ_,2)))); 74 beta_ = acos((ortX_*dX_+ortY_*dY_+ortZ_*dZ_)/(sqrt(pow(dX_,2)+pow(dY_,2)+pow(dZ_,2))*sqrt(pow(ortX_,2)+pow(ortY_,2)+pow(ortZ_,2)))); 75 vecX_ = dirY_*ortZ_ - dirZ_*ortY_; 76 vecY_ = dirZ_*ortX_ - dirX_*ortZ_; 77 vecZ_ = dirX_*ortY_ - dirY_*ortX_; 78 79 if((vecX_*dX_+vecY_*dY_+vecZ_*dZ_)>0){right_=true;} 80 else right_=false; 81 82 setMetricsMode(Ogre::GMM_PIXELS); 83 setPosition(left,top); 84 setDimensions(dim,dim); 85 setMaterialName("Orxonox/Radar"); 86 87 Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); 58 void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container){ 59 dim_ = dim; 60 left_ = left; 61 top_ = top; 62 count_ = 0; 63 container_ = container; 88 64 89 PanelOverlayElement* point = static_cast<PanelOverlayElement*>(overlayManager.createOverlayElement("Panel", "point")); 90 point->show(); 91 92 container->addChild(point); 93 94 if (right_){ 95 point->setPosition(sin(beta_)*alpha_/3.5*dim/2+dim/2+left-2,-cos(beta_)*alpha_/3.5*dim/2+dim/2+top-2); 96 point->setMaterialName("Orxonox/RedPoint"); 97 point->setDimensions(5,5); 98 point->setMetricsMode(Ogre::GMM_PIXELS); 65 shipPos_ = Vector3(0.0, 0.0, 0.0); 66 targetPos_ = Vector3(42.0, 42.0, 0.0); 67 initialDir_ = Vector3(0.0, 0.0, 1.0); 68 currentDir_ = initialDir_; 69 initialOrth_ = Vector3(0.0, 1.0, 0.0); 70 currentOrth_ = initialOrth_; 71 72 alpha_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length())); 73 beta_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length())); 74 vec_ = currentDir_.crossProduct(currentOrth_); 75 76 if(vec_.dotProduct(targetPos_ - shipPos_) > 0) 77 right_ = true; 78 else 79 right_=false; 80 81 setMetricsMode(Ogre::GMM_PIXELS); 82 setPosition(left,top); 83 setDimensions(dim_,dim_); 84 setMaterialName("Orxonox/Radar"); 85 86 om = &Ogre::OverlayManager::getSingleton(); 87 point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point")); 88 point->show(); 89 container->addChild(point); 90 91 if (right_){ 92 point->setPosition(sin(beta_)*alpha_/3.5*dim_/2+dim_/2+left-2,-cos(beta_)*alpha_/3.5*dim_/2+dim_/2+top-2); 93 point->setMaterialName("Orxonox/RedPoint"); 94 point->setDimensions(5,5); 95 point->setMetricsMode(Ogre::GMM_PIXELS); 96 } 97 98 else { 99 point->setPosition(-sin(beta_)*alpha_/3.5*dim_/2+dim_/2+left-2,-cos(beta_)*alpha_/3.5*dim_/2+dim_/2+top-2); 100 point->setMaterialName("Orxonox/RedPoint"); 101 point->setDimensions(5,5); 102 point->setMetricsMode(Ogre::GMM_PIXELS); 103 } 99 104 } 100 101 else { 102 point->setPosition(-sin(beta_)*alpha_/3.5*dim/2+dim/2+left-2,-cos(beta_)*alpha_/3.5*dim/2+dim/2+top-2); 103 point->setMaterialName("Orxonox/RedPoint"); 104 point->setDimensions(5,5); 105 point->setMetricsMode(Ogre::GMM_PIXELS); 105 106 // void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){ 107 // dirX_=dirX; 108 // dirY_=dirY; 109 // dirZ_=dirZ; 110 // ortX_=ortX; 111 // ortY_=ortY; 112 // ortZ_=ortZ; 113 // } 114 115 void RadarOverlayElement::update() { 116 shipPos_ = SpaceShip::instance_s->getPosition(); 117 currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; // according to beni.... 106 118 } 107 } 108 109 void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){ 110 dirX_=dirX; 111 dirY_=dirY; 112 dirZ_=dirZ; 113 ortX_=ortX; 114 ortY_=ortY; 115 ortZ_=ortZ; 116 } 117 118 119 119 120 120 } 121 121 -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.h
r1295 r1302 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 36 #include "core/Tickable.h" 38 37 #include <OgrePrerequisites.h> 38 #include "objects/SpaceShip.h" 39 39 #include "../OrxonoxPrereqs.h" 40 40 … … 42 42 { 43 43 44 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement , public Tickable44 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement 45 45 { 46 46 private: 47 48 PanelOverlayElement* point[100]; 49 50 Vector3 initialDir; //initial direction 51 int dirX_, dirY_, dirZ_; //flying direction 52 int ortX_, ortY_, ortZ_; //orthogonal direction 53 int dX_, dY_, dZ_; //distance between main ship and the object 54 int vecX_, vecY_, vecZ_; //vector product dir X ort 55 double alpha_; //defines the radius in the radar 56 double beta_; //defines the angle in the radar 57 bool right_; //checks whether the object is on the right side (since cos is not bijective) 58 59 // static int ID = 0; 47 48 Ogre::PanelOverlayElement* point; 49 Ogre::OverlayContainer* container_; 50 Ogre::OverlayManager* om; //pointer to the one and only overlay manager 51 Vector3 initialDir_; //initial direction of ship 52 Vector3 currentDir_; //current direction of ship 53 Vector3 initialOrth_; 54 Vector3 currentOrth_; 55 Vector3 targetPos_; //position of target 56 Vector3 shipPos_; //position of ship 57 Vector3 vec_; //vector product dir X ort 58 double alpha_; //defines the radius in the radar 59 double beta_; //defines the angle in the radar 60 float left_, top_; 61 bool right_; //checks whether the object is on the right side (since cos is not bijective) 62 int count_; 63 int dim_; 60 64 61 65 public: 62 66 63 67 RadarOverlayElement(const Ogre::String& name); 64 68 virtual ~RadarOverlayElement(); 65 69 virtual void initialise(); 66 70 void update(); 67 71 void initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container); 68 72 void setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ); 69 void tick(float dt);70 73 int newShip(int X, int Y, int Z); 71 74 72 75 void resetShip(int shipID, int Y, int Z); 73 76 }; 74 } 77 } 75 78 76 79 #endif -
code/branches/hud3/src/orxonox/objects/SpaceShip.h
r1295 r1302 64 64 65 65 void getFocus(); 66 66 static SpaceShip* instance_s; 67 67 static Vector3 getSPosition(); 68 68 static Quaternion getSOrientation(); … … 80 80 private: 81 81 void createCamera(); 82 static SpaceShip* instance_s;83 82 84 83 Vector3 testvector_;
Note: See TracChangeset
for help on using the changeset viewer.