/* Object Viewer Qt Copyright (C) 2010 Dzmitry Kamiahin This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef OBJECT_VIEWER_H #define OBJECT_VIEWER_H #include // STL includes #include #include // NeL includes #include #include #include // Project includes #include "entity.h" namespace NL3D { class UDriver; class UScene; class ULight; class UInstance; class UCamera; class USkeleton; class UTextContext; class UPlayListManager; class U3dMouseListener; } namespace NLQT { /** @class CObjectViewer @brief The class initializes the driver and creates a scene, provides basic control functions over the stage driver. @details The class initializes the driver (by choosing OpenGL or Direct3D), and creates a scene (set an aspect), respectively creates a light as well, load the font that is available further for all other subsystems (eg: the signature of the coordinate axes) and Mouse Listener. Settings are loaded from the configuration file. Also, the class provides the following features to scene control: - Loading and displaying of the shape, water shape and the particle system(loadMesh()). As well as the scene reset. (resetScene()) - Provides access to a animation object (getEntity(), getListObjects()). - Select of current object for various operation (mainly related to the animation and editing skeleton):setCurrentObject(), getCurrentObject(). - Operations with the viewport, setting the correct perspective and creating of a screenshot. - Function's updating keyboard and mouse (acts on the camera updateInput()), update(updateAnimatePS(), updateAnimation()) and render the scene (renderDriver(), renderScene()). - Provides access to a general NeL systems (getDriver(), getScene(), getPlayListManager(), getTextContext(), get3dMouseListener()). */ class CObjectViewer { public: /// Default constructor. CObjectViewer(); virtual ~CObjectViewer(); /// Init a driver and create scene. /// @param wnd - handle window. /// @param w - width window. /// @param h - height window. void init(nlWindow wnd, uint16 w, uint16 h); /// Release class. void release(); /// Update mouse and keyboard events. And update camera matrix. void updateInput(); /// Render Driver (clear all buffers and set background color). void renderDriver(); /// Render current scene. void renderScene(); /// Render Debug 2D (stuff for dev). void renderDebug2D(); /// Make a screenshot of the current scene and save. void saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga); /// Load a mesh or particle system and add to current scene. /// @param meshFileName - name loading shape or ps file. /// @param skelFileName - name loading skeletin file. /// @return true if file have been loaded, false if file have not been loaded. bool loadMesh (const std::string &meshFileName, const std::string &skelFileName); /// Reset current scene. void resetScene(); /// Update the navigation camera.(Note: deprecated) /// @param deltaPsi - delta angle horizontal (radians). /// @param deltaPhi - delta angle vertical (radians). /// @param deltaDist - delta distance. void updateCamera(float deltaPsi, float deltaPhi, float deltaDist); /// Update the animation time for Particle System animation. /// @param deltaTime - set the manual animation time. void updateAnimatePS(uint64 deltaTime = 0); /// Update animation from the scene /// @param time - current time in second void updateAnimation(NL3D::TAnimationTime time); /// Set the background color. /// @param backgroundColor - background color. void setBackgroundColor(NLMISC::CRGBA backgroundColor); /// Set type driver. /// @param Direct3D - type driver (true - Direct3D) or (false -OpenGL) void setGraphicsDriver(bool Direct3D); /// Set size viewport for correct set perspective /// @param w - width window. /// @param h - height window. void setSizeViewport(uint16 w, uint16 h); void setBloomEffect(bool enabled) { _BloomEffect = enabled; } /// Select instance from the scene /// @param name - name instance, "" if no instance edited void setCurrentObject(const std::string &name); /// Get current instance from the scene /// @return name current instance, "" if no instance edited const std::string& getCurrentObject() { return _CurrentInstance; } /// Get entity from the scene /// @return ref Entity CEntity& getEntity(const std::string &name); /// Get full list instances from the scene /// @param listObj - ref of return list instances void getListObjects(std::vector &listObj); /// Get value background color. /// @return background color. inline NLMISC::CRGBA getBackgroundColor() const { return _BackgroundColor; } /// Get type driver. /// @return true if have used Direct3D driver, false OpenGL driver. inline bool getDirect3D() const { return _Direct3D; } inline bool getBloomEffect() const { return _BloomEffect; } /// Get a game interface for window driver. /// @return pointer to the driver. inline NL3D::UDriver *getDriver() const { return _Driver; } /// Get a game interface for scene. /// @return pointer to the scene. inline NL3D::UScene *getScene() const { return _Scene; } /// Get a manager of playlist /// @return pointer to the UPlayListManager inline NL3D::UPlayListManager *getPlayListManager() const { return _PlayListManager; } /// Get a game interface to render string /// @return pointer to the UPlayListManager inline NL3D::UTextContext *getTextContext() const { return _TextContext; } /// Get a 3d mouse listener /// @return pointer to the U3dMouseListener inline NL3D::U3dMouseListener *get3dMouseListener() const { return _MouseListener; } private: void loadConfig(); void saveConfig(); // Delete all entities void deleteEntities(); // Load background color from config file, intended for CConfiguration. void cfcbBackgroundColor(NLMISC::CConfigFile::CVar &var); void cfcbGraphicsDriver(NLMISC::CConfigFile::CVar &var); void cfcbCameraFocal(NLMISC::CConfigFile::CVar &var); void cfcbFontName(NLMISC::CConfigFile::CVar &var); void cfcbBloomEffect(NLMISC::CConfigFile::CVar &var); NLMISC::CRGBA _BackgroundColor; NL3D::UDriver *_Driver; NL3D::UScene *_Scene; NL3D::UPlayListManager *_PlayListManager; NL3D::ULight *_Light; NL3D::UCamera *_Camera; NL3D::UTextContext *_TextContext; NL3D::U3dMouseListener *_MouseListener; // The entities storage CEntities _Entities; /// Camera parameters. float _phi, _psi, _dist; float _CameraFocal; std::string _FontName; bool _Direct3D; bool _BloomEffect; std::string _CurrentInstance; };/* class CObjectViewer */ } /* namespace NLQT */ #endif // OBJECT_VIEWER_H