QGearsUtility.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. -----------------------------------------------------------------------------
  3. Copyright (c) 26.10.2013 Tobias Peters <tobias.peters@kreativeffekt.at>
  4. This file is part of Q-Gears
  5. Q-Gears 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, version 2.0 (GPLv2) of the License.
  8. Q-Gears is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. -----------------------------------------------------------------------------
  13. */
  14. #include "QGearsUtility.h"
  15. namespace QGears
  16. {
  17. //--------------------------------------------------------------------------
  18. Utility::Utility(int argc, char *argv[]) :
  19. Application( argc, argv )
  20. , m_frame_listener( NULL )
  21. , m_scene_manager( NULL )
  22. , m_camera( NULL )
  23. , m_viewport( NULL )
  24. {
  25. }
  26. //--------------------------------------------------------------------------
  27. Utility::~Utility()
  28. {
  29. }
  30. //--------------------------------------------------------------------------
  31. Ogre::Camera*
  32. Utility::getCamera()
  33. {
  34. return m_camera;
  35. }
  36. //--------------------------------------------------------------------------
  37. void
  38. Utility::initComponents()
  39. {
  40. Application::initComponents();
  41. Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  42. Ogre::Root *root( getRoot() );
  43. m_scene_manager = root->createSceneManager( Ogre::ST_GENERIC, "Scene" );
  44. m_scene_manager->clearScene();
  45. m_scene_manager->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5 ) );
  46. Ogre::Light* directionalLight = m_scene_manager->createLight("directionalLight");
  47. directionalLight->setType( Ogre::Light::LT_DIRECTIONAL );
  48. directionalLight->setDiffuseColour( Ogre::ColourValue( 0.5, 0.5, 0.5) );
  49. directionalLight->setSpecularColour( Ogre::ColourValue( 0.5, 0.5, 0.5) );
  50. directionalLight->setDirection( Ogre::Vector3( 0, 0, -1 ) );
  51. m_camera = m_scene_manager->createCamera( "Camera" );
  52. m_camera->setNearClipDistance( 0.01f );
  53. m_camera->setPosition( 0, 5, 10 );
  54. m_camera->lookAt( 0, 0, 0 );
  55. Ogre::RenderWindow *window( getRenderWindow() );
  56. m_viewport = window->addViewport( m_camera );
  57. m_viewport->setBackgroundColour( Ogre::ColourValue( 0.0f, 0.4f, 0.0f ) );
  58. m_camera->setAspectRatio( Ogre::Real( m_viewport->getActualWidth() ) / Ogre::Real( m_viewport->getActualHeight() ) );
  59. m_frame_listener = new DisplayFrameListener( window );
  60. m_frame_listener->setCamera( m_camera );
  61. root->addFrameListener( m_frame_listener );
  62. }
  63. //--------------------------------------------------------------------------
  64. void
  65. Utility::destroyComponents()
  66. {
  67. delete m_frame_listener;
  68. m_frame_listener = NULL;
  69. Application::destroyComponents();
  70. }
  71. //--------------------------------------------------------------------------
  72. }