Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 31, 2010, 3:40:41 PM (14 years ago)
Author:
freicy
Message:

by Cyrill Frei

Location:
code/branches/fps/src/orxonox/worldentities/pawns
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/fps/src/orxonox/worldentities/pawns/FpsPlayer.cc

    r6908 r7052  
    3333#include <LinearMath/btVector3.h>
    3434#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
    35 
     35#include <OgreSceneManager.h>
     36#include <OgreSceneNode.h>
     37#include <OgreEntity.h>
    3638
    3739#include "core/CoreIncludes.h"
     
    4042#include "core/XMLPort.h"
    4143#include "items/Engine.h"
     44#include "Scene.h"
     45#include "weaponsystem/WeaponPack.h"
     46#include "weaponsystem/WeaponSlot.h"
     47#include "weaponsystem/Weapon.h"
    4248
    4349#include <cmath>
     
    8086        this->registerVariables();
    8187
     88        this->weaponNode = this->cameraPositionRootNode_;
     89        //this->weaponNode = this->getScene()->getRootSceneNode()->createChildSceneNode();
     90        //this->weaponNode = this->cameraPositionRootNode_->createChildSceneNode();
     91        this->attachNode(this->weaponNode);
    8292    }
    8393
    8494    FpsPlayer::~FpsPlayer()
    8595    {
     96        if (this->isInitialized() && this->mesh_.getEntity())
     97            this->detachOgreObject(this->mesh_.getEntity());
    8698    }
    8799
     
    93105        XMLPortParamVariable(FpsPlayer, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
    94106        XMLPortParamVariable(FpsPlayer, "rotationThrust", rotationThrust_, xmlelement, mode);
     107        XMLPortParam(FpsPlayer, "weapon", setMeshSource, getMeshSource, xmlelement, mode);
    95108    }
    96109
     
    100113        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
    101114        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
    102     }
     115        registerVariable(this->weaponmashname);
     116    }
     117   
     118   
    103119
    104120    void FpsPlayer::setConfigValues()
     
    145161            if (!this->isInMouseLook())
    146162            {
    147                 this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()),WorldEntity::Parent);
    148                 //this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     163                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()), WorldEntity::Parent);
     164               
    149165                Radian pitch=this->cameraPositionRootNode_->getOrientation().getPitch();
    150                 if( pitch<Radian(1.5707) && pitch>Radian(-1.5707) ) this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     166                if( pitch<Radian(1.5707) && pitch>Radian(-1.5707) ) {
     167                        //this->weaponNode->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     168                        this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     169                        }
    151170                else if(pitch<Radian(-1.5707)){
    152                         if(this->pitch_>0.0) this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
    153                         else if(pitch<Radian(-1.571)) this->cameraPositionRootNode_->pitch(-pitch+Radian(-1.570796));
     171                        if(this->pitch_>0.0) {
     172                                //this->weaponNode->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     173                                this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     174                                }
     175                        else if(pitch<Radian(-1.571)){
     176                                //this->weaponNode->pitch(-pitch+Radian(-1.570796));
     177                                this->cameraPositionRootNode_->pitch(-pitch+Radian(-1.570796));
     178                                }
    154179                }
    155180                else if(pitch>Radian(1.5707)){
    156                         if(this->pitch_<0.0) this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
    157                         else if(pitch>Radian(1.571)) this->cameraPositionRootNode_->pitch(-pitch+Radian(1.570796));
     181                        if(this->pitch_<0.0) {
     182                                //this->weaponNode->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     183                                this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     184                                }
     185                        else if(pitch>Radian(1.571)){
     186                                //this->weaponNode->pitch(-pitch+Radian(1.570796));
     187                                this->cameraPositionRootNode_->pitch(-pitch+Radian(1.570796));
     188                                }
    158189                }
    159                  
     190                //this->weaponNode->setOrientation(this->cameraPositionRootNode_->getOrientation());
    160191               
    161  //               this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
    162             }
     192            }
    163193
    164194            this->yaw_ = this->pitch_ = this->roll_ = 0;
     
    172202        SUPER(FpsPlayer, tick, dt);
    173203    }
     204   
     205    void FpsPlayer::changedMesh()
     206    {
     207        if (GameMode::showsGraphics())
     208        {
     209            if (this->mesh_.getEntity())
     210                this->weaponNode->detachObject(this->mesh_.getEntity());
     211
     212            this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
     213
     214            if (this->mesh_.getEntity())
     215            {
     216                this->weaponNode->attachObject(this->mesh_.getEntity());
     217            }
     218        }
     219    }
    174220
    175221    void FpsPlayer::setPlayer(PlayerInfo* player)
     
    244290    }
    245291   
     292    void FpsPlayer::addedWeaponPack(WeaponPack* wPack)
     293    {
     294        for (size_t i = 0; i < wPack->getNumWeapons(); ++i)
     295        {
     296            Weapon* weapon = wPack->getWeapon(i);
     297            if (weapon->getWeaponSlot())
     298            {
     299                weapon->getWeaponSlot()->removeWeapon();
     300                weapon->detachFromParent();
     301                weapon->attachToNode(this->weaponNode);
     302            }
     303        }
     304    }
    246305}
  • code/branches/fps/src/orxonox/worldentities/pawns/FpsPlayer.h

    r6872 r7052  
    3535#include <LinearMath/btVector3.h>
    3636#include "util/Math.h"
     37#include "tools/Mesh.h"
    3738#include "Pawn.h"
    3839
     
    5859            virtual void rotateRoll(const Vector2& value);
    5960           
     61           
     62            inline void setMeshSource(const std::string& meshname)
     63                { this->meshSrc_ = meshname; this->changedMesh(); }
     64            inline const std::string& getMeshSource() const
     65                { return this->meshSrc_; }
     66           
    6067            void boost();                                               //acctually jump
    6168
     
    6370           
    6471            bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     72
     73            virtual void addedWeaponPack(WeaponPack* wPack);
    6574           
    6675        protected:
     
    7584            float auxilaryThrust_;
    7685            float rotationThrust_;
     86            std::string weaponmashname;
    7787            btVector3 localLinearAcceleration_;
    7888            btVector3 localAngularAcceleration_;
     
    8292            float speed_;
    8393
     94            void changedMesh();
     95            Mesh mesh_;
     96            std::string meshSrc_;
    8497            float yaw_;
    8598            float pitch_;
     
    89102            bool thistickboost;
    90103            Quaternion savedOrientation_;
     104            Ogre::SceneNode* weaponNode;
     105            Ogre::Camera* camera_;
    91106    };
    92107}
  • code/branches/fps/src/orxonox/worldentities/pawns/Pawn.cc

    r6540 r7052  
    331331    {
    332332        if (this->weaponSystem_)
     333        {
    333334            this->weaponSystem_->addWeaponPack(wPack);
     335            this->addedWeaponPack(wPack);
     336        }
    334337    }
    335338
     
    337340    {
    338341        if (this->weaponSystem_)
     342        {
    339343            if (!this->weaponSystem_->addWeaponPack(wPack))
    340344                wPack->destroy();
     345            else
     346                this->addedWeaponPack(wPack);
     347        }
    341348    }
    342349
  • code/branches/fps/src/orxonox/worldentities/pawns/Pawn.h

    r6540 r7052  
    9090            void addWeaponPackXML(WeaponPack * wPack);
    9191            WeaponPack * getWeaponPack(unsigned int index) const;
     92           
     93            virtual void addedWeaponPack(WeaponPack* wPack) {}
    9294
    9395            inline const WorldEntity* getWorldEntity() const
Note: See TracChangeset for help on using the changeset viewer.