| [2072] | 1 | /* | 
|---|
 | 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
 | 3 |  *                    > www.orxonox.net < | 
|---|
 | 4 |  * | 
|---|
 | 5 |  * | 
|---|
 | 6 |  *   License notice: | 
|---|
 | 7 |  * | 
|---|
 | 8 |  *   This program is free software; you can redistribute it and/or | 
|---|
 | 9 |  *   modify it under the terms of the GNU General Public License | 
|---|
 | 10 |  *   as published by the Free Software Foundation; either version 2 | 
|---|
 | 11 |  *   of the License, or (at your option) any later version. | 
|---|
 | 12 |  * | 
|---|
 | 13 |  *   This program is distributed in the hope that it will be useful, | 
|---|
 | 14 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
 | 15 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
 | 16 |  *   GNU General Public License for more details. | 
|---|
 | 17 |  * | 
|---|
 | 18 |  *   You should have received a copy of the GNU General Public License | 
|---|
 | 19 |  *   along with this program; if not, write to the Free Software | 
|---|
 | 20 |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
 | 21 |  * | 
|---|
 | 22 |  *   Author: | 
|---|
 | 23 |  *      Fabian 'x3n' Landau | 
|---|
| [2662] | 24 |  *      Reto Grieder (physics) | 
|---|
| [2072] | 25 |  *   Co-authors: | 
|---|
 | 26 |  *      ... | 
|---|
 | 27 |  * | 
|---|
 | 28 |  */ | 
|---|
 | 29 |  | 
|---|
| [11080] | 30 | /** | 
|---|
 | 31 | @file Scene.h | 
|---|
 | 32 | @brief Definition of Scene Class | 
|---|
 | 33 | */ | 
|---|
 | 34 |  | 
|---|
| [2072] | 35 | #ifndef _Scene_H__ | 
|---|
 | 36 | #define _Scene_H__ | 
|---|
 | 37 |  | 
|---|
 | 38 | #include "OrxonoxPrereqs.h" | 
|---|
 | 39 |  | 
|---|
| [3196] | 40 | #include <list> | 
|---|
 | 41 | #include <set> | 
|---|
 | 42 | #include <string> | 
|---|
 | 43 |  | 
|---|
 | 44 | #include "util/Math.h" | 
|---|
 | 45 | #include "util/OgreForwardRefs.h" | 
|---|
 | 46 | #include "core/BaseObject.h" | 
|---|
| [11071] | 47 | #include "core/object/Context.h" | 
|---|
| [2662] | 48 | #include "network/synchronisable/Synchronisable.h" | 
|---|
| [5693] | 49 | #include "tools/interfaces/Tickable.h" | 
|---|
| [2072] | 50 |  | 
|---|
 | 51 | namespace orxonox | 
|---|
 | 52 | { | 
|---|
| [9667] | 53 |     class _OrxonoxExport Scene : public BaseObject, public Synchronisable, public Tickable, public Context | 
|---|
| [2072] | 54 |     { | 
|---|
 | 55 |         public: | 
|---|
| [11080] | 56 |             /** | 
|---|
 | 57 |             @brief  | 
|---|
 | 58 |                 This class holds a Scene which is a collection of all kinds of objects to be rendered in the same space, | 
|---|
 | 59 |                 with the same physics and the same light properties. Objects can be anything from a light source, over non physical objects | 
|---|
 | 60 |                 like Billboards to just plain Models with an attached Mesh | 
|---|
 | 61 |             */ | 
|---|
| [9667] | 62 |             Scene(Context* context); | 
|---|
| [2072] | 63 |             virtual ~Scene(); | 
|---|
 | 64 |  | 
|---|
| [11071] | 65 |             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; | 
|---|
| [2072] | 66 |             void registerVariables(); | 
|---|
 | 67 |  | 
|---|
 | 68 |             inline Ogre::SceneManager* getSceneManager() const | 
|---|
 | 69 |                 { return this->sceneManager_; } | 
|---|
 | 70 |             inline Ogre::SceneNode* getRootSceneNode() const | 
|---|
 | 71 |                 { return this->rootSceneNode_; } | 
|---|
| [11080] | 72 |             inline RenderQueueListener* getRenderQueueListener() const | 
|---|
 | 73 |                 { return this->renderQueueListener_; } | 
|---|
| [2072] | 74 |  | 
|---|
 | 75 |             void setSkybox(const std::string& skybox); | 
|---|
 | 76 |             inline const std::string& getSkybox() const | 
|---|
 | 77 |                 { return this->skybox_; } | 
|---|
 | 78 |  | 
|---|
 | 79 |             void setAmbientLight(const ColourValue& colour); | 
|---|
 | 80 |             inline const ColourValue& getAmbientLight() const | 
|---|
 | 81 |                 { return this->ambientLight_; } | 
|---|
 | 82 |  | 
|---|
 | 83 |             void setShadow(bool bShadow); | 
|---|
 | 84 |             inline bool getShadow() const | 
|---|
 | 85 |                 { return this->bShadows_; } | 
|---|
 | 86 |  | 
|---|
| [6417] | 87 |             inline void setSoundReferenceDistance(float distance) | 
|---|
 | 88 |                 { this->soundReferenceDistance_ = distance; } | 
|---|
 | 89 |             inline float getSoundReferenceDistance() const | 
|---|
 | 90 |                 { return this->soundReferenceDistance_; } | 
|---|
 | 91 |  | 
|---|
| [5929] | 92 |             inline Radar* getRadar() | 
|---|
 | 93 |                 { return this->radar_; } | 
|---|
| [6417] | 94 |  | 
|---|
| [11071] | 95 |             virtual inline uint32_t getSceneID() const override { return this->getObjectID(); } | 
|---|
| [5929] | 96 |  | 
|---|
| [11071] | 97 |             virtual void tick(float dt) override; | 
|---|
| [2171] | 98 |  | 
|---|
| [2072] | 99 |         private: | 
|---|
 | 100 |             void addObject(BaseObject* object); | 
|---|
 | 101 |             BaseObject* getObject(unsigned int index) const; | 
|---|
 | 102 |  | 
|---|
 | 103 |             void networkcallback_applySkybox() | 
|---|
 | 104 |                 { this->setSkybox(this->skybox_); } | 
|---|
 | 105 |             void networkcallback_applyAmbientLight() | 
|---|
 | 106 |                 { this->setAmbientLight(this->ambientLight_); } | 
|---|
| [2662] | 107 |             void networkcallback_applyShadows() | 
|---|
 | 108 |                 { this->setShadow(this->bShadows_); } | 
|---|
| [2072] | 109 |  | 
|---|
| [11080] | 110 |             Ogre::SceneManager*      sceneManager_; //!< This is a pointer to the Ogre SceneManager we're using to render the Scene | 
|---|
 | 111 |             Ogre::SceneNode*         rootSceneNode_; //!< This is a pointer to the root node of the Scene tree | 
|---|
 | 112 |             RenderQueueListener*     renderQueueListener_; //!< this is a pointer to the RenderQueueListener we're using for this Scene | 
|---|
| [2662] | 113 |  | 
|---|
| [11080] | 114 |             std::string              skybox_; //!< This string holds information about the skybox we're using | 
|---|
 | 115 |             ColourValue              ambientLight_; //!< This variable holds the color value for the ambient light in our scene, usually black in space | 
|---|
 | 116 |             std::list<BaseObject*>   objects_; //!< This list holds all the objects created in our scene | 
|---|
 | 117 |             bool                     bShadows_; //!< Do we want shadows in our scene? | 
|---|
 | 118 |             float                    soundReferenceDistance_; //!< This holds a reference distance, which represents the distance between our scene and the listener | 
|---|
 | 119 |             Radar*                   radar_; //!< This is a pointer to a Radar object assigned with this scene | 
|---|
| [11085] | 120 |             WeakPtr<GlobalShader>    glowShader_; | 
|---|
| [2662] | 121 |  | 
|---|
 | 122 |  | 
|---|
 | 123 |         ///////////// | 
|---|
 | 124 |         // Physics // | 
|---|
 | 125 |         ///////////// | 
|---|
 | 126 |  | 
|---|
 | 127 |         public: | 
|---|
| [10624] | 128 |             inline bool hasPhysics() const | 
|---|
| [11071] | 129 |                 { return this->physicalWorld_ != nullptr; } | 
|---|
| [2662] | 130 |             void setPhysicalWorld(bool wantsPhysics); | 
|---|
 | 131 |  | 
|---|
 | 132 |             void setNegativeWorldRange(const Vector3& range); | 
|---|
 | 133 |             inline const Vector3& getNegativeWorldRange() const | 
|---|
 | 134 |                 { return this->negativeWorldRange_; } | 
|---|
 | 135 |  | 
|---|
 | 136 |             void setPositiveWorldRange(const Vector3& range); | 
|---|
 | 137 |             inline const Vector3& getPositiveWorldRange() const | 
|---|
 | 138 |                 { return this->positiveWorldRange_; } | 
|---|
 | 139 |  | 
|---|
 | 140 |             void setGravity(const Vector3& gravity); | 
|---|
 | 141 |             inline const Vector3& getGravity() const | 
|---|
 | 142 |                 { return this->gravity_; } | 
|---|
 | 143 |  | 
|---|
 | 144 |             void addPhysicalObject(WorldEntity* object); | 
|---|
 | 145 |             void removePhysicalObject(WorldEntity* object); | 
|---|
 | 146 |  | 
|---|
| [10624] | 147 |             inline bool isUpdatingPhysics() const | 
|---|
 | 148 |                 { return this->bIsUpdatingPhysics_; } | 
|---|
 | 149 |  | 
|---|
| [10196] | 150 |             void setDebugDrawPhysics(bool bDraw, bool bFill, float fillAlpha); | 
|---|
 | 151 |  | 
|---|
 | 152 |             static void consoleCommand_debugDrawPhysics(bool bDraw, bool bFill, float fillAlpha); | 
|---|
 | 153 |  | 
|---|
| [2662] | 154 |         private: | 
|---|
 | 155 |             inline void networkcallback_hasPhysics() | 
|---|
 | 156 |                 { this->setPhysicalWorld(this->bHasPhysics_); } | 
|---|
 | 157 |             inline void networkcallback_negativeWorldRange() | 
|---|
 | 158 |                 { this->setNegativeWorldRange(this->negativeWorldRange_); } | 
|---|
 | 159 |             inline void networkcallback_positiveWorldRange() | 
|---|
 | 160 |                 { this->setPositiveWorldRange(this->positiveWorldRange_); } | 
|---|
 | 161 |             inline void networkcallback_gravity() | 
|---|
 | 162 |                 { this->setGravity(this->gravity_); } | 
|---|
 | 163 |  | 
|---|
 | 164 |             // collision callback from bullet | 
|---|
 | 165 |             static bool collisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, | 
|---|
 | 166 |                                           int index0, const btCollisionObject* colObj1, int partId1, int index1); | 
|---|
 | 167 |  | 
|---|
 | 168 |             // Bullet objects | 
|---|
 | 169 |             btDiscreteDynamicsWorld*             physicalWorld_; | 
|---|
 | 170 |             bt32BitAxisSweep3*                   broadphase_; | 
|---|
 | 171 |             btDefaultCollisionConfiguration*     collisionConfig_; | 
|---|
 | 172 |             btCollisionDispatcher*               dispatcher_; | 
|---|
 | 173 |             btSequentialImpulseConstraintSolver* solver_; | 
|---|
 | 174 |  | 
|---|
 | 175 |             std::set<WorldEntity*>               physicalObjectQueue_; | 
|---|
 | 176 |             std::set<WorldEntity*>               physicalObjects_; | 
|---|
 | 177 |             bool                                 bHasPhysics_; | 
|---|
 | 178 |             Vector3                              negativeWorldRange_; | 
|---|
 | 179 |             Vector3                              positiveWorldRange_; | 
|---|
 | 180 |             Vector3                              gravity_; | 
|---|
| [10196] | 181 |  | 
|---|
 | 182 |             BulletDebugDrawer*                   debugDrawer_; | 
|---|
 | 183 |             bool                                 bDebugDrawPhysics_; | 
|---|
| [10624] | 184 |             bool                                 bIsUpdatingPhysics_; | 
|---|
| [2072] | 185 |     }; | 
|---|
 | 186 | } | 
|---|
 | 187 |  | 
|---|
 | 188 | #endif /* _Scene_H__ */ | 
|---|