Changeset 1609
- Timestamp:
- Jun 17, 2008, 11:38:23 PM (17 years ago)
- Location:
- code/branches/hud
- Files:
-
- 6 added
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/orxonox/CMakeLists.txt
r1604 r1609 3 3 Main.cc 4 4 Orxonox.cc 5 Radar.cc 5 6 Settings.cc 6 7 … … 18 19 overlays/hud/HUDText.cc 19 20 overlays/hud/RadarObject.cc 21 overlays/hud/RadarViewable.cc 20 22 21 23 tolua/tolua_bind.cc -
code/branches/hud/src/orxonox/OrxonoxPrereqs.h
r1601 r1609 76 76 class Orxonox; 77 77 78 class RadarViewable; 79 class Radar; 80 class RadarListener; 81 78 82 // objects 79 83 class Ambient; -
code/branches/hud/src/orxonox/objects/WorldEntity.h
r1588 r1609 73 73 inline const Vector3& getPosition() const 74 74 { return this->node_->getPosition(); } 75 inline const Vector3& getWorldPosition() const 76 { return this->node_->getWorldPosition(); } 75 77 76 78 inline void translate(const Vector3 &d, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) … … 100 102 inline const Ogre::Quaternion& getOrientation() 101 103 { return this->node_->getOrientation(); } 104 inline const Ogre::Quaternion& getWorldOrientation() 105 { return this->node_->getWorldOrientation(); } 102 106 inline void setOrientation(const Ogre::Quaternion& quat) 103 107 { this->node_->setOrientation(quat); } -
code/branches/hud/src/orxonox/overlays/OverlayGroup.cc
r1604 r1609 70 70 BaseObject::XMLPort(xmlElement, mode); 71 71 72 XMLPortParam(OverlayGroup, "scale", scale, getScale, xmlElement, mode); 72 73 XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true); 73 XMLPortParam(OverlayGroup, "scale", scale, getScale, xmlElement, mode);74 74 } 75 75 -
code/branches/hud/src/orxonox/overlays/hud/HUDBar.cc
r1604 r1609 79 79 // create background 80 80 this->background_ = static_cast<PanelOverlayElement*>( 81 OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background "));81 OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background_" + getUniqueNumberStr())); 82 82 this->background_->setMaterialName("Orxonox/BarBackground"); 83 83 this->overlay_->add2D(this->background_); … … 93 93 94 94 // create bar 95 this->bar_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "Bar" ));95 this->bar_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "Bar" + getUniqueNumberStr())); 96 96 this->bar_->setMaterialName(materialname); 97 97 this->background_->addChild(bar_); -
code/branches/hud/src/orxonox/overlays/hud/HUDRadar.cc
r1604 r1609 32 32 #include <assert.h> 33 33 #include <OgreOverlayManager.h> 34 #include <OgreMaterialManager.h> 34 35 35 36 #include "core/ConsoleCommand.h" 36 #include "util/Math.h"37 37 #include "objects/SpaceShip.h" 38 38 #include "objects/WorldEntity.h" 39 #include "Radar Object.h"39 #include "RadarViewable.h" 40 40 41 41 namespace orxonox 42 42 { 43 43 CreateFactory(HUDRadar); 44 CreateFactory(RadarColour); 45 CreateFactory(RadarShape); 44 46 45 47 HUDRadar* HUDRadar::instance_s = 0; … … 62 64 if (this->background_) 63 65 OverlayManager::getSingleton().destroyOverlayElement(this->background_); 66 while (this->radarDots_.size() > 0) 67 { 68 OverlayManager::getSingleton().destroyOverlayElement(this->radarDots_[this->radarDots_.size() - 1]); 69 this->radarDots_.pop_back(); 70 } 64 71 } 65 72 … … 70 77 { 71 78 OrxonoxOverlay::XMLPort(xmlElement, mode); 79 80 XMLPortObject(HUDRadar, RadarColour, "shapes", addShape, getShape, xmlElement, mode, false, true); 72 81 73 82 if (mode == XMLPort::LoadObject) … … 77 86 overlay_->add2D(background_); 78 87 79 WorldEntity* object; 88 // create an array of all possible materials 89 unsigned int iMaterial = 0; 90 for (std::map<unsigned int, RadarShape*>::const_iterator itShape = shapes_.begin(); itShape != shapes_.end(); ++itShape) 91 { 92 Ogre::MaterialPtr originalMaterial = (Ogre::MaterialPtr)(Ogre::MaterialManager::getSingleton().getByName((*itShape).second->getAttribute())); 93 for (std::map<unsigned int, RadarColour*>::const_iterator itColour = colours_.begin(); itColour != colours_.end(); ++itColour) 94 { 95 Ogre::MaterialPtr newMaterial = originalMaterial->clone((*itShape).second->getAttribute() + convertToString(iMaterial++)); 96 newMaterial->getTechnique(0)->getPass(0)->setAmbient((*itColour).second->getAttribute()); 97 materialNames_[(*itShape).first + ((*itColour).first << 8)] = newMaterial->getName(); 98 } 99 } 100 101 /*WorldEntity* object; 80 102 object = new WorldEntity(); 81 103 object->setPosition(2000.0, 0.0, 0.0); … … 89 111 object = new WorldEntity(); 90 112 object->setPosition(10000.0,16000.0,0.0); 91 addRadarObject(object); 92 } 93 113 addRadarObject(object);*/ 114 } 115 } 116 117 void HUDRadar::addColour(RadarColour* colour) 118 { 119 this->colours_[colour->getIndex()] = colour; 120 } 121 122 RadarColour* HUDRadar::getColour(unsigned int index) const 123 { 124 if (index < this->colours_.size()) 125 { 126 std::map<unsigned int, RadarColour*>::const_iterator it = colours_.begin(); 127 for (unsigned int i = 0; i != index; ++it, ++i) 128 ; 129 return (*it).second; 130 } 131 else 132 return 0; 133 } 134 135 void HUDRadar::addShape(RadarShape* shape) 136 { 137 this->shapes_[shape->getIndex()] = shape; 138 } 139 140 RadarShape* HUDRadar::getShape(unsigned int index) const 141 { 142 if (index < this->shapes_.size()) 143 { 144 std::map<unsigned int, RadarShape*>::const_iterator it = shapes_.begin(); 145 for (unsigned int i = 0; i != index; ++it, ++i) 146 ; 147 return (*it).second; 148 } 149 else 150 return 0; 94 151 } 95 152 … … 97 154 { 98 155 // iterate through all RadarObjects 99 for(std::list<RadarObject*>::iterator it = getRadarObjects().begin(); it!= getRadarObjects().end(); it++) 100 { 101 // calc position on radar... 102 // set size to fit distance... 103 float size = 1.0/(((*it)->getPosition() - SpaceShip::getLocalShip()->getPosition()).length()); 104 size = clamp(size * 100.0f, 0.02f, 0.12f); 105 (*it)->getPanel()->setDimensions(size, size); 106 107 Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), (*it)->getPosition()); 108 coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture 109 (*it)->getPanel()->setPosition((1.0 + coord.x) * 0.5, (1.0 - coord.y) * 0.5); 156 unsigned int i = 0; 157 for (Iterator<RadarViewable> it = ObjectList<RadarViewable>::start(); it; ++it, ++i) 158 { 159 if ((*it)->isVisibleOnRadar()) 160 { 161 WorldEntity* object = (*it)->getWorldEntity(); 162 // Just to be sure that we actually have a WorldEntity 163 // We could do a dynamic_cast, but that's a lot slower 164 assert(object); 165 166 // set size to fit distance... 167 float size = 1.0/((object->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length()); 168 size = clamp(size * 100.0f, 0.02f, 0.12f); 169 if (i == radarDots_.size()) 170 { 171 // we have to create a new panel 172 radarDots_.push_back(static_cast<Ogre::PanelOverlayElement*>( 173 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + convertToString(i)))); 174 } 175 radarDots_[i]->setDimensions(size, size); 176 177 // calc position on radar... 178 Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), object->getWorldPosition()); 179 coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture 180 radarDots_[i]->setPosition((1.0 + coord.x) * 0.5, (1.0 - coord.y) * 0.5); 181 182 // apply the right material 183 RadarPoint description = (*it)->getDescription(); 184 radarDots_[i]->setMaterialName(materialNames_[description.shape_ + (description.colour_ << 8)]); 185 } 110 186 } 111 187 } … … 113 189 void HUDRadar::listObjects() 114 190 { 115 int i = 0;116 191 COUT(3) << "List of RadarObjects:\n"; 117 192 // iterate through all Radar Objects 118 for(std::list<RadarObject*>::const_iterator it = getRadarObjects().begin(); it != getRadarObjects().end(); ++it) 119 { 120 COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl; 121 } 122 } 123 124 void HUDRadar::addRadarObject(WorldEntity* object, const ColourValue& colour) 125 { 126 RadarObject* obj = new RadarObject(overlay_, object, colour); 127 roSet_.insert(roSet_.end(), obj); 128 } 129 130 void HUDRadar::removeRadarObject(WorldEntity* object) 131 { 132 for(std::list<RadarObject*>::iterator it=roSet_.begin(); it!=roSet_.end(); ++it) 133 { 134 if ((*it)->getObject() == object) 135 { 136 /*if (this->nav_ && this->nav_->getFocus() == (*it)) 137 this->nav_->releaseFocus();*/ 138 139 delete (*it); 140 roSet_.erase(it); 141 return; 142 } 193 unsigned int i = 0; 194 for (Iterator<RadarViewable> it = ObjectList<RadarViewable>::start(); it; ++it, ++i) 195 { 196 COUT(3) << i++ << ": " << (*it)->getWorldEntity()->getWorldPosition() << std::endl; 143 197 } 144 198 } -
code/branches/hud/src/orxonox/overlays/hud/HUDRadar.h
r1604 r1609 36 36 #include "overlays/OrxonoxOverlay.h" 37 37 #include "objects/Tickable.h" 38 #include "core/BaseObject.h" 39 #include "util/Math.h" 40 #include "core/Debug.h" 41 #include "Radar.h" 38 42 39 43 namespace orxonox 40 44 { 41 class _OrxonoxExport HUDRadar : public OrxonoxOverlay, public Tickable 45 template <class T, int Dummy> 46 class _OrxonoxExport RadarAttribute : public BaseObject 47 { 48 public: 49 RadarAttribute(); 50 ~RadarAttribute() { } 51 52 void XMLPort(Element& xmlElement, XMLPort::Mode mode); 53 void loadAttribute(Element& xmlElement, XMLPort::Mode mode); 54 55 void setAttribute(const T& attribute) { this->attribute_ = attribute; } 56 const T& getAttribute() const { return this->attribute_; } 57 58 void setIndex(unsigned int index); 59 unsigned int getIndex() { return this->index_; } 60 61 private: 62 unsigned int index_; 63 T attribute_; 64 }; 65 66 template <class T, int Dummy> 67 void RadarAttribute<T, Dummy>::setIndex(unsigned int index) 68 { 69 if (index > 0xFF) 70 { 71 COUT(1) << "Shape index was larger than 255 while parsing a RadarAttribute. " 72 << "Using random number!!!" << std::endl; 73 this->index_ = rand() & 0xFF; 74 } 75 else 76 this->index_ = index; 77 } 78 79 typedef RadarAttribute<std::string, 1> RadarShape; 80 81 template <> 82 RadarShape::RadarAttribute() : index_(0) 83 { RegisterObject(RadarShape); } 84 85 template <> 86 void RadarShape::XMLPort(Element& xmlElement, XMLPort::Mode mode) 87 { 88 BaseObject::XMLPort(xmlElement, mode); 89 XMLPortParam(RadarShape, "shape", setAttribute, getAttribute, xmlElement, mode); 90 XMLPortParam(RadarShape, "index", setIndex, getIndex, xmlElement, mode); 91 } 92 93 94 class _OrxonoxExport HUDRadar : public OrxonoxOverlay, public Tickable, public RadarListener 42 95 { 43 96 public: … … 47 100 void XMLPort(Element& xmlElement, XMLPort::Mode mode); 48 101 102 void addShape(RadarShape* shape); 103 RadarShape* getShape(unsigned int index) const; 104 49 105 void tick(float dt); 50 106 51 107 void listObjects(); 52 108 53 inline std::list<RadarObject*>& getRadarObjects() 54 { return this->roSet_; } 109 private: 110 void addColour(RadarColour* colour); 111 RadarColour* getColour(unsigned int index) const; 55 112 56 void addRadarObject(WorldEntity* object, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1)); 57 void removeRadarObject(WorldEntity* object); 113 std::map<unsigned int, std::string> materialNames_; 114 std::map<unsigned int, RadarColour*> colours_; 115 std::map<unsigned int, RadarShape*> shapes_; 58 116 59 static HUDRadar& getInstance();60 61 private:62 HUDRadar(HUDRadar& instance);63 64 std::list<RadarObject*> roSet_;65 117 Ogre::PanelOverlayElement* background_; 66 67 static HUDRadar* instance_s; 118 std::map<RadarViewable*, Ogre::PanelOverlayElement*> radarDots_; 68 119 }; 69 120 } -
code/branches/hud/src/util/Math.cc
r1566 r1609 30 30 31 31 #include "Math.h" 32 #include "Convert.h" 32 33 33 34 /** … … 123 124 return (targetposition + targetvelocity * time); 124 125 } 126 127 unsigned long getUniqueNumber() 128 { 129 static unsigned long aNumber = 135; 130 return aNumber++; 131 } 132 133 std::string getUniqueNumberStr() 134 { 135 return convertToString(getUniqueNumber()); 136 } -
code/branches/hud/src/util/Math.h
r1588 r1609 33 33 34 34 #include <ostream> 35 #include <string> 35 36 36 37 #include <OgreMath.h> … … 163 164 } 164 165 166 _UtilExport unsigned long getUniqueNumber(); 167 _UtilExport std::string getUniqueNumberStr(); 168 165 169 class _UtilExport IntVector2 166 170 { -
code/branches/hud/src/util/UtilPrereqs.h
r1505 r1609 61 61 //----------------------------------------------------------------------- 62 62 class ArgReader; 63 class Convert;64 63 class MultiTypePrimitive; 65 64 class MultiTypeString; -
code/branches/hud/visual_studio/vc8/orxonox.vcproj
r1604 r1609 185 185 </File> 186 186 <File 187 RelativePath="..\..\src\orxonox\Radar.cc" 188 > 189 </File> 190 <File 187 191 RelativePath="..\..\src\orxonox\Settings.cc" 188 192 > … … 393 397 <File 394 398 RelativePath="..\..\src\orxonox\tools\ParticleInterface.cc" 399 > 400 </File> 401 <File 402 RelativePath="..\..\src\orxonox\tools\TextureGenerator.cc" 395 403 > 396 404 </File> … … 480 488 <File 481 489 RelativePath="..\..\src\orxonox\overlays\hud\RadarObject.cc" 490 > 491 </File> 492 <File 493 RelativePath="..\..\src\orxonox\overlays\hud\RadarViewable.cc" 482 494 > 483 495 </File> … … 507 519 </File> 508 520 <File 521 RelativePath="..\..\src\orxonox\Radar.h" 522 > 523 </File> 524 <File 509 525 RelativePath="..\..\src\orxonox\Settings.h" 510 526 > … … 622 638 </File> 623 639 <File 640 RelativePath="..\..\src\orxonox\tools\TextureGenerator.h" 641 > 642 </File> 643 <File 624 644 RelativePath="..\..\src\orxonox\tools\Timer.h" 625 645 > … … 686 706 <File 687 707 RelativePath="..\..\src\orxonox\overlays\hud\RadarObject.h" 708 > 709 </File> 710 <File 711 RelativePath="..\..\src\orxonox\overlays\hud\RadarViewable.h" 688 712 > 689 713 </File>
Note: See TracChangeset
for help on using the changeset viewer.