Neo  0.5.0
Developer Documentation
Scene.h
Go to the documentation of this file.
1 //========================================================================
2 // Copyright (c) 2003-2011 Anael Seghezzi <www.maratis3d.com>
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgment in the product documentation would
15 // be appreciated but is not required.
16 //
17 // 2. Altered source versions must be plainly marked as such, and must not
18 // be misrepresented as being the original software.
19 //
20 // 3. This notice may not be removed or altered from any source
21 // distribution.
22 //
23 //========================================================================
24 
25 #ifndef __SCENE_H
26 #define __SCENE_H
27 
28 #include <map>
29 
30 namespace Neo
31 {
32 
33 // data modes
35 {
39 };
40 
48 class NEO_ENGINE_EXPORT Scene
49 {
50 public:
51 
52  // Definition of some additional data for rendering
53  class AdditionalData {};
54 
55  // constructor / destructor
56  Scene(void);
57  ~Scene(void);
58 
59 private:
60 
61  AdditionalData* m_additionalData;
62 
63  // name
64  String m_name;
65 
66  // data mode
67  M_DATA_MODES m_dataMode;
68 
69  // script
70  String m_scriptFilename;
71 
72  // objects pointers
73  vector <Object3d *> m_objects;
74 
75  // objects
76  vector <OCamera *> m_cameras;
77  vector <OLight *> m_lights;
78  vector <OEntity *> m_entities;
79  vector <OSound *> m_sounds;
80  vector <OText *> m_texts;
81 
82  // current frame
83  int m_currentFrame;
84 
85  map<int,Object3d*> m_handles;
86  unsigned long int m_ids;
87 
88  // current camera
89  unsigned int m_currentCamera;
90 
91  // gravity
92  Vector3 m_gravity;
93 
94  // Ambient light
95  Vector3 m_ambientLight;
96 
97 public:
98 
99  AdditionalData* getAdditionalData() { return m_additionalData; }
100  void setAdditionalData(AdditionalData* d) { m_additionalData = d; }
101 
102  // name
112  void setName(const char * name);
113 
118  inline const char * getName(void){ return m_name.getSafeString(); }
119 
120  inline Vector3 getAmbientLight() { return m_ambientLight; }
121  inline void setAmbientLight(Vector3 light) { m_ambientLight = light; }
122 
123  // data mode
124  inline void setDataMode(M_DATA_MODES dataMode){ m_dataMode = dataMode; }
125  inline M_DATA_MODES getDataMode(void){ return m_dataMode; }
126 
127  // script
135  void setScriptFilename(const char * scriptFilename);
136 
141  inline const char * getScriptFilename(void){ return m_scriptFilename.getData(); }
142 
143  // gravity
156  inline void setGravity(const Vector3 & gravity){ m_gravity = gravity; }
157 
162  inline Vector3 getGravity(void) const { return m_gravity; }
163 
164  // sounds
165  void playLoopSounds(void);
166  void stopAllSounds(void);
167 
168  // delete object
175  void deleteObject(Object3d * object);
176 
177  // add objects
185  OCamera * addNewCamera(void);
186 
192  OCamera * addNewCamera(const OCamera & camera);
193 
201  OLight * addNewLight(void);
202 
203  Object3d * addNewGroup(void);
204  Object3d * addNewGroup(const Object3d & object);
205 
211  OLight * addNewLight(const OLight & light);
212  OEntity * addNewEntity(MeshRef * meshRef);
213  OEntity * addNewEntity(const OEntity & entity);
214  OSound * addNewSound(SoundRef * soundRef);
215  OSound * addNewSound(const OSound & sound);
216  OText * addNewText(FontRef * fontRef);
217  OText * addNewText(const OText & text);
218 
219  // get objects number
224  inline unsigned int getObjectsNumber(void){ return m_objects.size(); }
225 
230  inline unsigned int getCamerasNumber(void){ return m_cameras.size(); }
231 
236  inline unsigned int getLightsNumber(void){ return m_lights.size(); }
237 
242  inline unsigned int getEntitiesNumber(void){ return m_entities.size(); }
243 
248  inline unsigned int getSoundsNumber(void){ return m_sounds.size(); }
249 
254  inline unsigned int getTextsNumber(void){ return m_texts.size(); }
255 
256  // current camera
257  inline void setCurrentCameraId(unsigned int id){ m_currentCamera = id; }
258  inline unsigned int getCurrentCameraId(void){ return m_currentCamera; }
259 
260  void setCurrentCamera(OCamera* c);
261 
269  OCamera * getCurrentCamera(void);
270 
271  // current frame
272  inline void setCurrentFrame(int currentFrame){ m_currentFrame = currentFrame; }
273  inline int getCurrentFrame(void){ return m_currentFrame; }
274 
275  // get objects
284  Object3d * getObjectByName(const char * name);
285 
294  Object3d * getObjectByHandle(unsigned long handle) { return m_handles[handle]; }
295 
304  OLight * getLightByName(const char * name);
305 
314  OCamera * getCameraByName(const char * name);
315 
324  OEntity * getEntityByName(const char * name);
325 
334  OSound * getSoundByName(const char * name);
335 
344  OText * getTextByName(const char * name);
345 
361  bool getObjectIndex(const char * name, unsigned int * id);
362 
363  inline Object3d * getObjectByIndex(unsigned int index){ return m_objects[index]; }
364  inline OLight * getLightByIndex(unsigned int index){ return m_lights[index]; }
365  inline OCamera * getCameraByIndex(unsigned int index){ return m_cameras[index]; }
366  inline OEntity * getEntityByIndex(unsigned int index){ return m_entities[index]; }
367  inline OSound * getSoundByIndex(unsigned int index){ return m_sounds[index]; }
368  inline OText * getTextByIndex(unsigned int index){ return m_texts[index]; }
369 
370  // begin / end
371  void begin(void);
372  void end(void);
373 
374  // physics
375  void prepareCollisionShape(OEntity * entity);
376  void prepareCollisionObject(OEntity * entity);
377  void prepareConstraints(OEntity * entity);
378  void preparePhysics(void);
379  void updatePhysics(void);
380 
381  // update
385  void update(void);
386 
387  // behaviors
392  void updateObjectsBehaviors(void);
393 
398  void drawObjectsBehaviors(void);
399 
400  // update objects
401  void updateObjectsMatrices(void);
402 
403  // draw
414  void draw(OCamera * camera);
415 };
416 }
417 
418 #endif
Vector3 getAmbientLight()
Definition: Scene.h:120
The Scene class represents a scene in a Maratis level.
Definition: Scene.h:48
Definition: SoundRef.h:32
void setCurrentCameraId(unsigned int id)
Definition: Scene.h:257
Definition: OSound.h:31
OCamera * getCameraByIndex(unsigned int index)
Definition: Scene.h:365
Definition: MeshRef.h:32
AdditionalData * getAdditionalData()
Definition: Scene.h:99
Definition: FontRef.h:32
void setCurrentFrame(int currentFrame)
Definition: Scene.h:272
Definition: Vector3.h:31
const char * getScriptFilename(void)
Returns the filename of the script that is currently attached to this scene.
Definition: Scene.h:141
OSound * getSoundByIndex(unsigned int index)
Definition: Scene.h:367
Definition: OText.h:40
void setAdditionalData(AdditionalData *d)
Definition: Scene.h:100
Implements a framework for string manipulation that operates directly on C strings.
Definition: NeoString.h:35
void setGravity(const Vector3 &gravity)
Sets the gravitational pull in this scene to the given value.
Definition: Scene.h:156
Definition: Scene.h:38
unsigned int getEntitiesNumber(void)
Returns the number of entities in the scene.
Definition: Scene.h:242
Definition: Scene.h:36
OLight * getLightByIndex(unsigned int index)
Definition: Scene.h:364
Definition: Scene.h:53
const char * getData(void)
Returns the current internal string buffer. Attention: Might return NULL!
Definition: NeoString.h:74
void setDataMode(M_DATA_MODES dataMode)
Definition: Scene.h:124
unsigned int getCurrentCameraId(void)
Definition: Scene.h:258
int getCurrentFrame(void)
Definition: Scene.h:273
unsigned int getTextsNumber(void)
Returns the number of text objects in the scene.
Definition: Scene.h:254
OText * getTextByIndex(unsigned int index)
Definition: Scene.h:368
unsigned int getSoundsNumber(void)
Returns the number of sounds in the scene.
Definition: Scene.h:248
Object3d * getObjectByHandle(unsigned long handle)
Returns the object with the given ID or NULL if it is not found.
Definition: Scene.h:294
The Object3d class represents a general object in a 3D scene.
Definition: Object3d.h:43
const char * getSafeString(void)
Returns the C string. This method is ensured to return a valid C string and never NULL...
unsigned int getObjectsNumber(void)
Returns the number of objects in the scene.
Definition: Scene.h:224
Represents a 3D light in the scene.
Definition: OLight.h:52
Represents a 3D mesh in the scene.
Definition: OEntity.h:270
void setAmbientLight(Vector3 light)
Definition: Scene.h:121
unsigned int getCamerasNumber(void)
Returns the number of cameras in the scene.
Definition: Scene.h:230
M_DATA_MODES getDataMode(void)
Definition: Scene.h:125
Definition: OCamera.h:30
const char * getName(void)
Returns the name of the scene.
Definition: Scene.h:118
Vector3 getGravity(void) const
Returns the current gravity in a MVector3.
Definition: Scene.h:162
Definition: Color.h:29
Definition: Scene.h:37
unsigned int getLightsNumber(void)
Returns the number of lights in the scene.
Definition: Scene.h:236
Object3d * getObjectByIndex(unsigned int index)
Definition: Scene.h:363
M_DATA_MODES
Definition: Scene.h:34
OEntity * getEntityByIndex(unsigned int index)
Definition: Scene.h:366