Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6310


Ignore:
Timestamp:
Dec 9, 2009, 10:58:26 PM (14 years ago)
Author:
wirthmi
Message:

Added damage overlays

Location:
code/branches/presentation2/src/orxonox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc

    r6295 r6310  
    6767        overlaySize_ = 0.08;
    6868        arrowsSize_ = 0.4;
     69
     70        damageOverlayTime_ = 0.6;
     71
    6972        controlMode_ = 0;
    7073        acceleration_ = 0;
    7174        accelerating_ = false;
    7275        firemode_ = -1;
     76
    7377        showArrows_ = true;
    7478        showOverlays_ = false;
     79        showDamageOverlay_ = true;
    7580
    7681        //currentPitch_ = 1;
     
    9196            centerOverlay_->hide();
    9297
    93             if (showArrows_)
     98            if ( showDamageOverlay_ )
     99            {
     100                damageOverlayTop_ = new OrxonoxOverlay(this);
     101                damageOverlayTop_->setBackgroundMaterial("Orxonox/DamageOverlayTop");
     102                damageOverlayTop_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
     103                damageOverlayTop_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     104                damageOverlayTop_->hide();
     105
     106                damageOverlayRight_ = new OrxonoxOverlay(this);
     107                damageOverlayRight_->setBackgroundMaterial("Orxonox/DamageOverlayRight");
     108                damageOverlayRight_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
     109                damageOverlayRight_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     110                damageOverlayRight_->hide();
     111
     112                damageOverlayBottom_ = new OrxonoxOverlay(this);
     113                damageOverlayBottom_->setBackgroundMaterial("Orxonox/DamageOverlayBottom");
     114                damageOverlayBottom_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
     115                damageOverlayBottom_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     116                damageOverlayBottom_->hide();
     117
     118                damageOverlayLeft_ = new OrxonoxOverlay(this);
     119                damageOverlayLeft_->setBackgroundMaterial("Orxonox/DamageOverlayLeft");
     120                damageOverlayLeft_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
     121                damageOverlayLeft_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     122                damageOverlayLeft_->hide();
     123            }
     124
     125            if ( showArrows_ )
    94126            {
    95127                arrowsOverlay1_ = new OrxonoxOverlay(this);
     
    168200
    169201                if ( !controlPaused_ ) {
    170                     if (this->getControllableEntity() && this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip")
     202                    if (this->getControllableEntity() && (this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip" || this->getControllableEntity()->getIdentifier()->getName() == "Rocket"))
    171203                        this->showOverlays();
    172204
     
    180212                    else
    181213                        hideArrows();
     214
     215                    if ( this->showDamageOverlay_ && ( this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0 ) ) {
     216                        this->damageOverlayTT_ -= dt;
     217                        this->damageOverlayTR_ -= dt;
     218                        this->damageOverlayTB_ -= dt;
     219                        this->damageOverlayTL_ -= dt;
     220                        if ( this->damageOverlayTT_ <= 0 )
     221                            this->damageOverlayTop_->hide();
     222                        if ( this->damageOverlayTR_ <= 0 )
     223                            this->damageOverlayRight_->hide();
     224                        if ( this->damageOverlayTB_ <= 0 )
     225                            this->damageOverlayBottom_->hide();
     226                        if ( this->damageOverlayTL_ <= 0 )
     227                            this->damageOverlayLeft_->hide();
     228                    }
    182229                }
    183230            }
     
    251298
    252299    void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) {
    253         Vector3 posA = multi_cast<Vector3>(contactpoint.getPositionWorldOnA());
    254         //Vector3 posB = multi_cast<Vector3>(contactpoint.getPositionWorldOnB());
    255         //posA and posB are almost identical
    256 
    257         Vector3 relativeHit = this->getControllableEntity()->getWorldOrientation() * (posA - this->getControllableEntity()->getPosition());
    258 
    259         COUT(0) << relativeHit << endl;
    260         //COUT(0) << "Damage: " << damage << " Point A: " << posA << " Point B: " << posB << endl;
     300        if ( showDamageOverlay_ ) {
     301            Vector3 posA;
     302            if ( originator )
     303                posA = originator->getWorldPosition();
     304            else
     305                posA = multi_cast<Vector3>(contactpoint.getPositionWorldOnA());
     306            //Vector3 posB = multi_cast<Vector3>(contactpoint.getPositionWorldOnB());
     307            //posA and posB are almost identical
     308
     309            Vector3 relativeHit = this->getControllableEntity()->getWorldOrientation().UnitInverse() * (this->getControllableEntity()->getWorldPosition() - posA);
     310
     311            //back is z positive
     312            //x is left positive
     313            //y is down positive
     314            relativeHit.normalise();
     315            COUT(0) << relativeHit << endl;
     316
     317            float threshold = 0.3;
     318            // && abs(relativeHit.y) < 0.5
     319            if ( relativeHit.x > threshold) // Left
     320            {
     321                this->damageOverlayLeft_->show();
     322                this->damageOverlayTL_ = this->damageOverlayTime_;
     323                //this->damageOverlayLeft_->setBackgroundAlpha(0.3);
     324            }
     325            if ( relativeHit.x < -threshold) //Right
     326            {
     327                this->damageOverlayRight_->show();
     328                this->damageOverlayTR_ = this->damageOverlayTime_;
     329                //this->damageOverlayRight_->setBackgroundAlpha(0.3);
     330            }
     331            if ( relativeHit.y > threshold) //Top
     332            {
     333                this->damageOverlayTop_->show();
     334                this->damageOverlayTT_ = this->damageOverlayTime_;
     335                //this->damageOverlayTop_->setBackgroundAlpha(0.3);
     336            }
     337            if ( relativeHit.y < -threshold) //Bottom
     338            {
     339                this->damageOverlayBottom_->show();
     340                this->damageOverlayTB_ = this->damageOverlayTime_;
     341                //this->damageOverlayBottom_->setBackgroundAlpha(0.3);
     342            }
     343
     344        }
    261345    }
    262346
     
    485569        this->centerOverlay_->hide();
    486570
     571        if ( showDamageOverlay_ ) {
     572            this->damageOverlayTop_->hide();
     573            this->damageOverlayRight_->hide();
     574            this->damageOverlayBottom_->hide();
     575            this->damageOverlayLeft_->hide();
     576        }
     577
    487578        this->hideArrows();
    488579    }
  • code/branches/presentation2/src/orxonox/controllers/NewHumanController.h

    r6295 r6310  
    8181            OrxonoxOverlay*             crossHairOverlay_;
    8282            OrxonoxOverlay*             centerOverlay_;
     83
     84            OrxonoxOverlay*             damageOverlayTop_;
     85            OrxonoxOverlay*             damageOverlayRight_;
     86            OrxonoxOverlay*             damageOverlayBottom_;
     87            OrxonoxOverlay*             damageOverlayLeft_;
     88            float                       damageOverlayTime_;
     89            float                       damageOverlayTT_;
     90            float                       damageOverlayTR_;
     91            float                       damageOverlayTB_;
     92            float                       damageOverlayTL_;
     93
    8394            OrxonoxOverlay*             arrowsOverlay1_;
    8495            OrxonoxOverlay*             arrowsOverlay2_;
    8596            OrxonoxOverlay*             arrowsOverlay3_;
    8697            OrxonoxOverlay*             arrowsOverlay4_;
     98
    8799            float                       overlaySize_;
    88100            float                       arrowsSize_;
     
    91103            int                         firemode_;
    92104            bool                        showArrows_;
     105            bool                        showDamageOverlay_;
    93106            bool                        showOverlays_;
    94107            ClassTreeMask               targetMask_;
  • code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.cc

    r6218 r6310  
    3939#include <OgrePanelOverlayElement.h>
    4040#include <OgreRenderWindow.h>
     41#include <OgreMaterialManager.h>
     42#include <OgreTechnique.h>
     43#include <OgrePass.h>
    4144
    4245#include "util/Convert.h"
     
    370373        }
    371374    }
     375
     376    void OrxonoxOverlay::setBackgroundAlpha(float alpha) {
     377        Ogre::MaterialPtr ptr = this->background_->getMaterial();
     378        Ogre::TextureUnitState* tempTx = ptr->getTechnique(0)->getPass(0)->getTextureUnitState(0);
     379        tempTx->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, alpha);
     380    }
    372381}
  • code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.h

    r6108 r6310  
    158158        const std::string& getBackgroundMaterial() const;
    159159
     160        void setBackgroundAlpha(float alpha);
     161
    160162        virtual void changedVisibility();
    161163
     
    205207        BaseObject* owner_;
    206208        OverlayGroup* group_;
     209        Ogre::Pass* backgroundAlphaPass_;
    207210  };
    208211
Note: See TracChangeset for help on using the changeset viewer.