Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 647


Ignore:
Timestamp:
Dec 19, 2007, 8:12:01 AM (16 years ago)
Author:
landauf
Message:

good morning everybody!
did some changes in the steering of SpaceShip

Location:
code/branches/FICN/src/orxonox
Files:
4 edited

Legend:

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

    r646 r647  
    4545        RegisterObject(SpaceShip);
    4646
    47         SetConfigValue(bInvertMouse_, true);
     47        SetConfigValue(bInvertYAxis_, false);
    4848        SetConfigValue(reloadTime_, 0.125);
    4949
     
    5151        this->bLMousePressed_ = false;
    5252        this->bRMousePressed_ = false;
     53        this->mouseX_ = 0;
     54        this->mouseY_ = 0;
    5355
    5456        this->camNode_ = 0;
     
    6163        this->timeToReload_ = 0;
    6264
     65        this->maxSpeed_ = 0;
     66        this->maxSideAndBackSpeed_ = 0;
     67        this->maxRotation_ = 0;
     68        this->translationAcceleration_ = 0;
     69        this->rotationAcceleration_ = 0;
     70        this->translationDamping_ = 0;
     71        this->rotationDamping_ = 0;
     72
     73        this->maxRotationRadian_ = 0;
     74        this->rotationAccelerationRadian_ = 0;
     75        this->rotationDampingRadian_ = 0;
     76        this->zeroRadian_ = Radian(0);
     77
     78        this->setRotationAxis(1, 0, 0);
     79        this->setStatic(false);
     80/*
    6381        this->moveForward_ = 0;
    6482        this->rotateUp_ = 0;
     
    95113        this->brakeRotate(rotate*10);
    96114        this->brakeLoop(loop);
    97 
     115*/
    98116        COUT(3) << "Info: SpaceShip was loaded" << std::endl;
    99117    }
     
    101119    SpaceShip::~SpaceShip()
    102120    {
    103         if (tt_)
    104             delete tt_;
    105     }
    106 
    107     void SpaceShip::setMaxSpeedValues(float maxSpeedForward, float maxSpeedRotateUpDown, float maxSpeedRotateRightLeft, float maxSpeedLoopRightLeft)
    108     {
    109         this->maxSpeedForward_ = maxSpeedForward;
    110         this->maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
    111         this->maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
    112         this->maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
     121        if (this->tt_)
     122            delete this->tt_;
    113123    }
    114124
     
    119129
    120130        // START CREATING THRUSTER
    121         tt_ = new particle::ParticleInterface(Orxonox::getSingleton()->getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
    122         tt_->getParticleSystem()->setParameter("local_space","true");
    123         tt_->newEmitter();
    124 /*
    125         tt_->setDirection(Vector3(0,0,1));
    126         tt_->setPositionOfEmitter(0, Vector3(20,-1,-15));
    127         tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15));
    128 */
    129         tt_->setDirection(Vector3(-1,0,0));
    130         tt_->setPositionOfEmitter(0, Vector3(-15,20,-1));
    131         tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1));
    132         tt_->setVelocity(50);
     131        this->tt_ = new particle::ParticleInterface(Orxonox::getSingleton()->getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
     132        this->tt_->getParticleSystem()->setParameter("local_space","true");
     133        this->tt_->newEmitter();
     134/*
     135        this->tt_->setDirection(Vector3(0,0,1));
     136        this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15));
     137        this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15));
     138*/
     139        this->tt_->setDirection(Vector3(-1,0,0));
     140        this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1));
     141        this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1));
     142        this->tt_->setVelocity(50);
    133143
    134144        emitterRate_ = tt_->getRate();
     
    156166
    157167
     168/*
    158169        if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
    159170        {
     
    170181            COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl;
    171182        }
     183*/
     184        if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp"))
     185        {
     186
     187            std::string msStr = xmlElem->Attribute("maxSpeed");
     188            std::string msabsStr = xmlElem->Attribute("maxSideAndBackSpeed");
     189            std::string mrStr = xmlElem->Attribute("maxRotation");
     190            std::string taStr = xmlElem->Attribute("transAcc");
     191            std::string raStr = xmlElem->Attribute("rotAcc");
     192            std::string tdStr = xmlElem->Attribute("transDamp");
     193            std::string rdStr = xmlElem->Attribute("rotDamp");
     194
     195            String2Number<float>(this->maxSpeed_, msStr);
     196            String2Number<float>(this->maxSideAndBackSpeed_, msabsStr);
     197            String2Number<float>(this->maxRotation_, mrStr);
     198            String2Number<float>(this->translationAcceleration_, taStr);
     199            String2Number<float>(this->rotationAcceleration_, raStr);
     200            String2Number<float>(this->translationDamping_, tdStr);
     201            String2Number<float>(this->rotationDamping_, rdStr);
     202
     203            this->maxRotationRadian_ = Radian(this->maxRotation_);
     204            this->rotationAccelerationRadian_ = Radian(this->rotationAcceleration_);
     205            this->rotationDampingRadian_ = Radian(this->rotationDamping_);
     206
     207            COUT(4) << "Loader: Initialized SpaceShip" << std::endl;
     208        }
    172209
    173210        if (xmlElem->Attribute("camera"))
     
    192229    }
    193230
     231    int sgn(float x)
     232    {
     233        if (x >= 0)
     234            return 1;
     235        else
     236            return -1;
     237    }
     238
    194239    bool SpaceShip::mouseMoved(const OIS::MouseEvent &e)
    195240    {
     241/*
    196242        this->mouseX += e.state.X.rel;
    197243        if (this->bInvertMouse_)
     
    205251
    206252        this->moved = true;
    207 
     253*/
    208254        if (this->bRMousePressed_)
    209255        {
    210256            this->camNode_->roll(Degree(-e.state.X.rel * 0.10));
    211257            this->camNode_->yaw(Degree(e.state.Y.rel * 0.10));
     258        }
     259        else
     260        {
     261            float minDimension = e.state.height;
     262            if (e.state.width < minDimension)
     263                minDimension = e.state.width;
     264
     265            this->mouseX_ += e.state.X.rel;
     266            if (this->mouseX_ < -minDimension)
     267                this->mouseX_ = -minDimension;
     268            if (this->mouseX_ > minDimension)
     269                this->mouseX_ = minDimension;
     270
     271            this->mouseY_ += e.state.Y.rel;
     272            if (this->mouseY_ < -minDimension)
     273                this->mouseY_ = -minDimension;
     274            if (this->mouseY_ > minDimension)
     275                this->mouseY_ = minDimension;
     276
     277            float xRotation = this->mouseX_ / minDimension;
     278            xRotation = xRotation*xRotation * sgn(xRotation);
     279            xRotation *= -this->rotationAcceleration_;
     280            if (xRotation > this->maxRotation_)
     281                xRotation = this->maxRotation_;
     282            if (xRotation < -this->maxRotation_)
     283                xRotation = -this->maxRotation_;
     284            this->mouseXRotation_ = Radian(xRotation);
     285
     286            float yRotation = this->mouseY_ / minDimension;
     287            yRotation = yRotation*yRotation * sgn(yRotation);
     288            yRotation *= this->rotationAcceleration_;
     289            if (yRotation > this->maxRotation_)
     290                yRotation = this->maxRotation_;
     291            if (yRotation < -this->maxRotation_)
     292                yRotation = -this->maxRotation_;
     293            this->mouseYRotation_ = Radian(yRotation);
    212294        }
    213295
     
    249331        }
    250332
    251         WorldEntity::tick(dt);
    252 
    253333        if (this->redNode_ && this->greenNode_)
    254334        {
     
    277357        mMouse->capture();
    278358
     359
     360        // #####################################
     361        // ############# STEERING ##############
     362        // #####################################
     363
     364        if (this->velocity_.x > this->maxSpeed_)
     365            this->velocity_.x = this->maxSpeed_;
     366        if (this->velocity_.x < -this->maxSideAndBackSpeed_)
     367            this->velocity_.x = -this->maxSideAndBackSpeed_;
     368        if (this->velocity_.y > this->maxSideAndBackSpeed_)
     369            this->velocity_.y = this->maxSideAndBackSpeed_;
     370        if (this->velocity_.y < -this->maxSideAndBackSpeed_)
     371            this->velocity_.y = -this->maxSideAndBackSpeed_;
     372        if (this->rotationRate_ > this->maxRotationRadian_)
     373            this->rotationRate_ = this->maxRotationRadian_;
     374        if (this->rotationRate_ < -this->maxRotationRadian_)
     375            this->rotationRate_ = -this->maxRotationRadian_;
     376
     377        if (this->acceleration_.x == 0)
     378        {
     379            if (this->velocity_.x > 0)
     380            {
     381                this->velocity_.x -= (this->translationDamping_ * dt);
     382                if (this->velocity_.x < 0)
     383                    this->velocity_.x = 0;
     384            }
     385            else if (this->velocity_.x < 0)
     386            {
     387                this->velocity_.x += (this->translationDamping_ * dt);
     388                if (this->velocity_.x > 0)
     389                    this->velocity_.x = 0;
     390            }
     391        }
     392
     393        if (this->acceleration_.y == 0)
     394        {
     395            if (this->velocity_.y > 0)
     396            {
     397                this->velocity_.y -= (this->translationDamping_ * dt);
     398                if (this->velocity_.y < 0)
     399                    this->velocity_.y = 0;
     400            }
     401            else if (this->velocity_.y < 0)
     402            {
     403                this->velocity_.y += (this->translationDamping_ * dt);
     404                if (this->velocity_.y > 0)
     405                    this->velocity_.y = 0;
     406            }
     407        }
     408
     409        if (this->momentum_ == this->zeroRadian_)
     410        {
     411            if (this->rotationRate_ > this->zeroRadian_)
     412            {
     413                this->rotationRate_ -= (this->rotationDampingRadian_ * dt);
     414                if (this->rotationRate_ < this->zeroRadian_)
     415                    this->rotationRate_ = 0;
     416            }
     417            else if (this->rotationRate_ < this->zeroRadian_)
     418            {
     419                this->rotationRate_ += (this->rotationDampingRadian_ * dt);
     420                if (this->rotationRate_ > this->zeroRadian_)
     421                    this->rotationRate_ = 0;
     422            }
     423        }
     424
     425        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
     426            this->acceleration_.x = this->translationAcceleration_;
     427        else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
     428            this->acceleration_.x = -this->translationAcceleration_;
     429        else
     430            this->acceleration_.x = 0;
     431
     432        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
     433            this->acceleration_.y = -this->translationAcceleration_;
     434        else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
     435            this->acceleration_.y = this->translationAcceleration_;
     436        else
     437            this->acceleration_.y = 0;
     438
     439        if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
     440            this->momentum_ = Radian(-this->rotationAccelerationRadian_);
     441        else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
     442            this->momentum_ = Radian(this->rotationAccelerationRadian_);
     443        else
     444            this->momentum_ = 0;
     445
     446        WorldEntity::tick(dt);
     447
     448        this->roll(this->mouseXRotation_ * dt);
     449        if (this->bInvertYAxis_)
     450            this->yaw(Radian(-this->mouseYRotation_ * dt));
     451        else
     452            this->yaw(Radian(this->mouseYRotation_ * dt));
     453
     454        if (this->acceleration_.x > 0)
     455            this->tt_->setRate(emitterRate_);
     456        else
     457            this->tt_->setRate(0);
     458
     459/*
    279460        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
    280461            this->moveForward(speed);
     
    311492            mouseX = 0;
    312493            moved = false;
    313         }
    314         else
     494        }*/
     495/*        else
    315496        {
    316497            this->rotateUp(0);
     
    318499            this->rotateRight(0);
    319500            this->rotateLeft(0);
    320         }
    321 
     501        }*/
     502/*
    322503        if(moveForward_ > 0)
    323504        {
     
    426607
    427608        Vector3 transVector = Vector3::ZERO;
     609*/
    428610/*
    429611        transVector.z = 1;
     
    433615        this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
    434616*/
    435 
     617/*
    436618        transVector.x = 1;
    437619        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
     
    439621        this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
    440622        this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
    441 
    442         if (accelerationForward_ > 25.0)
    443         {
    444             this->tt_->setRate(emitterRate_);
    445         }
    446         else
    447         {
    448             this->tt_->setRate(0);
    449         }
    450 
    451     }
    452 
     623*/
     624    }
     625/*
    453626    void SpaceShip::moveForward(float moveForward) {
    454627        moveForward_ = moveForward;
     
    506679        maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
    507680    }
     681*/
    508682}
  • code/branches/FICN/src/orxonox/objects/SpaceShip.h

    r644 r647  
    1919            ~SpaceShip();
    2020            virtual void loadParams(TiXmlElement* xmlElem);
    21             void setMaxSpeedValues(float maxSpeedForward, float maxSpeedRotateUpDown, float maxSpeedRotateRightLeft, float maxSpeedLoopRightLeft);
    2221            virtual void tick(float dt);
     22/*
    2323            void moveForward(float moveForward);
    2424            void rotateUp(float rotateUp);
     
    3535            void maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft);
    3636            void maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft);
     37*/
    3738            bool mouseMoved(const OIS::MouseEvent &e);
    3839            bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
     
    4142
    4243        private:
    43             bool bInvertMouse_;
     44            bool bInvertYAxis_;
    4445            bool setMouseEventCallback_;
    4546            bool bLMousePressed_;
     
    4849            Ogre::SceneNode* camNode_;
    4950
    50             particle::ParticleInterface *tt_;
     51            particle::ParticleInterface* tt_;
    5152
    5253            BillboardSet redBillboard_;
     
    5960            float reloadTime_;
    6061
     62            float maxSideAndBackSpeed_;
     63            float maxSpeed_;
     64            float maxRotation_;
     65            float translationAcceleration_;
     66            float rotationAcceleration_;
     67            float translationDamping_;
     68            float rotationDamping_;
     69
     70            Radian maxRotationRadian_;
     71            Radian rotationAccelerationRadian_;
     72            Radian rotationDampingRadian_;
     73            Radian zeroRadian_;
     74            Radian mouseXRotation_;
     75            Radian mouseYRotation_;
     76
     77            float mouseX_;
     78            float mouseY_;
     79
     80/*
    6181            float moveForward_;
    6282            float rotateUp_;
     
    93113            float minMouseX;
    94114            bool moved;
    95 
     115*/
    96116            int emitterRate_;
    97117    };
  • code/branches/FICN/src/orxonox/objects/WorldEntity.h

    r646 r647  
    133133      void registerAllVariables();
    134134
    135     private:
    136       Ogre::SceneNode* node_;
    137       static unsigned int worldEntityCounter_s;
    138 
    139       bool bStatic_;
    140135      Vector3 velocity_;
    141136      Vector3 acceleration_;
     
    143138      Radian rotationRate_;
    144139      Radian momentum_;
     140
     141    private:
     142      static unsigned int worldEntityCounter_s;
     143      Ogre::SceneNode* node_;
     144      bool bStatic_;
    145145  };
    146146}
  • code/branches/FICN/src/orxonox/particle/ParticleInterface.cc

    r646 r647  
    4040  ParticleInterface::~ParticleInterface(void)
    4141  {
    42 std::cout << "blubiblub_1\n";
    4342    sceneManager_->destroyParticleSystem(particleSystem_);
    44 std::cout << "blubiblub_2\n";
    45 
    46 //    delete sceneNode_;
    47 //    delete particleSystem_;
    48 //    delete sceneManager_;
    4943  }
    5044
Note: See TracChangeset for help on using the changeset viewer.