VGearsUtility.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears 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.
  14. */
  15. #include "VGearsUtility.h"
  16. namespace VGears
  17. {
  18. Utility::Utility(int argc, char *argv[]) :
  19. Application(argc, argv),
  20. frame_listener_(NULL),
  21. scene_manager_(NULL),
  22. camera_(NULL),
  23. viewport_(NULL)
  24. {}
  25. Utility::~Utility(){}
  26. Ogre::Camera* Utility::GetCamera(){return camera_;}
  27. void Utility::InitComponents(){
  28. Application::initComponents();
  29. Ogre::ResourceGroupManager::getSingleton()
  30. .initialiseAllResourceGroups();
  31. Ogre::Root *root(getRoot());
  32. scene_manager_ = root->createSceneManager(Ogre::ST_GENERIC, "Scene");
  33. scene_manager_->clearScene();
  34. scene_manager_->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
  35. Ogre::Light* directional_light = scene_manager_->createLight(
  36. "directional_light"
  37. );
  38. directional_light->setType(Ogre::Light::LT_DIRECTIONAL);
  39. directional_light->setDiffuseColour(Ogre::ColourValue(0.5, 0.5, 0.5));
  40. directional_light->setSpecularColour(Ogre::ColourValue(0.5, 0.5, 0.5));
  41. directional_light->setDirection(Ogre::Vector3(0, 0, -1));
  42. camera_ = scene_manager_->createCamera("Camera");
  43. camera_->setNearClipDistance(0.01f);
  44. camera_->setPosition(0, 5, 10);
  45. camera_->lookAt(0, 0, 0);
  46. Ogre::RenderWindow *window(getRenderWindow());
  47. viewport_ = window->addViewport(camera_);
  48. viewport_->setBackgroundColour(Ogre::ColourValue(0.0f, 0.4f, 0.0f));
  49. camera_->setAspectRatio(
  50. Ogre::Real(viewport_->getActualWidth())
  51. / Ogre::Real(viewport_->getActualHeight())
  52. );
  53. frame_listener_ = new DisplayFrameListener(window);
  54. frame_listener_->setCamera(camera_);
  55. root->addFrameListener(frame_listener_);
  56. }
  57. void Utility::DestroyComponents(){
  58. delete frame_listener_;
  59. frame_listener_ = NULL;
  60. Application::destroyComponents();
  61. }
  62. }