Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/main_reto/src/orxonox_scene.cc @ 273

Last change on this file since 273 was 267, checked in by rgrieder, 17 years ago
  • updated to current revision from Visual studio directory
  • hopefully working libraries with cmake
File size: 4.1 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software: you can redistribute it and/or modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 *
20 *
21 *   Author:
22 *      Reto Grieder
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "OgreSceneManager.h"
29#include "OgreSceneNode.h"
30#include "OgreEntity.h"
31#include "OgreLight.h"
32#include "OgreBillboard.h"
33#include "OgreBillboardSet.h"
34#include "OgreVector3.h"
35
36#include "orxonox_scene.h"
37
38namespace orxonox {
39  using namespace Ogre;
40
41  /**
42  * The orxonox scene includes everything running in the background like terrain,
43  * static figures, dangling lamp, etc.
44  */
45
46
47  /**
48  * Empty Consructor except the initialiser list.
49  * @param sceneMgr The Scene Manager.
50  */
51  OrxonoxScene::OrxonoxScene(SceneManager *sceneMgr) : sceneMgr_(sceneMgr)
52  {
53  }
54
55  /**
56  * Empty Destructor.
57  */
58  OrxonoxScene::~OrxonoxScene()
59  {
60  }
61
62  /**
63  * Ogre initialisation method.
64  * This function is called by the Run Manager to load the neccessary recources
65  * and to create the scene.
66  * @return False if failed.
67  */
68  bool OrxonoxScene::initialise()
69  {
70          // Load resources
71          loadResources();
72
73          distance_ = 0;
74          radius_ = 100;
75
76          createScene();
77
78          return true;
79  }
80
81
82  /**
83  * Resource loader.
84  * Currently, this method loads everything! TODO: If done this ugly, it should
85  * at least be in the Run Manager.
86  */
87  void OrxonoxScene::loadResources()
88  {
89          // Initialise, parse scripts etc
90          ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
91  }
92
93
94  /**
95  * Scene creation.
96  * Currently just a test scene with an ogre head an a surrounding light.
97  */
98  void OrxonoxScene::createScene()
99  {
100          sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3)*2);
101
102          //create first entity
103          Entity *head = sceneMgr_->createEntity("head", "ogrehead.mesh");
104
105          //create a scene node to attach the head to
106          SceneNode *node = sceneMgr_->getRootSceneNode()
107          ->createChildSceneNode("OgreHeadNode", Vector3(0,0,0));
108          //attach the ogre head
109          node->attachObject(head);
110
111          // set up skybox
112          sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox1");
113
114          // set up one light_ source
115          light_ = sceneMgr_->createLight("Light1");
116          light_->setType(Light::LT_POINT);
117          light_->setPosition(Vector3(0, 0, 0));
118          light_->setDiffuseColour(1.0, 1.0, 1.0);
119          light_->setSpecularColour(1.0, 1.0, 1.0);
120
121          //create billboard
122          bbs_ = sceneMgr_->createBillboardSet("bb", 1);
123          bbs_->createBillboard(Vector3::ZERO, ColourValue(1.0, 1.0, 1.0));
124          bbs_->setMaterialName("Examples/Flare");
125
126          lightNode_ = sceneMgr_->getRootSceneNode()
127          ->createChildSceneNode("lightNode_", Vector3(0, 100, 0));
128
129          lightNode_->attachObject(bbs_);
130          lightNode_->attachObject(light_);
131  }
132
133
134  /**
135  * Compute something between frames if neccessary.
136  * @param time Absolute time.
137  * @param deltaTime Relative time.
138  * @return Return true to continue rendering.
139  */
140  bool OrxonoxScene::tick(unsigned long time, Real deltaTime)
141  {
142          Real t = time/1000.0;
143
144          lightNode_->setPosition(radius_*sin(5*t), radius_*cos(5*t), sin(1*t)*distance_);
145       
146          light_->setDiffuseColour(sin(1*t), sin(1*t + 2.09), sin(1*t + 2.09*2));
147          light_->setSpecularColour(sin(1*t), sin(1*t + 2.09), sin(1*t + 2.09*2));
148
149          bbs_->getBillboard(0)->setColour(ColourValue(sin(1*t),
150          sin(1*t + 2.09), sin(1*t + 2.09*2)));
151   
152    return true;
153  }
154
155}
Note: See TracBrowser for help on using the repository browser.