Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 13, 2009, 11:21:40 AM (14 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.

File:
1 edited

Legend:

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