Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 13, 2009, 11:21:40 AM (15 years ago)
Author:
rgrieder
Message:

Resolved projectile targeting problem by introducing a ClassTreeMask. It's a bit hacky but currently I don't see another quick way.
There is a problem though: The weapons aim into other directions while rolling the space ship…
I just couldn't figure it out.

Location:
code/branches/steering/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/steering/src/modules/weapons/weaponmodes/HsW01.cc

    r6045 r6055  
    111111        model->setScale(5);
    112112
    113         //projectile->setOrientation(this->getMuzzleOrientation());
    114         projectile->lookAt(this->getTarget(), WorldEntity::World);
     113        this->computeMuzzleParameters();
     114        projectile->setOrientation(this->getMuzzleOrientation());
    115115        projectile->setPosition(this->getMuzzlePosition());
    116         projectile->setVelocity((projectile->getOrientation() * Vector3::UNIT_Z) * this->speed_); //getWorldOrientation??
    117         //projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
     116        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
    118117
    119118        projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
  • code/branches/steering/src/orxonox/controllers/Controller.cc

    r6045 r6055  
    4646    {
    4747    }
    48 
    49     Vector3 Controller::getTarget() {
    50         return this->controllableEntity_->getPosition() + (this->controllableEntity_->getOrientation() * Vector3::UNIT_Z);
    51     }
    5248}
  • code/branches/steering/src/orxonox/controllers/Controller.h

    r6045 r6055  
    5858            virtual void changedControllableEntity() {}
    5959
    60             virtual Vector3 getTarget();
     60            virtual bool canFindTarget()
     61                { return false; }
     62            virtual Vector3 getTarget()
     63                { return Vector3::ZERO; }
    6164
    6265        protected:
  • code/branches/steering/src/orxonox/controllers/NewHumanController.cc

    r6045 r6055  
    3737#include "core/ConsoleCommand.h"
    3838#include "worldentities/ControllableEntity.h"
    39 #include "worldentities/pawns/Pawn.h"
    40 #include "gametypes/Gametype.h"
    4139#include "infos/PlayerInfo.h"
    42 #include "overlays/Map.h"
     40#include "overlays/OrxonoxOverlay.h"
    4341#include "graphics/Camera.h"
    4442#include "sound/SoundManager.h"
    45 #include "Radar.h"
    4643#include "Scene.h"
    4744
    4845namespace orxonox
    4946{
    50 
    5147    CreateUnloadableFactory(NewHumanController);
    5248
     
    5551        RegisterObject(NewHumanController);
    5652
    57         overlaySize = 0.08;
     53        overlaySize_ = 0.08;
     54        controlMode_ = 0;
    5855
    59         controlMode = 0;
     56        crossHairOverlay_ = new OrxonoxOverlay(this);
     57        crossHairOverlay_->setBackgroundMaterial("Orxonox/Crosshair3");
     58        crossHairOverlay_->setSize(Vector2(overlaySize_, overlaySize_));
     59        crossHairOverlay_->show();
    6060
    61         CrossHairOverlay = new OrxonoxOverlay(this);
    62         CrossHairOverlay->setBackgroundMaterial("Orxonox/Crosshair3");
    63         CrossHairOverlay->setSize(Vector2(overlaySize,overlaySize));
    64         CrossHairOverlay->show();
     61        // HACK: Define which objects are targettable when considering the creator of an orxonox::Model
     62        this->targetMask_.exclude(ClassByString("BaseObject"));
     63        this->targetMask_.include(ClassByString("WorldEntity"));
     64        this->targetMask_.exclude(ClassByString("Projectile"));
    6565    }
    6666
    6767    NewHumanController::~NewHumanController()
    6868    {
    69         if( this->isInitialized() )
     69        if (this->isInitialized())
    7070        {
    7171        }
    7272    }
    7373
    74     void NewHumanController::tick(float dt) {
    75         CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize/2));
     74    void NewHumanController::tick(float dt)
     75    {
     76        crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2));
    7677
    7778        HumanController::tick(dt);
     
    99100
    100101/*
    101 
    102  // Get results, create a node/entity on the position
    103  for ( itr = result.begin(); itr != result.end(); itr++ )
    104  {
    105      if (itr->movable && itr->movable->getName() == "Head")
    106      {
    107          soundMgr->StopSound( &jaguarSoundChannel );
    108          soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
    109          break;
    110      } // if
    111  }
     102        // Get results, create a node/entity on the position
     103        for ( itr = result.begin(); itr != result.end(); itr++ )
     104        {
     105            if (itr->movable && itr->movable->getName() == "Head")
     106            {
     107                soundMgr->StopSound( &jaguarSoundChannel );
     108                soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
     109                break;
     110            } // if
     111        }
    112112*/
    113113
    114             HumanController::localController_s->getControllableEntity()->fire(firemode);
    115         //}
    116 //}
     114        HumanController::localController_s->getControllableEntity()->fire(firemode);
    117115    }
    118116
    119     Vector3 NewHumanController::getTarget() {
    120             Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
     117    Vector3 NewHumanController::getTarget()
     118    {
     119        Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
    121120
    122 //std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << "  Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;
     121        //std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << "  Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;
    123122
    124             Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5);
     123        Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5);
    125124
    126             rsq->setRay(mouseRay);
    127             rsq->setSortByDistance(true);
     125        rsq->setRay(mouseRay);
     126        rsq->setSortByDistance(true);
    128127
    129 /*
    130 Distance of objects:
    131 ignore everything under 200 maybe even take 1000 as min distance to shoot at
     128        /*
     129        Distance of objects:
     130        ignore everything under 200 maybe even take 1000 as min distance to shoot at
    132131
    133 shots are regularly traced and are entities!!!!!!!!! this is the biggest problem
    134 they vanish only after a distance of 10'000
    135 */
     132        shots are regularly traced and are entities!!!!!!!!! this is the biggest problem
     133        they vanish only after a distance of 10'000
     134        */
    136135
    137136
    138             Ogre::RaySceneQueryResult &result = rsq->execute();
     137        Ogre::RaySceneQueryResult& result = rsq->execute();
    139138
    140             Ogre::RaySceneQueryResult::iterator itr;
    141             for ( itr = result.begin(); itr != result.end(); itr++ )
     139        Ogre::RaySceneQueryResult::iterator itr;
     140        for (itr = result.begin(); itr != result.end(); ++itr)
     141        {
     142            //std::cout << "distance: " << itr->distance << "  name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType();
     143            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500)
    142144            {
    143                 //std::cout << "distance: " << itr->distance << "  name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType();
    144                 if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) {
    145                     //std::cout << "  TAGGED";
    146                     itr->movable->getParentSceneNode()->showBoundingBox(true);
    147 std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;
    148 return itr->movable->getParentSceneNode()->_getDerivedPosition();
     145                // Try to cast the user pointer
     146                WorldEntity* wePtr = dynamic_cast<WorldEntity*>(itr->movable->getUserObject());
     147                if (wePtr)
     148                {
     149                    BaseObject* creator = wePtr->getCreator();
     150                    if (this->targetMask_.isExcluded(creator->getIdentifier()))
     151                        continue;
    149152                }
    150                 //std::cout << endl;
     153                //std::cout << "  TAGGED";
     154                itr->movable->getParentSceneNode()->showBoundingBox(true);
     155                std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;
     156                return itr->movable->getParentSceneNode()->_getDerivedPosition();
    151157            }
     158            //std::cout << endl;
     159        }
    152160
    153 //if (result.front().movable->isInScene()) std::cout << "in scene" << endl;
    154 // && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);
    155 //result.front().movable->setVisible(false);
     161        //if (result.front().movable->isInScene()) std::cout << "in scene" << endl;
     162        // && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);
     163        //result.front().movable->setVisible(false);
    156164
    157             //std::cout << endl;
     165        //std::cout << endl;
    158166/*
    159             if (!result.empty()) {
    160                 Ogre::RaySceneQueryResultEntry obj = result.front();
    161                 std::cout << "distance: " << obj.distance << "  name: " << obj.movable->getName() << endl;
    162             }
     167        if (!result.empty()) {
     168            Ogre::RaySceneQueryResultEntry obj = result.front();
     169            std::cout << "distance: " << obj.distance << "  name: " << obj.movable->getName() << endl;
     170        }
    163171*/
    164         return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z);
    165 //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z);
     172        return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 100);
     173        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z);
    166174    }
    167175
     
    174182        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
    175183    }
     184
    176185    void NewHumanController::pitch(const Vector2& value)
    177186    {
     
    182191        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
    183192    }
    184 
    185193}
  • code/branches/steering/src/orxonox/controllers/NewHumanController.h

    r6045 r6055  
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include "core/ClassTreeMask.h"
    3435#include "HumanController.h"
    35 #include "overlays/OrxonoxOverlay.h"
    36 #include "util/OgreForwardRefs.h"
    3736
    3837namespace orxonox
     
    5352            void changeMode(unsigned int controleMode);
    5453
     54            virtual bool canFindTarget() { return true; }
    5555            virtual Vector3 getTarget();
    5656
     
    5858            float                       currentYaw_;
    5959            float                       currentPitch_;
    60             OrxonoxOverlay              *CrossHairOverlay;
    61             float                       overlaySize;
    62             unsigned int                controlMode;
     60            OrxonoxOverlay*             crossHairOverlay_;
     61            float                                   overlaySize_;
     62            unsigned int                controlMode_;
     63            ClassTreeMask               targetMask_;
    6364    };
    6465}
  • code/branches/steering/src/orxonox/infos/PlayerInfo.cc

    r6045 r6055  
    138138        assert(this->controller_);
    139139        this->controller_->setPlayer(this);
    140         if (this->controllableEntity_) {
     140        if (this->controllableEntity_)
     141        {
    141142            this->controller_->setControllableEntity(this->controllableEntity_);
    142143            this->controllableEntity_->setController(this->controller_);
     
    160161        this->bReadyToSpawn_ &= (!this->bSetUnreadyAfterSpawn_);
    161162
    162         if (this->controller_) {
     163        if (this->controller_)
     164        {
    163165            this->controller_->setControllableEntity(entity);
    164166            this->controllableEntity_->setController(this->controller_);
  • code/branches/steering/src/orxonox/weaponsystem/WeaponMode.cc

    r5929 r6055  
    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() * (this->weapon_->getWorldOrientation() * WorldEntity::FRONT).getRotationTo(muzzleDirection);
     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/steering/src/orxonox/weaponsystem/WeaponMode.h

    r6045 r6055  
    3838#include "core/SubclassIdentifier.h"
    3939#include "tools/Timer.h"
    40 
    41 #include "weaponsystem/Weapon.h"
    42 #include "weaponsystem/WeaponPack.h"
    43 #include "weaponsystem/WeaponSystem.h"
    44 #include "worldentities/pawns/Pawn.h"
    45 #include "controllers/Controller.h"
    4640
    4741namespace orxonox
     
    115109                { return this->muzzleOffset_; }
    116110
    117             Vector3 getMuzzlePosition() const;
    118             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_; }
    119116            Vector3 getMuzzleDirection() const;
    120117
     
    131128                { return this->mode_; }
    132129
    133             inline Vector3 getTarget()
    134                 { return this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getController()->getTarget(); }
     130            Vector3 getTarget();
    135131
    136132        protected:
     
    161157            Timer reloadTimer_;
    162158            bool bReloading_;
     159
     160            Vector3 muzzlePosition_;
     161            Quaternion muzzleOrientation_;
    163162    };
    164163}
  • code/branches/steering/src/orxonox/worldentities/ControllableEntity.h

    r6045 r6055  
    142142            inline Controller* getController() const
    143143                { return this->controller_; }
    144             inline void setController(Controller* c)
    145                 { this->controller_ = c; }
     144            inline void setController(Controller* val)
     145                { this->controller_ = val; }
    146146
    147147        protected:
  • code/branches/steering/src/orxonox/worldentities/WorldEntity.cc

    r6052 r6055  
    654654    /**
    655655    @brief
    656         Makes this WorldEntity look a specific target location.
     656        Makes this WorldEntity look at a specific target location.
    657657    @param relativeTo
    658658        @see WorldEntity::TransformSpace
Note: See TracChangeset for help on using the changeset viewer.