Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 3, 2007, 11:06:43 PM (17 years ago)
Author:
rgrieder
Message:
 
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  
    2626 */
    2727
     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
    2837#include "ogre_control.h"
    2938
    3039
     40/**
     41* Provide support for mac users.
     42*/
    3143#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    3244// This function will locate the path to our application on OS X,
     
    5668
    5769
    58 OgreControl::OgreControl()
    59 {
    60         mRoot = 0;
     70/**
     71* Constructor that determines the resource path platform dependant.
     72*/
     73OgreControl::OgreControl() : root_(0)
     74{
    6175        // Provide a nice cross platform solution for locating the configuration
    6276        // files. On windows files are searched for in the current working
     
    6478  // function macBundlePath does this for us.
    6579#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    66         mResourcePath = macBundlePath() + "/Contents/Resources/";
     80        resourcePath_ = macBundlePath() + "/Contents/Resources/";
    6781#else
    68         mResourcePath = "";
    69 #endif
    70 }
    71 
    72 
    73 // standard destructor
     82        resourcePath_ = "";
     83#endif
     84}
     85
     86
     87/**
     88* Standard Destructor.
     89*/
    7490OgreControl::~OgreControl()
    7591{
    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*/
    83102bool OgreControl::initialise(void)
    84103{
     
    86105        // only use plugins.cfg if not static
    87106#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");
    93112
    94113        setupResources();
     
    101120
    102121
    103 // Method which will define the source of resources
    104 // (other than current folder)
     122/**
     123* Defines the source of the resources.
     124*/
    105125void OgreControl::setupResources(void)
    106126{
    107127        // Load resource paths from config file
    108128        ConfigFile cf;
    109         cf.load(mResourcePath + "resources.cfg");
     129        cf.load(resourcePath_ + "resources.cfg");
    110130
    111131        // Go through all sections & settings in the file
     
    137157
    138158
     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*/
    139164bool OgreControl::configure(void)
    140165{
     
    142167        // You can skip this and use root.restoreConfig() to load configuration
    143168        // 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())
    145170                return false;
    146171
     
    148173        // Here we choose to let the system create a default
    149174  // rendering window by passing 'true'
    150         mWindow = mRoot->initialise(true);
    151         mRoot->saveConfig();
     175        root_->saveConfig();
     176        window_ = root_->initialise(true);
    152177        return true;
    153178}
    154179
    155180
     181/**
     182* Returns the root object.
     183* @return Root object.
     184*/
    156185Root* OgreControl::getRoot(void)
    157186{
    158         return mRoot;
    159 }
    160 
    161 
     187        return root_;
     188}
     189
     190
     191/**
     192* Returns the render window.
     193* @return Render window.
     194*/
    162195RenderWindow* OgreControl::getRenderWindow(void)
    163196{
    164         return mWindow;
    165 }
    166 
    167 
     197        return window_;
     198}
     199
     200
     201/**
     202* Returns the resource path.
     203* @return Resource path.
     204*/
    168205Ogre::String OgreControl::getResourcePath(void)
    169206{
    170         return mResourcePath;
    171 }
     207        return resourcePath_;
     208}
  • code/branches/main_reto_vs05/src/orxonox.cc

    r157 r159  
    2626 */
    2727
     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
    2834
    2935#include "orxonox.h"
    3036
    3137
     38/**
     39* Empty Constructor.
     40*/
     41Orxonox::Orxonox()
     42{
     43}
     44
     45
     46/**
     47* Empty Destructor.
     48*/
     49Orxonox::~Orxonox()
     50{
     51}
     52
     53
     54/**
     55* Starts and runs the game
     56*/
    3257void Orxonox::go(void)
    3358{
     
    3560                return;
    3661
    37         mTimer = new Timer();
     62        timer_ = new Timer();
    3863
    39         unsigned long lastTime = mTimer->getMilliseconds();
     64        unsigned long lastTime = timer_->getMilliseconds();
    4065
    4166        while (true)
     
    4469                WindowEventUtilities::messagePump();
    4570
    46                 mOgre->getRoot()->renderOneFrame();
     71                ogre_->getRoot()->renderOneFrame();
    4772
    48                 if (!mRunMgr->tick(mTimer->getMilliseconds(),
    49             (mTimer->getMilliseconds() - lastTime) / 1000.0))
     73                if (!runMgr_->tick(timer_->getMilliseconds(),
     74            (timer_->getMilliseconds() - lastTime) / 1000.0))
    5075                        break;
    51                 lastTime = mTimer->getMilliseconds();
     76                lastTime = timer_->getMilliseconds();
    5277        }
    5378
     
    5782
    5883
     84/**
     85* Create render engine, render window and the Run manager.
     86* @return False if failed.
     87*/
    5988bool Orxonox::setup(void)
    6089{
    6190        // create new 3D ogre render engine
    62         mOgre = new OgreControl();
    63         mOgre->initialise();
     91        ogre_ = new OgreControl();
     92        ogre_->initialise();
    6493
    65         mRunMgr = new RunManager(mOgre);
     94        runMgr_ = new RunManager(ogre_);
    6695
    6796        return true;
     
    6998
    7099
     100/**
     101* Clean everything up.
     102*/
    71103void Orxonox::destroy()
    72104{
    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_;
    79111}
  • code/branches/main_reto_vs05/src/orxonox_scene.cc

    r157 r159  
    2626 */
    2727
     28/**
     29* The orxonox scene includes everything running in the background like terrain,
     30* static figures, dangling lamp, etc.
     31*/
     32
     33
    2834#include "orxonox_scene.h"
    2935
    3036
    31 OrxonoxScene::OrxonoxScene(SceneManager *mSceneMgr) : mSceneMgr(mSceneMgr)
     37/**
     38* Empty Consructor except the initialiser list.
     39* @param sceneMgr The Scene Manager.
     40*/
     41OrxonoxScene::OrxonoxScene(SceneManager *sceneMgr) : sceneMgr_(sceneMgr)
    3242{
    3343}
    3444
    35 
     45/**
     46* Empty Destructor.
     47*/
    3648OrxonoxScene::~OrxonoxScene()
    3749{
    3850}
    3951
    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*/
    4158bool OrxonoxScene::initialise()
    4259{
     
    4461        loadResources();
    4562
    46         distance = 0;
    47         radius = 100;
     63        distance_ = 0;
     64        radius_ = 100;
    4865
    4966        createScene();
     
    5370
    5471
    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*/
     77void OrxonoxScene::loadResources()
    5978{
    6079        // Initialise, parse scripts etc
     
    6382
    6483
    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*/
     88void OrxonoxScene::createScene()
    6789{
    68         mSceneMgr->setAmbientLight(ColourValue(0.3,0.3,0.3));
     90        sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3));
    6991
    7092        //create first entity
    71         Entity *head = mSceneMgr->createEntity("head", "ogrehead.mesh");
     93        Entity *head = sceneMgr_->createEntity("head", "ogrehead.mesh");
    7294
    7395        //create a scene node to attach the head to
    74         SceneNode *node = mSceneMgr->getRootSceneNode()
     96        SceneNode *node = sceneMgr_->getRootSceneNode()
    7597        ->createChildSceneNode("OgreHeadNode", Vector3(0,0,0));
    7698        //attach the ogre head
     
    78100
    79101        // set up skybox
    80         mSceneMgr->setSkyBox(true, "Examples/SceneSkyBox2");
     102        sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox2");
    81103
    82         // set up one mLight source
    83         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);
    88110
    89111        //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");
    93115
    94         lightNode = mSceneMgr->getRootSceneNode()
    95         ->createChildSceneNode("LightNode", Vector3(0, 100, 0));
     116        lightNode_ = sceneMgr_->getRootSceneNode()
     117        ->createChildSceneNode("lightNode_", Vector3(0, 100, 0));
    96118
    97         lightNode->attachObject(bbs);
    98         lightNode->attachObject(mLight);
     119        lightNode_->attachObject(bbs_);
     120        lightNode_->attachObject(light_);
    99121}
    100122
    101123
    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*/
     130bool OrxonoxScene::tick(unsigned long time, Real deltaTime)
    104131{
    105         float t = time/1000.0;
     132        Real t = time/1000.0;
    106133
    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_);
    108135       
    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));
    111138
    112         bbs->getBillboard(0)->setColour(ColourValue(sin(1*t),
     139        bbs_->getBillboard(0)->setColour(ColourValue(sin(1*t),
    113140        sin(1*t + 2.09), sin(1*t + 2.09*2)));
     141 
     142  return true;
    114143}
  • code/branches/main_reto_vs05/src/orxonox_ship.cc

    r157 r159  
    5050* @param mNode The scene node which the ship will be attached to later.
    5151*/
    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)
     52OrxonoxShip::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)
    5656{
    5757}
     
    7272* It might be an idea to make this function static in order for the
    7373* SceneManger to call the initialise method of every needed class (macros..)
     74* @return Returns false when failed.
    7475*/
    7576bool OrxonoxShip::initialise()
     
    8182        // create the "space ship" (currently a fish..)
    8283        // 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");
    8586        fishNode->yaw(Degree(-90));
    86         fishNode->attachObject(mShip);
     87        fishNode->attachObject(shipEntity_);
    8788        fishNode->setScale(Vector3(10, 10, 10));
    8889
     
    9697* @param value Acceleration between 0 and 1
    9798*/
    98 void OrxonoxShip::setThrust(const Real value)
    99 {
    100         thrust = value * baseThrust;
     99void OrxonoxShip::setMainThrust(const Real value)
     100{
     101        //currentThrust_ = value * baseThrust_;
     102  currentThrust_.z = value * baseThrust_;
    101103}
    102104
     
    109111void OrxonoxShip::setSideThrust(const Real value)
    110112{
    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*/
     123void OrxonoxShip::setYThrust(const Real value)
     124{
     125  //currentYThrust_ = value * baseThrust_;
     126  currentThrust_.y = value * baseThrust_;
    112127}
    113128
     
    119134void OrxonoxShip::turnUpAndDown(const Radian &angle)
    120135{
    121   RootNode_->pitch(angle, Ogre::Node::TransformSpace::TS_LOCAL);
     136  rootNode_->pitch(-angle, Node::TS_LOCAL);
    122137}
    123138
     
    129144void OrxonoxShip::turnLeftAndRight(const Radian &angle)
    130145{
    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*/
     154Vector3 OrxonoxShip::getSpeed()
     155{
     156  return currentSpeed_;
     157}
     158
     159/**
     160* Returns the ship's root SceneNode.
     161* @return The Root Node.
     162*/
     163SceneNode* OrxonoxShip::getRootNode()
     164{
     165  return rootNode_;
    132166}
    133167
     
    137171* This method creates a new Entity plus a SceneNode. But be sure not make
    138172* the new Node a child of RootNode_!
     173* @return Bullet containing speed and entity.
    139174*/
    140175Bullet* OrxonoxShip::fire()
    141176{
    142177        // TODO: Names must be unique!
    143         SceneNode *temp = RootNode_->getParentSceneNode()->createChildSceneNode(
     178        SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode(
    144179        "BulletNode" + StringConverter::toString(objectCounter_));
    145         temp->setOrientation(RootNode_->getOrientation());
    146         temp->setPosition(RootNode_->getPosition());
     180        temp->setOrientation(rootNode_->getOrientation());
     181        temp->setPosition(rootNode_->getPosition());
    147182        temp->setScale(Vector3(1, 1, 1) * 10);
    148183        temp->yaw(Degree(-90));
    149         return new Bullet(temp, mSceneMgr->createEntity("bullet"
    150         + StringConverter::toString(objectCounter_++), "Barrel.mesh"), speed
    151         + (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()
    152187        * bulletSpeed_);
    153188}
     
    159194* @param time Absolute time.
    160195* @param deltaTime Relative time.
     196* @return Return true to continue render
    161197*/
    162198bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
    163199{
    164   Quaternion quad = mRootNode->getOrientation();
     200  Quaternion quad = rootNode_->getOrientation();
    165201  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);
    170207
    171208        return true;
  • code/branches/main_reto_vs05/src/run_manager.cc

    r157 r159  
    5454      statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0),
    5555      filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0),
     56      mouseSensitivity_(0.003),
    5657      debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0)
    5758{
     
    8081
    8182  // Construct a new spaceship and give it the node
    82   playerShip_ = new OrxonoxShip(sceneMgr_, getRootSceneNode()
     83  playerShip_ = new OrxonoxShip(sceneMgr_, sceneMgr_->getRootSceneNode()
    8384    ->createChildSceneNode("ShipNode", Vector3(20, 20, 20)));
    8485
     
    304305
    305306  if(keyboard_->isKeyDown(KC_UP) || keyboard_->isKeyDown(KC_W) )
    306     playerShip_->setThrust(1);
     307    playerShip_->setMainThrust(1);
    307308  else if(keyboard_->isKeyDown(KC_DOWN) || keyboard_->isKeyDown(KC_S) )
    308     playerShip_->setThrust(-1);
     309    playerShip_->setMainThrust(-1);
    309310  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);
    311319
    312320  if( keyboard_->isKeyDown(KC_ESCAPE) || keyboard_->isKeyDown(KC_Q) )
     
    351359    window_->writeContentsToFile(ss.str());
    352360    timeUntilNextToggle_ = 0.5;
    353     mDebugText = "Saved: " + ss.str();
     361    debugText_ = "Saved: " + ss.str();
    354362  }
    355363
     
    371379    timeUntilNextToggle_ = 0.5;
    372380    if (!displayCameraDetails)
    373       mDebugText = "";
     381      debugText_ = "";
    374382  }
    375383
    376384  // Print camera details
    377385  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_
    381389  //      ->getDerivedPosition()) + " " + "O: "
    382390  //      + StringConverter::toString(camera_->getDerivedOrientation());
     
    433441  // Simply give it the mouse movements.
    434442  playerShip_->turnUpAndDown(Radian(ms.Y.rel * mouseSensitivity_));
    435   playerShip_->turnLeftAndRight(Radian(ms.X.rel * mousSensitivity_));
     443  playerShip_->turnLeftAndRight(Radian(ms.X.rel * mouseSensitivity_));
    436444  //playerShip_->mRootNode->pitch(Degree(-ms.Y.rel * 0.13), Ogre::Node::TransformSpace::TS_LOCAL);
    437445  //playerShip_->mRootNode->yaw(Degree(-ms.X.rel * 0.13), Ogre::Node::TransformSpace::TS_PARENT);
     
    500508    OverlayElement* guiDbg = OverlayManager::getSingleton()
    501509      .getOverlayElement("Core/DebugText");
    502     guiDbg->setCaption(mDebugText);
     510    guiDbg->setCaption(debugText_);
    503511  }
    504512  catch(...) { /* ignore */ }
     
    516524{
    517525  camera_ = sceneMgr_->createCamera("PlayerCam");
    518   playerShip_Node->attachObject(camera_);
     526  playerShip_->getRootNode()->attachObject(camera_);
    519527  camera_->setNearClipDistance(5);
    520528  camera_->setPosition(Vector3(0,10,500));
    521   camera_->lookAtVector3(0,0,0));
     529  camera_->lookAt(Vector3(0,0,0));
    522530}
    523531
Note: See TracChangeset for help on using the changeset viewer.