Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2008, 9:07:08 PM (16 years ago)
Author:
rgrieder
Message:
  • merged input branch back to trunk
File:
1 edited

Legend:

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

    r1293 r1349  
    3838
    3939#include "CameraHandler.h"
    40 #include "tinyxml/tinyxml.h"
    41 #include "ois/OIS.h"
    42 #include "util/Convert.h"
     40//#include "util/Convert.h"
    4341#include "util/Math.h"
    4442#include "core/CoreIncludes.h"
     
    219217    }
    220218
    221     void SpaceShip::loadParams(TiXmlElement* xmlElem)
    222     {
    223         Model::loadParams(xmlElem);
    224         this->create();
    225         this->getFocus();
    226 /*
    227         if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
    228         {
    229             std::string forwardStr = xmlElem->Attribute("forward");
    230             std::string rotateupdownStr = xmlElem->Attribute("rotateupdown");
    231             std::string rotaterightleftStr = xmlElem->Attribute("rotaterightleft");
    232             std::string looprightleftStr = xmlElem->Attribute("looprightleft");
    233 
    234             String2Number<float>(this->maxSpeedForward_, forwardStr);
    235             String2Number<float>(this->maxSpeedRotateUpDown_, rotateupdownStr);
    236             String2Number<float>(this->maxSpeedRotateRightLeft_, rotaterightleftStr);
    237             String2Number<float>(this->maxSpeedLoopRightLeft_, looprightleftStr);
    238 
    239             COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl;
    240       }
    241 */
    242         if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp"))
    243         {
    244 
    245             std::string msStr = xmlElem->Attribute("maxSpeed");
    246             std::string msabsStr = xmlElem->Attribute("maxSideAndBackSpeed");
    247             std::string mrStr = xmlElem->Attribute("maxRotation");
    248             std::string taStr = xmlElem->Attribute("transAcc");
    249             std::string raStr = xmlElem->Attribute("rotAcc");
    250             std::string tdStr = xmlElem->Attribute("transDamp");
    251             std::string rdStr = xmlElem->Attribute("rotDamp");
    252 
    253             convertValue<std::string, float>(&this->maxSpeed_, msStr);
    254             convertValue<std::string, float>(&this->maxSideAndBackSpeed_, msabsStr);
    255             convertValue<std::string, float>(&this->maxRotation_, mrStr);
    256             convertValue<std::string, float>(&this->translationAcceleration_, taStr);
    257             convertValue<std::string, float>(&this->rotationAcceleration_, raStr);
    258             convertValue<std::string, float>(&this->translationDamping_, tdStr);
    259             convertValue<std::string, float>(&this->rotationDamping_, rdStr);
    260 
    261             this->maxRotationRadian_ = Radian(this->maxRotation_);
    262             this->rotationAccelerationRadian_ = Radian(this->rotationAcceleration_);
    263             this->rotationDampingRadian_ = Radian(this->rotationDamping_);
    264 
    265             COUT(4) << "Loader: Initialized SpaceShip" << std::endl;
    266         }
    267 
    268         if (xmlElem->Attribute("camera"))
    269         {
    270             this->setCamera();
    271         }
    272     }
    273 
    274219    void SpaceShip::setCamera(const std::string& camera)
    275220    {
     
    351296    }
    352297
    353     bool SpaceShip::mouseMoved(const MouseState& state)
     298    void SpaceShip::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    354299    {
    355300/*
     
    368313        if (this->bRMousePressed_)
    369314        {
    370             this->camNode_->roll(Degree(-state.X.rel * 0.10));
    371             this->camNode_->yaw(Degree(state.Y.rel * 0.10));
     315            this->camNode_->roll(Degree(-rel.x * 0.10));
     316            this->camNode_->yaw(Degree(rel.y * 0.10));
    372317        }
    373318        else
    374319        {
    375             float minDimension = state.height;
    376             if (state.width < minDimension)
    377                 minDimension = state.width;
    378 
    379             this->mouseX_ += state.X.rel;
     320            float minDimension = clippingSize.y;
     321            if (clippingSize.x < minDimension)
     322                minDimension = clippingSize.x;
     323
     324            this->mouseX_ += rel.x;
    380325            if (this->mouseX_ < -minDimension)
    381326                this->mouseX_ = -minDimension;
     
    383328                this->mouseX_ = minDimension;
    384329
    385             this->mouseY_ += state.Y.rel;
     330            this->mouseY_ += rel.y;
    386331            if (this->mouseY_ < -minDimension)
    387332                this->mouseY_ = -minDimension;
     
    407352            this->mouseYRotation_ = Radian(yRotation);
    408353        }
    409 
    410         return true;
    411     }
    412 
    413     bool SpaceShip::mouseButtonPressed(const MouseState& state, MouseButton::Enum id)
     354    }
     355
     356    void SpaceShip::mouseButtonPressed(MouseButton::Enum id)
    414357    {
    415358        if (id == MouseButton::Left)
     
    417360        else if (id == MouseButton::Right)
    418361            this->bRMousePressed_ = true;
    419 
    420         return true;
    421     }
    422 
    423     bool SpaceShip::mouseButtonReleased(const MouseState& state, MouseButton::Enum id)
     362    }
     363
     364    void SpaceShip::mouseButtonReleased(MouseButton::Enum id)
    424365    {
    425366        if (id == MouseButton::Left)
     
    430371            this->camNode_->resetOrientation();
    431372        }
    432 
    433         return true;
    434373    }
    435374
     
    564503        else
    565504            this->tt_->setRate(0);
    566 
    567 /*
    568         if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
    569             this->moveForward(speed);
    570         else
    571             this->moveForward(0);
    572 
    573         if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
    574             this->brakeForward(speed);
    575         else
    576             this->brakeForward(speed/10);
    577 
    578         if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
    579             this->loopRight(loop);
    580         else
    581             this->loopRight(0);
    582 
    583         if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
    584             this->loopLeft(loop);
    585         else
    586             this->loopLeft(0);
    587 
    588         if(moved)
    589         {
    590             if (mouseY<=0)
    591                 this->rotateUp(-mouseY*rotate);
    592             if (mouseY>0)
    593                 this->rotateDown(mouseY*rotate);
    594             if (mouseX>0)
    595                 this->rotateRight(mouseX*rotate);
    596             if (mouseX<=0)
    597                 this->rotateLeft(-mouseX*rotate);
    598 
    599             mouseY = 0;
    600             mouseX = 0;
    601             moved = false;
    602         }*/
    603 /*        else
    604         {
    605             this->rotateUp(0);
    606             this->rotateDown(0);
    607             this->rotateRight(0);
    608             this->rotateLeft(0);
    609         }*/
    610 /*
    611         if(moveForward_ > 0)
    612         {
    613             accelerationForward_ = moveForward_;
    614             if(speedForward_ < maxSpeedForward_)
    615                 speedForward_ += accelerationForward_*dt;
    616             if(speedForward_ > maxSpeedForward_)
    617                 speedForward_ = maxSpeedForward_;
    618         }
    619 
    620         if(moveForward_ <= 0)
    621         {
    622             accelerationForward_ = -brakeForward_;
    623             if(speedForward_ > 0)
    624                 speedForward_ += accelerationForward_*dt;
    625             if(speedForward_ < 0)
    626                 speedForward_ = 0;
    627         }
    628 
    629         if(rotateUp_ > 0)
    630         {
    631             accelerationRotateUpDown_ = rotateUp_;
    632             if(speedRotateUpDown_ < maxSpeedRotateUpDown_)
    633                 speedRotateUpDown_ += accelerationRotateUpDown_*dt;
    634             if(speedRotateUpDown_ > maxSpeedRotateUpDown_)
    635             speedRotateUpDown_ = maxSpeedRotateUpDown_;
    636         }
    637 
    638         if(rotateDown_ > 0)
    639         {
    640             accelerationRotateUpDown_ = rotateDown_;
    641             if(speedRotateUpDown_ > -maxSpeedRotateUpDown_)
    642                 speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
    643             if(speedRotateUpDown_ < -maxSpeedRotateUpDown_)
    644                 speedRotateUpDown_ = -maxSpeedRotateUpDown_;
    645         }
    646 
    647         if(rotateUp_ == 0 && rotateDown_ == 0)
    648         {
    649             accelerationRotateUpDown_ = brakeRotate_;
    650             if(speedRotateUpDown_ > 0)
    651                 speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
    652             if(speedRotateUpDown_ < 0)
    653                 speedRotateUpDown_ += accelerationRotateUpDown_*dt;
    654             if(fabs(speedRotateUpDown_) < accelerationRotateUpDown_*dt)
    655                 speedRotateUpDown_ = 0;
    656         }
    657 
    658         if(rotateRight_ > 0)
    659         {
    660             accelerationRotateRightLeft_ = rotateRight_;
    661             if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_)
    662                 speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
    663             if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_)
    664                 speedRotateRightLeft_ = -maxSpeedRotateRightLeft_;
    665         }
    666 
    667         if(rotateLeft_ > 0)
    668         {
    669             accelerationRotateRightLeft_ = rotateLeft_;
    670             if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_)
    671                 speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
    672             if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_)
    673                 speedRotateRightLeft_ = maxSpeedRotateRightLeft_;
    674         }
    675 
    676         if(rotateRight_ == 0 && rotateLeft_ == 0)
    677         {
    678             accelerationRotateRightLeft_ = brakeRotate_;
    679             if(speedRotateRightLeft_ > 0)
    680                 speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
    681             if(speedRotateRightLeft_ < 0)
    682                 speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
    683             if(fabs(speedRotateRightLeft_) < accelerationRotateRightLeft_*dt)
    684                 speedRotateRightLeft_ = 0;
    685         }
    686 
    687         if(loopRight_ > 0)
    688         {
    689             accelerationLoopRightLeft_ = loopRight_;
    690             if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_)
    691                 speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
    692             if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_)
    693                 speedLoopRightLeft_ = maxSpeedLoopRightLeft_;
    694         }
    695 
    696         if(loopLeft_ > 0)
    697         {
    698             accelerationLoopRightLeft_ = loopLeft_;
    699             if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_)
    700                 speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
    701             if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_)
    702                 speedLoopRightLeft_ = -maxSpeedLoopRightLeft_;
    703         }
    704 
    705         if(loopLeft_ == 0 && loopRight_ == 0)
    706         {
    707             accelerationLoopRightLeft_ = brakeLoop_;
    708             if(speedLoopRightLeft_ > 0)
    709                 speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
    710             if(speedLoopRightLeft_ < 0)
    711                 speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
    712             if(fabs(speedLoopRightLeft_) < accelerationLoopRightLeft_*dt)
    713                 speedLoopRightLeft_ = 0;
    714         }
    715 
    716         Vector3 transVector = Vector3::ZERO;
    717 */
    718 /*
    719         transVector.z = 1;
    720         this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
    721         this->pitch(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
    722         this->yaw(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
    723         this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
    724 */
    725 /*
    726         transVector.x = 1;
    727         this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
    728         this->yaw(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
    729         this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
    730         this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
    731 */
    732     }
    733 /*
    734     void SpaceShip::moveForward(float moveForward) {
    735         moveForward_ = moveForward;
    736     }
    737 
    738     void SpaceShip::rotateUp(float rotateUp) {
    739         rotateUp_ = rotateUp;
    740     }
    741 
    742     void SpaceShip::rotateDown(float rotateDown) {
    743         rotateDown_ = rotateDown;
    744     }
    745 
    746     void SpaceShip::rotateLeft(float rotateLeft) {
    747         rotateLeft_ = rotateLeft;
    748     }
    749 
    750     void SpaceShip::rotateRight(float rotateRight) {
    751         rotateRight_ = rotateRight;
    752     }
    753 
    754     void SpaceShip::loopLeft(float loopLeft) {
    755         loopLeft_ = loopLeft;
    756     }
    757 
    758     void SpaceShip::loopRight(float loopRight) {
    759         loopRight_ = loopRight;
    760     }
    761 
    762     void SpaceShip::brakeForward(float brakeForward) {
    763         brakeForward_ = brakeForward;
    764     }
    765 
    766     void SpaceShip::brakeRotate(float brakeRotate) {
    767         brakeRotate_ = brakeRotate;
    768     }
    769 
    770     void SpaceShip::brakeLoop(float brakeLoop) {
    771         brakeLoop_ = brakeLoop;
    772     }
    773 
    774     void SpaceShip::maxSpeedForward(float maxSpeedForward) {
    775         maxSpeedForward_ = maxSpeedForward;
    776     }
    777 
    778     void SpaceShip::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) {
    779         maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
    780     }
    781 
    782     void SpaceShip::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) {
    783         maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
    784     }
    785 
    786     void SpaceShip::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) {
    787         maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
    788     }
    789 */
     505    }
     506
    790507}
Note: See TracChangeset for help on using the changeset viewer.