Changeset 321
- Timestamp:
- Nov 28, 2007, 3:55:58 PM (17 years ago)
- Location:
- code/branches/merger/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merger/src/orxonox.cc
r320 r321 76 76 } 77 77 #endif 78 79 78 80 79 using namespace Ogre; … … 311 310 312 311 313 void setupScene()314 {315 // <<<<<<< .working316 // Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");317 // Ogre::Camera *cam = mgr->createCamera("Camera");318 // Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);319 // =======320 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));321 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true));322 323 }324 325 312 void setupInputSystem() 326 313 { … … 384 371 try 385 372 { 386 orxonox::OrxApplication orxonox;373 OrxApplication orxonox; 387 374 orxonox.go(); 388 375 } -
code/branches/merger/src/orxonox/orxonox.cc
r304 r321 41 41 #include "xml/xmlParser.h" 42 42 #include "loader/LevelLoader.h" 43 44 #include "spaceship_steering.h" 45 SpaceshipSteering* steering; 43 46 44 47 … … 76 79 namespace orxonox 77 80 { 78 class OrxExitListener : public Ogre::FrameListener 79 { 80 public: 81 OrxExitListener(OIS::Keyboard *keyboard) 82 : mKeyboard(keyboard) 83 { 84 } 85 86 bool frameStarted(const Ogre::FrameEvent& evt) 87 { 88 mKeyboard->capture(); 89 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 90 } 91 92 private: 93 OIS::Keyboard *mKeyboard; 94 }; 81 82 using namespace Ogre; 83 84 class OrxExitListener : public FrameListener, public OIS::MouseListener 85 { 86 public: 87 OrxExitListener(OIS::Keyboard *keyboard, OIS::Mouse *mouse) 88 : mKeyboard(keyboard), mMouse(mouse) 89 { 90 speed = 250; 91 loop = 100; 92 rotate = 10; 93 mouseX = 0; 94 mouseY = 0; 95 maxMouseX = 0; 96 minMouseX = 0; 97 moved = false; 98 steering->brakeRotate(rotate*10); 99 steering->brakeLoop(loop); 100 mMouse->setEventCallback(this); 101 } 102 bool frameStarted(const FrameEvent& evt) 103 { 104 mKeyboard->capture(); 105 mMouse->capture(); 106 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 107 steering->moveForward(speed); 108 else 109 steering->moveForward(0); 110 if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) 111 steering->brakeForward(speed); 112 else 113 steering->brakeForward(speed/10); 114 if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) 115 steering->loopRight(loop); 116 else 117 steering->loopRight(0); 118 if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) 119 steering->loopLeft(loop); 120 else 121 steering->loopLeft(0); 122 123 if(moved) { 124 if (mouseY<0) 125 steering->rotateUp(-mouseY*rotate); 126 if (mouseY>0) 127 steering->rotateDown(mouseY*rotate); 128 if (mouseX>0) 129 steering->rotateRight(mouseX*rotate); 130 if (mouseX<0) 131 steering->rotateLeft(-mouseX*rotate); 132 moved = false; 133 } 134 else { 135 steering->rotateUp(0); 136 steering->rotateDown(0); 137 steering->rotateRight(0); 138 steering->rotateLeft(0); 139 } 140 141 steering->tick(evt.timeSinceLastFrame); 142 // scenemanager->spacehip->tick(evt.timesincelastframe); 143 if(mKeyboard->isKeyDown(OIS::KC_ESCAPE)) 144 cout << "maximal MouseX: " << maxMouseX << "\tminMouseX: " << minMouseX << endl; 145 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 146 } 147 148 bool mouseMoved(const OIS::MouseEvent &e) 149 { 150 mouseX = e.state.X.rel; 151 mouseY = e.state.Y.rel; 152 if(mouseX>maxMouseX) maxMouseX = mouseX; 153 if(mouseX<minMouseX) minMouseX = mouseX; 154 cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl; 155 moved = true; 156 return true; 157 } 158 159 bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } 160 bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } 161 162 private: 163 float speed; 164 float rotate; 165 float loop; 166 float mouseY; 167 float mouseX; 168 float maxMouseX; 169 float minMouseX; 170 bool moved; 171 OIS::Keyboard *mKeyboard; 172 OIS::Mouse *mMouse; 173 }; 174 95 175 96 176 class OrxApplication … … 174 254 { 175 255 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) 176 throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");256 throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); 177 257 } 178 258 … … 184 264 void initializeResourceGroups() 185 265 { 186 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);187 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();266 TextureManager::getSingleton().setDefaultNumMipmaps(5); 267 ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 188 268 } 189 269 … … 191 271 { 192 272 193 string levelFile = "sp_level_moonstation.oxw"; 194 loader::LevelLoader* loader = new loader::LevelLoader(levelFile); 195 } 196 197 void setupScene() 198 { 199 Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 200 Ogre::Camera *cam = mgr->createCamera("Camera"); 201 Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 202 } 273 string levelFile = "sp_level_moonstation.oxw"; 274 loader::LevelLoader* loader = new loader::LevelLoader(levelFile); 275 } 276 277 void setupScene() 278 { 279 SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager"); 280 Camera *cam = mgr->createCamera("Camera"); 281 cam->setPosition(Vector3(0,0,-250)); 282 cam->lookAt(Vector3(0,0,0)); 283 Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 284 285 286 mgr->setAmbientLight(ColourValue(1,1,1)); 287 Entity* head = mgr->createEntity("head", "ogrehead.mesh"); 288 SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode", Vector3(0,0,0)); 289 node->attachObject(head); 290 node->attachObject(cam); 291 mgr->setSkyBox(true, "Examples/SceneSkyBox2"); 292 293 Entity* head1 = mgr->createEntity("head1", "ogrehead.mesh"); 294 SceneNode *node1 = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode1", Vector3(200,0,0)); 295 node1->attachObject(head1); 296 Entity* head2 = mgr->createEntity("head2", "ogrehead.mesh"); 297 SceneNode *node2 = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode2", Vector3(200,400,-100)); 298 node2->attachObject(head2); 299 Entity* head3 = mgr->createEntity("head3", "ogrehead.mesh"); 300 SceneNode *node3 = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode3", Vector3(0,400,200)); 301 node3->attachObject(head3); 302 Entity* head4 = mgr->createEntity("head4", "ogrehead.mesh"); 303 SceneNode *node4 = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode4", Vector3(-400,-200,600)); 304 node4->attachObject(head4); 305 Entity* head5 = mgr->createEntity("head5", "ogrehead.mesh"); 306 SceneNode *node5 = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode5", Vector3(0,0,-400)); 307 node5->attachObject(head5); 308 309 steering = new SpaceshipSteering(500, 200, 200, 200); 310 steering->addNode(node); 311 312 } 313 203 314 204 315 void setupInputSystem() … … 237 348 } 238 349 239 void createFrameListener() 240 {241 mListener = new OrxExitListener(mKeyboard);242 mRoot->addFrameListener(mListener);243 }244 350 351 void createFrameListener() 352 { 353 mListener = new OrxExitListener(mKeyboard, mMouse); 354 mRoot->addFrameListener(mListener); 355 } 245 356 void startRenderLoop() 246 357 {
Note: See TracChangeset
for help on using the changeset viewer.