Changeset 159 for code/branches/main_reto_vs05/src
- Timestamp:
- Nov 3, 2007, 11:06:43 PM (17 years ago)
- Location:
- code/branches/main_reto_vs05/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/ogre_control.cc
r157 r159 26 26 */ 27 27 28 /** 29 * Ogre control class. 30 * This is merely a convenient way to handle Ogre. It only holds the Root 31 * object and the render Window. These are the objects, that are independant 32 * of the game state (playing, menu browsing, loading, etc.). 33 * This class could easily be merged into the Orxnox class. 34 */ 35 36 28 37 #include "ogre_control.h" 29 38 30 39 40 /** 41 * Provide support for mac users. 42 */ 31 43 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 32 44 // This function will locate the path to our application on OS X, … … 56 68 57 69 58 OgreControl::OgreControl() 59 { 60 mRoot = 0; 70 /** 71 * Constructor that determines the resource path platform dependant. 72 */ 73 OgreControl::OgreControl() : root_(0) 74 { 61 75 // Provide a nice cross platform solution for locating the configuration 62 76 // files. On windows files are searched for in the current working … … 64 78 // function macBundlePath does this for us. 65 79 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 66 mResourcePath= macBundlePath() + "/Contents/Resources/";80 resourcePath_ = macBundlePath() + "/Contents/Resources/"; 67 81 #else 68 mResourcePath = ""; 69 #endif 70 } 71 72 73 // standard destructor 82 resourcePath_ = ""; 83 #endif 84 } 85 86 87 /** 88 * Standard Destructor. 89 */ 74 90 OgreControl::~OgreControl() 75 91 { 76 if (mRoot) 77 delete mRoot; 78 } 79 80 81 /**------------- SETTING UP OGRE --------------**/ 82 92 if (root_) 93 delete root_; 94 } 95 96 97 /* Sets up Ogre. 98 * First, the Root object is being created, then the resources are defined 99 * (not loaded!). And last but not least, the render settings (like resolution 100 * or AA level) are prompted to the user. 101 */ 83 102 bool OgreControl::initialise(void) 84 103 { … … 86 105 // only use plugins.cfg if not static 87 106 #ifndef OGRE_STATIC_LIB 88 pluginsPath = mResourcePath+ "plugins.cfg";89 #endif 90 91 mRoot= new Root(pluginsPath,92 mResourcePath + "ogre.cfg", mResourcePath+ "Ogre.log");107 pluginsPath = resourcePath_ + "plugins.cfg"; 108 #endif 109 110 root_ = new Root(pluginsPath, 111 resourcePath_ + "ogre.cfg", resourcePath_ + "Ogre.log"); 93 112 94 113 setupResources(); … … 101 120 102 121 103 // Method which will define the source of resources 104 // (other than current folder) 122 /** 123 * Defines the source of the resources. 124 */ 105 125 void OgreControl::setupResources(void) 106 126 { 107 127 // Load resource paths from config file 108 128 ConfigFile cf; 109 cf.load( mResourcePath+ "resources.cfg");129 cf.load(resourcePath_ + "resources.cfg"); 110 130 111 131 // Go through all sections & settings in the file … … 137 157 138 158 159 /** 160 * Prompts a setting window for the render engine if that has not already 161 * been done. 162 * The method also calls the root initialiser in order to get a render window. 163 */ 139 164 bool OgreControl::configure(void) 140 165 { … … 142 167 // You can skip this and use root.restoreConfig() to load configuration 143 168 // settings if you were sure there are valid ones saved in ogre.cfg 144 if(! mRoot->restoreConfig() && !mRoot->showConfigDialog())169 if(!root_->restoreConfig() && !root_->showConfigDialog()) 145 170 return false; 146 171 … … 148 173 // Here we choose to let the system create a default 149 174 // rendering window by passing 'true' 150 mWindow = mRoot->initialise(true);151 mRoot->saveConfig();175 root_->saveConfig(); 176 window_ = root_->initialise(true); 152 177 return true; 153 178 } 154 179 155 180 181 /** 182 * Returns the root object. 183 * @return Root object. 184 */ 156 185 Root* OgreControl::getRoot(void) 157 186 { 158 return mRoot; 159 } 160 161 187 return root_; 188 } 189 190 191 /** 192 * Returns the render window. 193 * @return Render window. 194 */ 162 195 RenderWindow* OgreControl::getRenderWindow(void) 163 196 { 164 return mWindow; 165 } 166 167 197 return window_; 198 } 199 200 201 /** 202 * Returns the resource path. 203 * @return Resource path. 204 */ 168 205 Ogre::String OgreControl::getResourcePath(void) 169 206 { 170 return mResourcePath;171 } 207 return resourcePath_; 208 } -
code/branches/main_reto_vs05/src/orxonox.cc
r157 r159 26 26 */ 27 27 28 /** 29 * Basic part of the game. 30 * It sets up Ogre and most important of all: Orxonox is the master of the 31 * main loop and therefore time itself. 32 */ 33 28 34 29 35 #include "orxonox.h" 30 36 31 37 38 /** 39 * Empty Constructor. 40 */ 41 Orxonox::Orxonox() 42 { 43 } 44 45 46 /** 47 * Empty Destructor. 48 */ 49 Orxonox::~Orxonox() 50 { 51 } 52 53 54 /** 55 * Starts and runs the game 56 */ 32 57 void Orxonox::go(void) 33 58 { … … 35 60 return; 36 61 37 mTimer= new Timer();62 timer_ = new Timer(); 38 63 39 unsigned long lastTime = mTimer->getMilliseconds();64 unsigned long lastTime = timer_->getMilliseconds(); 40 65 41 66 while (true) … … 44 69 WindowEventUtilities::messagePump(); 45 70 46 mOgre->getRoot()->renderOneFrame();71 ogre_->getRoot()->renderOneFrame(); 47 72 48 if (! mRunMgr->tick(mTimer->getMilliseconds(),49 ( mTimer->getMilliseconds() - lastTime) / 1000.0))73 if (!runMgr_->tick(timer_->getMilliseconds(), 74 (timer_->getMilliseconds() - lastTime) / 1000.0)) 50 75 break; 51 lastTime = mTimer->getMilliseconds();76 lastTime = timer_->getMilliseconds(); 52 77 } 53 78 … … 57 82 58 83 84 /** 85 * Create render engine, render window and the Run manager. 86 * @return False if failed. 87 */ 59 88 bool Orxonox::setup(void) 60 89 { 61 90 // create new 3D ogre render engine 62 mOgre= new OgreControl();63 mOgre->initialise();91 ogre_ = new OgreControl(); 92 ogre_->initialise(); 64 93 65 mRunMgr = new RunManager(mOgre);94 runMgr_ = new RunManager(ogre_); 66 95 67 96 return true; … … 69 98 70 99 100 /** 101 * Clean everything up. 102 */ 71 103 void Orxonox::destroy() 72 104 { 73 if ( mTimer)74 delete mTimer;75 if ( mRunMgr)76 delete mRunMgr;77 if ( mOgre)78 delete mOgre;105 if (timer_) 106 delete timer_; 107 if (runMgr_) 108 delete runMgr_; 109 if (ogre_) 110 delete ogre_; 79 111 } -
code/branches/main_reto_vs05/src/orxonox_scene.cc
r157 r159 26 26 */ 27 27 28 /** 29 * The orxonox scene includes everything running in the background like terrain, 30 * static figures, dangling lamp, etc. 31 */ 32 33 28 34 #include "orxonox_scene.h" 29 35 30 36 31 OrxonoxScene::OrxonoxScene(SceneManager *mSceneMgr) : mSceneMgr(mSceneMgr) 37 /** 38 * Empty Consructor except the initialiser list. 39 * @param sceneMgr The Scene Manager. 40 */ 41 OrxonoxScene::OrxonoxScene(SceneManager *sceneMgr) : sceneMgr_(sceneMgr) 32 42 { 33 43 } 34 44 35 45 /** 46 * Empty Destructor. 47 */ 36 48 OrxonoxScene::~OrxonoxScene() 37 49 { 38 50 } 39 51 40 52 /** 53 * Ogre initialisation method. 54 * This function is called by the Run Manager to load the neccessary recources 55 * and to create the scene. 56 * @return False if failed. 57 */ 41 58 bool OrxonoxScene::initialise() 42 59 { … … 44 61 loadResources(); 45 62 46 distance = 0;47 radius = 100;63 distance_ = 0; 64 radius_ = 100; 48 65 49 66 createScene(); … … 53 70 54 71 55 // method where you can perform resource group loading 56 // Must at least do 57 // ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 58 void OrxonoxScene::loadResources(void) 72 /** 73 * Resource loader. 74 * Currently, this method loads everything! TODO: If done this ugly, it should 75 * at least be in the Run Manager. 76 */ 77 void OrxonoxScene::loadResources() 59 78 { 60 79 // Initialise, parse scripts etc … … 63 82 64 83 65 // Currently just a test scene with an ogre head an a surrounding light 66 void OrxonoxScene::createScene(void) 84 /** 85 * Scene creation. 86 * Currently just a test scene with an ogre head an a surrounding light. 87 */ 88 void OrxonoxScene::createScene() 67 89 { 68 mSceneMgr->setAmbientLight(ColourValue(0.3,0.3,0.3));90 sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3)); 69 91 70 92 //create first entity 71 Entity *head = mSceneMgr->createEntity("head", "ogrehead.mesh");93 Entity *head = sceneMgr_->createEntity("head", "ogrehead.mesh"); 72 94 73 95 //create a scene node to attach the head to 74 SceneNode *node = mSceneMgr->getRootSceneNode()96 SceneNode *node = sceneMgr_->getRootSceneNode() 75 97 ->createChildSceneNode("OgreHeadNode", Vector3(0,0,0)); 76 98 //attach the ogre head … … 78 100 79 101 // set up skybox 80 mSceneMgr->setSkyBox(true, "Examples/SceneSkyBox2");102 sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox2"); 81 103 82 // set up one mLightsource83 mLight = mSceneMgr->createLight("Light1");84 mLight->setType(Light::LT_POINT);85 mLight->setPosition(Vector3(0, 0, 0));86 mLight->setDiffuseColour(1.0, 1.0, 1.0);87 mLight->setSpecularColour(1.0, 1.0, 1.0);104 // set up one light_ source 105 light_ = sceneMgr_->createLight("Light1"); 106 light_->setType(Light::LT_POINT); 107 light_->setPosition(Vector3(0, 0, 0)); 108 light_->setDiffuseColour(1.0, 1.0, 1.0); 109 light_->setSpecularColour(1.0, 1.0, 1.0); 88 110 89 111 //create billboard 90 bbs = mSceneMgr->createBillboardSet("bb", 1);91 bbs ->createBillboard(Vector3::ZERO, ColourValue(1.0, 1.0, 1.0));92 bbs ->setMaterialName("Examples/Flare");112 bbs_ = sceneMgr_->createBillboardSet("bb", 1); 113 bbs_->createBillboard(Vector3::ZERO, ColourValue(1.0, 1.0, 1.0)); 114 bbs_->setMaterialName("Examples/Flare"); 93 115 94 lightNode = mSceneMgr->getRootSceneNode()95 ->createChildSceneNode(" LightNode", Vector3(0, 100, 0));116 lightNode_ = sceneMgr_->getRootSceneNode() 117 ->createChildSceneNode("lightNode_", Vector3(0, 100, 0)); 96 118 97 lightNode ->attachObject(bbs);98 lightNode ->attachObject(mLight);119 lightNode_->attachObject(bbs_); 120 lightNode_->attachObject(light_); 99 121 } 100 122 101 123 102 // compute something between frames if neccessary 103 void OrxonoxScene::tick(unsigned long time, float deltaTime) 124 /** 125 * Compute something between frames if neccessary. 126 * @param time Absolute time. 127 * @param deltaTime Relative time. 128 * @return Return true to continue rendering. 129 */ 130 bool OrxonoxScene::tick(unsigned long time, Real deltaTime) 104 131 { 105 floatt = time/1000.0;132 Real t = time/1000.0; 106 133 107 lightNode ->setPosition(radius*sin(5*t), radius*cos(5*t), sin(1*t)*distance);134 lightNode_->setPosition(radius_*sin(5*t), radius_*cos(5*t), sin(1*t)*distance_); 108 135 109 mLight->setDiffuseColour(sin(1*t), sin(1*t + 2.09), sin(1*t + 2.09*2));110 mLight->setSpecularColour(sin(1*t), sin(1*t + 2.09), sin(1*t + 2.09*2));136 light_->setDiffuseColour(sin(1*t), sin(1*t + 2.09), sin(1*t + 2.09*2)); 137 light_->setSpecularColour(sin(1*t), sin(1*t + 2.09), sin(1*t + 2.09*2)); 111 138 112 bbs ->getBillboard(0)->setColour(ColourValue(sin(1*t),139 bbs_->getBillboard(0)->setColour(ColourValue(sin(1*t), 113 140 sin(1*t + 2.09), sin(1*t + 2.09*2))); 141 142 return true; 114 143 } -
code/branches/main_reto_vs05/src/orxonox_ship.cc
r157 r159 50 50 * @param mNode The scene node which the ship will be attached to later. 51 51 */ 52 OrxonoxShip::OrxonoxShip(SceneManager * mSceneMgr, SceneNode *mNode)53 : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)),54 baseThrust (1000), thrust(0), sideThrust(0), n(0),55 bulletSpeed(400)52 OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node) 53 : sceneMgr_(sceneMgr), rootNode_(node), currentSpeed_(Vector3(0, 0, 0)), 54 baseThrust_(1000), currentThrust_(Vector3::ZERO), 55 objectCounter_(0), bulletSpeed_(400) 56 56 { 57 57 } … … 72 72 * It might be an idea to make this function static in order for the 73 73 * SceneManger to call the initialise method of every needed class (macros..) 74 * @return Returns false when failed. 74 75 */ 75 76 bool OrxonoxShip::initialise() … … 81 82 // create the "space ship" (currently a fish..) 82 83 // TODO: names must be unique! use static variables.. 83 mShip = mSceneMgr->createEntity("Ship", "fish.mesh");84 SceneNode *fishNode = mRootNode->createChildSceneNode("fishNode");84 shipEntity_ = sceneMgr_->createEntity("Ship", "fish.mesh"); 85 SceneNode *fishNode = rootNode_->createChildSceneNode("fishNode"); 85 86 fishNode->yaw(Degree(-90)); 86 fishNode->attachObject( mShip);87 fishNode->attachObject(shipEntity_); 87 88 fishNode->setScale(Vector3(10, 10, 10)); 88 89 … … 96 97 * @param value Acceleration between 0 and 1 97 98 */ 98 void OrxonoxShip::setThrust(const Real value) 99 { 100 thrust = value * baseThrust; 99 void OrxonoxShip::setMainThrust(const Real value) 100 { 101 //currentThrust_ = value * baseThrust_; 102 currentThrust_.z = value * baseThrust_; 101 103 } 102 104 … … 109 111 void OrxonoxShip::setSideThrust(const Real value) 110 112 { 111 sideThrust = value * baseThrust; 113 //currentSideThrust_ = value * baseThrust_; 114 currentThrust_.x = value * baseThrust_; 115 } 116 117 118 /** 119 * Gets the ship to accelerate up and down. 120 * The value should be between 0 and 1, with one beeing full thrust and 0 none. 121 * @param value Acceleration between 0 and 1 122 */ 123 void OrxonoxShip::setYThrust(const Real value) 124 { 125 //currentYThrust_ = value * baseThrust_; 126 currentThrust_.y = value * baseThrust_; 112 127 } 113 128 … … 119 134 void OrxonoxShip::turnUpAndDown(const Radian &angle) 120 135 { 121 RootNode_->pitch(angle, Ogre::Node::TransformSpace::TS_LOCAL);136 rootNode_->pitch(-angle, Node::TS_LOCAL); 122 137 } 123 138 … … 129 144 void OrxonoxShip::turnLeftAndRight(const Radian &angle) 130 145 { 131 RootNode_->yaw(angle, Ogre::Node::TransformSpace::TS_PARENT); 146 rootNode_->yaw(-angle, Node::TS_PARENT); 147 } 148 149 150 /** 151 * Returns the current speed of the ship according to its parent node. 152 * @return The current speed. 153 */ 154 Vector3 OrxonoxShip::getSpeed() 155 { 156 return currentSpeed_; 157 } 158 159 /** 160 * Returns the ship's root SceneNode. 161 * @return The Root Node. 162 */ 163 SceneNode* OrxonoxShip::getRootNode() 164 { 165 return rootNode_; 132 166 } 133 167 … … 137 171 * This method creates a new Entity plus a SceneNode. But be sure not make 138 172 * the new Node a child of RootNode_! 173 * @return Bullet containing speed and entity. 139 174 */ 140 175 Bullet* OrxonoxShip::fire() 141 176 { 142 177 // TODO: Names must be unique! 143 SceneNode *temp = RootNode_->getParentSceneNode()->createChildSceneNode(178 SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode( 144 179 "BulletNode" + StringConverter::toString(objectCounter_)); 145 temp->setOrientation( RootNode_->getOrientation());146 temp->setPosition( RootNode_->getPosition());180 temp->setOrientation(rootNode_->getOrientation()); 181 temp->setPosition(rootNode_->getPosition()); 147 182 temp->setScale(Vector3(1, 1, 1) * 10); 148 183 temp->yaw(Degree(-90)); 149 return new Bullet(temp, mSceneMgr->createEntity("bullet"150 + StringConverter::toString(objectCounter_++), "Barrel.mesh"), speed151 + ( RootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy()184 return new Bullet(temp, sceneMgr_->createEntity("bullet" 185 + StringConverter::toString(objectCounter_++), "Barrel.mesh"), currentSpeed_ 186 + (rootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy() 152 187 * bulletSpeed_); 153 188 } … … 159 194 * @param time Absolute time. 160 195 * @param deltaTime Relative time. 196 * @return Return true to continue render 161 197 */ 162 198 bool OrxonoxShip::tick(unsigned long time, Real deltaTime) 163 199 { 164 Quaternion quad = mRootNode->getOrientation();200 Quaternion quad = rootNode_->getOrientation(); 165 201 quad.normalise(); 166 speed += quad * Vector3(0, 0, -1) * currentThrust_ * deltaTime; 167 speed += quad * Vector3(-1, 0, 0) * current_SideThrust_ * deltaTime; 168 169 RootNode_->translate(currentSpeed_ * deltaTime); 202 currentSpeed_ += quad * (Vector3(-1, -1, -1) * currentThrust_) * deltaTime; 203 //currentSpeed_ += quad * Vector3(0, 0, -1) * currentThrust_ * deltaTime; 204 //currentSpeed_ += quad * Vector3(-1, 0, 0) * currentSideThrust_ * deltaTime; 205 206 rootNode_->translate(currentSpeed_ * deltaTime); 170 207 171 208 return true; -
code/branches/main_reto_vs05/src/run_manager.cc
r157 r159 54 54 statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0), 55 55 filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0), 56 mouseSensitivity_(0.003), 56 57 debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0) 57 58 { … … 80 81 81 82 // Construct a new spaceship and give it the node 82 playerShip_ = new OrxonoxShip(sceneMgr_, getRootSceneNode()83 playerShip_ = new OrxonoxShip(sceneMgr_, sceneMgr_->getRootSceneNode() 83 84 ->createChildSceneNode("ShipNode", Vector3(20, 20, 20))); 84 85 … … 304 305 305 306 if(keyboard_->isKeyDown(KC_UP) || keyboard_->isKeyDown(KC_W) ) 306 playerShip_->set Thrust(1);307 playerShip_->setMainThrust(1); 307 308 else if(keyboard_->isKeyDown(KC_DOWN) || keyboard_->isKeyDown(KC_S) ) 308 playerShip_->set Thrust(-1);309 playerShip_->setMainThrust(-1); 309 310 else 310 playerShip_->setThrust(0); 311 playerShip_->setMainThrust(0); 312 313 if (keyboard_->isKeyDown(KC_C)) 314 playerShip_->setYThrust(1); 315 else if (keyboard_->isKeyDown(KC_SPACE)) 316 playerShip_->setYThrust(-1); 317 else 318 playerShip_->setYThrust(0); 311 319 312 320 if( keyboard_->isKeyDown(KC_ESCAPE) || keyboard_->isKeyDown(KC_Q) ) … … 351 359 window_->writeContentsToFile(ss.str()); 352 360 timeUntilNextToggle_ = 0.5; 353 mDebugText= "Saved: " + ss.str();361 debugText_ = "Saved: " + ss.str(); 354 362 } 355 363 … … 371 379 timeUntilNextToggle_ = 0.5; 372 380 if (!displayCameraDetails) 373 mDebugText= "";381 debugText_ = ""; 374 382 } 375 383 376 384 // Print camera details 377 385 if(displayCameraDetails) 378 mDebugText = StringConverter::toString(playerShip_->getThrust())379 + " | Speed = " + StringConverter::toString(playerShip_->speed);380 // mDebugText= "P: " + StringConverter::toString(camera_386 debugText_ = " | Speed = " 387 + StringConverter::toString(playerShip_->getSpeed()); 388 // debugText_ = "P: " + StringConverter::toString(camera_ 381 389 // ->getDerivedPosition()) + " " + "O: " 382 390 // + StringConverter::toString(camera_->getDerivedOrientation()); … … 433 441 // Simply give it the mouse movements. 434 442 playerShip_->turnUpAndDown(Radian(ms.Y.rel * mouseSensitivity_)); 435 playerShip_->turnLeftAndRight(Radian(ms.X.rel * mous Sensitivity_));443 playerShip_->turnLeftAndRight(Radian(ms.X.rel * mouseSensitivity_)); 436 444 //playerShip_->mRootNode->pitch(Degree(-ms.Y.rel * 0.13), Ogre::Node::TransformSpace::TS_LOCAL); 437 445 //playerShip_->mRootNode->yaw(Degree(-ms.X.rel * 0.13), Ogre::Node::TransformSpace::TS_PARENT); … … 500 508 OverlayElement* guiDbg = OverlayManager::getSingleton() 501 509 .getOverlayElement("Core/DebugText"); 502 guiDbg->setCaption( mDebugText);510 guiDbg->setCaption(debugText_); 503 511 } 504 512 catch(...) { /* ignore */ } … … 516 524 { 517 525 camera_ = sceneMgr_->createCamera("PlayerCam"); 518 playerShip_ Node->attachObject(camera_);526 playerShip_->getRootNode()->attachObject(camera_); 519 527 camera_->setNearClipDistance(5); 520 528 camera_->setPosition(Vector3(0,10,500)); 521 camera_->lookAt Vector3(0,0,0));529 camera_->lookAt(Vector3(0,0,0)); 522 530 } 523 531
Note: See TracChangeset
for help on using the changeset viewer.