Changeset 9259 for code/trunk/src/modules
- Timestamp:
- May 28, 2012, 4:47:47 PM (13 years ago)
- Location:
- code/trunk/src/modules
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.cc
r9016 r9259 23 23 * Matthias Spalinger 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 29 29 #include "HUDEnemyHealthBar.h" 30 30 31 #include <OgreCamera.h>32 33 #include "util/Convert.h"34 31 #include "core/ConfigValueIncludes.h" 35 #include "core/CoreIncludes.h" 36 #include "core/XMLPort.h" 37 #include "infos/PlayerInfo.h" 38 #include "overlays/OverlayGroup.h" 39 #include "CameraManager.h" 40 #include "graphics/Camera.h" 41 #include "util/Math.h" 42 #include "HUDNavigation.h" 43 #include "core/input/InputManager.h" 44 #include "controllers/HumanController.h" 45 #include "core/GraphicsManager.h" 46 #include "Scene.h" 47 #include "Radar.h" 48 #include "controllers/NewHumanController.h" 32 #include "worldentities/pawns/Pawn.h" 49 33 50 34 namespace orxonox … … 57 41 58 42 this->setConfigValues(); 59 setSensibility(0.1f);60 43 this->owner_ = 0; 61 markerLimit_ = 3; //TODO connect with markerLimit_ from the settings / from HUDNavigation.cc62 currentYaw = 0;63 currentPitch = 0;64 65 this->getOverlayText()->setCaption("");66 44 } 67 45 68 46 HUDEnemyHealthBar::~HUDEnemyHealthBar() 69 47 { 70 sortedObjectList_.clear();71 48 } 72 49 … … 76 53 } 77 54 78 void HUDEnemyHealthBar:: XMLPort(Element& xmlelement, XMLPort::Mode mode)55 void HUDEnemyHealthBar::tick(float dt) 79 56 { 80 SUPER(HUDEnemyHealthBar, XMLPort, xmlelement, mode);57 this->updateTarget(); 81 58 82 XMLPortParam ( HUDEnemyHealthBar, "sensibility", setSensibility, getSensibility, xmlelement, mode);59 SUPER(HUDEnemyHealthBar, tick, dt); 83 60 } 84 61 85 bool compareDist ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b)62 void HUDEnemyHealthBar::updateTarget() 86 63 { 87 return a.second<b.second; 88 } 89 90 void HUDEnemyHealthBar::tick(float dt) 91 { 92 if (!useEnemyBar_){ 93 this->setValue(0); //TODO hide it instead of setting it to 0 94 this->getOverlayText()->setCaption(""); 95 return; 64 Pawn* pawn = NULL; 65 if (this->owner_ && this->useEnemyBar_) 66 { 67 // Get the owner's current target (target is usually a Model) 68 WorldEntity* target = this->owner_->getTarget(); 69 // Find the Pawn that belongs to this target (if any) 70 while (target && !target->isA(Class(Pawn))) 71 target = target->getParent(); 72 pawn = orxonox_cast<Pawn*>(target); 73 // Don't show the HealthBar if the pawn is invisible 74 if (pawn && !pawn->isVisible()) 75 pawn = NULL; 96 76 } 97 98 Camera* cam = CameraManager::getInstance().getActiveCamera(); 99 if ( cam == NULL ) 100 return; 101 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 102 103 unsigned int markerCount_ = 0; 104 105 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt ) 106 { 107 listIt->second = ( int ) ( ( listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition() ).length() + 0.5f ); 108 } 109 110 sortedObjectList_.sort ( compareDist ); 111 112 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt ) 113 { 114 if ( markerCount_ < markerLimit_ ) 115 { 116 // Transform to screen coordinates and reverse x-axis 117 Vector3 pos = (camTransform * listIt->first->getRVWorldPosition()); 118 pos.x = -pos.x; 119 120 // get mouse position 121 if(this->getOwner() && dynamic_cast<ControllableEntity*>(this->getOwner())->getController() && dynamic_cast<NewHumanController*>(dynamic_cast<ControllableEntity*>(this->getOwner())->getController())) 122 { 123 currentYaw = dynamic_cast<NewHumanController*>(dynamic_cast<ControllableEntity*>(this->getOwner())->getController())->getCurrentYaw(); 124 currentPitch = dynamic_cast<NewHumanController*>(dynamic_cast<ControllableEntity*>(this->getOwner())->getController())->getCurrentPitch(); 125 } 126 // Compare cursor position to object position 127 if ( fabs(pos.x - currentYaw) < sens_ && fabs(pos.y - currentPitch) < sens_ ) 128 { 129 this->owner_ = orxonox_cast<Pawn*>(listIt->first); 130 break; 131 } 132 } 133 this->owner_ = 0; 134 } 135 136 137 138 if (this->owner_) 139 { 140 this->setValue(this->owner_->getHealth() / this->owner_->getInitialHealth()); 141 this->getOverlayText()->setCaption(multi_cast<std::string>(static_cast<int>(this->owner_->getHealth()))); 142 } 143 else 144 { 145 this->setValue(0); //TODO hide it instead of setting it to zero 146 this->getOverlayText()->setCaption(""); 147 } 148 149 if (this->getTextUseBarColour()) 150 this->getOverlayText()->setColour(this->getCurrentBarColour()); 151 } 152 153 void HUDEnemyHealthBar::addObject ( RadarViewable* object ) 154 { 155 if( showObject(object)==false ) 156 return; 157 158 if ( sortedObjectList_.size() >= markerLimit_ ) 159 if ( object == NULL ) 160 return; 161 162 sortedObjectList_.push_front ( std::make_pair ( object, ( unsigned int ) 0 ) ); 163 164 //remove duplicates 165 sortedObjectList_.unique(); 166 } 167 168 bool HUDEnemyHealthBar::showObject(RadarViewable* rv) 169 { 170 if ( rv == dynamic_cast<RadarViewable*> ( this->getOwner() ) ) 171 return false; 172 assert( rv->getWorldEntity() ); 173 if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false ) 174 return false; 175 return true; 176 } 177 178 void HUDEnemyHealthBar::removeObject ( RadarViewable* viewable ) 179 { 180 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt ) 181 { 182 if ( (listIt->first) == viewable ) 183 { 184 sortedObjectList_.erase ( listIt ); 185 break; 186 } 187 188 } 189 190 } 191 192 void HUDEnemyHealthBar::objectChanged(RadarViewable* viewable) 193 { 194 // TODO: niceification neccessary - and while you're at it: the same function exists in HUDNavigation.cc ;) 195 removeObject(viewable); 196 addObject(viewable); 77 // Set the pawn as owner of the HealthBar 78 this->setHealthBarOwner(pawn); 79 this->setVisible(pawn != NULL); 197 80 } 198 81 199 82 void HUDEnemyHealthBar::changedOwner() 200 83 { 201 202 const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects(); 203 for ( std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it ) 204 { 205 if ( ! ( *it )->isHumanShip_ ) 206 this->addObject ( *it ); 207 } 84 SUPER(HUDEnemyHealthBar, changedOwner); 85 86 this->owner_ = orxonox_cast<ControllableEntity*>(this->getOwner()); 87 this->updateTarget(); 208 88 } 209 210 89 } -
code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.h
r9016 r9259 23 23 * Matthias Spalinger 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 30 30 #define _HUDEnemyHealthBar_H__ 31 31 32 #include "interfaces/RadarViewable.h"33 #include "worldentities/pawns/Pawn.h"34 35 32 #include "HUDHealthBar.h" 36 #include "interfaces/RadarListener.h"37 33 38 34 namespace orxonox 39 35 { 40 class _OverlaysExport HUDEnemyHealthBar : public HUDHealthBar , public RadarListener36 class _OverlaysExport HUDEnemyHealthBar : public HUDHealthBar 41 37 { 42 38 public: 43 39 HUDEnemyHealthBar(BaseObject* creator); 44 40 virtual ~HUDEnemyHealthBar(); 41 45 42 void setConfigValues(); 46 47 bool compareDistance ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b );48 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);50 43 virtual void tick(float dt); 51 52 //RadarListener interface53 void addObject ( RadarViewable* object );54 void removeObject ( RadarViewable* viewable );55 void objectChanged(RadarViewable* viewable);56 virtual void radarTick ( float dt ) {}57 inline float getRadarSensitivity() const58 { return 1.0f; }59 44 60 45 void changedOwner(); 61 46 62 47 private: 48 void updateTarget(); 63 49 64 void setSensibility (float sense){ 65 this->sens_ = sense;} 66 float getSensibility(){ 67 return this->sens_;} 68 69 bool showObject(RadarViewable* rv); 70 71 typedef std::list < std::pair<RadarViewable*, unsigned int > > sortedList; 72 sortedList sortedObjectList_; 73 74 Pawn* owner_; 75 float sens_; 50 ControllableEntity* owner_; 76 51 bool useEnemyBar_; 77 unsigned int markerLimit_;78 79 float currentYaw;80 float currentPitch;81 52 }; 82 53 } -
code/trunk/src/modules/overlays/hud/HUDHealthBar.h
r9016 r9259 110 110 { return this->textoverlay_->getSpaceWidth(); } 111 111 112 inline void setOverlayText(SmartPtr<OverlayText> textoverlay) 113 { this->textoverlay_ = textoverlay; } 114 inline SmartPtr<OverlayText> getOverlayText() const 115 {return this->textoverlay_; } 112 inline void setHealthBarOwner(Pawn* owner) 113 { this->owner_ = owner; } 116 114 117 115 private: -
code/trunk/src/modules/pong/PongScore.cc
r9258 r9259 130 130 { 131 131 if (this->bShowName_ && this->bShowScore_ && player1_ != NULL) 132 132 output1 = name1 + " - " + score1; 133 133 else if (this->bShowScore_) 134 134 output1 = score1; 135 135 else if (this->bShowName_) 136 136 output1 = name1; 137 137 } 138 138
Note: See TracChangeset
for help on using the changeset viewer.