[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 | |
---|
| 30 | #ifndef _Scene_H__ |
---|
| 31 | #define _Scene_H__ |
---|
| 32 | |
---|
| 33 | #include "OrxonoxPrereqs.h" |
---|
| 34 | |
---|
[3196] | 35 | #include <list> |
---|
| 36 | #include <set> |
---|
| 37 | #include <string> |
---|
| 38 | |
---|
| 39 | #include "util/Math.h" |
---|
| 40 | #include "util/OgreForwardRefs.h" |
---|
| 41 | #include "core/BaseObject.h" |
---|
[11071] | 42 | #include "core/object/Context.h" |
---|
[2662] | 43 | #include "network/synchronisable/Synchronisable.h" |
---|
[5693] | 44 | #include "tools/interfaces/Tickable.h" |
---|
[2072] | 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
[9667] | 48 | class _OrxonoxExport Scene : public BaseObject, public Synchronisable, public Tickable, public Context |
---|
[2072] | 49 | { |
---|
| 50 | public: |
---|
[9667] | 51 | Scene(Context* context); |
---|
[2072] | 52 | virtual ~Scene(); |
---|
| 53 | |
---|
[11071] | 54 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; |
---|
[2072] | 55 | void registerVariables(); |
---|
| 56 | |
---|
| 57 | inline Ogre::SceneManager* getSceneManager() const |
---|
| 58 | { return this->sceneManager_; } |
---|
| 59 | inline Ogre::SceneNode* getRootSceneNode() const |
---|
| 60 | { return this->rootSceneNode_; } |
---|
| 61 | |
---|
| 62 | void setSkybox(const std::string& skybox); |
---|
| 63 | inline const std::string& getSkybox() const |
---|
| 64 | { return this->skybox_; } |
---|
| 65 | |
---|
| 66 | void setAmbientLight(const ColourValue& colour); |
---|
| 67 | inline const ColourValue& getAmbientLight() const |
---|
| 68 | { return this->ambientLight_; } |
---|
| 69 | |
---|
| 70 | void setShadow(bool bShadow); |
---|
| 71 | inline bool getShadow() const |
---|
| 72 | { return this->bShadows_; } |
---|
| 73 | |
---|
[6417] | 74 | inline void setSoundReferenceDistance(float distance) |
---|
| 75 | { this->soundReferenceDistance_ = distance; } |
---|
| 76 | inline float getSoundReferenceDistance() const |
---|
| 77 | { return this->soundReferenceDistance_; } |
---|
| 78 | |
---|
[5929] | 79 | inline Radar* getRadar() |
---|
| 80 | { return this->radar_; } |
---|
[6417] | 81 | |
---|
[11071] | 82 | virtual inline uint32_t getSceneID() const override { return this->getObjectID(); } |
---|
[5929] | 83 | |
---|
[11071] | 84 | virtual void tick(float dt) override; |
---|
[2171] | 85 | |
---|
[2072] | 86 | private: |
---|
| 87 | void addObject(BaseObject* object); |
---|
| 88 | BaseObject* getObject(unsigned int index) const; |
---|
| 89 | |
---|
| 90 | void networkcallback_applySkybox() |
---|
| 91 | { this->setSkybox(this->skybox_); } |
---|
| 92 | void networkcallback_applyAmbientLight() |
---|
| 93 | { this->setAmbientLight(this->ambientLight_); } |
---|
[2662] | 94 | void networkcallback_applyShadows() |
---|
| 95 | { this->setShadow(this->bShadows_); } |
---|
[2072] | 96 | |
---|
[2662] | 97 | Ogre::SceneManager* sceneManager_; |
---|
| 98 | Ogre::SceneNode* rootSceneNode_; |
---|
| 99 | |
---|
| 100 | std::string skybox_; |
---|
| 101 | ColourValue ambientLight_; |
---|
| 102 | std::list<BaseObject*> objects_; |
---|
| 103 | bool bShadows_; |
---|
[6417] | 104 | float soundReferenceDistance_; |
---|
[5929] | 105 | Radar* radar_; |
---|
[2662] | 106 | |
---|
| 107 | |
---|
| 108 | ///////////// |
---|
| 109 | // Physics // |
---|
| 110 | ///////////// |
---|
| 111 | |
---|
| 112 | public: |
---|
[10624] | 113 | inline bool hasPhysics() const |
---|
[11071] | 114 | { return this->physicalWorld_ != nullptr; } |
---|
[2662] | 115 | void setPhysicalWorld(bool wantsPhysics); |
---|
| 116 | |
---|
| 117 | void setNegativeWorldRange(const Vector3& range); |
---|
| 118 | inline const Vector3& getNegativeWorldRange() const |
---|
| 119 | { return this->negativeWorldRange_; } |
---|
| 120 | |
---|
| 121 | void setPositiveWorldRange(const Vector3& range); |
---|
| 122 | inline const Vector3& getPositiveWorldRange() const |
---|
| 123 | { return this->positiveWorldRange_; } |
---|
| 124 | |
---|
| 125 | void setGravity(const Vector3& gravity); |
---|
| 126 | inline const Vector3& getGravity() const |
---|
| 127 | { return this->gravity_; } |
---|
| 128 | |
---|
| 129 | void addPhysicalObject(WorldEntity* object); |
---|
| 130 | void removePhysicalObject(WorldEntity* object); |
---|
| 131 | |
---|
[10624] | 132 | inline bool isUpdatingPhysics() const |
---|
| 133 | { return this->bIsUpdatingPhysics_; } |
---|
| 134 | |
---|
[10196] | 135 | void setDebugDrawPhysics(bool bDraw, bool bFill, float fillAlpha); |
---|
| 136 | |
---|
| 137 | static void consoleCommand_debugDrawPhysics(bool bDraw, bool bFill, float fillAlpha); |
---|
| 138 | |
---|
[2662] | 139 | private: |
---|
| 140 | inline void networkcallback_hasPhysics() |
---|
| 141 | { this->setPhysicalWorld(this->bHasPhysics_); } |
---|
| 142 | inline void networkcallback_negativeWorldRange() |
---|
| 143 | { this->setNegativeWorldRange(this->negativeWorldRange_); } |
---|
| 144 | inline void networkcallback_positiveWorldRange() |
---|
| 145 | { this->setPositiveWorldRange(this->positiveWorldRange_); } |
---|
| 146 | inline void networkcallback_gravity() |
---|
| 147 | { this->setGravity(this->gravity_); } |
---|
| 148 | |
---|
| 149 | // collision callback from bullet |
---|
| 150 | static bool collisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, |
---|
| 151 | int index0, const btCollisionObject* colObj1, int partId1, int index1); |
---|
| 152 | |
---|
| 153 | // Bullet objects |
---|
| 154 | btDiscreteDynamicsWorld* physicalWorld_; |
---|
| 155 | bt32BitAxisSweep3* broadphase_; |
---|
| 156 | btDefaultCollisionConfiguration* collisionConfig_; |
---|
| 157 | btCollisionDispatcher* dispatcher_; |
---|
| 158 | btSequentialImpulseConstraintSolver* solver_; |
---|
| 159 | |
---|
| 160 | std::set<WorldEntity*> physicalObjectQueue_; |
---|
| 161 | std::set<WorldEntity*> physicalObjects_; |
---|
| 162 | bool bHasPhysics_; |
---|
| 163 | Vector3 negativeWorldRange_; |
---|
| 164 | Vector3 positiveWorldRange_; |
---|
| 165 | Vector3 gravity_; |
---|
[10196] | 166 | |
---|
| 167 | BulletDebugDrawer* debugDrawer_; |
---|
| 168 | bool bDebugDrawPhysics_; |
---|
[10624] | 169 | bool bIsUpdatingPhysics_; |
---|
[2072] | 170 | }; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | #endif /* _Scene_H__ */ |
---|