Changeset 317 for code/branches
- Timestamp:
- Nov 28, 2007, 3:00:45 PM (17 years ago)
- Location:
- code/branches/steering/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/steering/src/orxonox.cc
r209 r317 79 79 using namespace Ogre; 80 80 81 class OrxExitListener : public FrameListener 81 class OrxExitListener : public FrameListener, public OIS::MouseListener 82 82 { 83 83 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 } 89 99 bool frameStarted(const FrameEvent& evt) 90 100 { 91 float speed = 1;92 float rotate = 1;93 101 mKeyboard->capture(); 94 if (mKeyboard->isKeyDown(OIS::KC_SPACE)) 102 mMouse->capture(); 103 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 95 104 steering->moveForward(speed); 96 105 else 97 106 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); 100 109 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); 110 111 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); 120 113 else 121 114 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); 124 117 else 125 118 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 126 138 steering->tick(evt.timeSinceLastFrame); 127 139 // scenemanager->spacehip->tick(evt.timesincelastframe); 140 if(mKeyboard->isKeyDown(OIS::KC_ESCAPE)) 141 cout << "maximal MouseX: " << maxMouseX << "\tminMouseX: " << minMouseX << endl; 128 142 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 129 143 } 130 144 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 131 159 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; 132 168 OIS::Keyboard *mKeyboard; 169 OIS::Mouse *mMouse; 133 170 }; 134 171 … … 286 323 { 287 324 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)); 289 326 } 290 327 catch (const OIS::Exception &e) … … 308 345 void createFrameListener() 309 346 { 310 mListener = new OrxExitListener(mKeyboard );347 mListener = new OrxExitListener(mKeyboard, mMouse); 311 348 mRoot->addFrameListener(mListener); 312 349 } -
code/branches/steering/src/spaceship_steering.cc
r209 r317 7 7 maxSpeedLoopRightLeft) { 8 8 moveForward_ = 0; 9 brake_ = 0;10 9 rotateUp_ = 0; 11 10 rotateDown_ = 0; … … 14 13 loopRight_ = 0; 15 14 loopLeft_ = 0; 15 brakeForward_ = 0; 16 brakeRotate_ = 0; 17 brakeLoop_ = 0; 16 18 speedForward_ = 0; 17 19 speedRotateUpDown_ = 0; … … 33 35 accelerationForward_ = moveForward_; 34 36 if(speedForward_ < maxSpeedForward_) 35 speedForward_ += accelerationForward_ ;37 speedForward_ += accelerationForward_*time; 36 38 if(speedForward_ > maxSpeedForward_) 37 39 speedForward_ = maxSpeedForward_; 38 40 } 39 else{40 accelerationForward_ = brake _;41 if(moveForward_ <= 0) { 42 accelerationForward_ = brakeForward_; 41 43 if(speedForward_ > 0) 42 speedForward_ -= accelerationForward_ ;44 speedForward_ -= accelerationForward_*time; 43 45 if(speedForward_ < 0) 44 46 speedForward_ = 0; … … 48 50 accelerationRotateUpDown_ = rotateUp_; 49 51 if(speedRotateUpDown_ < maxSpeedRotateUpDown_) 50 speedRotateUpDown_ += accelerationRotateUpDown_ ;52 speedRotateUpDown_ += accelerationRotateUpDown_*time; 51 53 if(speedRotateUpDown_ > maxSpeedRotateUpDown_) 52 54 speedRotateUpDown_ = maxSpeedRotateUpDown_; 53 55 } 54 elseif(rotateDown_ > 0) {56 if(rotateDown_ > 0) { 55 57 accelerationRotateUpDown_ = rotateDown_; 56 58 if(speedRotateUpDown_ > -maxSpeedRotateUpDown_) 57 speedRotateUpDown_ -= accelerationRotateUpDown_ ;59 speedRotateUpDown_ -= accelerationRotateUpDown_*time; 58 60 if(speedRotateUpDown_ < -maxSpeedRotateUpDown_) 59 61 speedRotateUpDown_ = -maxSpeedRotateUpDown_; 60 62 } 61 else { 63 if(rotateUp_ == 0 && rotateDown_ == 0) { 64 accelerationRotateUpDown_ = brakeRotate_; 62 65 if(speedRotateUpDown_ > 0) 63 speedRotateUpDown_ -= accelerationRotateUpDown_ ;66 speedRotateUpDown_ -= accelerationRotateUpDown_*time; 64 67 if(speedRotateUpDown_ < 0) 65 speedRotateUpDown_ += accelerationRotateUpDown_ ;68 speedRotateUpDown_ += accelerationRotateUpDown_*time; 66 69 } 67 70 … … 69 72 accelerationRotateRightLeft_ = rotateRight_; 70 73 if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_) 71 speedRotateRightLeft_ -= accelerationRotateRightLeft_ ;74 speedRotateRightLeft_ -= accelerationRotateRightLeft_*time; 72 75 if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_) 73 76 speedRotateRightLeft_ = -maxSpeedRotateRightLeft_; 74 77 } 75 elseif(rotateLeft_ > 0) {78 if(rotateLeft_ > 0) { 76 79 accelerationRotateRightLeft_ = rotateLeft_; 77 80 if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_) 78 speedRotateRightLeft_ += accelerationRotateRightLeft_ ;81 speedRotateRightLeft_ += accelerationRotateRightLeft_*time; 79 82 if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_) 80 83 speedRotateRightLeft_ = maxSpeedRotateRightLeft_; 81 84 } 82 else { 85 if(rotateRight_ == 0 && rotateLeft_ == 0) { 86 accelerationRotateRightLeft_ = brakeRotate_; 83 87 if(speedRotateRightLeft_ > 0) 84 speedRotateRightLeft_ -= accelerationRotateRightLeft_ ;88 speedRotateRightLeft_ -= accelerationRotateRightLeft_*time; 85 89 if(speedRotateRightLeft_ < 0) 86 speedRotateRightLeft_ += accelerationRotateRightLeft_ ;90 speedRotateRightLeft_ += accelerationRotateRightLeft_*time; 87 91 } 88 92 … … 90 94 accelerationLoopRightLeft_ = loopRight_; 91 95 if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_) 92 speedLoopRightLeft_ += accelerationLoopRightLeft_ ;96 speedLoopRightLeft_ += accelerationLoopRightLeft_*time; 93 97 if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_) 94 98 speedLoopRightLeft_ = maxSpeedLoopRightLeft_; 95 99 } 96 elseif(loopLeft_ > 0) {100 if(loopLeft_ > 0) { 97 101 accelerationLoopRightLeft_ = loopLeft_; 98 102 if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_) 99 speedLoopRightLeft_ -= accelerationLoopRightLeft_ ;103 speedLoopRightLeft_ -= accelerationLoopRightLeft_*time; 100 104 if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_) 101 105 speedLoopRightLeft_ = -maxSpeedLoopRightLeft_; 102 106 } 103 else { 107 if(loopLeft_ == 0 && loopRight_ == 0) { 108 accelerationLoopRightLeft_ = brakeLoop_; 104 109 if(speedLoopRightLeft_ > 0) 105 speedLoopRightLeft_ -= accelerationLoopRightLeft_ ;110 speedLoopRightLeft_ -= accelerationLoopRightLeft_*time; 106 111 if(speedLoopRightLeft_ < 0) 107 speedLoopRightLeft_ += accelerationLoopRightLeft_ ;112 speedLoopRightLeft_ += accelerationLoopRightLeft_*time; 108 113 } 109 114 … … 123 128 void SpaceshipSteering::moveForward(float moveForward) { 124 129 moveForward_ = moveForward; 125 }126 127 void SpaceshipSteering::brake(float brake) {128 brake_ = brake;129 130 } 130 131 … … 153 154 } 154 155 156 void SpaceshipSteering::brakeForward(float brakeForward) { 157 brakeForward_ = brakeForward; 158 } 159 160 void SpaceshipSteering::brakeRotate(float brakeRotate) { 161 brakeRotate_ = brakeRotate; 162 } 163 164 void SpaceshipSteering::brakeLoop(float brakeLoop) { 165 brakeLoop_ = brakeLoop; 166 } 167 155 168 void SpaceshipSteering::maxSpeedForward(float maxSpeedForward) { 156 169 maxSpeedForward_ = maxSpeedForward; -
code/branches/steering/src/spaceship_steering.h
r209 r317 11 11 void tick(float time); 12 12 void moveForward(float moveForward); 13 void brake(float brake);14 13 void rotateUp(float rotateUp); 15 14 void rotateDown(float rotateDown); … … 18 17 void loopRight(float loopRight); 19 18 void loopLeft(float loopLeft); 19 void brakeForward(float brakeForward); 20 void brakeRotate(float brakeRotate); 21 void brakeLoop(float brakeLoop); 20 22 void maxSpeedForward(float maxSpeedForward); 21 23 void maxSpeedRotateUpDown(float maxSpeedRotateUpDown); … … 29 31 private: 30 32 float moveForward_; 31 float brake_;32 33 float rotateUp_; 33 34 float rotateDown_; … … 36 37 float loopRight_; 37 38 float loopLeft_; 39 float brakeForward_; 40 float brakeRotate_; 41 float brakeLoop_; 38 42 39 43 float speedForward_;
Note: See TracChangeset
for help on using the changeset viewer.