Changeset 1564
- Timestamp:
- Jun 8, 2008, 5:46:52 AM (16 years ago)
- Location:
- code/trunk/src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/GraphicsEngine.cc
r1563 r1564 53 53 54 54 #include "console/InGameConsole.h" 55 #include "hud/HUD.h" 55 56 #include "tools/ParticleInterface.h" 56 57 #include "Settings.h" … … 455 456 InputManager::setWindowExtents(w, h); 456 457 InGameConsole::getInstance().resize(); 458 HUD::getSingleton().resize(); 457 459 } 458 460 -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r1563 r1564 114 114 // hud 115 115 class BarOverlayElement; 116 class BarOverlayElementFactory; 116 117 class HUD; 117 118 class Navigation; 118 119 class RadarObject; 119 120 class RadarOverlayElement; 121 class RadarOverlayElementFactory; 120 122 121 123 //console -
code/trunk/src/orxonox/hud/BarOverlayElement.cc
r1505 r1564 31 31 #include <OgreOverlayManager.h> 32 32 #include "GraphicsEngine.h" 33 #include "util/Math.h" 33 34 34 35 namespace orxonox … … 36 37 using namespace Ogre; 37 38 38 BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){ 39 BarOverlayElement::BarOverlayElement(const String& name) : PanelOverlayElement(name) 40 { 39 41 name_ = name; 42 widthratio_ = 100.0f / 800.0f; // calculates the ratio (backgroundwidth - barwidth) / backgroundwidth 40 43 } 41 44 42 BarOverlayElement::~BarOverlayElement(){} 45 BarOverlayElement::~BarOverlayElement() 46 { 47 OverlayManager::getSingleton().destroyOverlayElement(this->background_); 48 } 43 49 44 50 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 45 51 // init some values... 46 container_ = container;47 om = &OverlayManager::getSingleton();48 52 value_ = 0; 49 colo r_ = 2;50 autoColo r_ = true;51 left2Right = false; // default is right to left progress53 colour_ = 2; 54 autoColour_ = true; 55 right2Left_ = false; // default is left to right progress 52 56 leftRel_ = leftRel; 53 57 topRel_ = topRel; … … 55 59 56 60 // create background... 57 background_ = static_cast<OverlayContainer*>( om->createOverlayElement("Panel", name_+"container"));61 background_ = static_cast<OverlayContainer*>(OverlayManager::getSingleton().createOverlayElement("Panel", name_+"container")); 58 62 background_->show(); 59 container _->addChild(background_);63 container->addChild(background_); 60 64 background_->setMetricsMode(GMM_PIXELS); 61 65 background_->setMaterialName("Orxonox/BarBackground"); … … 71 75 72 76 void BarOverlayElement::resize(){ 73 windowW_ = GraphicsEngine::getSingleton().getWindowWidth();74 windowH_ = GraphicsEngine::getSingleton().getWindowHeight();75 77 // calculate new absolute coordinates... 76 left_ = (int) (leftRel_ * windowW_); 77 top_ = (int) (topRel_ * windowH_); 78 width_ = (int) (dimRel_ * windowW_); 79 height_ = (int) (0.1*width_); // the texture has dimensions height:length = 1:10 78 left_ = (int) (leftRel_ * GraphicsEngine::getSingleton().getWindowWidth()); 79 top_ = (int) (topRel_ * GraphicsEngine::getSingleton().getWindowHeight()); 80 width_ = (int) (dimRel_ * GraphicsEngine::getSingleton().getWindowWidth()); 81 height_ = (int) (0.1 * width_); // the texture has dimensions height:length = 1:10 82 offset_ = (int) (width_ * widthratio_ * 0.5); 83 barwidth_ = (int) (width_ * (1.0f - widthratio_)); 84 80 85 // adapt background 81 86 background_->setPosition(left_, top_); … … 86 91 87 92 void BarOverlayElement::setValue(float value){ 88 value_ = value;89 // set colo r, if nescessary90 if(autoColo r_){91 if (value_>0.5) {setColo r(BarOverlayElement::GREEN);}92 else if (value_>0.25) {setColo r(BarOverlayElement::YELLOW);}93 else setColo r(BarOverlayElement::RED);93 value_ = clamp<float>(value, 0, 1); 94 // set colour, if nescessary 95 if(autoColour_){ 96 if (value_>0.5) {setColour(BarOverlayElement::GREEN);} 97 else if (value_>0.25) {setColour(BarOverlayElement::YELLOW);} 98 else setColour(BarOverlayElement::RED); 94 99 } 100 95 101 // set value 96 if( left2Right){ // backward case97 setPosition( 0+width_-width_*value_, 0);98 setDimensions( width_*value_,height_);102 if(right2Left_){ // backward case 103 setPosition(offset_ + barwidth_ * (1 - value_), 0); 104 setDimensions(barwidth_ * value_, height_); 99 105 }else{ // default case 100 setPosition( 0, 0);101 setDimensions( width_*value_,height_);106 setPosition(offset_, 0); 107 setDimensions(barwidth_ * value_, height_); 102 108 } 103 109 if(value_ != 0) setTiling(value_, 1.0); 104 110 } 105 111 106 void BarOverlayElement::setColo r(int color){107 colo r_ = color;108 switch(colo r){112 void BarOverlayElement::setColour(int colour){ 113 colour_ = colour; 114 switch(colour){ 109 115 case 0: 110 116 setMaterialName("Orxonox/Red"); … … 117 123 } 118 124 } 119 120 float BarOverlayElement::getValue(){121 return(value_);122 }123 124 int BarOverlayElement::getBarColor(){125 return(color_);126 }127 125 } -
code/trunk/src/orxonox/hud/BarOverlayElement.h
r1505 r1564 39 39 class _OrxonoxExport BarOverlayElement : public Ogre::PanelOverlayElement 40 40 { 41 public: 42 BarOverlayElement(const Ogre::String& name); 43 virtual ~BarOverlayElement(); 44 45 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 46 void resize(); 47 void setValue(float value); 48 void setColour(int colour); 49 50 inline void setRightToLeft(bool r2l) 51 { this->right2Left_ = r2l; } 52 inline bool getRightToLeft() const 53 { return this->right2Left_; } 54 inline float getValue() const 55 { return this->value_; } 56 inline int getBarColour() const 57 { return this->colour_; } 58 41 59 private: 42 bool autoColor_; // whether bar changes color automatically 60 static const int RED = 0; // predefined colours 61 static const int YELLOW = 1; 62 static const int GREEN = 2; 63 64 bool right2Left_; 65 bool autoColour_; // whether bar changes colour automatically 43 66 float value_; // progress of bar 44 int colo r_;67 int colour_; 45 68 int left_; 46 69 int top_; 47 70 int width_; 48 71 int height_; 49 int windowW_, windowH_; 72 float widthratio_; 73 int offset_; 74 int barwidth_; 50 75 Ogre::Real leftRel_; 51 76 Ogre::Real topRel_; 52 77 Ogre::Real dimRel_; 53 Ogre::OverlayManager* om; // our overlay manager54 Ogre::OverlayContainer* container_; // our parent container to attach to55 78 Ogre::OverlayContainer* background_; 56 79 Ogre::String name_; 57 58 public:59 bool left2Right;60 static const int RED = 0; // predefined colors61 static const int YELLOW = 1;62 static const int GREEN = 2;63 64 BarOverlayElement(const Ogre::String& name);65 virtual ~BarOverlayElement();66 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);67 void resize();68 void setValue(float value);69 void setColor(int color);70 float getValue();71 int getBarColor();72 80 }; 73 81 } -
code/trunk/src/orxonox/hud/HUD.cc
r1562 r1564 40 40 #include "core/ConsoleCommand.h" 41 41 #include "objects/SpaceShip.h" 42 #include "objects/WorldEntity.h" 42 43 #include "GraphicsEngine.h" 43 44 #include "BarOverlayElement.h" … … 50 51 { 51 52 SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User); 53 SetConsoleCommandShortcut(HUD, releaseNavigationFocus).setAccessLevel(AccessLevel::User); 52 54 SetConsoleCommandShortcut(HUD, toggleFPS).setAccessLevel(AccessLevel::User); 53 55 SetConsoleCommandShortcut(HUD, toggleRenderTime).setAccessLevel(AccessLevel::User); … … 55 57 using namespace Ogre; 56 58 57 HUD::HUD(){ 58 om = &Ogre::OverlayManager::getSingleton(); 59 sm = GraphicsEngine::getSingleton().getSceneManager(); 60 showFPS = true; 61 showRenderTime = true; 59 HUD::HUD() 60 { 61 showFPS_ = true; 62 showRenderTime_ = true; 62 63 63 64 // create Factories 64 BarOverlayElementFactory *barOverlayElementFactory= new BarOverlayElementFactory();65 om->addOverlayElementFactory(barOverlayElementFactory);66 RadarOverlayElementFactory *radarOverlayElementFactory= new RadarOverlayElementFactory();67 om->addOverlayElementFactory(radarOverlayElementFactory);68 69 orxonoxHUD = om->create("Orxonox/HUD");70 container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));65 barOverlayElementFactory_ = new BarOverlayElementFactory(); 66 Ogre::OverlayManager::getSingleton().addOverlayElementFactory(barOverlayElementFactory_); 67 radarOverlayElementFactory_ = new RadarOverlayElementFactory(); 68 Ogre::OverlayManager::getSingleton().addOverlayElementFactory(radarOverlayElementFactory_); 69 70 orxonoxHUD_ = Ogre::OverlayManager::getSingleton().create("Orxonox/HUD"); 71 container_ = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "Orxonox/HUD/container")); 71 72 72 73 // creating text to display fps 73 fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));74 fpsText ->show();75 fpsText ->setMetricsMode(Ogre::GMM_PIXELS);76 fpsText ->setDimensions(0.001, 0.001);77 fpsText ->setPosition(10, 10);78 fpsText ->setFontName("Console");79 fpsText ->setCharHeight(20);80 fpsText ->setCaption("init");74 fpsText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", "fpsText")); 75 fpsText_->show(); 76 fpsText_->setMetricsMode(Ogre::GMM_PIXELS); 77 fpsText_->setDimensions(0.001, 0.001); 78 fpsText_->setPosition(10, 10); 79 fpsText_->setFontName("Console"); 80 fpsText_->setCharHeight(20); 81 fpsText_->setCaption("init"); 81 82 82 83 // creating text to display render time ratio 83 rTRText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "rTRText"));84 rTRText ->show();85 rTRText ->setMetricsMode(Ogre::GMM_PIXELS);86 rTRText ->setDimensions(0.001, 0.001);87 rTRText ->setPosition(10, 30);88 rTRText ->setFontName("Console");89 rTRText ->setCharHeight(20);90 rTRText ->setCaption("init");84 rTRText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", "rTRText")); 85 rTRText_->show(); 86 rTRText_->setMetricsMode(Ogre::GMM_PIXELS); 87 rTRText_->setDimensions(0.001, 0.001); 88 rTRText_->setPosition(10, 30); 89 rTRText_->setFontName("Console"); 90 rTRText_->setCharHeight(20); 91 rTRText_->setCaption("init"); 91 92 92 93 // create energy bar 93 energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar"));94 energyBar ->show();94 energyBar_ = static_cast<BarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Bar", "energyBar")); 95 energyBar_->show(); 95 96 // create speedo bar 96 speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar"));97 speedoBar ->show();97 speedoBar_ = static_cast<BarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Bar", "speedoBar")); 98 speedoBar_->show(); 98 99 // create radar 99 radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));100 radar ->show();100 radar_ = static_cast<RadarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Radar", "radar")); 101 radar_->show(); 101 102 102 103 // create Navigation 103 nav = new Navigation(container);104 nav_ = new Navigation(container_); 104 105 105 106 // set up screen-wide container 106 container->show(); 107 108 orxonoxHUD->add2D(container); 109 orxonoxHUD->show(); 110 container->setLeft(0.0); 111 container->setTop(0.0); 112 container->setWidth(1.0); 113 container->setHeight(1.0); 114 container->setMetricsMode(Ogre::GMM_RELATIVE); 115 container->addChild(fpsText); 116 container->addChild(rTRText); 117 118 energyBar->init(0.01, 0.94, 0.4, container); 119 energyBar->setValue(1); 120 121 speedoBar->init(0.01, 0.90, 0.4, container); 122 123 radar->init(0.5, 0.9, 0.2, container); 124 SceneNode* node; 125 node = sm->getRootSceneNode()->createChildSceneNode("tomato1", Vector3(2000.0, 0.0, 0.0)); 126 addRadarObject(node, ColourValue(0.5, 0, 0, 1)); 127 node = sm->getRootSceneNode()->createChildSceneNode("tomato2", Vector3(0.0, 2000.0, 0.0)); 128 addRadarObject(node, ColourValue(0.5, 0, 0, 1)); 129 node = sm->getRootSceneNode()->createChildSceneNode("tomato3", Vector3(0.0, 0.0, 2000.0)); 130 addRadarObject(node, ColourValue(0.5, 0, 0, 1)); 131 node = sm->getRootSceneNode()->createChildSceneNode("station", Vector3(10000.0,16000.0,0.0)); 132 addRadarObject(node); 133 } 134 135 HUD::~HUD(){ 136 //todo: clean up objects 107 container_->show(); 108 109 orxonoxHUD_->add2D(container_); 110 orxonoxHUD_->show(); 111 container_->setLeft(0.0); 112 container_->setTop(0.0); 113 container_->setWidth(1.0); 114 container_->setHeight(1.0); 115 container_->setMetricsMode(Ogre::GMM_RELATIVE); 116 container_->addChild(fpsText_); 117 container_->addChild(rTRText_); 118 119 energyBar_->init(0.01, 0.94, 0.4, container_); 120 energyBar_->setValue(1); 121 122 speedoBar_->init(0.01, 0.90, 0.4, container_); 123 124 radar_->init(0.5, 0.9, 0.2, container_); 125 126 WorldEntity* object; 127 object = new WorldEntity(); 128 object->setPosition(2000.0, 0.0, 0.0); 129 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 130 object = new WorldEntity(); 131 object->setPosition(0.0, 2000.0, 0.0); 132 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 133 object = new WorldEntity(); 134 object->setPosition(0.0, 0.0, 2000.0); 135 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 136 object = new WorldEntity(); 137 object->setPosition(10000.0,16000.0,0.0); 138 addRadarObject(object); 139 } 140 141 HUD::~HUD() 142 { 143 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->container_); 144 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->fpsText_); 145 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->rTRText_); 146 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->energyBar_); 147 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->speedoBar_); 148 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->radar_); 149 150 delete this->nav_; 151 delete this->barOverlayElementFactory_; 152 delete this->radarOverlayElementFactory_; 137 153 } 138 154 139 155 void HUD::tick(float dt) 140 156 { 141 energyBar->resize();142 143 157 if(!SpaceShip::getLocalShip()) 144 158 return; 159 145 160 float v = SpaceShip::getLocalShip()->getVelocity().length(); 146 161 float vmax = SpaceShip::getLocalShip()->getMaxSpeed(); 147 speedoBar->setValue(v/vmax); 148 speedoBar->resize(); 149 150 radar->resize(); 151 radar->update(); 152 153 nav->update(); 162 speedoBar_->setValue(v/vmax); 163 164 radar_->update(); 165 nav_->update(); 154 166 155 167 setFPS(); 156 168 } 157 169 170 void HUD::resize() 171 { 172 this->speedoBar_->resize(); 173 this->energyBar_->resize(); 174 this->radar_->resize(); 175 } 176 158 177 void HUD::setRenderTimeRatio(float ratio) 159 178 { 160 if(showRenderTime ){161 rTRText ->setCaption("Render time ratio: " + Ogre::StringConverter::toString(ratio));179 if(showRenderTime_){ 180 rTRText_->setCaption("Render time ratio: " + Ogre::StringConverter::toString(ratio)); 162 181 } 163 182 else{ 164 rTRText ->setCaption("");183 rTRText_->setCaption(""); 165 184 return; 166 185 } … … 168 187 169 188 void HUD::setFPS(){ 170 if(showFPS ){189 if(showFPS_){ 171 190 float fps = GraphicsEngine::getSingleton().getAverageFPS(); 172 fpsText ->setCaption("FPS: " + Ogre::StringConverter::toString(fps));191 fpsText_->setCaption("FPS: " + Ogre::StringConverter::toString(fps)); 173 192 } 174 193 else{ 175 fpsText ->setCaption("");194 fpsText_->setCaption(""); 176 195 return; 177 196 } 178 197 } 179 198 180 void HUD::addRadarObject( SceneNode* node, const ColourValue& colour){181 RadarObject* obj = new RadarObject(container , node, colour);182 roSet .insert(obj);199 void HUD::addRadarObject(WorldEntity* object, const ColourValue& colour){ 200 RadarObject* obj = new RadarObject(container_, object, colour); 201 roSet_.insert(roSet_.end(), obj); 183 202 // // check if this is the first RadarObject to create 184 203 // if(firstRadarObject == NULL){ 185 // firstRadarObject = new RadarObject(container , node, colour);204 // firstRadarObject = new RadarObject(container_, object, colour); 186 205 // lastRadarObject = firstRadarObject; 187 206 // } 188 207 // else{ // if not, append to list 189 // lastRadarObject->next = new RadarObject(container , node, colour);208 // lastRadarObject->next = new RadarObject(container_, object, colour); 190 209 // lastRadarObject = lastRadarObject->next; 191 210 // } 192 211 } 193 212 194 void HUD::removeRadarObject( Ogre::SceneNode* node){195 for(std:: set<RadarObject*>::iterator it=roSet.begin(); it!=roSet.end(); ++it){196 if ((*it)->get Node() == node)213 void HUD::removeRadarObject(WorldEntity* object){ 214 for(std::list<RadarObject*>::iterator it=roSet_.begin(); it!=roSet_.end(); ++it){ 215 if ((*it)->getObject() == object) 197 216 { 198 if (this->nav->focus_ == (*it)) 199 { 200 this->nav->cycleFocus(); 201 if (this->nav->focus_ == (*it)) 202 this->nav->focus_ = 0; 203 } 217 if (this->nav_->getFocus() == (*it)) 218 this->nav_->setFocus(0); 219 204 220 delete (*it); 205 roSet .erase(it);221 roSet_.erase(it); 206 222 return; 207 223 } … … 215 231 216 232 /*static*/ void HUD::setEnergy(float value){ 217 HUD::getSingleton().energyBar ->setValue(value);233 HUD::getSingleton().energyBar_->setValue(value); 218 234 } 219 235 220 236 /*static*/ void HUD::cycleNavigationFocus(){ 221 HUD::getSingleton().nav->cycleFocus(); 237 HUD::getSingleton().nav_->cycleFocus(); 238 } 239 240 /*static*/ void HUD::releaseNavigationFocus(){ 241 HUD::getSingleton().nav_->setFocus(0); 222 242 } 223 243 224 244 /*static*/ void HUD::toggleFPS(){ 225 HUD::getSingleton().showFPS = !HUD::getSingleton().showFPS;245 HUD::getSingleton().showFPS_ = !HUD::getSingleton().showFPS_; 226 246 } 227 247 228 248 /*static*/ void HUD::toggleRenderTime(){ 229 HUD::getSingleton().showRenderTime = !HUD::getSingleton().showRenderTime;249 HUD::getSingleton().showRenderTime_ = !HUD::getSingleton().showRenderTime_; 230 250 } 231 251 } 232 233 234 235 236 237 -
code/trunk/src/orxonox/hud/HUD.h
r1562 r1564 35 35 #include <OgrePrerequisites.h> 36 36 #include <OgreTextAreaOverlayElement.h> 37 #include <OgreSceneNode.h>38 37 #include "objects/Tickable.h" 39 38 #include "util/Math.h" … … 43 42 class _OrxonoxExport HUD : public TickableReal 44 43 { 45 private: 46 HUD(); 47 HUD(HUD& instance); 48 ~HUD(); 49 Ogre::OverlayManager* om; 50 Ogre::SceneManager* sm; 51 Ogre::Overlay* orxonoxHUD; 52 Ogre::OverlayContainer* container; 53 Ogre::TextAreaOverlayElement* fpsText; 54 Ogre::TextAreaOverlayElement* rTRText; 55 BarOverlayElement* energyBar; 56 BarOverlayElement* speedoBar; 57 RadarOverlayElement* radar; 58 Navigation* nav; 44 public: 45 static HUD& getSingleton(); 46 virtual void tick(float); 59 47 60 bool showFPS; 61 bool showRenderTime; 62 63 public: 64 virtual void tick(float); 65 void addRadarObject(Ogre::SceneNode* node, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1)); 66 void removeRadarObject(Ogre::SceneNode* node); 48 void resize(); 49 void addRadarObject(WorldEntity* object, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1)); 50 void removeRadarObject(WorldEntity* object); 67 51 void setRenderTimeRatio(float ratio); 68 52 void setFPS(); 69 53 70 std::set<RadarObject*> roSet; 54 inline std::list<RadarObject*>& getRadarObjects() 55 { return this->roSet_; } 56 57 static void setEnergy(float value); 58 static void cycleNavigationFocus(); 59 static void releaseNavigationFocus(); 60 static void toggleFPS(); 61 static void toggleRenderTime(); 62 63 private: 64 HUD(); 65 HUD(const HUD& instance); 66 ~HUD(); 71 67 72 68 static HUD* instance_s; 73 static HUD& getSingleton(); 74 static void setEnergy(float value); 75 static void cycleNavigationFocus(); 76 static void toggleFPS(); 77 static void toggleRenderTime(); 69 70 std::list<RadarObject*> roSet_; 71 Ogre::Overlay* orxonoxHUD_; 72 Ogre::OverlayContainer* container_; 73 BarOverlayElementFactory* barOverlayElementFactory_; 74 RadarOverlayElementFactory* radarOverlayElementFactory_; 75 Ogre::TextAreaOverlayElement* fpsText_; 76 Ogre::TextAreaOverlayElement* rTRText_; 77 BarOverlayElement* energyBar_; 78 BarOverlayElement* speedoBar_; 79 RadarOverlayElement* radar_; 80 Navigation* nav_; 81 82 bool showFPS_; 83 bool showRenderTime_; 78 84 }; 79 85 } -
code/trunk/src/orxonox/hud/Navigation.cc
r1562 r1564 41 41 #include "HUD.h" 42 42 #include "core/Debug.h" 43 #include "util/Math.h" 43 44 44 45 namespace orxonox … … 58 59 } 59 60 61 Navigation::~Navigation() 62 { 63 OverlayManager::getSingleton().destroyOverlayElement(this->navText_); 64 OverlayManager::getSingleton().destroyOverlayElement(this->navMarker_); 65 OverlayManager::getSingleton().destroyOverlayElement(this->aimMarker_); 66 } 67 60 68 void Navigation::init(){ 61 om = &OverlayManager::getSingleton();62 navCam_ = NULL;63 69 // create nav text 64 navText_ = static_cast<TextAreaOverlayElement*>( om->createOverlayElement("TextArea", "navText"));70 navText_ = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("TextArea", "navText")); 65 71 navText_->show(); 66 72 navText_->setMetricsMode(Ogre::GMM_PIXELS); … … 70 76 navText_->setCharHeight(20); 71 77 navText_->setCaption(""); 78 navText_->hide(); 72 79 container_->addChild(navText_); 73 80 74 81 75 82 // create nav marker ... 76 navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker")); 83 navMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", "NavMarker")); 84 aimMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", "aimMarker")); 77 85 navMarker_->setMetricsMode(GMM_PIXELS); 86 aimMarker_->setMetricsMode(GMM_PIXELS); 78 87 navMarker_->hide(); 79 navText_->hide();88 aimMarker_->hide(); 80 89 container_->addChild(navMarker_); 90 container_->addChild(aimMarker_); 81 91 } 82 92 83 93 void Navigation::update(){ 84 if(focus_ == NULL) return; 85 navCamPos_ = SpaceShip::getLocalShip()->getPosition(); 86 currentDir_ = SpaceShip::getLocalShip()->getDir(); 87 currentOrth_ = SpaceShip::getLocalShip()->getOrth(); 88 89 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 90 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 94 if (!focus_) 95 return; 96 91 97 updateMarker(); 92 98 } 93 99 94 100 void Navigation::updateMarker(){ 101 int windowW = GraphicsEngine::getSingleton().getWindowWidth(); 102 int windowH = GraphicsEngine::getSingleton().getWindowHeight(); 103 95 104 // set text 96 105 int dist = (int) getDist2Focus()/100; 97 106 navText_->setCaption(Ogre::StringConverter::toString(dist)); 98 107 99 if(navCam_ == NULL) navCam_ = SpaceShip::getLocalShip()->getCamera()->cam_;100 108 Vector3 pos = focus_->getPosition(); 109 Ogre::Camera* navCam = SpaceShip::getLocalShip()->getCamera()->cam_; 101 110 // transform to screen coordinates 102 pos = navCam_->getProjectionMatrix()*navCam_->getViewMatrix()*pos; 111 pos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * pos; 112 103 113 float xPosRel = 0.5*pos.x+0.5; 104 114 float yPosRel = 1-(0.5*pos.y+0.5); 105 int xPos = (int) (xPosRel*windowW_); 106 int yPos = (int) (yPosRel*windowH_); 107 int xFromCenter = xPos-windowW_/2; 108 int yFromCenter = yPos-windowH_/2; 115 int xPos = (int) (xPosRel*windowW); 116 int yPos = (int) (yPosRel*windowH); 117 int xFromCenter = xPos-windowW/2; 118 int yFromCenter = yPos-windowH/2; 119 109 120 // is object in view? 110 float radius = RadarOverlayElement::calcRadius(navCamPos_, currentDir_, currentOrth_, focus_); 111 bool isRight = (currentDir_.crossProduct(currentOrth_)).dotProduct(focus_->getPosition() - navCamPos_)>0; 112 bool isAbove = currentOrth_.dotProduct(focus_->getPosition() - navCamPos_)>0; 121 Vector3 navCamPos = SpaceShip::getLocalShip()->getPosition(); 122 Vector3 currentDir = SpaceShip::getLocalShip()->getDir(); 123 Vector3 currentOrth = SpaceShip::getLocalShip()->getOrth(); 124 float radius = getAngle(navCamPos, currentDir, focus_->getPosition()); 125 bool isRight = (currentDir.crossProduct(currentOrth)).dotProduct(focus_->getPosition() - navCamPos)>0; 126 bool isAbove = currentOrth.dotProduct(focus_->getPosition() - navCamPos)>0; 113 127 bool outOfView = (xPosRel<0 || xPosRel>1 || yPosRel<0 || yPosRel>1); 114 128 // if object is behind us, it is out of view anyway: 115 if(!outOfView && radius >3.14/2) outOfView = true;129 if(!outOfView && radius > Ogre::Math::PI / 2) outOfView = true; 116 130 117 131 if(outOfView){ … … 119 133 navMarker_->setMaterialName("Orxonox/NavArrows"); 120 134 navMarker_->setDimensions(16,16); 121 float phiUpperCorner = atan((float)(windowW _)/(float)(windowH_));135 float phiUpperCorner = atan((float)(windowW)/(float)(windowH)); 122 136 // from the angle we find out on which edge to draw the marker 123 137 // and which of the four arrows to take … … 128 142 if(-phiNav<phiUpperCorner){ 129 143 //COUT(3) << "arrow up\n"; 130 navMarker_->setPosition(-tan(phiNav)*windowH _/2+windowW_/2, 0);144 navMarker_->setPosition(-tan(phiNav)*windowH/2+windowW/2, 0); 131 145 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 132 146 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); … … 135 149 else { 136 150 //COUT(3) << "arrow right\n"; 137 navMarker_->setPosition(windowW _-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);151 navMarker_->setPosition(windowW-16, tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); 138 152 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); 139 153 navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth()); … … 145 159 if(phiNav<phiUpperCorner) { 146 160 //COUT(3) << "arrow down\n"; 147 navMarker_->setPosition(tan(phiNav)*windowH _/2+windowW_/2, windowH_-16);161 navMarker_->setPosition(tan(phiNav)*windowH/2+windowW/2, windowH-16); 148 162 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 149 163 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); … … 152 166 else { 153 167 //COUT(3) << "arrow right\n"; 154 navMarker_->setPosition(windowW _-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);168 navMarker_->setPosition(windowW-16, tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); 155 169 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); 156 170 navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth()); … … 162 176 if(phiNav<phiUpperCorner){ 163 177 //COUT(3) << "arrow up\n"; 164 navMarker_->setPosition(-tan(phiNav)*windowH _/2+windowW_/2, 0);178 navMarker_->setPosition(-tan(phiNav)*windowH/2+windowW/2, 0); 165 179 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 166 180 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); … … 169 183 else { 170 184 //COUT(3) << "arrow left\n"; 171 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW _/2+windowH_/2);185 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); 172 186 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); 173 187 navText_->setLeft(navMarker_->getWidth()); … … 179 193 if(phiNav>-phiUpperCorner) { 180 194 //COUT(3) << "arrow down\n"; 181 navMarker_->setPosition(tan(phiNav)*windowH _/2+windowW_/2, windowH_-16);195 navMarker_->setPosition(tan(phiNav)*windowH/2+windowW/2, windowH-16); 182 196 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 183 197 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); … … 186 200 else { 187 201 //COUT(3) << "arrow left\n"; 188 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW _/2+windowH_/2);202 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); 189 203 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); 190 204 navText_->setLeft(navMarker_->getWidth()); … … 205 219 void Navigation::cycleFocus(){ 206 220 if(focus_ == NULL){ 207 it_ = HUD::getSingleton().roSet.begin(); 208 focus_ = *it_; 209 ++it_; 221 // Get closest object 222 float distance = (unsigned int) -1; 223 Vector3 shipPos = SpaceShip::getLocalShip()->getPosition(); 224 it_ = HUD::getSingleton().getRadarObjects().begin(); 225 226 for (std::list<RadarObject*>::iterator it = HUD::getSingleton().getRadarObjects().begin(); it != HUD::getSingleton().getRadarObjects().end(); ++it) 227 { 228 float newdist = (*it)->getPosition().squaredDistance(shipPos); 229 if (newdist < distance) 230 { 231 distance = newdist; 232 it_ = it; 233 } 234 } 235 236 if (it_ != HUD::getSingleton().getRadarObjects().end()) 237 { 238 focus_ = *it_; 239 240 // move the focused object to the begin of the list, so we will iterate through all other objects when cycling 241 HUD::getSingleton().getRadarObjects().erase(it_); 242 HUD::getSingleton().getRadarObjects().insert(HUD::getSingleton().getRadarObjects().begin(), focus_); 243 it_ = HUD::getSingleton().getRadarObjects().begin(); 244 ++it_; 245 } 210 246 } 211 247 else{ 212 248 focus_->resetMaterial(); 213 if(it_ != HUD::getSingleton(). roSet.end()){249 if(it_ != HUD::getSingleton().getRadarObjects().end()){ 214 250 focus_ = *it_; 215 251 ++it_; … … 217 253 else focus_ = NULL; 218 254 } 255 updateFocus(); 256 } 257 258 void Navigation::updateFocus(){ 219 259 if(focus_ == NULL){ 220 260 navMarker_->hide(); … … 228 268 } 229 269 230 float Navigation::getDist2Focus() {270 float Navigation::getDist2Focus() const { 231 271 if(focus_ == NULL) return(0.0); 232 272 return((focus_->getPosition()-SpaceShip::getLocalShip()->getPosition()).length()); -
code/trunk/src/orxonox/hud/Navigation.h
r1505 r1564 35 35 #include <OgreTextAreaOverlayElement.h> 36 36 #include <OgrePanelOverlayElement.h> 37 #include "util/Math.h"38 37 39 38 namespace orxonox 40 39 { 41 42 40 class _OrxonoxExport Navigation 43 41 { 44 private:45 Ogre::OverlayManager* om; // our one and only overlay manager46 Ogre::OverlayContainer* container_;47 Ogre::PanelOverlayElement* navMarker_; // the panel used to show the arrow48 Ogre::TextAreaOverlayElement* navText_; // displaying distance49 Ogre::Camera* navCam_;50 Vector3 navCamPos_; // position of ship51 Vector3 currentDir_;52 Vector3 currentOrth_;53 std::set<RadarObject*>::iterator it_;54 int windowW_, windowH_;55 void init();56 void updateMarker();57 58 42 public: 59 43 Navigation(Ogre::OverlayContainer* container); 60 44 Navigation(Ogre::OverlayContainer* container, RadarObject* focus); 61 45 ~Navigation(); 62 RadarObject* focus_; // next pointer of linked list63 46 64 47 void update(); 65 48 void cycleFocus(); 66 float getDist2Focus(); 49 float getDist2Focus() const; 50 51 inline RadarObject* getFocus() const 52 { return this->focus_; } 53 inline void setFocus(RadarObject* object) 54 { this->focus_ = object; this->updateFocus(); } 55 56 private: 57 void init(); 58 void updateMarker(); 59 void updateFocus(); 60 61 Ogre::OverlayContainer* container_; 62 Ogre::PanelOverlayElement* navMarker_; // the panel used to show the arrow 63 Ogre::PanelOverlayElement* aimMarker_; 64 Ogre::TextAreaOverlayElement* navText_; // displaying distance 65 std::list<RadarObject*>::iterator it_; 66 RadarObject* focus_; // next pointer of linked list 67 67 }; 68 68 } -
code/trunk/src/orxonox/hud/OverlayElementFactories.h
r1505 r1564 39 39 #include "RadarOverlayElement.h" 40 40 41 namespace orxonox{ 41 namespace orxonox 42 { 42 43 class _OrxonoxExport BarOverlayElementFactory : public Ogre::OverlayElementFactory{ 43 44 public: -
code/trunk/src/orxonox/hud/RadarObject.cc
r1563 r1564 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 35 35 36 36 #include "GraphicsEngine.h" 37 #include "objects/WorldEntity.h" 37 38 #include "util/Convert.h" 38 39 … … 43 44 { 44 45 public: 45 bool operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) 46 bool operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) const 46 47 { 47 48 if (__x.r == __y.r) … … 68 69 std::map<std::string, std::map<ColourValue, std::string> > RadarObject::materials_s; 69 70 70 RadarObject::RadarObject(Ogre::OverlayContainer* container, Ogre::SceneNode* node, const ColourValue& colour, const std::string& texturename)71 RadarObject::RadarObject(Ogre::OverlayContainer* container, WorldEntity* object, const ColourValue& colour, const std::string& texturename) 71 72 { 72 73 this->colour_ = colour; 73 74 this->texturename_ = texturename; 74 75 75 this->container_ = container; 76 this->node_ = node; 76 this->object_ = object; 77 77 78 this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarObject" + getConvertedValue<unsigned int, std::string>(RadarObject::count_s )));78 this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarObject" + getConvertedValue<unsigned int, std::string>(RadarObject::count_s++))); 79 79 this->setMaterial(colour, texturename); 80 80 81 this->panel_->setDimensions(3, 3);81 this->panel_->setDimensions(3, 3); 82 82 this->panel_->setMetricsMode(Ogre::GMM_PIXELS); 83 83 this->panel_->show(); 84 84 85 this->index_ = count_s++; 86 this->container_->addChild(panel_); 85 container->addChild(panel_); 87 86 } 88 87 89 88 RadarObject::~RadarObject() 90 89 { 91 delete panel_;90 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_); 92 91 } 93 92 … … 116 115 } 117 116 118 Vector3 RadarObject::getPosition()117 const Vector3& RadarObject::getPosition() const 119 118 { 120 return node_->getPosition();119 return this->object_->getPosition(); 121 120 } 122 121 123 Ogre::SceneNode* RadarObject::getNode()122 const Vector3& RadarObject::getVelocity() const 124 123 { 125 return node_;124 return this->object_->getVelocity(); 126 125 } 127 126 } -
code/trunk/src/orxonox/hud/RadarObject.h
r1563 r1564 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 30 30 #define _RadarObject_H__ 31 31 32 #include "OrxonoxPrereqs.h" 33 32 34 #include <map> 35 #include <OgrePanelOverlayElement.h> 33 36 34 #include <OgrePrerequisites.h>35 #include <OgreSceneNode.h>36 #include <OgrePanelOverlayElement.h>37 #include "OrxonoxPrereqs.h"38 37 #include "util/Math.h" 39 38 … … 43 42 { 44 43 public: 45 RadarObject(Ogre::OverlayContainer* container, Ogre::SceneNode* node, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1), const std::string& texturename = "white.tga");44 RadarObject(Ogre::OverlayContainer* container, WorldEntity* object, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1), const std::string& texturename = "white.tga"); 46 45 ~RadarObject(); 47 46 … … 54 53 { this->setMaterial(this->colour_, this->texturename_); } 55 54 56 Vector3 getPosition();57 Ogre::SceneNode* getNode();55 const Vector3& getPosition() const; 56 const Vector3& getVelocity() const; 58 57 59 bool right_;60 int index_; // index number of object61 Ogre::OverlayContainer* container_;62 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot58 inline WorldEntity* getObject() const 59 { return this->object_; } 60 inline Ogre::PanelOverlayElement* getPanel() const 61 { return this->panel_; } 63 62 64 63 private: … … 66 65 static unsigned int count_s; 67 66 static unsigned int materialcount_s; 68 Ogre::SceneNode* node_; // node of object 67 68 WorldEntity* object_; // the object 69 69 ColourValue colour_; 70 70 std::string texturename_; 71 }; 71 72 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot 73 }; 72 74 } 73 75 -
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 } -
code/trunk/src/orxonox/hud/RadarOverlayElement.h
r1505 r1564 40 40 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement 41 41 { 42 private:43 Ogre::OverlayManager* om; // our one and only overlay manager44 Ogre::OverlayContainer* container_; // pointer to the container we're in45 Vector3 currentDir_;46 Vector3 currentOrth_;47 Vector3 shipPos_; // position of ship48 49 Ogre::Real leftRel_, topRel_, dimRel_; // relative position/dimension50 int left_, top_, dim_; // absolute position/dimension51 int windowW_, windowH_; // absolute window dimensions52 53 42 public: 54 43 RadarOverlayElement(const Ogre::String& name); … … 57 46 void resize(); 58 47 void update(); 59 void listObjects() ;48 void listObjects() const; 60 49 61 static float calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);62 static float calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);63 static bool calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);50 private: 51 Ogre::Real leftRel_, topRel_, dimRel_; // relative position/dimension 52 int left_, top_, dim_; // absolute position/dimension 64 53 }; 65 54 } -
code/trunk/src/orxonox/objects/SpaceShip.cc
r1563 r1564 152 152 153 153 if (!this->myShip_) 154 HUD::getSingleton().removeRadarObject(this ->getNode());154 HUD::getSingleton().removeRadarObject(this); 155 155 } 156 156 } … … 161 161 myShip_=true; 162 162 else 163 HUD::getSingleton().addRadarObject(this ->getNode(), this->getProjectileColour());163 HUD::getSingleton().addRadarObject(this, this->getProjectileColour()); 164 164 } 165 165 if(Model::create()) … … 508 508 this->mouseXRotation_ = Radian(0); 509 509 this->mouseYRotation_ = Radian(0); 510 this->bLMousePressed_ = false;511 510 }/*else 512 511 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 512 513 this->bLMousePressed_ = false; 513 514 } 514 515 -
code/trunk/src/orxonox/objects/SpaceShipAI.cc
r1563 r1564 226 226 this->moveToTargetPosition(dt); 227 227 228 if (this->bShooting_ && this->isCloseAtTarget(2500) && this->isLookingAtTarget(Ogre::Math::PI / 10))228 if (this->bShooting_ && this->isCloseAtTarget(2500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0)) 229 229 this->doFire(); 230 230 … … 234 234 void SpaceShipAI::moveToTargetPosition(float dt) 235 235 { 236 Vector3 proj = Ogre::Plane(this->getDir(), this->getPosition()).projectVector(this->targetPosition_ - this->getPosition()); 237 float angle = acos((this->getOrth().dotProduct(proj)) / (this->getOrth().length()*proj.length())); 238 239 if ((this->getDir().crossProduct(this->getOrth())).dotProduct(this->targetPosition_ - this->getPosition()) > 0) 240 this->setMoveYaw(sgn(sin(angle))); 241 else 242 this->setMoveYaw(-sgn(sin(angle))); 243 this->setMovePitch(sgn(cos(angle))); 236 Vector2 coord = get2DViewdirection(this->getPosition(), this->getDir(), this->getOrth(), this->targetPosition_); 237 this->setMoveYaw(0.8 * sgn(coord.x)); 238 this->setMovePitch(0.8 * sgn(coord.y)); 244 239 245 240 if ((this->targetPosition_ - this->getPosition()).length() > 300) 246 this->setMoveLongitudinal( 1);241 this->setMoveLongitudinal(0.8); 247 242 248 243 if (this->isCloseAtTarget(300) && this->target_) 249 244 { 250 245 if (this->getVelocity().length() > this->target_->getVelocity().length()) 251 this->setMoveLongitudinal(- 1);246 this->setMoveLongitudinal(-0.5); 252 247 } 253 248 } … … 319 314 bool SpaceShipAI::isLookingAtTarget(float angle) 320 315 { 321 Vector3 dist = this->targetPosition_ - this->getPosition(); 322 return (acos((this->getDir().dotProduct(dist)) / (dist.length() * this->getDir().length())) < angle); 316 return (getAngle(this->getPosition(), this->getDir(), this->targetPosition_) < angle); 323 317 } 324 318 -
code/trunk/src/util/Math.cc
r1505 r1564 26 26 * 27 27 */ 28 29 #include <OgrePlane.h> 28 30 29 31 #include "Math.h" … … 68 70 return in; 69 71 } 72 73 74 float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition) 75 { 76 orxonox::Vector3 distance = otherposition - myposition; 77 return acos(mydirection.dotProduct(distance) / distance.length()); 78 } 79 80 orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition) 81 { 82 orxonox::Vector3 distance = otherposition - myposition; 83 84 // project difference vector on our plane 85 orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance); 86 float angle = acos(myorthonormal.dotProduct(projection) / projection.length()); 87 88 if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0) 89 return orxonox::Vector2(sin(angle), cos(angle)); 90 else 91 return orxonox::Vector2(-sin(angle), cos(angle)); 92 } 93 94 orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition) 95 { 96 orxonox::Vector3 distance = otherposition - myposition; 97 98 // project difference vector on our plane 99 orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance); 100 float angle = acos(myorthonormal.dotProduct(projection) / projection.length()); 101 float radius = acos(mydirection.dotProduct(distance) / distance.length()) / Ogre::Math::PI; 102 103 if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0) 104 return orxonox::Vector2(sin(angle) * radius, cos(angle) * radius); 105 else 106 return orxonox::Vector2(-sin(angle) * radius, cos(angle) * radius); 107 } -
code/trunk/src/util/Math.h
r1505 r1564 58 58 _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree); 59 59 _UtilExport std::istream& operator>>(std::istream& in, orxonox::Degree& degree); 60 61 _UtilExport float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition); 62 _UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition); 63 _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition); 60 64 61 65 template <typename T>
Note: See TracChangeset
for help on using the changeset viewer.