Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1833


Ignore:
Timestamp:
Sep 25, 2008, 10:14:31 PM (16 years ago)
Author:
scheusso
Message:

splitted up SpaceShip into 2 files (don't panic, this applies only to the tutorial ;) )

Location:
code/branches/orxonox_tutorial/src/orxonox/objects
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/orxonox_tutorial/src/orxonox/objects/SpaceShip.cc

    r1789 r1833  
    2727 */
    2828
    29 #include "OrxonoxStableHeaders.h"
    3029#include "SpaceShip.h"
    31 
    32 #include <OgreCamera.h>
    33 #include <OgreRenderWindow.h>
    34 #include <OgreParticleSystem.h>
    35 #include <OgreSceneNode.h>
    36 
    37 #include "util/Convert.h"
    38 #include "util/Math.h"
    39 #include "util/Debug.h"
    40 #include "core/CoreIncludes.h"
    41 #include "core/ConfigValueIncludes.h"
    42 #include "core/Iterator.h"
    43 #include "core/input/InputManager.h"
    44 #include "core/XMLPort.h"
    45 #include "core/ConsoleCommand.h"
    46 #include "tools/ParticleInterface.h"
    47 #include "network/Client.h"
    48 #include "Backlight.h"
    49 #include "CameraHandler.h"
    50 #include "ParticleSpawner.h"
    51 #include "Settings.h"
    52 #include "RotatingProjectile.h"
    53 #include "ParticleProjectile.h"
    54 #include "GraphicsEngine.h"
    55 #include "SpaceShipAI.h"
     30#include "SpaceShip_backend.cc"
    5631
    5732namespace orxonox
    5833{
    59     SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).accessLevel(AccessLevel::Debug);
    60     SetConsoleCommand(SpaceShip, whereAmI, true).accessLevel(AccessLevel::User);
    61     SetConsoleCommand(SpaceShip, moveLongitudinal, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
    62     SetConsoleCommand(SpaceShip, moveLateral, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
    63     SetConsoleCommand(SpaceShip, moveYaw, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
    64     SetConsoleCommand(SpaceShip, movePitch, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
    65     SetConsoleCommand(SpaceShip, moveRoll, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
    66     SetConsoleCommand(SpaceShip, fire, true).accessLevel(AccessLevel::User).keybindMode(KeybindMode::OnHold);
    67     SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setMaxSpeed", 1, false).accessLevel(AccessLevel::Debug);
    68     SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setMaxBlubber", 2, false).accessLevel(AccessLevel::Debug);
    69     SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setRofl", 3, false).accessLevel(AccessLevel::Debug);
    70 
    71     CreateFactory(SpaceShip);
    72 
    73     SpaceShip* SpaceShip::instance_s;
    74 
    75 
    76     SpaceShip *SpaceShip::getLocalShip(){
    77       ObjectList<SpaceShip>::iterator it;
    78       for(it = ObjectList<SpaceShip>::begin(); it; ++it){
    79         assert(it->isA(Class(SpaceShip)));
    80         if( (it)->myShip_ || (network::Host::running() && network::Host::getShipID()==(it)->objectID) ){
    81 //        COUT(1) << "^^^^^^^^^^ myShip_:" << *it << " classname: " << (*it)->getIdentifier()->getName() << " objectid: " << (*it)->objectID << std::endl;
    82           return *it;
    83         }
    84       }
    85       return 0;
    86     }
    87 
     34   
    8835    SpaceShip::SpaceShip()
    8936    {
     
    169116    }
    170117
    171     bool SpaceShip::create()
    172     {
    173         if (!myShip_)
    174         {
    175             if (network::Host::running())
    176                 //COUT(3) << "this id: " << this->objectID << " myShipID: " << network::Host::getShipID() << std::endl;
    177                 if (network::Host::running() && objectID == network::Host::getShipID())
    178                 {
    179                     if (!network::Host::isServer())
    180                         setObjectMode(0x3);
    181                     myShip_ = true;
    182                 }
    183         }
    184         else
    185             this->setRadarObjectColour(this->getProjectileColour());
    186         assert(Model::create());
    187         this->init();
    188         return true;
    189     }
    190 
    191     void SpaceShip::registerAllVariables()
    192     {
    193         registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 );
    194         registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1);
    195         registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1);
    196         registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1);
    197         registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1);
    198         registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1);
    199         registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1);
    200         registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1);
    201         registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1);
    202         registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1);
    203     }
    204 
     118   
    205119    void SpaceShip::init()
    206120    {
     
    304218    }
    305219
    306     void SpaceShip::changedVisibility()
    307     {
    308         SUPER(SpaceShip, changedVisibility);
    309 
    310         this->tt1_->setEnabled(this->isVisible());
    311         this->tt2_->setEnabled(this->isVisible());
    312         this->redBillboard_.setVisible(this->isVisible());
    313         this->greenBillboard_.setVisible(this->isVisible());
    314         this->crosshairNear_.setVisible(this->isVisible());
    315         this->crosshairFar_.setVisible(this->isVisible());
    316         this->rightThrusterFlare_.setVisible(this->isVisible());
    317         this->leftThrusterFlare_.setVisible(this->isVisible());
    318         this->smoke_->setVisible(this->isVisible());
    319         this->fire_->setVisible(this->isVisible());
    320         this->backlight_->setVisible(this->isVisible());
    321     }
    322 
    323     void SpaceShip::changedActivity()
    324     {
    325         SUPER(SpaceShip, changedActivity);
    326 
    327         this->tt1_->setEnabled(this->isVisible());
    328         this->tt2_->setEnabled(this->isVisible());
    329         this->redBillboard_.setVisible(this->isVisible());
    330         this->greenBillboard_.setVisible(this->isVisible());
    331         this->crosshairNear_.setVisible(this->isVisible());
    332         this->crosshairFar_.setVisible(this->isVisible());
    333         this->rightThrusterFlare_.setVisible(this->isVisible());
    334         this->leftThrusterFlare_.setVisible(this->isVisible());
    335     }
    336 
    337     void SpaceShip::setCamera(const std::string& camera)
    338     {
    339       camName_=camera;
    340       // change camera attributes here, if you want to ;)
    341     }
    342 
    343     void SpaceShip::getFocus(){
    344       COUT(4) << "requesting focus" << std::endl;
    345       //if(!network::Host::running() || network::Host::getShipID()==objectID)
    346       if(myShip_)
    347         CameraHandler::getInstance()->requestFocus(cam_);
    348 
    349     }
    350 
    351     Camera* SpaceShip::getCamera(){
    352         return cam_;
    353     }
    354 
    355     void SpaceShip::createCamera(){
    356 //       COUT(4) << "begin camera creation" << std::endl;
    357       this->camNode_ = this->getNode()->createChildSceneNode(camName_);
    358       COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
    359       this->camNode_->setPosition(Vector3(-25,0,5));
    360 //      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    361 //      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
    362 //      camNode_->setOrientation(q1*q2);
    363       COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
    364       cam_ = new Camera(this->camNode_);
    365 
    366       cam_->setTargetNode(this->getNode());
    367 //        cam->setPosition(Vector3(0,-350,0));
    368 //      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,0,1));
    369 //      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,1,0));
    370       Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    371       Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0));
    372 
    373        this->camNode_->setOrientation(q2*q1);
    374       //if(!network::Host::running() || network::Host::getShipID()==objectID){ //TODO: check this
    375       if(myShip_){
    376         COUT(4) << "requesting focus for camera" << std::endl;
    377         //CameraHandler::getInstance()->requestFocus(cam_);
    378         if(this->isExactlyA(Class(SpaceShip))){
    379           getFocus();
    380           COUT(4) << "getting focus for obj id: " << objectID << std::endl;
    381         }else
    382           COUT(4) << "not getting focus (not exactly spaceship) for obj id: " << objectID << std::endl;
    383       }else
    384         COUT(4) << "not getting focus (not my ship) for obj id: " << objectID << std::endl;
    385     }
    386 
    387     void SpaceShip::setMaxSpeed(float value)
    388     { this->maxSpeed_ = value; }
    389     void SpaceShip::setMaxSideAndBackSpeed(float value)
    390     { this->maxSideAndBackSpeed_ = value; }
    391     void SpaceShip::setMaxRotation(float value)
    392     { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); }
    393     void SpaceShip::setTransAcc(float value)
    394     { this->translationAcceleration_ = value; }
    395     void SpaceShip::setRotAcc(float value)
    396     { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); }
    397     void SpaceShip::setTransDamp(float value)
    398     { this->translationDamping_ = value; }
    399     void SpaceShip::setRotDamp(float value)
    400     { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); }
    401 
     220   
    402221    /**
    403222        @brief XML loading and saving.
     
    425244    }
    426245
    427     std::string SpaceShip::whereAmI() {
    428         return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
    429         + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y)
    430         + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z);
    431     }
     246   
    432247
    433248    void SpaceShip::tick(float dt)
Note: See TracChangeset for help on using the changeset viewer.