Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6111


Ignore:
Timestamp:
Nov 21, 2009, 12:33:37 AM (15 years ago)
Author:
scheusso
Message:

made some changes in NewHumanController, Pawn, CE, Controller and WeaponMode preparing the synchronisation of clients target and aimPosition

Location:
code/branches/presentation2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2

  • code/branches/presentation2/src/orxonox/controllers/Controller.h

    r6108 r6111  
    5454            virtual void changedControllableEntity() {}
    5555
    56             virtual bool canFindTarget()
    57                 { return false; }
    58             virtual Vector3 getTarget()
    59                 { return Vector3::ZERO; }
    60 
    6156        protected:
    6257            // don't use this directly, use getPlayer()->startControl(entity) (unless you know exactly what you do)
  • code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc

    r6108 r6111  
    3737#include "core/ConsoleCommand.h"
    3838#include "worldentities/ControllableEntity.h"
     39#include "worldentities/pawns/Pawn.h"
    3940#include "infos/PlayerInfo.h"
    4041#include "overlays/OrxonoxOverlay.h"
     
    8081    void NewHumanController::tick(float dt)
    8182    {
    82         crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2));
     83        if( !this->controllableEntity_->isInMouseLook() )
     84        {
     85            this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2));
     86            this->crossHairOverlay_->show();
     87        }
     88        else
     89            this->crossHairOverlay_->hide();
     90        // TODO: update aimPosition of Pawn
    8391
    8492        HumanController::tick(dt);
     
    117125        }
    118126*/
     127        if( !NewHumanController::localController_s->getControllableEntity()->isInMouseLook() )
     128            this->updateTarget();
    119129
    120130        HumanController::localController_s->getControllableEntity()->fire(firemode);
    121131    }
    122132
    123     Vector3 NewHumanController::getTarget()
     133    void NewHumanController::updateTarget()
    124134    {
    125135        Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
     
    140150
    141151        Ogre::RaySceneQueryResult& result = rsq->execute();
     152        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
    142153
    143154        Ogre::RaySceneQueryResult::iterator itr;
     
    154165                        continue;
    155166                }
     167               
     168                this->getControllableEntity()->setTarget(wePtr);
    156169
    157170                itr->movable->getParentSceneNode()->showBoundingBox(true);
    158171                //std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;
    159                 return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition()
     172                //return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition()
     173                if ( pawn )
     174                {
     175                    pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance ); // or itr->movable->getParentSceneNode()->_getDerivedPosition()
     176                    pawn->setTarget( wePtr );
     177                }
     178                return;
    160179            }
    161180
    162181        }
    163 
    164         return mouseRay.getOrigin() + mouseRay.getDirection() * 1200;
     182        if ( pawn )
     183        {
     184            pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 1200 );
     185            pawn->setTarget( 0 );
     186        }
     187
     188    //return mouseRay.getOrigin() + mouseRay.getDirection() * 1200;
     189   
    165190
    166191        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000);
     
    189214
    190215    void NewHumanController::changeMode() {
    191         if (NewHumanController::localController_s->controlMode_ == 0)
    192             NewHumanController::localController_s->controlMode_ = 1;
     216        if (NewHumanController::localController_s && NewHumanController::localController_s->controlMode_ == 0)
     217        {
     218            if (NewHumanController::localController_s->controllableEntity_ && !NewHumanController::localController_s->controllableEntity_->isInMouseLook() )
     219                NewHumanController::localController_s->controlMode_ = 1;
     220        }
    193221        else
    194222            NewHumanController::localController_s->controlMode_ = 0;
  • code/branches/presentation2/src/orxonox/controllers/NewHumanController.h

    r6108 r6111  
    5252            static void changeMode();
    5353
    54             virtual bool canFindTarget() { return true; }
    55             virtual Vector3 getTarget();
    56 
    5754        protected:
     55            void updateTarget();
     56           
    5857            unsigned int                controlMode_;
    5958            static NewHumanController* localController_s;
  • code/branches/presentation2/src/orxonox/weaponsystem/WeaponMode.cc

    r6108 r6111  
    202202            this->muzzlePosition_ = this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_;
    203203
    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();
     204            Pawn* pawn = this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn();
     205            Vector3 muzzleDirection;
     206            if ( pawn->getTarget() )
     207            {
     208                muzzleDirection = pawn->getTarget()->getWorldPosition() - this->muzzlePosition_;
    209209            }
    210210            else
    211                 this->muzzleOrientation_ = this->weapon_->getWorldOrientation();
     211                muzzleDirection = pawn->getAimPosition() - this->muzzlePosition_;
     212//             COUT(0) << "muzzleDirection " << muzzleDirection << endl;
     213                //this->muzzleOrientation_ = this->weapon_->getWorldOrientation();
     214            this->muzzleOrientation_ = (this->weapon_->getWorldOrientation() * WorldEntity::FRONT).getRotationTo(muzzleDirection) * this->weapon_->getWorldOrientation();
    212215        }
    213216        else
  • code/branches/presentation2/src/orxonox/worldentities/ControllableEntity.h

    r6108 r6111  
    145145            inline void setController(Controller* val)
    146146                { this->controller_ = val; }
     147           
     148            virtual void setTarget( WorldEntity* target )
     149                { this->target_ = target; }
     150            virtual WorldEntity* getTarget()
     151                { return this->target_.get(); }
    147152
    148153        protected:
     
    209214            Controller* controller_;
    210215            CameraPosition* reverseCamera_;
     216            WeakPtr<WorldEntity> target_;
    211217    };
    212218}
  • code/branches/presentation2/src/orxonox/worldentities/pawns/Pawn.cc

    r6107 r6111  
    6767
    6868        this->spawnparticleduration_ = 3.0f;
     69       
     70        this->aimPosition_ = Vector3::ZERO;
    6971
    7072        this->getPickups().setOwner(this);
  • code/branches/presentation2/src/orxonox/worldentities/pawns/Pawn.h

    r6107 r6111  
    116116
    117117            virtual void startLocalHumanControl();
     118           
     119            void setAimPosition( Vector3 position )
     120                { this->aimPosition_ = position; }
     121            Vector3 getAimPosition()
     122                { return this->aimPosition_; }
    118123
    119124        protected:
     
    146151            inline void setWeaponSystem(WeaponSystem* weaponsystem)
    147152                { this->weaponSystem_ = weaponsystem; }
     153           
     154            Vector3 aimPosition_;
    148155    };
    149156}
Note: See TracChangeset for help on using the changeset viewer.