Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/main_reto_vs05/src/orxonox_scene.cc @ 159

Last change on this file since 159 was 159, checked in by rgrieder, 16 years ago
File size: 3.6 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/**
29* The orxonox scene includes everything running in the background like terrain,
30* static figures, dangling lamp, etc.
31*/
32
33
34#include "orxonox_scene.h"
35
36
37/**
38* Empty Consructor except the initialiser list.
39* @param sceneMgr The Scene Manager.
40*/
41OrxonoxScene::OrxonoxScene(SceneManager *sceneMgr) : sceneMgr_(sceneMgr)
42{
43}
44
45/**
46* Empty Destructor.
47*/
48OrxonoxScene::~OrxonoxScene()
49{
50}
51
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*/
58bool OrxonoxScene::initialise()
59{
60        // Load resources
61        loadResources();
62
63        distance_ = 0;
64        radius_ = 100;
65
66        createScene();
67
68        return true;
69}
70
71
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()
78{
79        // Initialise, parse scripts etc
80        ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
81}
82
83
84/**
85* Scene creation.
86* Currently just a test scene with an ogre head an a surrounding light.
87*/
88void OrxonoxScene::createScene()
89{
90        sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3));
91
92        //create first entity
93        Entity *head = sceneMgr_->createEntity("head", "ogrehead.mesh");
94
95        //create a scene node to attach the head to
96        SceneNode *node = sceneMgr_->getRootSceneNode()
97        ->createChildSceneNode("OgreHeadNode", Vector3(0,0,0));
98        //attach the ogre head
99        node->attachObject(head);
100
101        // set up skybox
102        sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox2");
103
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);
110
111        //create billboard
112        bbs_ = sceneMgr_->createBillboardSet("bb", 1);
113        bbs_->createBillboard(Vector3::ZERO, ColourValue(1.0, 1.0, 1.0));
114        bbs_->setMaterialName("Examples/Flare");
115
116        lightNode_ = sceneMgr_->getRootSceneNode()
117        ->createChildSceneNode("lightNode_", Vector3(0, 100, 0));
118
119        lightNode_->attachObject(bbs_);
120        lightNode_->attachObject(light_);
121}
122
123
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)
131{
132        Real t = time/1000.0;
133
134        lightNode_->setPosition(radius_*sin(5*t), radius_*cos(5*t), sin(1*t)*distance_);
135       
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));
138
139        bbs_->getBillboard(0)->setColour(ColourValue(sin(1*t),
140        sin(1*t + 2.09), sin(1*t + 2.09*2)));
141 
142  return true;
143}
Note: See TracBrowser for help on using the repository browser.