ComputerGraphik TU WIEN
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Scene Class Reference

Encapsulates the Rendering Engine, holds a complete scene and it's assets. More...

#include <scene.hpp>

Public Types

enum  {
  SentinelPre = 0, SentinelDraw = 1000, SentinelDrawPickable = 1500, SentinelPost = 2000,
  SentinelUnordered = 3000
}
 
typedef std::map< std::size_t, std::shared_ptr< SceneObject > >::const_iterator ConstIterator
 

Public Member Functions

 Scene (GLFWwindow *window)
 
 ~Scene ()
 
void init (const std::string &scenePath)
 
void clearRender ()
 
void remRender (std::shared_ptr< SceneObject > &object)
 
void getRender (size_t idx, std::shared_ptr< SceneObject > &object) const
 
size_t pushRender (std::shared_ptr< SceneObject > &object, size_t idx=SentinelUnordered)
 
size_t insertRender (std::shared_ptr< SceneObject > &object, size_t idx=SentinelUnordered)
 
ShadergetShader (const std::string &name) const
 
void addShader (const std::string &name, std::unique_ptr< Shader > &shader)
 
void changeRenderShader (const std::string &from, const std::string &to)
 
GLFWwindow * getWindow () const
 
std::shared_ptr< LightgetLight () const
 
std::shared_ptr< CameragetCamera () const
 
std::shared_ptr< SceneObjectgetRootNode () const
 
std::shared_ptr< CubeMapObjectgetCubeMapObject () const
 
std::shared_ptr< LightCameragetLightCam () const
 
std::shared_ptr< SunVolumetricgetSunVolumetric () const
 
std::shared_ptr< MouseSemanticsgetMouseSemantics () const
 
std::shared_ptr< SelectorBasegetActiveSelector () const
 
std::shared_ptr< LegendgetLegend () const
 
std::shared_ptr< BubbleCursorgetBubbleCursor () const
 
bool getObject (const std::string &name, std::shared_ptr< SceneObject > &object, size_t pos=1) const
 
void setWindow (GLFWwindow *val)
 
void setLight (std::shared_ptr< Light > val)
 
void setCamera (std::shared_ptr< Camera > val)
 
void setRootNode (std::shared_ptr< SceneObject > root)
 
void setCubeMapObject (std::shared_ptr< CubeMapObject > val)
 
void setLightCam (std::shared_ptr< LightCamera > val)
 
void setSunVolumetric (std::shared_ptr< SunVolumetric > val)
 
void setMouseSemantics (std::shared_ptr< MouseSemantics > val)
 
void setActiveSelector (std::shared_ptr< SelectorBase > val)
 
void setLegend (std::shared_ptr< Legend > val)
 
void setBubbleCursor (std::shared_ptr< BubbleCursor > val)
 
ConstIterator end () const
 
ConstIterator begin () const
 
ConstIterator end (size_t idx) const
 
ConstIterator begin (size_t idx) const
 

Static Public Member Functions

static std::shared_ptr< SceneObjectget (const ConstIterator &it)
 

Private Member Functions

bool getObjectRecursive (const std::string &name, std::shared_ptr< SceneObject > &object, size_t &pos) const
 

Private Attributes

GLFWwindow * window
 
std::shared_ptr< Lightlight
 
std::shared_ptr< Cameracamera
 
std::shared_ptr< CubeMapObjectcmObject
 
std::shared_ptr< LightCameralightCam
 
std::shared_ptr< SunVolumetricsunVolumetric
 
std::shared_ptr< MouseSemanticsmouseSemantics
 
std::shared_ptr< SelectorBaseactiveSelector
 
std::shared_ptr< Legendlegend
 
std::shared_ptr< BubbleCursorbubbleCursor
 
std::shared_ptr< SceneObjectrootNode
 
std::map< std::string, std::unique_ptr< Model > > models
 
std::map< std::string, std::unique_ptr< Shader > > shaders
 
std::map< std::string, std::unique_ptr< Texture > > textures
 
std::map< std::size_t, std::shared_ptr< SceneObject > > renderList
 

Friends

class Debug
 
class AssimpLoader
 

Detailed Description

Encapsulates the Rendering Engine, holds a complete scene and it's assets.

Author
Adam Felix
Design

The rendering engine has the same hierarchy as the Assimp aiScene class. The Assimp Scene Structure can be seen on the following image.

assimp.png
http://ephenationopengl.blogspot.co.at

The rendering engine is designed in parent-child relation. Each SceneObject holds it's local model matrix. In order to compute the global model matrix of an object, the parents must be traversed until the root. This way the camera is also the part of the scene, therefore camera animation can be handled. Also animated objects like the tank can be displayed.

Each SceneObject (Assimp:aiNode) has a corresponding aiNodeAnim, which is accessible through the name. For convenience, the number of Quaternion, Position and Scaling and their time at the same index must be the same. The time is a measurement since the start of the global scene animation. The local model matrices are computed using the equation M = T * R * S, where the Quaternions, Position and Scalings are interpolated values between two T, R, S from aiNodeAnim. The SceneObject class has a virtual animate() function, which takes the time since start as an argument. This function takes the $i^{th}$ local model matrix from the animation, where $M_i.time < time <= M_{i+1}.time$ and sets it as the current local model matrix. The animate() function was chosen to be virtual, because special objects might need special calls, for example the camera class needs to compute the view matrix on every model matrix change.

The models are also loaded using the Assimp library. The material information is stored in the model object. Images are loaded using the OpenCV library and stored in a texture object. Multiple SceneObjects can use the same model or texture objects. Shader loading is redesigned to be able to link together arbitrary number of shaders of different types.

Implementation
The assets are stored as a std::map of std::unique_ptr. If needed they can be searched by name, but objects can have direct access through raw pointers. This design does not allow easy swapping of assets between different scenes. The SceneObjects are stored in parent-child hierarchy, therefore only the root node is stored. For rendering purpose, a render list is stored as a std::map. Objects can be pushed or inserted according to indices, and can be removed with pointers. The SceneObjects are stored as std::shared_ptr. This might be a performance decrease, because of the atomic increments, in the current design where there is no multithreading.

Member Typedef Documentation

typedef std::map<std::size_t, std::shared_ptr<SceneObject> >::const_iterator Scene::ConstIterator

Member Enumeration Documentation

anonymous enum
Enumerator
SentinelPre 
SentinelDraw 
SentinelDrawPickable 
SentinelPost 
SentinelUnordered 

Constructor & Destructor Documentation

Scene::Scene ( GLFWwindow *  window)
Scene::~Scene ( )

Member Function Documentation

void Scene::addShader ( const std::string &  name,
std::unique_ptr< Shader > &  shader 
)
ConstIterator Scene::begin ( ) const
inline
ConstIterator Scene::begin ( size_t  idx) const
inline
void Scene::changeRenderShader ( const std::string &  from,
const std::string &  to 
)
void Scene::clearRender ( )
ConstIterator Scene::end ( ) const
inline
ConstIterator Scene::end ( size_t  idx) const
inline
static std::shared_ptr<SceneObject> Scene::get ( const ConstIterator it)
inlinestatic
std::shared_ptr<SelectorBase> Scene::getActiveSelector ( ) const
inline
std::shared_ptr<BubbleCursor> Scene::getBubbleCursor ( ) const
inline
std::shared_ptr<Camera> Scene::getCamera ( ) const
inline
std::shared_ptr<CubeMapObject> Scene::getCubeMapObject ( ) const
inline
std::shared_ptr<Legend> Scene::getLegend ( ) const
inline
std::shared_ptr<Light> Scene::getLight ( ) const
inline
std::shared_ptr<LightCamera> Scene::getLightCam ( ) const
inline
std::shared_ptr<MouseSemantics> Scene::getMouseSemantics ( ) const
inline
bool Scene::getObject ( const std::string &  name,
std::shared_ptr< SceneObject > &  object,
size_t  pos = 1 
) const
bool Scene::getObjectRecursive ( const std::string &  name,
std::shared_ptr< SceneObject > &  object,
size_t &  pos 
) const
private
void Scene::getRender ( size_t  idx,
std::shared_ptr< SceneObject > &  object 
) const
std::shared_ptr<SceneObject> Scene::getRootNode ( ) const
inline
Shader * Scene::getShader ( const std::string &  name) const
std::shared_ptr<SunVolumetric> Scene::getSunVolumetric ( ) const
inline
GLFWwindow* Scene::getWindow ( ) const
inline
void Scene::init ( const std::string &  scenePath)
size_t Scene::insertRender ( std::shared_ptr< SceneObject > &  object,
size_t  idx = SentinelUnordered 
)
size_t Scene::pushRender ( std::shared_ptr< SceneObject > &  object,
size_t  idx = SentinelUnordered 
)
void Scene::remRender ( std::shared_ptr< SceneObject > &  object)
void Scene::setActiveSelector ( std::shared_ptr< SelectorBase val)
inline
void Scene::setBubbleCursor ( std::shared_ptr< BubbleCursor val)
inline
void Scene::setCamera ( std::shared_ptr< Camera val)
inline
void Scene::setCubeMapObject ( std::shared_ptr< CubeMapObject val)
inline
void Scene::setLegend ( std::shared_ptr< Legend val)
inline
void Scene::setLight ( std::shared_ptr< Light val)
inline
void Scene::setLightCam ( std::shared_ptr< LightCamera val)
inline
void Scene::setMouseSemantics ( std::shared_ptr< MouseSemantics val)
inline
void Scene::setRootNode ( std::shared_ptr< SceneObject root)
inline
void Scene::setSunVolumetric ( std::shared_ptr< SunVolumetric val)
inline
void Scene::setWindow ( GLFWwindow *  val)
inline

Friends And Related Function Documentation

friend class AssimpLoader
friend
friend class Debug
friend

Member Data Documentation

std::shared_ptr<SelectorBase> Scene::activeSelector
private
std::shared_ptr<BubbleCursor> Scene::bubbleCursor
private
std::shared_ptr<Camera> Scene::camera
private
std::shared_ptr<CubeMapObject> Scene::cmObject
private
std::shared_ptr<Legend> Scene::legend
private
std::shared_ptr<Light> Scene::light
private
std::shared_ptr<LightCamera> Scene::lightCam
private
std::map<std::string, std::unique_ptr<Model> > Scene::models
private
std::shared_ptr<MouseSemantics> Scene::mouseSemantics
private
std::map<std::size_t, std::shared_ptr<SceneObject> > Scene::renderList
private
std::shared_ptr<SceneObject> Scene::rootNode
private
std::map<std::string, std::unique_ptr<Shader> > Scene::shaders
private
std::shared_ptr<SunVolumetric> Scene::sunVolumetric
private
std::map<std::string, std::unique_ptr<Texture> > Scene::textures
private
GLFWwindow* Scene::window
private

The documentation for this class was generated from the following files: