VGearsUtility.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. Utility::Utility(int argc, char *argv[]) :
  18. Application(argc, argv), frame_listener_(NULL), scene_manager_(NULL),
  19. camera_(NULL), viewport_(NULL)
  20. {}
  21. Utility::~Utility(){}
  22. Ogre::Camera* Utility::GetCamera(){return camera_;}
  23. void Utility::InitComponents(){
  24. Application::initComponents();
  25. Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  26. Ogre::Root *root(getRoot());
  27. scene_manager_ = root->createSceneManager(Ogre::ST_GENERIC, "Scene");
  28. scene_manager_->clearScene();
  29. scene_manager_->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
  30. Ogre::Light* directional_light = scene_manager_->createLight("directional_light");
  31. directional_light->setType(Ogre::Light::LT_DIRECTIONAL);
  32. directional_light->setDiffuseColour(Ogre::ColourValue(0.5, 0.5, 0.5));
  33. directional_light->setSpecularColour(Ogre::ColourValue(0.5, 0.5, 0.5));
  34. directional_light->setDirection(Ogre::Vector3(0, 0, -1));
  35. camera_ = scene_manager_->createCamera("Camera");
  36. camera_->setNearClipDistance(0.01f);
  37. camera_->setPosition(0, 5, 10);
  38. camera_->lookAt(0, 0, 0);
  39. Ogre::RenderWindow *window(getRenderWindow());
  40. viewport_ = window->addViewport(camera_);
  41. viewport_->setBackgroundColour(Ogre::ColourValue(0.0f, 0.4f, 0.0f));
  42. camera_->setAspectRatio(
  43. Ogre::Real(viewport_->getActualWidth()) / Ogre::Real(viewport_->getActualHeight())
  44. );
  45. frame_listener_ = new DisplayFrameListener(window);
  46. frame_listener_->setCamera(camera_);
  47. root->addFrameListener(frame_listener_);
  48. }
  49. void Utility::DestroyComponents(){
  50. delete frame_listener_;
  51. frame_listener_ = NULL;
  52. Application::destroyComponents();
  53. }
  54. }