Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 20, 2009, 8:15:25 PM (15 years ago)
Author:
scheusso
Message:

merged steering branch to presentation2 branch

Location:
code/branches/presentation2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2

  • code/branches/presentation2/src/orxonox/weaponsystem/WeaponMode.cc

    r5929 r6108  
    3232#include "core/CoreIncludes.h"
    3333#include "core/XMLPort.h"
     34#include "controllers/Controller.h"
     35#include "worldentities/pawns/Pawn.h"
    3436
    3537#include "Munition.h"
     
    194196    }
    195197
    196     Vector3 WeaponMode::getMuzzlePosition() const
     198    void WeaponMode::computeMuzzleParameters()
    197199    {
    198200        if (this->weapon_)
    199             return (this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_);
    200         else
    201             return this->muzzleOffset_;
    202     }
    203 
    204     const Quaternion& WeaponMode::getMuzzleOrientation() const
     201        {
     202            this->muzzlePosition_ = this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_;
     203
     204            Controller* controller = this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getController();
     205            if (controller->canFindTarget())
     206            {
     207                Vector3 muzzleDirection(controller->getTarget() - this->muzzlePosition_);
     208                this->muzzleOrientation_ = (this->weapon_->getWorldOrientation() * WorldEntity::FRONT).getRotationTo(muzzleDirection) * this->weapon_->getWorldOrientation();
     209            }
     210            else
     211                this->muzzleOrientation_ = this->weapon_->getWorldOrientation();
     212        }
     213        else
     214        {
     215            this->muzzlePosition_ = this->muzzleOffset_;
     216            this->muzzleOrientation_ = Quaternion::IDENTITY;
     217        }
     218    }
     219
     220    Vector3 WeaponMode::getMuzzleDirection() const
    205221    {
    206222        if (this->weapon_)
    207             return this->weapon_->getWorldOrientation();
    208         else
    209             return Quaternion::IDENTITY;
    210     }
    211 
    212     Vector3 WeaponMode::getMuzzleDirection() const
    213     {
    214         if (this->weapon_)
    215             return (this->weapon_->getWorldOrientation() * WorldEntity::FRONT);
     223            return (this->getMuzzleOrientation() * WorldEntity::FRONT);
    216224        else
    217225            return WorldEntity::FRONT;
  • code/branches/presentation2/src/orxonox/weaponsystem/WeaponMode.h

    r5929 r6108  
    109109                { return this->muzzleOffset_; }
    110110
    111             Vector3 getMuzzlePosition() const;
    112             const Quaternion& getMuzzleOrientation() const;
     111            void computeMuzzleParameters();
     112            const Vector3& getMuzzlePosition() const
     113                { return this->muzzlePosition_; }
     114            const Quaternion& getMuzzleOrientation() const
     115                { return this->muzzleOrientation_; }
    113116            Vector3 getMuzzleDirection() const;
    114117
     
    124127            inline unsigned int getMode() const
    125128                { return this->mode_; }
     129
     130            Vector3 getTarget();
    126131
    127132        protected:
     
    152157            Timer reloadTimer_;
    153158            bool bReloading_;
     159
     160            Vector3 muzzlePosition_;
     161            Quaternion muzzleOrientation_;
    154162    };
    155163}
Note: See TracChangeset for help on using the changeset viewer.