VGearsUtility.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <boost/algorithm/string.hpp>
  16. #include "VGearsUtility.h"
  17. #include "Characters.h"
  18. namespace VGears{
  19. Utility::Utility(int argc, char *argv[]) :
  20. Application(argc, argv), frame_listener_(NULL), scene_manager_(NULL), camera_(NULL), viewport_(NULL)
  21. {}
  22. Utility::~Utility(){}
  23. Ogre::Camera* Utility::GetCamera(){return camera_;}
  24. void Utility::InitComponents(){
  25. Application::initComponents();
  26. Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  27. Ogre::Root *root(getRoot());
  28. scene_manager_ = root->createSceneManager(Ogre::ST_GENERIC, "Scene");
  29. scene_manager_->clearScene();
  30. scene_manager_->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
  31. Ogre::Light* directional_light = scene_manager_->createLight("directional_light");
  32. directional_light->setType(Ogre::Light::LT_DIRECTIONAL);
  33. directional_light->setDiffuseColour(Ogre::ColourValue(0.5, 0.5, 0.5));
  34. directional_light->setSpecularColour(Ogre::ColourValue(0.5, 0.5, 0.5));
  35. directional_light->setDirection(Ogre::Vector3(0, 0, -1));
  36. camera_ = scene_manager_->createCamera("Camera");
  37. camera_->setNearClipDistance(0.01f);
  38. camera_->setPosition(0, 5, 10);
  39. camera_->lookAt(0, 0, 0);
  40. Ogre::RenderWindow *window(getRenderWindow());
  41. viewport_ = window->addViewport(camera_);
  42. viewport_->setBackgroundColour(Ogre::ColourValue(0.0f, 0.4f, 0.0f));
  43. camera_->setAspectRatio(Ogre::Real(viewport_->getActualWidth()) / Ogre::Real(viewport_->getActualHeight()));
  44. frame_listener_ = new DisplayFrameListener(window);
  45. frame_listener_->setCamera(camera_);
  46. root->addFrameListener(frame_listener_);
  47. }
  48. void Utility::DestroyComponents(){
  49. delete frame_listener_;
  50. frame_listener_ = NULL;
  51. Application::destroyComponents();
  52. }
  53. std::string Utility::DecodeString(const u8* bytes, const unsigned int size){
  54. std::string decoded("");
  55. for (int i = 0; i < size; i ++) if (bytes[i] > 0x00 && bytes[i] < 0XFF) decoded += ENGLISH_CHARS[bytes[i]];
  56. boost::algorithm::trim(decoded);
  57. return decoded;
  58. }
  59. }