- Timestamp:
- Nov 3, 2007, 6:20:21 PM (17 years ago)
- Location:
- code/branches/main_reto
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto/include/orxonox_ship.h
r146 r152 39 39 { 40 40 public: 41 Vector3 speed;42 float thrust, sideThrust, baseThrust;43 Vector3 bulletSpeed;44 45 41 OrxonoxShip(SceneManager*, SceneNode*); 46 42 virtual ~OrxonoxShip(); … … 50 46 void setThrust(const Real); 51 47 void setSideThrust(const Real); 52 void setYaw(const Radian); 53 void setPitch(const Radian); 54 void setRoll(const Radian); 55 56 Real getThrust(); 48 void turnUpAndDown(const Radian&); 49 void turnLeftAndRight(const Radian&); 57 50 58 51 Bullet* fire(); … … 60 53 bool tick(unsigned long, Real); 61 54 62 SceneNode *mRootNode; 55 protected: 56 57 58 public: 59 63 60 64 61 protected: 65 SceneManager *mSceneMgr; 66 Entity *mShip; 62 SceneManager *SceneMgr_; 63 SceneNode *RootNode_; 64 Entity *ShipEntity_; 67 65 68 int n; 66 Vector3 currentSpeed_; 67 float CurrentThrust_; 68 float CurrentSideThrust_; 69 float baseThrust_; 70 int objectCounter_; 71 Vector3 bulletSpeed_; 69 72 70 73 }; -
code/branches/main_reto/include/run_manager.h
r146 r152 38 38 #include "orxonox_ship.h" 39 39 40 40 41 //Use this define to signify OIS will be used as a DLL 41 42 //(so that dll import/export macros are in effect) … … 55 56 virtual ~RunManager(); 56 57 57 virtual bool tick(unsigned long, float);58 virtual bool tick(unsigned long, Real); 58 59 59 60 protected: 60 OgreControl *mOgre;61 62 SceneManager *mSceneMgr;63 RenderWindow* mWindow;64 65 OrxonoxScene *mScene;66 Camera* mCamera;67 SceneNode *mShipNode;68 OrxonoxShip *mShip;69 70 bool mStatsOn;71 72 std::string mDebugText;73 74 unsigned int mNumScreenShots;75 // just to stop toggles flipping too fast76 Real mTimeUntilNextToggle ;77 TextureFilterOptions mFiltering;78 int mAniso;79 80 int mSceneDetailIndex ;81 Overlay* mDebugOverlay;82 83 //OIS Input devices84 OIS::InputManager* mInputManager;85 OIS::Mouse* mMouse;86 OIS::Keyboard* mKeyboard;87 OIS::JoyStick* mJoy;88 89 bool leftButtonDown;90 Bullet **mBullets;91 int mBulletsSize;92 int mBulletsPosition;93 94 // previously elapsed render time95 unsigned long mTime;96 97 61 virtual void createCamera(void); 98 62 … … 121 85 virtual void showDebugOverlay(bool); 122 86 87 protected: 88 OgreControl *ogre_; 89 SceneManager *sceneMgr_; 90 RenderWindow *window_; 91 OrxonoxScene *backgroundScene_; 92 Camera *camera_; 93 OrxonoxShip *playerShip_; 94 95 bool statsOn_; 96 std::string debugText_; 97 98 unsigned int screenShotCounter_; 99 // just to stop toggles flipping too fast 100 Real timeUntilNextToggle_; 101 bool leftButtonDown_; 102 TextureFilterOptions filtering_; 103 int aniso_; 104 105 int sceneDetailIndex_; 106 Overlay* debugOverlay_; 107 108 //OIS Input devices 109 OIS::InputManager* inputManager_; 110 OIS::Mouse* mouse_; 111 OIS::Keyboard* keyboard_; 112 OIS::JoyStick* joystick_; 113 114 // Bullet array 115 Bullet **bullets_; 116 int bulletsSize_; 117 int bulletsIndex_; 118 119 // previously elapsed render time 120 unsigned long totalTime_; 121 123 122 }; 124 123 -
code/branches/main_reto/src/orxonox_ship.cc
r147 r152 26 26 */ 27 27 28 /** 29 * Base class for any kind of flyable ship in Orxonox. 30 * 31 * The ship offers steering methods (like left, right, etc.) and translates 32 * them into movement. A ship can also hold more than one weapons (where each 33 * of these can be replaced during the game). This means that a ship can have 34 * many WeaponManagers but only one MunitionManager (independant object that 35 * is referenced in each WeaponManager). 36 * Furthermore a ship in Orxonox is responsible for its visualization, which is 37 * why it receives a pointer to the SceneManager. 38 */ 39 40 28 41 #include "orxonox_ship.h" 29 42 30 43 44 /** 45 * Standard constructor, that only initalizes a few variables. Some of them 46 * could be made static, since any new ship would be derived from the BaseShip. 47 * Or even better: write config files for each ship so that manipulating 48 * its properties would be even easier. 49 * @param mSceneMgr The current main SceneManager 50 * @param mNode The scene node which the ship will be attached to later. 51 */ 31 52 OrxonoxShip::OrxonoxShip(SceneManager *mSceneMgr, SceneNode *mNode) 32 53 : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)), … … 37 58 38 59 60 /** 61 * Standard destructor. 62 * Doesn't have any work to do yet. 63 */ 39 64 OrxonoxShip::~OrxonoxShip() 40 65 { … … 42 67 43 68 69 /** 70 * Initialises everything. 71 * Once that ResourceGroups are organised, this method loads them. 72 * It might be an idea to make this function static in order for the 73 * SceneManger to call the initialise method of every needed class (macros..) 74 */ 44 75 bool OrxonoxShip::initialise() 45 76 { … … 49 80 50 81 // create the "space ship" (currently a fish..) 51 // TODO: names must be unique! 82 // TODO: names must be unique! use static variables.. 52 83 mShip = mSceneMgr->createEntity("Ship", "fish.mesh"); 53 84 SceneNode *fishNode = mRootNode->createChildSceneNode("fishNode"); … … 60 91 61 92 93 /** 94 * Gets the ship to accelerate in the current direction. 95 * The value should be between 0 and 1, with one beeing full thrust and 0 none. 96 * @param value Acceleration between 0 and 1 97 */ 62 98 void OrxonoxShip::setThrust(const Real value) 63 99 { … … 66 102 67 103 104 /** 105 * Gets the ship to accelerate sideways regarding the current direction. 106 * The value should be between 0 and 1, with one beeing full thrust and 0 none. 107 * @param value Acceleration between 0 and 1 108 */ 68 109 void OrxonoxShip::setSideThrust(const Real value) 69 110 { … … 71 112 } 72 113 73 void OrxonoxShip::setYaw(const Radian value) 114 115 /** 116 * Rotate the ship along with the camera up and down. 117 * @param angle Pitch value. 118 */ 119 void OrxonoxShip::turnUpAndDown(const Radian &angle) 74 120 { 75 mRootNode->yaw(value);121 RootNode_->pitch(angle, Ogre::Node::TransformSpace::TS_LOCAL); 76 122 } 77 123 78 void OrxonoxShip::setPitch(const Radian value) 124 125 /** 126 * Rotate the ship along with the camera left and right. 127 * @param angle Yaw value. 128 */ 129 void OrxonoxShip::turnLeftAndRight(const Radian &angle) 79 130 { 80 mRootNode->pitch(value);131 RootNode_->yaw(angle, Ogre::Node::TransformSpace::TS_PARENT); 81 132 } 82 133 83 void OrxonoxShip::setRoll(const Radian value)84 {85 mRootNode->roll(value);86 }87 134 88 Real OrxonoxShip::getThrust() 89 { 90 return thrust; 91 } 92 135 /** 136 * Fire a bullet (Entity with SceneNode). 137 * This method creates a new Entity plus a SceneNode. But be sure not make 138 * the new Node a child of RootNode_! 139 */ 93 140 Bullet* OrxonoxShip::fire() 94 141 { 95 142 // TODO: Names must be unique! 96 SceneNode *temp = mRootNode->getParentSceneNode()->createChildSceneNode(97 "BulletNode" + StringConverter::toString( n));98 temp->setOrientation( mRootNode->getOrientation());99 temp->setPosition( mRootNode->getPosition());143 SceneNode *temp = RootNode_->getParentSceneNode()->createChildSceneNode( 144 "BulletNode" + StringConverter::toString(objectCounter_)); 145 temp->setOrientation(RootNode_->getOrientation()); 146 temp->setPosition(RootNode_->getPosition()); 100 147 temp->setScale(Vector3(1, 1, 1) * 10); 101 148 temp->yaw(Degree(-90)); 102 149 return new Bullet(temp, mSceneMgr->createEntity("bullet" 103 + StringConverter::toString( n++), "Barrel.mesh"), speed104 + ( mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy()105 * bulletSpeed );150 + StringConverter::toString(objectCounter_++), "Barrel.mesh"), speed 151 + (RootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy() 152 * bulletSpeed_); 106 153 } 107 154 155 156 /** 157 * Standard tick() function. 158 * Currently, only the speed is applied according to the thrust values. 159 * @param time Absolute time. 160 * @param deltaTime Relative time. 161 */ 108 162 bool OrxonoxShip::tick(unsigned long time, Real deltaTime) 109 163 { 110 164 Quaternion quad = mRootNode->getOrientation(); 111 165 quad.normalise(); 112 speed += quad * Vector3(0, 0, -1) * thrust* deltaTime;113 speed += quad * Vector3(-1, 0, 0) * sideThrust* deltaTime;166 speed += quad * Vector3(0, 0, -1) * currentThrust_ * deltaTime; 167 speed += quad * Vector3(-1, 0, 0) * current_SideThrust_ * deltaTime; 114 168 115 mRootNode->translate(speed* deltaTime);169 RootNode_->translate(currentSpeed_ * deltaTime); 116 170 117 171 return true; -
code/branches/main_reto/src/run_manager.cc
r146 r152 48 48 * 49 49 * 50 * @param mOgre The OgreControl object holding the render window and the Root 51 */ 52 RunManager::RunManager(OgreControl * mOgre, bool bufferedKeys, 53 bool bufferedMouse, bool bufferedJoy ) 54 : mOgre(mOgre), mWindow(mOgre->getRenderWindow()), leftButtonDown(false), 55 mStatsOn(true), mNumScreenShots(0), mTimeUntilNextToggle(0), 56 mFiltering(TFO_BILINEAR), mAniso(1), mSceneDetailIndex(0), 57 mDebugOverlay(0), mInputManager(0), mMouse(0), mKeyboard(0), mJoy(0) 50 * @param ogre_ The OgreControl object holding the render window and the Root 51 */ 52 RunManager::RunManager(OgreControl * ogre) 53 : ogre_(ogre), window_(ogre->getRenderWindow()), leftButtonDown_(false), 54 statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0), 55 filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0), 56 debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0) 58 57 { 59 58 … … 61 60 62 61 // create one new SceneManger 63 mSceneMgr = mOgre->getRoot()->createSceneManager(ST_GENERIC, "mScene");62 sceneMgr_ = ogre_->getRoot()->createSceneManager(ST_GENERIC, "backgroundScene_"); 64 63 65 64 // background scene (world objects, skybox, lights, etc.) 66 mScene = new OrxonoxScene(mSceneMgr);65 backgroundScene_ = new OrxonoxScene(sceneMgr_); 67 66 68 67 // PLAYER SPACESHIP 69 68 70 // create a steerable SceneNode (not derived!) object. The idea is that this 71 // object only receives the mouse and the keyboard input (not specifi keys, 72 // more like up, down, left, right, roll left, roll right, move down, 73 // move up). The steering class can then decide how to control the node for 74 // the spaceship. This gives a certain flexibility. 75 // It should also be considered, that this class should provide another Node 69 // Create a space ship object and its SceneNode. 70 // Some ideas about the steering: The ship should only receive events like 71 // up, down, left, right, roll left, roll right, move down, move up, etc). 72 // Multiple interpretations of these commands would make the game more 73 // but it also makes AI steering more difficult, since for every type of 74 // steering, new methods have to be written. 75 // --> clearly define how a space ship can fly (rolling?, conservation of 76 // impuls?, direct mouse sight steeering?, etc.) 77 // It should also be considered, that the ship should provide another Node 76 78 // for a camera to be attached (otherwise the spaceship in front of the 77 // would be very static, never moving at all. 78 mShipNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("ShipNode", 79 Vector3(20, 20, 20)); 80 81 // Construct a new spaceship and attach it to the node 82 mShip = new OrxonoxShip(mSceneMgr, mShipNode); 79 // would be very static, never moving at all). 80 81 // Construct a new spaceship and give it the node 82 playerShip_ = new OrxonoxShip(sceneMgr_, getRootSceneNode() 83 ->createChildSceneNode("ShipNode", Vector3(20, 20, 20))); 83 84 84 85 … … 87 88 // load all resources and create the entities by calling the initialise() 88 89 // methods for each object (don't initialise in the constructor!). 89 mScene->initialise();90 mShip->initialise();90 backgroundScene_->initialise(); 91 playerShip_->initialise(); 91 92 92 93 … … 109 110 110 111 // TODO: Use STL to make life easier. But it works this way too.. 111 mBullets= new Bullet*[10];112 mBulletsPosition= 0;113 mBulletsSize= 10;112 bullets_ = new Bullet*[10]; 113 bulletsIndex_ = 0; 114 bulletsSize_ = 10; 114 115 115 116 … … 118 119 using namespace OIS; 119 120 120 mDebugOverlay= OverlayManager::getSingleton()121 debugOverlay_ = OverlayManager::getSingleton() 121 122 .getByName("Core/DebugOverlay"); 122 123 … … 126 127 std::ostringstream windowHndStr; 127 128 128 mWindow->getCustomAttribute("WINDOW", &windowHnd);129 window_->getCustomAttribute("WINDOW", &windowHnd); 129 130 windowHndStr << windowHnd; 130 131 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 131 132 132 mInputManager= InputManager::createInputSystem( pl );133 inputManager_ = InputManager::createInputSystem( pl ); 133 134 134 135 // Create all devices (We only catch joystick exceptions here, 135 136 // as, most people have Key/Mouse) 136 mKeyboard = static_cast<Keyboard*>(mInputManager137 ->createInputObject( OISKeyboard, bufferedKeys));138 m Mouse = static_cast<Mouse*>(mInputManager139 ->createInputObject( OISMouse, bufferedMouse ));137 keyboard_ = static_cast<Keyboard*>(inputManager_ 138 ->createInputObject( OISKeyboard, false )); 139 mouse_ = static_cast<Mouse*>(inputManager_ 140 ->createInputObject( OISMouse, false )); 140 141 try { 141 mJoy = static_cast<JoyStick*>(mInputManager142 ->createInputObject( OISJoyStick, bufferedJoy));142 joystick_ = static_cast<JoyStick*>(inputManager_ 143 ->createInputObject( OISJoyStick, false )); 143 144 } 144 145 catch(...) { 145 mJoy= 0;146 joystick_ = 0; 146 147 } 147 148 148 149 //Set initial mouse clipping size 149 windowResized( mWindow);150 windowResized(window_); 150 151 151 152 showDebugOverlay(true); … … 153 154 // REGISTER THIS OBJECT AS A WINDOW EVENT LISTENER IN OGRE 154 155 // It will then receive events liek windowClosed, windowResized, etc. 155 WindowEventUtilities::addWindowEventListener( mWindow, this);156 WindowEventUtilities::addWindowEventListener(window_, this); 156 157 } 157 158 … … 164 165 { 165 166 //Remove ourself as a Window listener 166 WindowEventUtilities::removeWindowEventListener( mWindow, this);167 windowClosed( mWindow);168 169 if ( mScene)170 delete mScene;171 if ( mShip)172 delete mShip;167 WindowEventUtilities::removeWindowEventListener(window_, this); 168 windowClosed(window_); 169 170 if (backgroundScene_) 171 delete backgroundScene_; 172 if (playerShip_) 173 delete playerShip_; 173 174 174 175 // clean up the bullet list 175 for (int i = 0; i < mBulletsPosition; i++)176 delete mBullets[i];177 delete mBullets;176 for (int i = 0; i < bulletsIndex_; i++) 177 delete bullets_[i]; 178 delete bullets_; 178 179 } 179 180 … … 193 194 { 194 195 // synchronize with internal class timer 195 mTime= time;196 totalTime_ = time; 196 197 197 198 // Call tick() for every object 198 199 // This could be done by registering (needs a factory..) 199 mScene->tick(time, deltaTime);200 mShip->tick(time, deltaTime);200 backgroundScene_->tick(time, deltaTime); 201 playerShip_->tick(time, deltaTime); 201 202 202 203 … … 205 206 206 207 // update the bullet positions 207 for (int i = 0; i < mBulletsPosition; i++)208 { 209 mBullets[i]->mNode->translate(mBullets[i]->mSpeed*deltaTime);210 mBullets[i]->mNode->yaw(Degree(deltaTime*100));211 mBullets[i]->mNode->roll(Degree(deltaTime*300));208 for (int i = 0; i < bulletsIndex_; i++) 209 { 210 bullets_[i]->mNode->translate(bullets_[i]->mSpeed*deltaTime); 211 bullets_[i]->mNode->yaw(Degree(deltaTime*100)); 212 bullets_[i]->mNode->roll(Degree(deltaTime*300)); 212 213 } 213 214 … … 216 217 using namespace OIS; 217 218 218 if( mWindow->isClosed()) return false;219 if(window_->isClosed()) return false; 219 220 220 221 //Need to capture/update each device 221 mKeyboard->capture();222 m Mouse->capture();223 if( mJoy ) mJoy->capture();224 225 bool buffJ = ( mJoy) ? mJoy->buffered() : true;222 keyboard_->capture(); 223 mouse_->capture(); 224 if( joystick_ ) joystick_->capture(); 225 226 bool buffJ = (joystick_) ? joystick_->buffered() : true; 226 227 227 228 //Check if one of the devices is not buffered 228 if( !m Mouse->buffered() || !mKeyboard->buffered() || !buffJ )229 if( !mouse_->buffered() || !keyboard_->buffered() || !buffJ ) 229 230 { 230 231 // one of the input modes is immediate, so setup what 231 232 // is needed for immediate movement 232 if (mTimeUntilNextToggle >= 0) 233 mTimeUntilNextToggle -= deltaTime; 234 } 235 236 //Check to see which device is not buffered, and handle it 237 if( !mKeyboard->buffered() ) 238 if( processUnbufferedKeyInput() == false ) 233 if (timeUntilNextToggle_ >= 0) 234 timeUntilNextToggle_ -= deltaTime; 235 } 236 237 // handle HID devices 238 if( processUnbufferedKeyInput() == false ) 239 239 return false; 240 if( !mMouse->buffered() ) 241 if( processUnbufferedMouseInput() == false ) 240 if( processUnbufferedMouseInput() == false ) 242 241 return false; 243 242 … … 259 258 rw->getMetrics(width, height, depth, left, top); 260 259 261 const OIS::MouseState &ms = m Mouse->getMouseState();260 const OIS::MouseState &ms = mouse_->getMouseState(); 262 261 ms.width = width; 263 262 ms.height = height; … … 273 272 { 274 273 //Only close for window that created OIS (the main window in these demos) 275 if( rw == mWindow)276 { 277 if( mInputManager)274 if( rw == window_ ) 275 { 276 if( inputManager_ ) 278 277 { 279 mInputManager->destroyInputObject( mMouse);280 mInputManager->destroyInputObject( mKeyboard);281 mInputManager->destroyInputObject( mJoy);282 283 OIS::InputManager::destroyInputSystem( mInputManager);284 mInputManager= 0;278 inputManager_->destroyInputObject( mouse_ ); 279 inputManager_->destroyInputObject( keyboard_ ); 280 inputManager_->destroyInputObject( joystick_ ); 281 282 OIS::InputManager::destroyInputSystem(inputManager_); 283 inputManager_ = 0; 285 284 } 286 285 } … … 297 296 using namespace OIS; 298 297 299 if( mKeyboard->isKeyDown(KC_A) || mKeyboard->isKeyDown(KC_LEFT))300 mShip->setSideThrust(1);301 else if( mKeyboard->isKeyDown(KC_D) || mKeyboard->isKeyDown(KC_RIGHT))302 mShip->setSideThrust(-1);298 if(keyboard_->isKeyDown(KC_A) || keyboard_->isKeyDown(KC_LEFT)) 299 playerShip_->setSideThrust(1); 300 else if(keyboard_->isKeyDown(KC_D) || keyboard_->isKeyDown(KC_RIGHT)) 301 playerShip_->setSideThrust(-1); 303 302 else 304 mShip->setSideThrust(0);305 306 if( mKeyboard->isKeyDown(KC_UP) || mKeyboard->isKeyDown(KC_W) )307 mShip->setThrust(1);308 else if( mKeyboard->isKeyDown(KC_DOWN) || mKeyboard->isKeyDown(KC_S) )309 mShip->setThrust(-1);303 playerShip_->setSideThrust(0); 304 305 if(keyboard_->isKeyDown(KC_UP) || keyboard_->isKeyDown(KC_W) ) 306 playerShip_->setThrust(1); 307 else if(keyboard_->isKeyDown(KC_DOWN) || keyboard_->isKeyDown(KC_S) ) 308 playerShip_->setThrust(-1); 310 309 else 311 mShip->setThrust(0);312 313 if( mKeyboard->isKeyDown(KC_ESCAPE) || mKeyboard->isKeyDown(KC_Q) )310 playerShip_->setThrust(0); 311 312 if( keyboard_->isKeyDown(KC_ESCAPE) || keyboard_->isKeyDown(KC_Q) ) 314 313 return false; 315 314 316 if( mKeyboard->isKeyDown(KC_F) && mTimeUntilNextToggle<= 0 )317 { 318 mStatsOn = !mStatsOn;319 showDebugOverlay( mStatsOn);320 mTimeUntilNextToggle= 1;321 } 322 323 if( mKeyboard->isKeyDown(KC_T) && mTimeUntilNextToggle<= 0 )324 { 325 switch( mFiltering)315 if( keyboard_->isKeyDown(KC_F) && timeUntilNextToggle_ <= 0 ) 316 { 317 statsOn_ = !statsOn_; 318 showDebugOverlay(statsOn_); 319 timeUntilNextToggle_ = 1; 320 } 321 322 if( keyboard_->isKeyDown(KC_T) && timeUntilNextToggle_ <= 0 ) 323 { 324 switch(filtering_) 326 325 { 327 326 case TFO_BILINEAR: 328 mFiltering= TFO_TRILINEAR;329 mAniso= 1;327 filtering_ = TFO_TRILINEAR; 328 aniso_ = 1; 330 329 break; 331 330 case TFO_TRILINEAR: 332 mFiltering= TFO_ANISOTROPIC;333 mAniso= 8;331 filtering_ = TFO_ANISOTROPIC; 332 aniso_ = 8; 334 333 break; 335 334 case TFO_ANISOTROPIC: 336 mFiltering= TFO_BILINEAR;337 mAniso= 1;335 filtering_ = TFO_BILINEAR; 336 aniso_ = 1; 338 337 break; 339 338 default: break; 340 339 } 341 MaterialManager::getSingleton().setDefaultTextureFiltering( mFiltering);342 MaterialManager::getSingleton().setDefaultAnisotropy( mAniso);343 344 showDebugOverlay( mStatsOn);345 mTimeUntilNextToggle= 1;346 } 347 348 if( mKeyboard->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle<= 0)340 MaterialManager::getSingleton().setDefaultTextureFiltering(filtering_); 341 MaterialManager::getSingleton().setDefaultAnisotropy(aniso_); 342 343 showDebugOverlay(statsOn_); 344 timeUntilNextToggle_ = 1; 345 } 346 347 if(keyboard_->isKeyDown(KC_SYSRQ) && timeUntilNextToggle_ <= 0) 349 348 { 350 349 std::ostringstream ss; 351 ss << "screenshot_" << ++ mNumScreenShots<< ".png";352 mWindow->writeContentsToFile(ss.str());353 mTimeUntilNextToggle= 0.5;350 ss << "screenshot_" << ++screenShotCounter_ << ".png"; 351 window_->writeContentsToFile(ss.str()); 352 timeUntilNextToggle_ = 0.5; 354 353 mDebugText = "Saved: " + ss.str(); 355 354 } 356 355 357 if( mKeyboard->isKeyDown(KC_R) && mTimeUntilNextToggle<=0)358 { 359 mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;360 switch( mSceneDetailIndex) {361 case 0 : mCamera->setPolygonMode(PM_SOLID); break;362 case 1 : mCamera->setPolygonMode(PM_WIREFRAME); break;363 case 2 : mCamera->setPolygonMode(PM_POINTS); break;356 if(keyboard_->isKeyDown(KC_R) && timeUntilNextToggle_ <=0) 357 { 358 sceneDetailIndex_ = (sceneDetailIndex_+1)%3 ; 359 switch(sceneDetailIndex_) { 360 case 0 : camera_->setPolygonMode(PM_SOLID); break; 361 case 1 : camera_->setPolygonMode(PM_WIREFRAME); break; 362 case 2 : camera_->setPolygonMode(PM_POINTS); break; 364 363 } 365 mTimeUntilNextToggle= 0.5;364 timeUntilNextToggle_ = 0.5; 366 365 } 367 366 368 367 static bool displayCameraDetails = false; 369 if( mKeyboard->isKeyDown(KC_P) && mTimeUntilNextToggle<= 0)368 if(keyboard_->isKeyDown(KC_P) && timeUntilNextToggle_ <= 0) 370 369 { 371 370 displayCameraDetails = !displayCameraDetails; 372 mTimeUntilNextToggle= 0.5;371 timeUntilNextToggle_ = 0.5; 373 372 if (!displayCameraDetails) 374 373 mDebugText = ""; … … 377 376 // Print camera details 378 377 if(displayCameraDetails) 379 mDebugText = StringConverter::toString( mShip->getThrust())380 + " | Speed = " + StringConverter::toString( mShip->speed);381 // mDebugText = "P: " + StringConverter::toString( mCamera378 mDebugText = StringConverter::toString(playerShip_->getThrust()) 379 + " | Speed = " + StringConverter::toString(playerShip_->speed); 380 // mDebugText = "P: " + StringConverter::toString(camera_ 382 381 // ->getDerivedPosition()) + " " + "O: " 383 // + StringConverter::toString( mCamera->getDerivedOrientation());382 // + StringConverter::toString(camera_->getDerivedOrientation()); 384 383 385 384 // Return true to continue rendering … … 399 398 using namespace OIS; 400 399 401 const MouseState &ms = m Mouse->getMouseState();400 const MouseState &ms = mouse_->getMouseState(); 402 401 403 402 // This is a 'hack' to show some flying barrels.. 404 403 // Usually, the Bullet created by the ship should be managed 405 404 // by the physics engine.. 406 if (ms.buttonDown(MB_Left) && !leftButtonDown )405 if (ms.buttonDown(MB_Left) && !leftButtonDown_) 407 406 { 408 407 // Prevent continuous fire for the moment. 409 leftButtonDown = true;408 leftButtonDown_ = true; 410 409 411 410 // let ship fire one shot with its only weapon (Barrels..) 412 Bullet * mTempBullet = mShip->fire();411 Bullet *tempBullet = playerShip_->fire(); 413 412 414 413 // resize array if neccessary (double the size then) 415 if ( mBulletsPosition >= mBulletsSize)414 if (bulletsIndex_ >= bulletsSize_) 416 415 { 417 416 // redimension the array 418 Bullet ** mTempArray = new Bullet*[2*mBulletsSize];419 for (int i = 0; i < mBulletsSize; i++)420 mTempArray[i] = mBullets[i];421 mBulletsSize*= 2;422 delete mBullets;423 mBullets = mTempArray;417 Bullet **tempArray = new Bullet*[2*bulletsSize_]; 418 for (int i = 0; i < bulletsSize_; i++) 419 tempArray[i] = bullets_[i]; 420 bulletsSize_ *= 2; 421 delete bullets_; 422 bullets_ = tempArray; 424 423 } 425 424 426 425 // add the bullet to the list 427 mBullets[mBulletsPosition++] = mTempBullet;426 bullets_[bulletsIndex_++] = tempBullet; 428 427 429 428 } 430 429 else if (!ms.buttons) 431 leftButtonDown = false;430 leftButtonDown_ = false; 432 431 433 432 // space ship steering. This should definitely be done in the steering object 434 433 // Simply give it the mouse movements. 435 mShip->mRootNode->pitch(Degree(-ms.Y.rel * 0.13), Ogre::Node::TransformSpace::TS_LOCAL); 436 mShip->mRootNode->yaw(Degree(-ms.X.rel * 0.13), Ogre::Node::TransformSpace::TS_PARENT); 434 playerShip_->turnUpAndDown(Radian(ms.Y.rel * mouseSensitivity_)); 435 playerShip_->turnLeftAndRight(Radian(ms.X.rel * mousSensitivity_)); 436 //playerShip_->mRootNode->pitch(Degree(-ms.Y.rel * 0.13), Ogre::Node::TransformSpace::TS_LOCAL); 437 //playerShip_->mRootNode->yaw(Degree(-ms.X.rel * 0.13), Ogre::Node::TransformSpace::TS_PARENT); 437 438 438 439 // keep rendering … … 446 447 void RunManager::showDebugOverlay(bool show) 447 448 { 448 if ( mDebugOverlay)449 if (debugOverlay_) 449 450 { 450 451 if (show) 451 mDebugOverlay->show();452 debugOverlay_->show(); 452 453 else 453 mDebugOverlay->hide();454 debugOverlay_->hide(); 454 455 } 455 456 } … … 480 481 .getOverlayElement("Core/WorstFps"); 481 482 482 const RenderTarget::FrameStats& stats = mWindow->getStatistics();483 const RenderTarget::FrameStats& stats = window_->getStatistics(); 483 484 guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 484 485 guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); … … 508 509 /** 509 510 * Simple camera creator. 510 * mShipNode->attachObject(mCamera) should no be here! This is what the camera511 * playerShip_Node->attachObject(camera_) should no be here! This is what the camera 511 512 * manager is for. Right now, this method should do just fine, setting the 512 513 * cam behind the ship. … … 514 515 void RunManager::createCamera(void) 515 516 { 516 mCamera = mSceneMgr->createCamera("PlayerCam");517 mShipNode->attachObject(mCamera);518 mCamera->setNearClipDistance(5);519 mCamera->setPosition(Vector3(0,10,500));520 mCamera->lookAt(Vector3(0,0,0));517 camera_ = sceneMgr_->createCamera("PlayerCam"); 518 playerShip_Node->attachObject(camera_); 519 camera_->setNearClipDistance(5); 520 camera_->setPosition(Vector3(0,10,500)); 521 camera_->lookAtVector3(0,0,0)); 521 522 } 522 523 … … 531 532 { 532 533 // Create one viewport, entire window 533 Viewport* vp = mWindow->addViewport(mCamera);534 Viewport* vp = window_->addViewport(camera_); 534 535 vp->setBackgroundColour(ColourValue(0,0,0)); 535 536 536 537 // Alter the camera aspect ratio to match the viewport 537 mCamera->setAspectRatio(538 camera_->setAspectRatio( 538 539 Real(vp->getActualWidth()) / Real(vp->getActualHeight())); 539 540 }
Note: See TracChangeset
for help on using the changeset viewer.