Changeset 2485 for code/branches/presentation/src/orxonox/overlays/hud
- Timestamp:
- Dec 16, 2008, 6:01:13 PM (16 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 9 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
-
code/branches/presentation/src/orxonox/overlays/hud/CMakeLists.txt
r2131 r2485 4 4 HUDRadar.cc 5 5 HUDSpeedBar.cc 6 HUDHealthBar.cc 6 7 ChatOverlay.cc 8 GametypeStatus.cc 7 9 ) 8 10 -
code/branches/presentation/src/orxonox/overlays/hud/HUDBar.cc
r2087 r2485 51 51 RegisterObject(BarColour); 52 52 53 setColour(ColourValue(1.0, 1.0, 1.0, 1.0));54 setPosition(0.0);53 this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); 54 this->setPosition(0.0); 55 55 } 56 56 … … 84 84 this->bar_->setMaterialName(materialname); 85 85 86 setValue(0.4567654f); 87 setRightToLeft(false); 88 setAutoColour(true); 86 this->value_ = 1.0f; // initielize with 1.0f to trigger a change when calling setValue(0.0f) on the line below 87 this->setValue(0.0f); // <-- 88 this->setRightToLeft(false); 89 this->setAutoColour(true); 90 this->currentColour_ = ColourValue::White; 89 91 90 92 this->background_->addChild(bar_); … … 101 103 SUPER(HUDBar, XMLPort, xmlElement, mode); 102 104 103 XMLPortParam(HUDBar, "initialValue", setValue, getValue, xmlElement, mode); 104 XMLPortParam(HUDBar, "rightToLeft", setRightToLeft, getRightToLeft, xmlElement, mode); 105 XMLPortParam(HUDBar, "autoColour", setAutoColour, getAutoColour, xmlElement, mode); 105 XMLPortParam(HUDBar, "initialvalue", setValue, getValue, xmlElement, mode); 106 XMLPortParam(HUDBar, "righttoleft", setRightToLeft, getRightToLeft, xmlElement, mode); 107 XMLPortParam(HUDBar, "autocolour", setAutoColour, getAutoColour, xmlElement, mode); 108 XMLPortParam(HUDBar, "bartexture", setBarTexture, getBarTexture, xmlElement, mode); 106 109 XMLPortObject(HUDBar, BarColour, "", addColour, getColour, xmlElement, mode); 107 110 } … … 130 133 { 131 134 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour2); 135 this->currentColour_ = colour2; 132 136 } 133 137 else if (value1 < this->value_) 134 138 { 135 139 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour1); 140 this->currentColour_ = colour1; 136 141 } 137 142 else … … 139 144 //float interpolationfactor = (this->value_ - value2) / (value1 - value2); 140 145 float interpolationfactor = interpolateSmooth((this->value_ - value2) / (value1 - value2), 0.0f, 1.0f); 141 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour1 * interpolationfactor + colour2 * (1 - interpolationfactor)); 146 this->currentColour_ = colour1 * interpolationfactor + colour2 * (1 - interpolationfactor); 147 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, this->currentColour_); 148 142 149 } 143 150 } … … 181 188 this->colours_.clear(); 182 189 } 190 191 void HUDBar::setBarTexture(const std::string& texture) 192 { 193 this->textureUnitState_->setTextureName(texture); 194 } 195 196 const std::string& HUDBar::getBarTexture() const 197 { 198 return this->textureUnitState_->getTextureName(); 199 } 183 200 } -
code/branches/presentation/src/orxonox/overlays/hud/HUDBar.h
r2087 r2485 71 71 void clearColours(); 72 72 73 void setRightToLeft(bool r2l) { this->right2Left_ = r2l; this->valueChanged(); } 74 bool getRightToLeft() const { return this->right2Left_; } 73 inline void setRightToLeft(bool r2l) 74 { 75 if (r2l != this->right2Left_) 76 { 77 this->right2Left_ = r2l; 78 this->valueChanged(); 79 } 80 } 81 inline bool getRightToLeft() const 82 { return this->right2Left_; } 75 83 76 void setValue(float value) { this->value_ = clamp(value, 0.0f, 1.0f); this->valueChanged(); } 77 float getValue() const { return this->value_; } 84 inline void setValue(float value) 85 { 86 float temp = clamp(value, 0.0f, 1.0f); 87 if (temp != this->value_) 88 { 89 this->value_ = temp; 90 this->valueChanged(); 91 } 92 } 93 inline float getValue() const 94 { return this->value_; } 78 95 79 void setAutoColour(bool val) { this->autoColour_ = val; this->valueChanged(); } 80 bool getAutoColour() const { return this->autoColour_; } 96 inline void setAutoColour(bool val) 97 { 98 if (val != this->autoColour_) 99 { 100 this->autoColour_ = val; 101 this->valueChanged(); 102 103 if (!val) 104 this->currentColour_ = ColourValue::White; 105 } 106 } 107 inline bool getAutoColour() const 108 { return this->autoColour_; } 109 110 void setBarTexture(const std::string& texture); 111 const std::string& getBarTexture() const; 112 113 inline const ColourValue& getCurrentBarColour() const 114 { return this->currentColour_; } 81 115 82 116 protected: … … 90 124 bool autoColour_; //!< whether bar changes colour automatically 91 125 float value_; //!< progress of bar 126 ColourValue currentColour_; 92 127 93 128 Ogre::PanelOverlayElement* bar_; -
code/branches/presentation/src/orxonox/overlays/hud/HUDNavigation.cc
r2087 r2485 129 129 void HUDNavigation::tick(float dt) 130 130 { 131 SUPER(HUDNavigation, tick, dt); 132 131 133 if (!Radar::getInstance().getFocus()) 132 134 { … … 149 151 */ 150 152 // transform to screen coordinates 151 Vector3 pos = /*transformationMatrix * */Radar::getInstance().getFocus()->get WorldPosition();153 Vector3 pos = /*transformationMatrix * */Radar::getInstance().getFocus()->getRVWorldPosition(); 152 154 153 155 bool outOfView; … … 223 225 /* 224 226 Vector3 aimpos = transformationMatrix * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), 225 Projectile::getSpeed(), Radar::getInstance().getFocus()->get WorldPosition(), Radar::getInstance().getFocus()->getOrientedVelocity());227 Projectile::getSpeed(), Radar::getInstance().getFocus()->getRVWorldPosition(), Radar::getInstance().getFocus()->getRVOrientedVelocity()); 226 228 */ 227 229 if (wasOutOfView_) … … 250 252 /* 251 253 if (Radar::getInstance().getFocus()) 252 return (Radar::getInstance().getFocus()->get WorldPosition() - SpaceShip::getLocalShip()->getPosition()).length();254 return (Radar::getInstance().getFocus()->getRVWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length(); 253 255 else 254 256 */ -
code/branches/presentation/src/orxonox/overlays/hud/HUDRadar.cc
r2087 r2485 40 40 #include "core/XMLPort.h" 41 41 #include "objects/Radar.h" 42 #include "objects/worldentities/WorldEntity.h" 43 #include "objects/worldentities/pawns/Pawn.h" 42 44 #include "tools/TextureGenerator.h" 43 45 … … 51 53 RegisterObject(HUDRadar); 52 54 53 marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()55 this->marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 54 56 .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberString())); 55 marker_->setMaterialName("Orxonox/RadarMarker");56 overlay_->add2D(marker_);57 marker_->hide();57 this->marker_->setMaterialName("Orxonox/RadarMarker"); 58 this->overlay_->add2D(this->marker_); 59 this->marker_->hide(); 58 60 59 setRadarSensitivity(1.0f);60 setHalfDotSizeDistance(3000.0f);61 setMaximumDotSize(0.1f);61 this->setRadarSensitivity(1.0f); 62 this->setHalfDotSizeDistance(3000.0f); 63 this->setMaximumDotSize(0.1f); 62 64 63 shapeMaterials_[RadarViewable::Dot] = "RadarSquare.tga"; 64 shapeMaterials_[RadarViewable::Triangle] = "RadarSquare.tga"; 65 shapeMaterials_[RadarViewable::Square] = "RadarSquare.tga"; 65 this->shapeMaterials_[RadarViewable::Dot] = "RadarDot.tga"; 66 this->shapeMaterials_[RadarViewable::Triangle] = "RadarSquare.tga"; 67 this->shapeMaterials_[RadarViewable::Square] = "RadarSquare.tga"; 68 69 this->owner_ = 0; 66 70 } 67 71 … … 90 94 void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked) 91 95 { 92 /* 96 if (object == (RadarViewable*)this->owner_) 97 return; 98 93 99 const WorldEntity* wePointer = object->getWorldEntity(); 94 100 95 101 // Just to be sure that we actually have a WorldEntity. 96 102 // We could do a dynamic_cast, but that would be a lot slower. 97 if (!wePointer )103 if (!wePointer || !this->owner_) 98 104 { 99 CCOUT(4) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 105 if (!wePointer) 106 CCOUT(2) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 107 if (!this->owner_) 108 CCOUT(2) << "No owner defined" << std::endl; 100 109 return; 101 110 } 102 */ 111 103 112 // try to find a panel already created 104 113 Ogre::PanelOverlayElement* panel; … … 112 121 // get right material 113 122 panel->setMaterialName(TextureGenerator::getMaterialName( 114 shapeMaterials_[object->getRadarObject Type()], object->getRadarObjectColour()));123 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour())); 115 124 this->overlay_->add2D(panel); 116 125 this->itRadarDots_ = this->radarDots_.end(); … … 121 130 ++itRadarDots_; 122 131 std::string materialName = TextureGenerator::getMaterialName( 123 shapeMaterials_[object->getRadarObject Type()], object->getRadarObjectColour());132 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour()); 124 133 if (materialName != panel->getMaterialName()) 125 134 panel->setMaterialName(materialName); 126 135 } 127 136 panel->show(); 128 /* 137 129 138 // set size to fit distance... 130 float distance = (wePointer->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length();139 float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length(); 131 140 // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda) 132 141 float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance); … … 134 143 135 144 // calc position on radar... 136 Vector2 coord = get2DViewcoordinates( SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), wePointer->getWorldPosition());145 Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition()); 137 146 coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture 138 147 panel->setPosition((1.0 + coord.x - size) * 0.5, (1.0 - coord.y - size) * 0.5); … … 144 153 this->marker_->setPosition((1.0 + coord.x - size * 1.5) * 0.5, (1.0 - coord.y - size * 1.5) * 0.5); 145 154 } 146 */147 155 } 148 156 … … 154 162 this->marker_->hide(); 155 163 } 164 165 void HUDRadar::changedOwner() 166 { 167 SUPER(HUDRadar, changedOwner); 168 169 this->owner_ = dynamic_cast<Pawn*>(this->getOwner()); 170 } 156 171 } -
code/branches/presentation/src/orxonox/overlays/hud/HUDRadar.h
r2087 r2485 49 49 50 50 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 51 virtual void changedOwner(); 51 52 52 53 private: … … 76 77 77 78 float sensitivity_; 79 80 Pawn* owner_; 78 81 }; 79 82 } -
code/branches/presentation/src/orxonox/overlays/hud/HUDSpeedBar.cc
r2087 r2485 31 31 #include "HUDSpeedBar.h" 32 32 #include "core/CoreIncludes.h" 33 #include "objects/worldentities/pawns/SpaceShip.h" 34 #include "objects/items/Engine.h" 33 35 34 36 namespace orxonox … … 41 43 RegisterObject(HUDSpeedBar); 42 44 45 this->owner_ = 0; 43 46 } 44 47 … … 49 52 void HUDSpeedBar::tick(float dt) 50 53 { 51 /* 52 SpaceShip* ship = SpaceShip::getLocalShip(); 53 if ( ship)54 SUPER(HUDSpeedBar, tick, dt); 55 56 if (this->owner_ && this->owner_->getEngine()) 54 57 { 55 float v = ship->getVelocity().length(); 56 float value = v / ship->getMaxSpeed(); 57 if (value != this->getValue()) 58 this->setValue(value); 58 float value = this->owner_->getVelocity().length() / (this->owner_->getEngine()->getMaxSpeedFront() * this->owner_->getEngine()->getSpeedFactor() * this->owner_->getEngine()->getBoostFactor()); 59 this->setValue(value); 59 60 } 60 */ 61 } 62 63 void HUDSpeedBar::changedOwner() 64 { 65 SUPER(HUDSpeedBar, changedOwner); 66 67 this->owner_ = dynamic_cast<SpaceShip*>(this->getOwner()); 61 68 } 62 69 } -
code/branches/presentation/src/orxonox/overlays/hud/HUDSpeedBar.h
r2087 r2485 45 45 46 46 virtual void tick(float dt); 47 virtual void changedOwner(); 48 49 private: 50 SpaceShip* owner_; 47 51 }; 48 52 }
Note: See TracChangeset
for help on using the changeset viewer.