Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 317 for code/branches


Ignore:
Timestamp:
Nov 28, 2007, 3:00:45 PM (17 years ago)
Author:
mbiber
Message:

update steering

Location:
code/branches/steering/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/steering/src/orxonox.cc

    r209 r317  
    7979using namespace Ogre;
    8080
    81 class OrxExitListener : public FrameListener
     81class OrxExitListener : public FrameListener, public OIS::MouseListener
    8282{
    8383  public:
    84     OrxExitListener(OIS::Keyboard *keyboard)
    85   : mKeyboard(keyboard)
    86     {
    87     }
    88 
     84    OrxExitListener(OIS::Keyboard *keyboard, OIS::Mouse *mouse)
     85  : mKeyboard(keyboard), mMouse(mouse)
     86    {
     87      speed = 250;
     88      loop = 100;
     89      rotate = 10;
     90      mouseX = 0;
     91      mouseY = 0;
     92      maxMouseX = 0;
     93      minMouseX = 0;
     94      moved = false;
     95      steering->brakeRotate(rotate*10);
     96      steering->brakeLoop(loop);
     97      mMouse->setEventCallback(this);
     98    }
    8999    bool frameStarted(const FrameEvent& evt)
    90100    {
    91       float speed = 1;
    92       float rotate = 1;
    93101      mKeyboard->capture();
    94       if (mKeyboard->isKeyDown(OIS::KC_SPACE))
     102      mMouse->capture();
     103      if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
    95104        steering->moveForward(speed);
    96105      else
    97106        steering->moveForward(0);
    98       if(mKeyboard->isKeyDown(OIS::KC_C))
    99         steering->brake(speed);
     107      if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
     108        steering->brakeForward(speed);
    100109      else
    101         steering->brake(0.1);
    102       if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
    103         steering->rotateUp(rotate);
    104       else
    105         steering->rotateUp(0);
    106       if (mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
    107         steering->rotateDown(rotate);
    108       else
    109         steering->rotateDown(0);
     110        steering->brakeForward(speed/10);
    110111      if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
    111         steering->rotateRight(rotate);
    112       else
    113         steering->rotateRight(0);
    114       if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
    115         steering->rotateLeft(rotate);
    116       else
    117         steering->rotateLeft(0);
    118       if (mKeyboard->isKeyDown(OIS::KC_E))
    119         steering->loopRight(rotate);
     112        steering->loopRight(loop);
    120113      else
    121114        steering->loopRight(0);
    122       if (mKeyboard->isKeyDown(OIS::KC_Q))
    123         steering->loopLeft(rotate);
     115      if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
     116        steering->loopLeft(loop);
    124117      else
    125118        steering->loopLeft(0);
     119
     120      if(moved) {
     121        if (mouseY<0)
     122          steering->rotateUp(-mouseY*rotate);
     123        if (mouseY>0)
     124          steering->rotateDown(mouseY*rotate);
     125        if (mouseX>0)
     126          steering->rotateRight(mouseX*rotate);
     127        if (mouseX<0)
     128          steering->rotateLeft(-mouseX*rotate);
     129        moved = false;
     130      }
     131      else {
     132        steering->rotateUp(0);
     133        steering->rotateDown(0);
     134        steering->rotateRight(0);
     135        steering->rotateLeft(0);
     136      }
     137
    126138      steering->tick(evt.timeSinceLastFrame);
    127139//      scenemanager->spacehip->tick(evt.timesincelastframe);
     140      if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
     141        cout << "maximal MouseX: " << maxMouseX << "\tminMouseX: " << minMouseX << endl;
    128142      return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
    129143    }
    130144
     145    bool mouseMoved(const OIS::MouseEvent &e)
     146    {
     147      mouseX = e.state.X.rel;
     148      mouseY = e.state.Y.rel;
     149      if(mouseX>maxMouseX) maxMouseX = mouseX;
     150      if(mouseX<minMouseX) minMouseX = mouseX;
     151      cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;
     152      moved = true;
     153      return true;
     154    }
     155
     156    bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; }
     157    bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; }
     158
    131159  private:
     160    float speed;
     161    float rotate;
     162    float loop;
     163    float mouseY;
     164    float mouseX;
     165    float maxMouseX;
     166    float minMouseX;
     167    bool moved;
    132168    OIS::Keyboard *mKeyboard;
     169    OIS::Mouse *mMouse;
    133170};
    134171
     
    286323      {
    287324        mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
    288         mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
     325        mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true));
    289326      }
    290327      catch (const OIS::Exception &e)
     
    308345    void createFrameListener()
    309346    {
    310       mListener = new OrxExitListener(mKeyboard);
     347      mListener = new OrxExitListener(mKeyboard, mMouse);
    311348      mRoot->addFrameListener(mListener);     
    312349    }
  • code/branches/steering/src/spaceship_steering.cc

    r209 r317  
    77maxSpeedLoopRightLeft) {
    88  moveForward_ = 0;
    9   brake_ = 0;
    109  rotateUp_ = 0;
    1110  rotateDown_ = 0;
     
    1413  loopRight_ = 0;
    1514  loopLeft_ = 0;
     15  brakeForward_ = 0;
     16  brakeRotate_ = 0;
     17  brakeLoop_ = 0;
    1618  speedForward_ = 0;
    1719  speedRotateUpDown_ = 0;
     
    3335    accelerationForward_ = moveForward_;
    3436    if(speedForward_ < maxSpeedForward_)
    35       speedForward_ += accelerationForward_;
     37      speedForward_ += accelerationForward_*time;
    3638    if(speedForward_ > maxSpeedForward_)
    3739      speedForward_ = maxSpeedForward_;
    3840  }
    39   else {
    40     accelerationForward_ = brake_;
     41  if(moveForward_ <= 0) {
     42    accelerationForward_ = brakeForward_;
    4143    if(speedForward_ > 0)
    42       speedForward_ -= accelerationForward_;
     44      speedForward_ -= accelerationForward_*time;
    4345    if(speedForward_ < 0)
    4446      speedForward_ = 0;
     
    4850    accelerationRotateUpDown_ = rotateUp_;
    4951    if(speedRotateUpDown_ < maxSpeedRotateUpDown_)
    50       speedRotateUpDown_ += accelerationRotateUpDown_;
     52      speedRotateUpDown_ += accelerationRotateUpDown_*time;
    5153    if(speedRotateUpDown_ > maxSpeedRotateUpDown_)
    5254      speedRotateUpDown_ = maxSpeedRotateUpDown_;
    5355  }
    54   else if(rotateDown_ > 0) {
     56  if(rotateDown_ > 0) {
    5557    accelerationRotateUpDown_ = rotateDown_;
    5658    if(speedRotateUpDown_ > -maxSpeedRotateUpDown_)
    57       speedRotateUpDown_ -= accelerationRotateUpDown_;
     59      speedRotateUpDown_ -= accelerationRotateUpDown_*time;
    5860    if(speedRotateUpDown_ < -maxSpeedRotateUpDown_)
    5961      speedRotateUpDown_ = -maxSpeedRotateUpDown_;
    6062  }
    61   else {
     63  if(rotateUp_ == 0 && rotateDown_ == 0) {
     64    accelerationRotateUpDown_ = brakeRotate_;
    6265    if(speedRotateUpDown_ > 0)
    63       speedRotateUpDown_ -= accelerationRotateUpDown_;
     66      speedRotateUpDown_ -= accelerationRotateUpDown_*time;
    6467    if(speedRotateUpDown_ < 0)
    65       speedRotateUpDown_ += accelerationRotateUpDown_;
     68      speedRotateUpDown_ += accelerationRotateUpDown_*time;
    6669  }
    6770
     
    6972    accelerationRotateRightLeft_ = rotateRight_;
    7073    if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_)
    71       speedRotateRightLeft_ -= accelerationRotateRightLeft_;
     74      speedRotateRightLeft_ -= accelerationRotateRightLeft_*time;
    7275    if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_)
    7376      speedRotateRightLeft_ = -maxSpeedRotateRightLeft_;
    7477  }
    75   else if(rotateLeft_ > 0) {
     78  if(rotateLeft_ > 0) {
    7679    accelerationRotateRightLeft_ = rotateLeft_;
    7780    if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_)
    78       speedRotateRightLeft_ += accelerationRotateRightLeft_;
     81      speedRotateRightLeft_ += accelerationRotateRightLeft_*time;
    7982    if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_)
    8083      speedRotateRightLeft_ = maxSpeedRotateRightLeft_;
    8184  }
    82   else {
     85  if(rotateRight_ == 0 && rotateLeft_ == 0) {
     86    accelerationRotateRightLeft_ = brakeRotate_;
    8387    if(speedRotateRightLeft_ > 0)
    84       speedRotateRightLeft_ -= accelerationRotateRightLeft_;
     88      speedRotateRightLeft_ -= accelerationRotateRightLeft_*time;
    8589    if(speedRotateRightLeft_ < 0)
    86       speedRotateRightLeft_ += accelerationRotateRightLeft_;
     90      speedRotateRightLeft_ += accelerationRotateRightLeft_*time;
    8791  }
    8892
     
    9094    accelerationLoopRightLeft_ = loopRight_;
    9195    if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_)
    92       speedLoopRightLeft_ += accelerationLoopRightLeft_;
     96      speedLoopRightLeft_ += accelerationLoopRightLeft_*time;
    9397    if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_)
    9498      speedLoopRightLeft_ = maxSpeedLoopRightLeft_;
    9599  }
    96   else if(loopLeft_ > 0) {
     100  if(loopLeft_ > 0) {
    97101    accelerationLoopRightLeft_ = loopLeft_;
    98102    if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_)
    99       speedLoopRightLeft_ -= accelerationLoopRightLeft_;
     103      speedLoopRightLeft_ -= accelerationLoopRightLeft_*time;
    100104    if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_)
    101105      speedLoopRightLeft_ = -maxSpeedLoopRightLeft_;
    102106  }
    103   else {
     107  if(loopLeft_ == 0 && loopRight_ == 0) {
     108    accelerationLoopRightLeft_ = brakeLoop_;
    104109    if(speedLoopRightLeft_ > 0)
    105       speedLoopRightLeft_ -= accelerationLoopRightLeft_;
     110      speedLoopRightLeft_ -= accelerationLoopRightLeft_*time;
    106111    if(speedLoopRightLeft_ < 0)
    107       speedLoopRightLeft_ += accelerationLoopRightLeft_;
     112      speedLoopRightLeft_ += accelerationLoopRightLeft_*time;
    108113  }
    109114
     
    123128void SpaceshipSteering::moveForward(float moveForward) {
    124129  moveForward_ = moveForward;
    125 }
    126 
    127 void SpaceshipSteering::brake(float brake) {
    128   brake_ = brake;
    129130}
    130131
     
    153154}
    154155
     156void SpaceshipSteering::brakeForward(float brakeForward) {
     157  brakeForward_ = brakeForward;
     158}
     159
     160void SpaceshipSteering::brakeRotate(float brakeRotate) {
     161  brakeRotate_ = brakeRotate;
     162}
     163
     164void SpaceshipSteering::brakeLoop(float brakeLoop) {
     165  brakeLoop_ = brakeLoop;
     166}
     167
    155168void SpaceshipSteering::maxSpeedForward(float maxSpeedForward) {
    156169  maxSpeedForward_ = maxSpeedForward;
  • code/branches/steering/src/spaceship_steering.h

    r209 r317  
    1111    void tick(float time);
    1212    void moveForward(float moveForward);
    13     void brake(float brake);
    1413    void rotateUp(float rotateUp);
    1514    void rotateDown(float rotateDown);
     
    1817    void loopRight(float loopRight);
    1918    void loopLeft(float loopLeft);
     19    void brakeForward(float brakeForward);
     20    void brakeRotate(float brakeRotate);
     21    void brakeLoop(float brakeLoop);
    2022    void maxSpeedForward(float maxSpeedForward);
    2123    void maxSpeedRotateUpDown(float maxSpeedRotateUpDown);
     
    2931  private:
    3032    float moveForward_;
    31     float brake_;
    3233    float rotateUp_;
    3334    float rotateDown_;
     
    3637    float loopRight_;
    3738    float loopLeft_;
     39    float brakeForward_;
     40    float brakeRotate_;
     41    float brakeLoop_;
    3842
    3943    float speedForward_;
Note: See TracChangeset for help on using the changeset viewer.