Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (16 years ago)
Author:
rgrieder
Message:
  • @everyone: Do not create a branch until I've added the svn:eol-style property correctly. Otherwise this would cost me another 4 hours or so when we want to merge back.
  • merged network branch back to trunk
  • I had to omit the changes from last evening concerning the line endings
  • might not work yet because of the line endings
  • @beni: script branch is the only branch still open. you probably will have to apply a patch because of inconsistent new lines
File:
1 edited

Legend:

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

    r1407 r1502  
    4545#include "particle/ParticleInterface.h"
    4646#include "Projectile.h"
     47#include "RotatingProjectile.h"
    4748#include "core/XMLPort.h"
    4849#include "core/ConsoleCommand.h"
    4950#include "network/Client.h"
     51#include "hud/HUD.h"
    5052
    5153namespace orxonox
    5254{
    53     ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);
    54     ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true);
    55     ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);
    56     ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);
    57     ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false);
     55    SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug);
     56    SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User);
     57    SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     58    SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     59    SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     60    SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     61    SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     62    SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold);
     63    SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug);
     64    SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug);
     65    SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug);
    5866
    5967    CreateFactory(SpaceShip);
     
    6472      Iterator<SpaceShip> it;
    6573      for(it = ObjectList<SpaceShip>::start(); it; ++it){
    66         if((it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ) )
     74        if( (it)->myShip_ )
    6775          return *it;
    6876      }
    6977      return NULL;
    7078    }
    71    
     79
    7280    SpaceShip::SpaceShip() :
    7381      //testvector_(0,0,0),
     
    103111      mouseY_(0.0f),
    104112      emitterRate_(0.0f),
    105       server_(false)
     113      myShip_(false),
     114      teamNr_(0),
     115      health_(100)
    106116    {
    107117        RegisterObject(SpaceShip);
     
    112122        this->setConfigValues();
    113123
     124        initialDir_ = Vector3(1.0, 0.0, 0.0);
     125        currentDir_ = initialDir_;
     126        initialOrth_ = Vector3(0.0, 0.0, 1.0);
     127        currentOrth_ = initialOrth_;
     128
     129        this->camName_ = this->getName() + "CamNode";
    114130
    115131        this->setRotationAxis(1, 0, 0);
     
    127143        if (this->cam_)
    128144          delete this->cam_;
     145        if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL)
     146          //remove the radar object
     147          HUD::getSingleton().removeRadarObject(this->getNode());
    129148    }
    130149
    131150    bool SpaceShip::create(){
     151      if(!myShip_){
     152        if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID())
     153          myShip_=true;
     154        else
     155          HUD::getSingleton().addRadarObject(this->getNode(), 3);
     156      }
    132157      if(Model::create())
    133158        this->init();
     
    153178    void SpaceShip::init()
    154179    {
    155         if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))
    156         {
    157               if (!setMouseEventCallback_)
    158               {
    159                   InputManager::addMouseHandler(this, "SpaceShip");
    160                   //InputManager::enableMouseHandler("SpaceShip");
    161                   setMouseEventCallback_ = true;
    162               }
    163         }
    164 
    165180        // START CREATING THRUSTER
    166181        this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
     
    200215        // END CREATING BLINKING LIGHTS
    201216
    202         // START of testing crosshair
    203         this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
    204         this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
    205 
    206         this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
    207         this->chNearNode_->setInheritScale(false);
    208         this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
    209         this->chFarNode_->setInheritScale(false);
    210 
    211         this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
    212         this->chNearNode_->setScale(0.2, 0.2, 0.2);
    213 
    214         this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
    215         this->chFarNode_->setScale(0.4, 0.4, 0.4);
     217        if (this->isExactlyA(Class(SpaceShip)))
     218        {
     219            // START of testing crosshair
     220            this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
     221            this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
     222
     223            this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
     224            this->chNearNode_->setInheritScale(false);
     225            this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
     226            this->chFarNode_->setInheritScale(false);
     227
     228            this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
     229            this->chNearNode_->setScale(0.2, 0.2, 0.2);
     230
     231            this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
     232            this->chFarNode_->setScale(0.4, 0.4, 0.4);
     233        }
    216234
    217235        createCamera();
     
    237255        CameraHandler::getInstance()->requestFocus(cam_);
    238256
     257    }
     258
     259    Camera* SpaceShip::getCamera(){
     260        return cam_;
    239261    }
    240262
     
    295317        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    296318        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
    297         server_=true; // TODO: this is only a hack
     319        myShip_=true; // TODO: this is only a hack
     320
    298321        SpaceShip::create();
    299         getFocus();
     322        if (this->isExactlyA(Class(SpaceShip)))
     323            getFocus();
    300324    }
    301325
     
    308332    }
    309333
    310     void SpaceShip::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    311     {
    312 /*
    313         this->mouseX += e.state.X.rel;
    314         if (this->bInvertMouse_)
    315             this->mouseY += e.state.Y.rel;
    316         else
    317             this->mouseY -= e.state.Y.rel;
    318 
    319 //        if(mouseX>maxMouseX) maxMouseX = mouseX;
    320 //        if(mouseX<minMouseX) minMouseX = mouseX;
    321 //        cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;
    322 
    323         this->moved = true;
    324 */
    325         if (this->bRMousePressed_)
    326         {
    327             this->camNode_->roll(Degree(-rel.x * 0.10));
    328             this->camNode_->yaw(Degree(rel.y * 0.10));
    329         }
    330         else
    331         {
    332             float minDimension = clippingSize.y;
    333             if (clippingSize.x < minDimension)
    334                 minDimension = clippingSize.x;
    335 
    336             this->mouseX_ += rel.x;
    337             if (this->mouseX_ < -minDimension)
    338                 this->mouseX_ = -minDimension;
    339             if (this->mouseX_ > minDimension)
    340                 this->mouseX_ = minDimension;
    341 
    342             this->mouseY_ += rel.y;
    343             if (this->mouseY_ < -minDimension)
    344                 this->mouseY_ = -minDimension;
    345             if (this->mouseY_ > minDimension)
    346                 this->mouseY_ = minDimension;
    347 
    348             float xRotation = this->mouseX_ / minDimension;
    349             xRotation = xRotation*xRotation * sgn(xRotation);
    350             xRotation *= -this->rotationAcceleration_;
    351             if (xRotation > this->maxRotation_)
    352                 xRotation = this->maxRotation_;
    353             if (xRotation < -this->maxRotation_)
    354                 xRotation = -this->maxRotation_;
    355             this->mouseXRotation_ = Radian(xRotation);
    356 
    357             float yRotation = this->mouseY_ / minDimension;
    358             yRotation = yRotation*yRotation * sgn(yRotation);
    359             yRotation *= this->rotationAcceleration_;
    360             if (yRotation > this->maxRotation_)
    361                 yRotation = this->maxRotation_;
    362             if (yRotation < -this->maxRotation_)
    363                 yRotation = -this->maxRotation_;
    364             this->mouseYRotation_ = Radian(yRotation);
    365         }
    366     }
    367 
    368     void SpaceShip::mouseButtonPressed(MouseButton::Enum id)
    369     {
    370         if (id == MouseButton::Left)
    371             this->bLMousePressed_ = true;
    372         else if (id == MouseButton::Right)
    373             this->bRMousePressed_ = true;
    374     }
    375 
    376     void SpaceShip::mouseButtonReleased(MouseButton::Enum id)
    377     {
    378         if (id == MouseButton::Left)
    379             this->bLMousePressed_ = false;
    380         else if (id == MouseButton::Right)
    381         {
    382             this->bRMousePressed_ = false;
    383             this->camNode_->resetOrientation();
    384         }
    385     }
    386 
    387334    std::string SpaceShip::whereAmI() {
    388335        return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
     
    391338    }
    392339
    393     Vector3 SpaceShip::getSPosition() {
    394         return SpaceShip::getLocalShip()->getPosition();
    395     }
    396 
    397     Quaternion SpaceShip::getSOrientation() {
    398         return SpaceShip::getLocalShip()->getOrientation();
     340    Vector3 SpaceShip::getDir() {
     341        return currentDir_;
     342    }
     343
     344    Vector3 SpaceShip::getOrth(){
     345        return currentOrth_;
    399346    }
    400347
     
    403350    void SpaceShip::tick(float dt)
    404351    {
     352        currentDir_ = getOrientation()*initialDir_;
     353                currentOrth_ = getOrientation()*initialOrth_;
     354
    405355        if (this->cam_)
    406356            this->cam_->tick(dt);
     
    422372        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
    423373        {
    424          
    425             Projectile *p = new Projectile(this);
    426            
     374
     375            Projectile *p;
     376            if (this->isExactlyA(Class(SpaceShip)))
     377                p = new RotatingProjectile(this);
     378            else
     379                p = new Projectile(this);
     380            p->setColour(this->getProjectileColour());
     381            p->create();
     382            if(p->classID==0)
     383              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
     384
    427385            p->setBacksync(true);
    428386            this->timeToReload_ = this->reloadTime_;
     
    495453        }
    496454
    497         if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ )
    498         {
    499           COUT(4) << "steering our ship: " << objectID << std::endl;
    500           if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W))
    501             this->acceleration_.x = this->translationAcceleration_;
    502           else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S))
    503             this->acceleration_.x = -this->translationAcceleration_;
    504           else
    505             this->acceleration_.x = 0;
    506 
    507           if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D))
    508             this->acceleration_.y = -this->translationAcceleration_;
    509           else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A))
    510             this->acceleration_.y = this->translationAcceleration_;
    511           else
    512             this->acceleration_.y = 0;
    513 
    514           if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q))
    515             this->momentum_ = Radian(-this->rotationAccelerationRadian_);
    516           else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E))
    517             this->momentum_ = Radian(this->rotationAccelerationRadian_);
    518           else
    519             this->momentum_ = 0;
    520         }/*else
    521           COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
    522455
    523456        WorldEntity::tick(dt);
     
    533466        else
    534467            this->tt_->setRate(0);
    535     }
    536 
     468
     469        if( myShip_ )
     470        {
     471          COUT(4) << "steering our ship: " << objectID << std::endl;
     472          this->acceleration_.x = 0;
     473          this->acceleration_.y = 0;
     474          this->momentum_ = 0;
     475          this->mouseXRotation_ = Radian(0);
     476          this->mouseYRotation_ = Radian(0);
     477          this->bLMousePressed_ = false;
     478        }/*else
     479          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
     480    }
     481
     482    void SpaceShip::movePitch(float val)
     483    {   getLocalShip()->setMovePitch(val);   }
     484    void SpaceShip::moveYaw(float val)
     485    {   getLocalShip()->setMoveYaw(val);   }
     486    void SpaceShip::moveRoll(float val)
     487    {   getLocalShip()->setMoveRoll(val);   }
     488    void SpaceShip::moveLongitudinal(float val)
     489    {   getLocalShip()->setMoveLongitudinal(val);   }
     490    void SpaceShip::moveLateral(float val)
     491    {   getLocalShip()->setMoveLateral(val);   }
     492    void SpaceShip::fire()
     493    {   getLocalShip()->doFire();   }
     494
     495    void SpaceShip::setMovePitch(float val)
     496    {
     497        val = -val * val * sgn(val) * this->rotationAcceleration_;
     498        if (val > this->maxRotation_)
     499            val = this->maxRotation_;
     500        if (val < -this->maxRotation_)
     501            val = -this->maxRotation_;
     502        this->mouseYRotation_ = Radian(val);
     503    }
     504
     505    void SpaceShip::setMoveYaw(float val)
     506    {
     507        val = -val * val * sgn(val) * this->rotationAcceleration_;
     508        if (val > this->maxRotation_)
     509            val = this->maxRotation_;
     510        if (val < -this->maxRotation_)
     511            val = -this->maxRotation_;
     512        this->mouseXRotation_ = Radian(val);
     513    }
     514
     515    void SpaceShip::setMoveRoll(float val)
     516    {
     517        this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val);
     518        //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl;
     519    }
     520
     521    void SpaceShip::setMoveLongitudinal(float val)
     522    {
     523        this->acceleration_.x = this->translationAcceleration_ * val;
     524    }
     525
     526    void SpaceShip::setMoveLateral(float val)
     527    {
     528        this->acceleration_.y = -this->translationAcceleration_ * val;
     529    }
     530
     531    void SpaceShip::doFire()
     532    {
     533        this->bLMousePressed_ = true;
     534    }
    537535}
Note: See TracChangeset for help on using the changeset viewer.