Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

The SpaceShips HUD is working again (Speedbar and Radar)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.