[157] | 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 | |
---|
[161] | 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" |
---|
[159] | 35 | |
---|
[157] | 36 | #include "orxonox_scene.h" |
---|
| 37 | |
---|
[169] | 38 | namespace orxonox { |
---|
[161] | 39 | using namespace Ogre; |
---|
[157] | 40 | |
---|
[161] | 41 | /** |
---|
| 42 | * The orxonox scene includes everything running in the background like terrain, |
---|
| 43 | * static figures, dangling lamp, etc. |
---|
| 44 | */ |
---|
[157] | 45 | |
---|
| 46 | |
---|
[161] | 47 | /** |
---|
| 48 | * Empty Consructor except the initialiser list. |
---|
| 49 | * @param sceneMgr The Scene Manager. |
---|
| 50 | */ |
---|
| 51 | OrxonoxScene::OrxonoxScene(SceneManager *sceneMgr) : sceneMgr_(sceneMgr) |
---|
| 52 | { |
---|
| 53 | } |
---|
[157] | 54 | |
---|
[161] | 55 | /** |
---|
| 56 | * Empty Destructor. |
---|
| 57 | */ |
---|
| 58 | OrxonoxScene::~OrxonoxScene() |
---|
| 59 | { |
---|
| 60 | } |
---|
[157] | 61 | |
---|
[161] | 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(); |
---|
[157] | 72 | |
---|
[161] | 73 | distance_ = 0; |
---|
| 74 | radius_ = 100; |
---|
[157] | 75 | |
---|
[161] | 76 | createScene(); |
---|
[157] | 77 | |
---|
[161] | 78 | return true; |
---|
| 79 | } |
---|
[157] | 80 | |
---|
| 81 | |
---|
[161] | 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 | } |
---|
[157] | 92 | |
---|
| 93 | |
---|
[161] | 94 | /** |
---|
| 95 | * Scene creation. |
---|
| 96 | * Currently just a test scene with an ogre head an a surrounding light. |
---|
| 97 | */ |
---|
| 98 | void OrxonoxScene::createScene() |
---|
| 99 | { |
---|
[198] | 100 | sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3)*2); |
---|
[157] | 101 | |
---|
[161] | 102 | //create first entity |
---|
| 103 | Entity *head = sceneMgr_->createEntity("head", "ogrehead.mesh"); |
---|
[157] | 104 | |
---|
[161] | 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); |
---|
[157] | 110 | |
---|
[161] | 111 | // set up skybox |
---|
[198] | 112 | sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox1"); |
---|
[157] | 113 | |
---|
[161] | 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); |
---|
[157] | 120 | |
---|
[161] | 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"); |
---|
[157] | 125 | |
---|
[161] | 126 | lightNode_ = sceneMgr_->getRootSceneNode() |
---|
| 127 | ->createChildSceneNode("lightNode_", Vector3(0, 100, 0)); |
---|
[157] | 128 | |
---|
[161] | 129 | lightNode_->attachObject(bbs_); |
---|
| 130 | lightNode_->attachObject(light_); |
---|
| 131 | } |
---|
[157] | 132 | |
---|
| 133 | |
---|
[161] | 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 | |
---|
[157] | 155 | } |
---|