3 Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef OBJECT_VIEWER_H
21 #define OBJECT_VIEWER_H
23 #include <nel/misc/types_nl.h>
30 #include <nel/misc/rgba.h>
31 #include <nel/3d/event_mouse_listener.h>
43 class UPlayListManager
;
44 class U3dMouseListener
;
55 @brief The class initializes the driver and creates a scene, provides basic control functions over the stage driver.
56 @details The class initializes the driver (by choosing OpenGL or Direct3D), and creates a scene (set an aspect), respectively
57 creates a light as well, load the font that is available further for
58 all other subsystems (eg: the signature of the coordinate axes) and Mouse Listener.
59 Settings are loaded from the configuration file.
60 Also, the class provides the following features to scene control:
61 - Loading and displaying of the shape, water shape and the particle system(loadMesh()). As well as the scene reset. (resetScene())
62 - Provides access to a animation object (getEntity(), getListObjects()).
63 - Select of current object for various operation (mainly related to the animation and editing skeleton):setCurrentObject(), getCurrentObject().
64 - Operations with the viewport, setting the correct perspective and creating of a screenshot.
65 - Function's updating keyboard and mouse (acts on the camera updateInput()), update(updateAnimatePS(), updateAnimation())
66 and render the scene (renderDriver(), renderScene()).
67 - Provides access to a general NeL systems (getDriver(), getScene(), getPlayListManager(), getTextContext(), get3dMouseListener()).
72 /// Default constructor.
75 virtual ~CObjectViewer();
77 /// Init a driver and create scene.
78 /// @param wnd - handle window.
79 /// @param w - width window.
80 /// @param h - height window.
81 void init( NL3D::UDriver
*driver
);
86 /// Update mouse and keyboard events. And update camera matrix.
89 /// Render Driver (clear all buffers and set background color).
92 /// Render current scene.
95 /// Render Debug 2D (stuff for dev).
98 void reloadTextures();
100 /// Make a screenshot of the current scene and save.
101 void saveScreenshot(const std::string
&nameFile
, bool jpg
, bool png
, bool tga
);
103 /// Load a mesh or particle system and add to current scene.
104 /// @param meshFileName - name loading shape or ps file.
105 /// @param skelFileName - name loading skeletin file.
106 /// @return true if file have been loaded, false if file have not been loaded.
107 bool loadMesh (const std::string
&meshFileName
, const std::string
&skelFileName
);
109 bool loadInstanceGroup(const std::string
&igName
);
111 void setCamera(NLMISC::CAABBox
&bbox
, NL3D::UTransform
&entity
, bool high_z
);
113 /// Reset current scene.
116 /// Update the animation time for Particle System animation.
117 /// @param deltaTime - set the manual animation time.
118 void updateAnimatePS(uint64 deltaTime
= 0);
120 /// Update animation from the scene
121 /// @param time - current time in second
122 void updateAnimation(NL3D::TAnimationTime time
);
124 /// Set the background color.
125 /// @param backgroundColor - background color.
126 void setBackgroundColor(NLMISC::CRGBA backgroundColor
);
129 /// @param Direct3D - type driver (true - Direct3D) or (false -OpenGL)
130 void setGraphicsDriver(bool Direct3D
);
132 /// Set size viewport for correct set perspective
133 /// @param w - width window.
134 /// @param h - height window.
135 void setSizeViewport(uint16 w
, uint16 h
);
137 void setBloomEffect(bool enabled
)
139 _BloomEffect
= enabled
;
142 /// Select instance from the scene
143 /// @param name - name instance, "" if no instance edited
144 void setCurrentObject(const std::string
&name
);
146 /// Get current instance from the scene
147 /// @return name current instance, "" if no instance edited
148 std::string
getCurrentObject() const
150 return _CurrentInstance
;
153 /// Get entity from the scene
154 /// @return ref Entity
155 CEntity
&getEntity(const std::string
&name
);
157 /// Get full list instances from the scene
158 /// @param listObj - ref of return list instances
159 void getListObjects(std::vector
<std::string
> &listObj
);
161 /// Get value background color.
162 /// @return background color.
163 inline NLMISC::CRGBA
getBackgroundColor() const
165 return _BackgroundColor
;
169 /// @return true if have used Direct3D driver, false OpenGL driver.
170 inline bool getDirect3D() const
175 inline bool getBloomEffect() const
180 /// Get a game interface for window driver.
181 /// @return pointer to the driver.
182 inline NL3D::UDriver
*getDriver() const
187 NL3D::IDriver
*getIDriver() const
192 /// Get a game interface for scene.
193 /// @return pointer to the scene.
194 inline NL3D::UScene
*getScene() const
199 NL3D::CScene
*getCScene() const
204 /// Get a manager of playlist
205 /// @return pointer to the UPlayListManager
206 inline NL3D::UPlayListManager
*getPlayListManager() const
208 return _PlayListManager
;
211 /// Get a game interface to render string
212 /// @return pointer to the UPlayListManager
213 inline NL3D::UTextContext
*getTextContext() const
218 /// Get a 3d mouse listener
219 /// @return pointer to the U3dMouseListener
220 inline NL3D::U3dMouseListener
*get3dMouseListener() const
222 return _MouseListener
;
230 // Delete all entities
231 void deleteEntities();
233 NLMISC::CRGBA _BackgroundColor
;
234 NL3D::IDriver
*_IDriver
;
235 NL3D::CScene
*_CScene
;
237 NL3D::UDriver
*_Driver
;
238 NL3D::UScene
*_Scene
;
239 NL3D::UPlayListManager
*_PlayListManager
;
240 NL3D::ULight
*_Light
;
241 NL3D::UCamera
*_Camera
;
242 NL3D::UTextContext
*_TextContext
;
243 NL3D::U3dMouseListener
*_MouseListener
;
244 std::vector
<NL3D::UInstanceGroup
*> _ListIG
;
246 // The entities storage
251 std::string _FontName
;
258 std::string _CurrentInstance
;
260 };/* class CObjectViewer */
262 } /* namespace NLQT */
264 #endif // OBJECT_VIEWER_H