Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 23, 2008, 4:02:03 PM (16 years ago)
Author:
rgrieder
Message:
  • fixed some bugs
File:
1 edited

Legend:

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

    r1386 r1391  
    5353    ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);
    5454    ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true);
     55    ConsoleCommand(SpaceShip, moveLongitudinal, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     56    ConsoleCommand(SpaceShip, moveLateral, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     57    ConsoleCommand(SpaceShip, moveYaw, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     58    ConsoleCommand(SpaceShip, movePitch, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     59    ConsoleCommand(SpaceShip, moveRoll, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     60    ConsoleCommand(SpaceShip, fire, AccessLevel::User, true).setKeybindMode(KeybindMode::OnHold);
    5561    ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);
    5662    ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);
     
    308314    }
    309315
    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 
    368316    void SpaceShip::mouseButtonPressed(MouseButton::Enum id)
    369317    {
    370         if (id == MouseButton::Left)
    371             this->bLMousePressed_ = true;
    372         else if (id == MouseButton::Right)
     318        if (id == MouseButton::Right)
    373319            this->bRMousePressed_ = true;
    374320    }
     
    376322    void SpaceShip::mouseButtonReleased(MouseButton::Enum id)
    377323    {
    378         if (id == MouseButton::Left)
    379             this->bLMousePressed_ = false;
    380         else if (id == MouseButton::Right)
     324        if (id == MouseButton::Right)
    381325        {
    382326            this->bRMousePressed_ = false;
     
    495439        }
    496440
    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;*/
    522441
    523442        WorldEntity::tick(dt);
     
    533452        else
    534453            this->tt_->setRate(0);
    535     }
    536 
     454
     455        if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ )
     456        {
     457          COUT(4) << "steering our ship: " << objectID << std::endl;
     458          this->acceleration_.x = 0;
     459          this->acceleration_.y = 0;
     460          this->momentum_ = 0;
     461          this->mouseXRotation_ = Radian(0);
     462          this->mouseYRotation_ = Radian(0);
     463          this->bLMousePressed_ = false;
     464        }/*else
     465          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
     466    }
     467    void SpaceShip::movePitch(float val)
     468    {
     469        SpaceShip* this_ = getLocalShip();
     470        val = -val * val * sgn(val) * this_->rotationAcceleration_;
     471        if (val > this_->maxRotation_)
     472            val = this_->maxRotation_;
     473        if (val < -this_->maxRotation_)
     474            val = -this_->maxRotation_;
     475        this_->mouseYRotation_ = Radian(val);
     476    }
     477
     478    void SpaceShip::moveYaw(float val)
     479    {
     480        SpaceShip* this_ = getLocalShip();
     481        val = -val * val * sgn(val) * this_->rotationAcceleration_;
     482        if (val > this_->maxRotation_)
     483            val = this_->maxRotation_;
     484        if (val < -this_->maxRotation_)
     485            val = -this_->maxRotation_;
     486        this_->mouseXRotation_ = Radian(val);
     487    }
     488
     489    void SpaceShip::moveRoll(float val)
     490    {
     491        SpaceShip* this_ = getLocalShip();
     492        this_->momentum_ = Radian(-this_->rotationAccelerationRadian_ * val);
     493    }
     494
     495    void SpaceShip::moveLongitudinal(float val)
     496    {
     497        SpaceShip* this_ = getLocalShip();
     498        COUT(3) << val << std::endl;
     499        this_->acceleration_.x = this_->translationAcceleration_ * val;
     500    }
     501
     502    void SpaceShip::moveLateral(float val)
     503    {
     504        SpaceShip* this_ = getLocalShip();
     505        this_->acceleration_.y = -this_->translationAcceleration_ * val;
     506    }
     507
     508    void SpaceShip::fire()
     509    {
     510        SpaceShip* this_ = getLocalShip();
     511        this_->bLMousePressed_ = true;
     512    }
    537513}
Note: See TracChangeset for help on using the changeset viewer.