]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CSceneManager.h
Readd CSceneCollisionManager with only the method we need
[irrlicht.git] / source / Irrlicht / CSceneManager.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_SCENE_MANAGER_H_INCLUDED__\r
6 #define __C_SCENE_MANAGER_H_INCLUDED__\r
7 \r
8 #include "ISceneManager.h"\r
9 #include "ISceneNode.h"\r
10 #include "ICursorControl.h"\r
11 #include "irrString.h"\r
12 #include "irrArray.h"\r
13 #include "IMeshLoader.h"\r
14 #include "CAttributes.h"\r
15 \r
16 namespace irr\r
17 {\r
18 namespace io\r
19 {\r
20         class IFileSystem;\r
21 }\r
22 namespace scene\r
23 {\r
24         class IMeshCache;\r
25 \r
26         /*!\r
27                 The Scene Manager manages scene nodes, mesh resources, cameras and all the other stuff.\r
28         */\r
29         class CSceneManager : public ISceneManager, public ISceneNode\r
30         {\r
31         public:\r
32 \r
33                 //! constructor\r
34                 CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,\r
35                         gui::ICursorControl* cursorControl, IMeshCache* cache = 0,\r
36                         gui::IGUIEnvironment *guiEnvironment = 0);\r
37 \r
38                 //! destructor\r
39                 virtual ~CSceneManager();\r
40 \r
41                 //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.\r
42                 virtual IAnimatedMesh* getMesh(const io::path& filename, const io::path& alternativeCacheName) _IRR_OVERRIDE_;\r
43 \r
44                 //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.\r
45                 virtual IAnimatedMesh* getMesh(io::IReadFile* file) _IRR_OVERRIDE_;\r
46 \r
47                 //! Returns an interface to the mesh cache which is shared between all existing scene managers.\r
48                 virtual IMeshCache* getMeshCache() _IRR_OVERRIDE_;\r
49 \r
50                 //! returns the video driver\r
51                 virtual video::IVideoDriver* getVideoDriver() _IRR_OVERRIDE_;\r
52 \r
53                 //! return the gui environment\r
54                 virtual gui::IGUIEnvironment* getGUIEnvironment() _IRR_OVERRIDE_;\r
55 \r
56                 //! return the filesystem\r
57                 virtual io::IFileSystem* getFileSystem() _IRR_OVERRIDE_;\r
58 \r
59                 //! adds a scene node for rendering an animated mesh model\r
60                 virtual IAnimatedMeshSceneNode* addAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, s32 id=-1,\r
61                         const core::vector3df& position = core::vector3df(0,0,0),\r
62                         const core::vector3df& rotation = core::vector3df(0,0,0),\r
63                         const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f),\r
64                         bool alsoAddIfMeshPointerZero=false) _IRR_OVERRIDE_;\r
65 \r
66                 //! adds a scene node for rendering a static mesh\r
67                 //! the returned pointer must not be dropped.\r
68                 virtual IMeshSceneNode* addMeshSceneNode(IMesh* mesh, ISceneNode* parent=0, s32 id=-1,\r
69                         const core::vector3df& position = core::vector3df(0,0,0),\r
70                         const core::vector3df& rotation = core::vector3df(0,0,0),\r
71                         const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f),\r
72                         bool alsoAddIfMeshPointerZero=false) _IRR_OVERRIDE_;\r
73 \r
74                 //! renders the node.\r
75                 virtual void render() _IRR_OVERRIDE_;\r
76 \r
77                 //! returns the axis aligned bounding box of this node\r
78                 virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_;\r
79 \r
80                 //! registers a node for rendering it at a specific time.\r
81                 virtual u32 registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDER_PASS pass = ESNRP_AUTOMATIC) _IRR_OVERRIDE_;\r
82 \r
83                 //! Clear all nodes which are currently registered for rendering\r
84                 virtual void clearAllRegisteredNodesForRendering() _IRR_OVERRIDE_;\r
85 \r
86                 //! draws all scene nodes\r
87                 virtual void drawAll() _IRR_OVERRIDE_;\r
88 \r
89                 //! Adds a camera scene node to the tree and sets it as active camera.\r
90                 //! \param position: Position of the space relative to its parent where the camera will be placed.\r
91                 //! \param lookat: Position where the camera will look at. Also known as target.\r
92                 //! \param parent: Parent scene node of the camera. Can be null. If the parent moves,\r
93                 //! the camera will move too.\r
94                 //! \return Pointer to interface to camera\r
95                 virtual ICameraSceneNode* addCameraSceneNode(ISceneNode* parent = 0,\r
96                         const core::vector3df& position = core::vector3df(0,0,0),\r
97                         const core::vector3df& lookat = core::vector3df(0,0,100),\r
98                         s32 id=-1, bool makeActive=true) _IRR_OVERRIDE_;\r
99 \r
100                 //! Adds a billboard scene node to the scene. A billboard is like a 3d sprite: A 2d element,\r
101                 //! which always looks to the camera. It is usually used for things like explosions, fire,\r
102                 //! lensflares and things like that.\r
103                 virtual IBillboardSceneNode* addBillboardSceneNode(ISceneNode* parent = 0,\r
104                         const core::dimension2d<f32>& size = core::dimension2d<f32>(10.0f, 10.0f),\r
105                         const core::vector3df& position = core::vector3df(0,0,0), s32 id=-1,\r
106                         video::SColor shadeTop = 0xFFFFFFFF, video::SColor shadeBottom = 0xFFFFFFFF) _IRR_OVERRIDE_;\r
107 \r
108                 //! Adds a dummy transformation scene node to the scene graph.\r
109                 virtual IDummyTransformationSceneNode* addDummyTransformationSceneNode(\r
110                         ISceneNode* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
111 \r
112                 //! Adds an empty scene node.\r
113                 virtual ISceneNode* addEmptySceneNode(ISceneNode* parent, s32 id=-1) _IRR_OVERRIDE_;\r
114 \r
115                 //! Returns the root scene node. This is the scene node which is parent\r
116                 //! of all scene nodes. The root scene node is a special scene node which\r
117                 //! only exists to manage all scene nodes. It is not rendered and cannot\r
118                 //! be removed from the scene.\r
119                 //! \return Pointer to the root scene node.\r
120                 virtual ISceneNode* getRootSceneNode() _IRR_OVERRIDE_;\r
121 \r
122                 //! Returns the current active camera.\r
123                 //! \return The active camera is returned. Note that this can be NULL, if there\r
124                 //! was no camera created yet.\r
125                 virtual ICameraSceneNode* getActiveCamera() const _IRR_OVERRIDE_;\r
126 \r
127                 //! Sets the active camera. The previous active camera will be deactivated.\r
128                 //! \param camera: The new camera which should be active.\r
129                 virtual void setActiveCamera(ICameraSceneNode* camera) _IRR_OVERRIDE_;\r
130 \r
131                 //! Adds an external mesh loader.\r
132                 virtual void addExternalMeshLoader(IMeshLoader* externalLoader) _IRR_OVERRIDE_;\r
133 \r
134                 //! Returns the number of mesh loaders supported by Irrlicht at this time\r
135                 virtual u32 getMeshLoaderCount() const _IRR_OVERRIDE_;\r
136 \r
137                 //! Retrieve the given mesh loader\r
138                 virtual IMeshLoader* getMeshLoader(u32 index) const _IRR_OVERRIDE_;\r
139 \r
140                 //! Adds an external scene loader.\r
141                 virtual void addExternalSceneLoader(ISceneLoader* externalLoader) _IRR_OVERRIDE_;\r
142 \r
143                 //! Returns the number of scene loaders supported by Irrlicht at this time\r
144                 virtual u32 getSceneLoaderCount() const _IRR_OVERRIDE_;\r
145 \r
146                 //! Retrieve the given scene loader\r
147                 virtual ISceneLoader* getSceneLoader(u32 index) const _IRR_OVERRIDE_;\r
148 \r
149                 //! Returns a pointer to the scene collision manager.\r
150                 virtual ISceneCollisionManager* getSceneCollisionManager() _IRR_OVERRIDE_;\r
151 \r
152                 //! Returns a pointer to the mesh manipulator.\r
153                 virtual IMeshManipulator* getMeshManipulator() _IRR_OVERRIDE_;\r
154 \r
155                 //! Adds a scene node to the deletion queue.\r
156                 virtual void addToDeletionQueue(ISceneNode* node) _IRR_OVERRIDE_;\r
157 \r
158                 //! Returns the first scene node with the specified id.\r
159                 virtual ISceneNode* getSceneNodeFromId(s32 id, ISceneNode* start=0) _IRR_OVERRIDE_;\r
160 \r
161                 //! Returns the first scene node with the specified name.\r
162                 virtual ISceneNode* getSceneNodeFromName(const c8* name, ISceneNode* start=0) _IRR_OVERRIDE_;\r
163 \r
164                 //! Returns the first scene node with the specified type.\r
165                 virtual ISceneNode* getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, ISceneNode* start=0) _IRR_OVERRIDE_;\r
166 \r
167                 //! returns scene nodes by type.\r
168                 virtual void getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array<scene::ISceneNode*>& outNodes, ISceneNode* start=0) _IRR_OVERRIDE_;\r
169 \r
170                 //! Posts an input event to the environment. Usually you do not have to\r
171                 //! use this method, it is used by the internal engine.\r
172                 virtual bool postEventFromUser(const SEvent& event) _IRR_OVERRIDE_;\r
173 \r
174                 //! Clears the whole scene. All scene nodes are removed.\r
175                 virtual void clear() _IRR_OVERRIDE_;\r
176 \r
177                 //! Removes all children of this scene node\r
178                 virtual void removeAll() _IRR_OVERRIDE_;\r
179 \r
180                 //! Returns interface to the parameters set in this scene.\r
181                 virtual io::IAttributes* getParameters() _IRR_OVERRIDE_;\r
182 \r
183                 //! Returns current render pass.\r
184                 virtual E_SCENE_NODE_RENDER_PASS getSceneNodeRenderPass() const _IRR_OVERRIDE_;\r
185 \r
186                 //! Creates a new scene manager.\r
187                 virtual ISceneManager* createNewSceneManager(bool cloneContent) _IRR_OVERRIDE_;\r
188 \r
189                 //! Returns type of the scene node\r
190                 virtual ESCENE_NODE_TYPE getType() const _IRR_OVERRIDE_ { return ESNT_SCENE_MANAGER; }\r
191 \r
192                 //! Returns the default scene node factory which can create all built in scene nodes\r
193                 virtual ISceneNodeFactory* getDefaultSceneNodeFactory() _IRR_OVERRIDE_;\r
194 \r
195                 //! Adds a scene node factory to the scene manager.\r
196                 /** Use this to extend the scene manager with new scene node types which it should be\r
197                 able to create automatically, for example when loading data from xml files. */\r
198                 virtual void registerSceneNodeFactory(ISceneNodeFactory* factoryToAdd) _IRR_OVERRIDE_;\r
199 \r
200                 //! Returns amount of registered scene node factories.\r
201                 virtual u32 getRegisteredSceneNodeFactoryCount() const _IRR_OVERRIDE_;\r
202 \r
203                 //! Returns a scene node factory by index\r
204                 virtual ISceneNodeFactory* getSceneNodeFactory(u32 index) _IRR_OVERRIDE_;\r
205 \r
206                 //! Returns a typename from a scene node type or null if not found\r
207                 virtual const c8* getSceneNodeTypeName(ESCENE_NODE_TYPE type) _IRR_OVERRIDE_;\r
208 \r
209                 //! Adds a scene node to the scene by name\r
210                 virtual ISceneNode* addSceneNode(const char* sceneNodeTypeName, ISceneNode* parent=0) _IRR_OVERRIDE_;\r
211 \r
212                 //! Saves the current scene into a file.\r
213                 virtual bool saveScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) _IRR_OVERRIDE_;\r
214 \r
215                 //! Saves the current scene into a file.\r
216                 virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) _IRR_OVERRIDE_;\r
217 \r
218                 //! Loads a scene. Note that the current scene is not cleared before.\r
219                 virtual bool loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) _IRR_OVERRIDE_;\r
220 \r
221                 //! Loads a scene. Note that the current scene is not cleared before.\r
222                 virtual bool loadScene(io::IReadFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) _IRR_OVERRIDE_;\r
223 \r
224                 //! Writes attributes of the scene node.\r
225                 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_;\r
226 \r
227                 //! Reads attributes of the scene node.\r
228                 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;\r
229 \r
230                 //! Returns a mesh writer implementation if available\r
231                 virtual IMeshWriter* createMeshWriter(EMESH_WRITER_TYPE type) _IRR_OVERRIDE_;\r
232 \r
233                 //! Get a skinned mesh, which is not available as header-only code\r
234                 virtual ISkinnedMesh* createSkinnedMesh() _IRR_OVERRIDE_;\r
235 \r
236                 //! Sets ambient color of the scene\r
237                 virtual void setAmbientLight(const video::SColorf &ambientColor) _IRR_OVERRIDE_;\r
238 \r
239                 //! Returns ambient color of the scene\r
240                 virtual const video::SColorf& getAmbientLight() const _IRR_OVERRIDE_;\r
241 \r
242                 //! Get current render time.\r
243                 virtual E_SCENE_NODE_RENDER_PASS getCurrentRenderPass() const _IRR_OVERRIDE_ { return CurrentRenderPass; }\r
244 \r
245                 //! Set current render time.\r
246                 virtual void setCurrentRenderPass(E_SCENE_NODE_RENDER_PASS nextPass) _IRR_OVERRIDE_ { CurrentRenderPass = nextPass; }\r
247 \r
248                 //! returns if node is culled\r
249                 virtual bool isCulled(const ISceneNode* node) const _IRR_OVERRIDE_;\r
250 \r
251         private:\r
252 \r
253                 // load and create a mesh which we know already isn't in the cache and put it in there\r
254                 IAnimatedMesh* getUncachedMesh(io::IReadFile* file, const io::path& filename, const io::path& cachename);\r
255 \r
256                 //! clears the deletion list\r
257                 void clearDeletionList();\r
258 \r
259                 struct DefaultNodeEntry\r
260                 {\r
261                         DefaultNodeEntry(ISceneNode* n) :\r
262                                 Node(n), TextureValue(0)\r
263                         {\r
264                                 if (n->getMaterialCount())\r
265                                         TextureValue = (n->getMaterial(0).getTexture(0));\r
266                         }\r
267 \r
268                         bool operator < (const DefaultNodeEntry& other) const\r
269                         {\r
270                                 return (TextureValue < other.TextureValue);\r
271                         }\r
272 \r
273                         ISceneNode* Node;\r
274                         private:\r
275                         void* TextureValue;\r
276                 };\r
277 \r
278                 //! sort on distance (center) to camera\r
279                 struct TransparentNodeEntry\r
280                 {\r
281                         TransparentNodeEntry(ISceneNode* n, const core::vector3df& camera)\r
282                                 : Node(n)\r
283                         {\r
284                                 Distance = Node->getAbsoluteTransformation().getTranslation().getDistanceFromSQ(camera);\r
285                         }\r
286 \r
287                         bool operator < (const TransparentNodeEntry& other) const\r
288                         {\r
289                                 return Distance > other.Distance;\r
290                         }\r
291 \r
292                         ISceneNode* Node;\r
293                         private:\r
294                                 f64 Distance;\r
295                 };\r
296 \r
297                 //! sort on distance (sphere) to camera\r
298                 struct DistanceNodeEntry\r
299                 {\r
300                         DistanceNodeEntry(ISceneNode* n, const core::vector3df& cameraPos)\r
301                                 : Node(n)\r
302                         {\r
303                                 setNodeAndDistanceFromPosition(n, cameraPos);\r
304                         }\r
305 \r
306                         bool operator < (const DistanceNodeEntry& other) const\r
307                         {\r
308                                 return Distance < other.Distance;\r
309                         }\r
310 \r
311                         void setNodeAndDistanceFromPosition(ISceneNode* n, const core::vector3df & fromPosition)\r
312                         {\r
313                                 Node = n;\r
314                                 Distance = Node->getAbsoluteTransformation().getTranslation().getDistanceFromSQ(fromPosition);\r
315                                 Distance -= Node->getBoundingBox().getExtent().getLengthSQ() * 0.5;\r
316                         }\r
317 \r
318                         ISceneNode* Node;\r
319                         private:\r
320                         f64 Distance;\r
321                 };\r
322 \r
323                 //! video driver\r
324                 video::IVideoDriver* Driver;\r
325 \r
326                 //! file system\r
327                 io::IFileSystem* FileSystem;\r
328 \r
329                 //! GUI Enviroment ( Debug Purpose )\r
330                 gui::IGUIEnvironment* GUIEnvironment;\r
331 \r
332                 //! cursor control\r
333                 gui::ICursorControl* CursorControl;\r
334 \r
335                 //! collision manager\r
336                 ISceneCollisionManager* CollisionManager;\r
337 \r
338                 //! render pass lists\r
339                 core::array<ISceneNode*> CameraList;\r
340                 core::array<ISceneNode*> SkyBoxList;\r
341                 core::array<DefaultNodeEntry> SolidNodeList;\r
342                 core::array<TransparentNodeEntry> TransparentNodeList;\r
343                 core::array<TransparentNodeEntry> TransparentEffectNodeList;\r
344                 core::array<ISceneNode*> GuiNodeList;\r
345 \r
346                 core::array<IMeshLoader*> MeshLoaderList;\r
347                 core::array<ISceneLoader*> SceneLoaderList;\r
348                 core::array<ISceneNode*> DeletionList;\r
349                 core::array<ISceneNodeFactory*> SceneNodeFactoryList;\r
350 \r
351                 //! current active camera\r
352                 ICameraSceneNode* ActiveCamera;\r
353                 core::vector3df camWorldPos; // Position of camera for transparent nodes.\r
354 \r
355                 video::SColor ShadowColor;\r
356                 video::SColorf AmbientLight;\r
357 \r
358                 //! String parameters\r
359                 // NOTE: Attributes are slow and should only be used for debug-info and not in release\r
360                 io::CAttributes* Parameters;\r
361 \r
362                 //! Mesh cache\r
363                 IMeshCache* MeshCache;\r
364 \r
365                 E_SCENE_NODE_RENDER_PASS CurrentRenderPass;\r
366         };\r
367 \r
368 } // end namespace video\r
369 } // end namespace scene\r
370 \r
371 #endif\r
372 \r