Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2256


Ignore:
Timestamp:
Nov 25, 2008, 1:14:19 AM (16 years ago)
Author:
landauf
Message:

The SpaceShips HUD is working again (Speedbar and Radar)

Location:
code/branches/objecthierarchy2/src/orxonox
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/orxonox/objects/Radar.cc

    r2087 r2256  
    112112            for (ObjectList<RadarViewable>::iterator itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement)
    113113            {
    114 /*
    115                 if ((*itElement) != SpaceShip::getLocalShip() && (*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage())
     114                if ((*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage())
    116115                    (*itListener)->displayObject(*itElement, *itElement == this->focus_);
    117 */
    118116            }
    119117        }
     
    128126            this->focus_ = 0;
    129127        }
    130         else
    131         {
    132             Vector3 localPosition;// = SpaceShip::getLocalShip()->getPosition();
     128/*
     129        else if (this->owner_)
     130        {
     131            Vector3 localPosition = this->owner_->getPosition();
    133132            Vector3 targetPosition = localPosition;
    134133            if (*(this->itFocus_))
     
    143142            for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it)
    144143            {
    145 /*
    146                 if (*it == SpaceShip::getLocalShip())
     144                if (*it == (RadarViewable*)this->owner_)
    147145                    continue;
    148 */
     146
    149147                float targetDistance = localPosition.squaredDistance((*it)->getWorldPosition());
    150148                if (targetDistance > currentDistance && targetDistance < nextDistance)
     
    171169            }
    172170        }
     171*/
    173172    }
    174173
  • code/branches/objecthierarchy2/src/orxonox/objects/RadarViewable.cc

    r2087 r2256  
    2929#include "OrxonoxStableHeaders.h"
    3030#include "RadarViewable.h"
     31
    3132#include "util/Debug.h"
     33#include "util/Exception.h"
    3234#include "core/CoreIncludes.h"
    33 //#include "objects/WorldEntity.h"
    34 #include "Radar.h"
     35#include "objects/worldentities/WorldEntity.h"
     36#include "objects/Radar.h"
    3537
    3638namespace orxonox
     
    4042    */
    4143    RadarViewable::RadarViewable()
    42         : radarObject_(0)
    43         , radarObjectCamouflage_(0.0f)
    44         , radarObjectType_(Dot)
     44        : radarObjectCamouflage_(0.0f)
     45        , radarObjectShape_(Dot)
    4546        , radarObjectDescription_("staticObject")
    4647    {
     
    5253        Radar* radar = Radar::getInstancePtr();
    5354        if (radar)
    54             this->radarObjectType_ = radar->addObjectDescription(str);
     55            this->radarObjectShape_ = radar->addObjectDescription(str);
    5556        else
    5657        {
     
    6263    const Vector3& RadarViewable::getWorldPosition() const
    6364    {
    64         validate();
    65         return Vector3::ZERO;//this->radarObject_->getWorldPosition();
     65        const WorldEntity* object = this->getWorldEntity();
     66        validate(object);
     67        return object->getWorldPosition();
    6668    }
    6769
    6870    Vector3 RadarViewable::getOrientedVelocity() const
    6971    {
    70         validate();
    71         return Vector3::ZERO;//this->radarObject_->getOrientation() * this->radarObject_->getVelocity();
     72        const WorldEntity* object = this->getWorldEntity();
     73        validate(object);
     74        return object->getWorldOrientation() * object->getVelocity();
    7275    }
    7376}
  • code/branches/objecthierarchy2/src/orxonox/objects/RadarViewable.h

    r2087 r2256  
    4444    class _OrxonoxExport RadarViewable : virtual public OrxonoxClass
    4545    {
    46     class WorldEntity;
    47 
    4846    public:
    4947        enum Shape
     
    5856        virtual ~RadarViewable() { }
    5957
    60         float getRadarObjectCamouflage() const { return this->radarObjectCamouflage_; }
    61         void setRadarObjectCamouflage(float camouflage) { this->radarObjectCamouflage_ = camouflage; }
     58        inline void setRadarObjectCamouflage(float camouflage)
     59            { this->radarObjectCamouflage_ = camouflage; }
     60        inline float getRadarObjectCamouflage() const
     61            { return this->radarObjectCamouflage_; }
    6262
    63         const ColourValue& getRadarObjectColour() const { return this->radarObjectColour_; }
    64         void setRadarObjectColour(const ColourValue& colour) { this->radarObjectColour_ = colour; }
     63        inline void setRadarObjectColour(const ColourValue& colour)
     64            { this->radarObjectColour_ = colour; }
     65        inline const ColourValue& getRadarObjectColour() const
     66            { return this->radarObjectColour_; }
    6567
    66         const std::string& getRadarObjectDescription() const { return this->radarObjectDescription_; }
    6768        void setRadarObjectDescription(const std::string& str);
     69        inline const std::string& getRadarObjectDescription() const
     70            { return this->radarObjectDescription_; }
    6871
    69         const WorldEntity* getWorldEntity() const { return this->radarObject_; }
     72        virtual const WorldEntity* getWorldEntity() const = 0;
     73
    7074        const Vector3& getWorldPosition() const;
    7175        Vector3 getOrientedVelocity() const;
    7276
    73         Shape getRadarObjectType() const { return this->radarObjectType_; }
    74 
    75     protected:
    76         WorldEntity* radarObject_;
     77        inline void setRadarObjectShape(Shape shape)
     78            { this->radarObjectShape_ = shape; }
     79        inline Shape getRadarObjectShape() const
     80            { return this->radarObjectShape_; }
    7781
    7882    private:
    79         void validate() const { if (!this->radarObject_)
    80         { COUT(1) << "Assertation: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl; assert(0); } }
     83        void validate(const WorldEntity* object) const
     84        {
     85            if (!object)
     86            {
     87                COUT(1) << "Assertation: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl;
     88                assert(0);
     89            }
     90        }
    8191
    8292        float radarObjectCamouflage_;
    83         Shape radarObjectType_;
     93        Shape radarObjectShape_;
    8494        std::string radarObjectDescription_;
    8595        ColourValue radarObjectColour_;
  • code/branches/objecthierarchy2/src/orxonox/objects/items/Engine.cc

    r2254 r2256  
    6464    Engine::~Engine()
    6565    {
     66        if (this->isInitialized() && this->ship_)
     67            this->ship_->setEngine(0);
    6668    }
    6769
     
    111113            Synchronisable* object = Synchronisable::getSynchronisable(this->shipID_);
    112114            if (object)
    113                 this->ship_ = dynamic_cast<SpaceShip*>(object);
     115                this->addToSpaceShip(dynamic_cast<SpaceShip*>(object));
    114116        }
    115117    }
     
    182184        this->ship_ = ship;
    183185        if (ship)
     186        {
    184187            this->shipID_ = ship->getObjectID();
     188            if (ship->getEngine() != this)
     189                ship->setEngine(this);
     190        }
    185191    }
    186192
  • code/branches/objecthierarchy2/src/orxonox/objects/items/Engine.h

    r2254 r2256  
    7272                { this->maxSpeedUpDown_ = speed; }
    7373
     74            inline float getMaxSpeedFront() const
     75                { return this->maxSpeedFront_; }
     76            inline float getMaxSpeedBack() const
     77                { return this->maxSpeedBack_; }
     78            inline float getMaxSpeedLeftRight() const
     79                { return this->maxSpeedLeftRight_; }
     80            inline float getMaxSpeedUpDown() const
     81                { return this->maxSpeedUpDown_; }
     82
    7483            inline void setAccelerationFront(float acceleration)
    7584                { this->accelerationFront_ = acceleration; }
     
    8291            inline void setAccelerationUpDown(float acceleration)
    8392                { this->accelerationUpDown_ = acceleration; }
     93
     94            inline float getAccelerationFront() const
     95                { return this->accelerationFront_; }
     96            inline float getAccelerationBrake() const
     97                { return this->accelerationBrake_; }
     98            inline float getAccelerationBack() const
     99                { return this->accelerationBack_; }
     100            inline float getAccelerationLeftRight() const
     101                { return this->accelerationLeftRight_; }
     102            inline float getAccelerationUpDown() const
     103                { return this->accelerationUpDown_; }
    84104
    85105            virtual const Vector3& getDirection() const;
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2254 r2256  
    168168            {
    169169                this->client_overwrite_ = this->server_overwrite_;
    170 COUT(0) << "CE: bidirectional synchronization" << std::endl;
    171170                this->setObjectMode(direction::bidirectional);
    172171            }
     
    202201    void ControllableEntity::startLocalHumanControl()
    203202    {
    204 //        std::cout << this->getObjectID() << " ###### start local control" << std::endl;
    205203        this->camera_ = new Camera(this);
    206204        this->camera_->requestFocus();
     
    216214            this->hud_ = new OverlayGroup(this);
    217215            this->hud_->addTemplate(this->hudtemplate_);
     216            this->hud_->setOwner(this);
    218217        }
    219218    }
     
    221220    void ControllableEntity::stopLocalHumanControl()
    222221    {
    223 //        std::cout << "###### stop local control" << std::endl;
    224222        this->camera_->detachFromParent();
    225223        delete this->camera_;
     
    244242            else if (this->bHasLocalController_)
    245243            {
    246 //                COUT(2) << "setting client position" << endl;
    247244                this->client_velocity_ = this->velocity_;
    248245                this->client_position_ = this->node_->getPosition();
     
    254251    {
    255252        REGISTERSTRING(this->cameraPositionTemplate_, direction::toclient);
     253        REGISTERSTRING(this->hudtemplate_, direction::toclient);
    256254
    257255        REGISTERDATA(this->client_overwrite_,   direction::toserver);
     
    304302        if (this->server_overwrite_ == this->client_overwrite_)
    305303        {
    306 //            COUT(2) << "callback: setting client position" << endl;
    307304            this->node_->setPosition(this->client_position_);
    308305            this->server_position_ = this->client_position_;
    309306        }
    310 //        else
    311 //          COUT(2) << "callback: not setting client position" << endl;
    312307    }
    313308
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.h

    r2212 r2256  
    7272            inline void translate(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    7373                { this->translate(Vector3(x, y, z), relativeTo); }
     74
     75            virtual inline const Vector3& getVelocity() const
     76                { return Vector3::ZERO; }
    7477
    7578            virtual void setOrientation(const Quaternion& orientation) = 0;
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2171 r2256  
    6161        this->weaponSystem_->getWeaponSetPointer(0)->getWeaponSlotPointer(0)->setAmmoType(true);
    6262        */
     63
     64        this->setRadarObjectColour(ColourValue::Red);
     65        this->setRadarObjectShape(RadarViewable::Dot);
    6366
    6467        this->registerVariables();
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2098 r2256  
    3333
    3434#include "objects/worldentities/ControllableEntity.h"
     35#include "objects/RadarViewable.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport Pawn : public ControllableEntity
     39    class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable
    3940    {
    4041        public:
     
    7879            virtual void postSpawn();
    7980
     81            inline const WorldEntity* getWorldEntity() const
     82                { return (WorldEntity*)this; }
     83
    8084        protected:
    8185            virtual void spawn();
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2254 r2256  
    229229        }
    230230    }
     231
     232    void SpaceShip::setEngine(Engine* engine)
     233    {
     234        this->engine_ = engine;
     235        if (engine && engine->getShip() != this)
     236            engine->addToSpaceShip(this);
     237    }
    231238}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.h

    r2254 r2256  
    5858            virtual void boost();
    5959
     60            void setEngine(Engine* engine);
     61            inline Engine* getEngine() const
     62                { return this->engine_; }
     63
    6064            void setMaxRotation(const Degree& value)
    6165                { this->maxRotation_ = value; }
  • code/branches/objecthierarchy2/src/orxonox/overlays/OrxonoxOverlay.cc

    r2171 r2256  
    6060    {
    6161        RegisterObject(OrxonoxOverlay);
     62
     63        this->owner_ = 0;
    6264
    6365        if (!Core::showsGraphics())
  • code/branches/objecthierarchy2/src/orxonox/overlays/OrxonoxOverlay.h

    r2087 r2256  
    154154        virtual void changedVisibility();
    155155
     156        inline void setOwner(ControllableEntity* owner)
     157        {
     158            if (this->owner_ != owner)
     159            {
     160                this->owner_ = owner;
     161                this->changedOwner();
     162            }
     163        }
     164        inline ControllableEntity* getOwner() const
     165            { return this->owner_; }
     166        virtual void changedOwner() {}
     167
    156168    protected:
    157169        virtual void angleChanged();
     
    182194            We could also use the ObjectList, but that doesn't guarantee XMLPort(.) was called and is slower. */
    183195        static std::map<std::string, OrxonoxOverlay*> overlays_s;
     196        ControllableEntity* owner_;
    184197  };
     198
     199  SUPER_FUNCTION(7, OrxonoxOverlay, changedOwner, false);
    185200}
    186201
  • code/branches/objecthierarchy2/src/orxonox/overlays/OverlayGroup.cc

    r2087 r2256  
    5555        RegisterObject(OverlayGroup);
    5656
     57        this->owner_ = 0;
     58
    5759        setScale(Vector2(1.0, 1.0));
    5860        setScroll(Vector2(0.0, 0.0));
     
    113115            hudElements_[element->getName()] = element;
    114116            element->setVisible(this->isVisible());
     117            if (this->owner_)
     118                element->setOwner(this->owner_);
    115119        }
    116120    }
     
    137141    }
    138142
     143    void OverlayGroup::setOwner(ControllableEntity* owner)
     144    {
     145        this->owner_ = owner;
     146
     147        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     148            (*it).second->setOwner(owner);
     149    }
    139150
    140151    //########### Console commands ############
  • code/branches/objecthierarchy2/src/orxonox/overlays/OverlayGroup.h

    r2087 r2256  
    6969        void changedVisibility();
    7070
     71        void setOwner(ControllableEntity* owner);
     72        inline ControllableEntity* getOwner() const
     73            { return this->owner_; }
     74
    7175    private:
    7276        //! Scales each OrxonoxOverlay individually by scale.
     
    8892        Vector2 scale_;                                         //!< Current scale (independant of the elements).
    8993        Vector2 scroll_;                                        //!< Current scrolling offset.
     94        ControllableEntity* owner_;                             //!< The owner of this OverlayGroup
    9095    };
    9196}
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDRadar.cc

    r2087 r2256  
    4040#include "core/XMLPort.h"
    4141#include "objects/Radar.h"
     42#include "objects/worldentities/WorldEntity.h"
     43#include "objects/worldentities/pawns/Pawn.h"
    4244#include "tools/TextureGenerator.h"
    4345
     
    5153        RegisterObject(HUDRadar);
    5254
    53         marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
     55        this->marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    5456            .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();
    5860
    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);
    6264
    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;
    6670    }
    6771
     
    9094    void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked)
    9195    {
    92 /*
     96        if (object == (RadarViewable*)this->owner_)
     97            return;
     98
    9399        const WorldEntity* wePointer = object->getWorldEntity();
    94100
    95101        // Just to be sure that we actually have a WorldEntity.
    96102        // We could do a dynamic_cast, but that would be a lot slower.
    97         if (!wePointer)
     103        if (!wePointer || !this->owner_)
    98104        {
    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;
    100109            return;
    101110        }
    102 */
     111
    103112        // try to find a panel already created
    104113        Ogre::PanelOverlayElement* panel;
     
    112121            // get right material
    113122            panel->setMaterialName(TextureGenerator::getMaterialName(
    114                 shapeMaterials_[object->getRadarObjectType()], object->getRadarObjectColour()));
     123                shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour()));
    115124            this->overlay_->add2D(panel);
    116125            this->itRadarDots_ = this->radarDots_.end();
     
    121130            ++itRadarDots_;
    122131            std::string materialName = TextureGenerator::getMaterialName(
    123                 shapeMaterials_[object->getRadarObjectType()], object->getRadarObjectColour());
     132                shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour());
    124133            if (materialName != panel->getMaterialName())
    125134                panel->setMaterialName(materialName);
    126135        }
    127136        panel->show();
    128 /*
     137
    129138        // set size to fit distance...
    130         float distance = (wePointer->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length();
     139        float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length();
    131140        // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda)
    132141        float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance);
     
    134143
    135144        // 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());
    137146        coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture
    138147        panel->setPosition((1.0 + coord.x - size) * 0.5, (1.0 - coord.y - size) * 0.5);
     
    144153            this->marker_->setPosition((1.0 + coord.x - size * 1.5) * 0.5, (1.0 - coord.y - size * 1.5) * 0.5);
    145154        }
    146 */
    147155    }
    148156
     
    154162        this->marker_->hide();
    155163    }
     164
     165    void HUDRadar::changedOwner()
     166    {
     167        SUPER(HUDRadar, changedOwner);
     168
     169        this->owner_ = dynamic_cast<Pawn*>(this->getOwner());
     170    }
    156171}
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDRadar.h

    r2087 r2256  
    4949
    5050        virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
     51        virtual void changedOwner();
    5152
    5253    private:
     
    7677
    7778        float sensitivity_;
     79
     80        Pawn* owner_;
    7881    };
    7982}
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDSpeedBar.cc

    r2087 r2256  
    3131#include "HUDSpeedBar.h"
    3232#include "core/CoreIncludes.h"
     33#include "objects/worldentities/pawns/SpaceShip.h"
     34#include "objects/items/Engine.h"
    3335
    3436namespace orxonox
     
    4143        RegisterObject(HUDSpeedBar);
    4244
     45        this->owner_ = 0;
    4346    }
    4447
     
    4952    void HUDSpeedBar::tick(float dt)
    5053    {
    51 /*
    52         SpaceShip* ship = SpaceShip::getLocalShip();
    53         if (ship)
     54        if (this->owner_ && this->owner_->getEngine())
    5455        {
    55             float v = ship->getVelocity().length();
    56             float value = v / ship->getMaxSpeed();
     56            float v = this->owner_->getVelocity().length();
     57            float value = v / (this->owner_->getEngine()->getMaxSpeedFront() * this->owner_->getEngine()->getSpeedFactor() * this->owner_->getEngine()->getBoostFactor());
    5758            if (value != this->getValue())
    5859                this->setValue(value);
    5960        }
    60 */
     61    }
     62
     63    void HUDSpeedBar::changedOwner()
     64    {
     65        SUPER(HUDSpeedBar, changedOwner);
     66
     67        this->owner_ = dynamic_cast<SpaceShip*>(this->getOwner());
    6168    }
    6269}
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDSpeedBar.h

    r2087 r2256  
    4545
    4646        virtual void tick(float dt);
     47        virtual void changedOwner();
     48
     49    private:
     50        SpaceShip* owner_;
    4751    };
    4852}
Note: See TracChangeset for help on using the changeset viewer.