VGearsCameraMatrixFile.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <OgreLogManager.h>
  16. #include "data/VGearsCameraMatrixFile.h"
  17. #include "data/VGearsCameraMatrixFileSerializer.h"
  18. namespace VGears{
  19. const String CameraMatrixFile::RESOURCE_TYPE("VGearsCameraMatrixFile");
  20. CameraMatrixFile::CameraMatrixFile(
  21. Ogre::ResourceManager *creator, const String &name,
  22. Ogre::ResourceHandle handle, const String &group, bool is_manual,
  23. Ogre::ManualResourceLoader *loader
  24. ) : Resource(creator, name, handle, group, is_manual, loader){}
  25. CameraMatrixFile::~CameraMatrixFile(){unload();}
  26. void CameraMatrixFile::loadImpl(){
  27. CameraMatrixFileSerializer serializer;
  28. Ogre::DataStreamPtr stream(openResource());
  29. serializer.ImportCameraMatrixFile(stream, this);
  30. }
  31. void CameraMatrixFile::unloadImpl(){
  32. matrix_ = Ogre::Matrix3::ZERO;
  33. position_ = Ogre::Vector3::ZERO;
  34. offset_.x = 0;
  35. offset_.y = 0;
  36. focal_length_ = 0;
  37. count_ = 0;
  38. }
  39. size_t CameraMatrixFile::CalculateSize() const{
  40. // TODO: Here something should probably get counted. But what?
  41. return 0;
  42. }
  43. Ogre::Quaternion CameraMatrixFile::GetOrientation() const{
  44. return Ogre::Quaternion(matrix_);
  45. }
  46. const Ogre::Matrix3& CameraMatrixFile::GetMatrix() const{return matrix_;}
  47. void CameraMatrixFile::SetMatrix(const Ogre::Matrix3& matrix){
  48. matrix_ = matrix;
  49. }
  50. const Ogre::Vector3& CameraMatrixFile::GetPosition() const{
  51. return position_;
  52. }
  53. void CameraMatrixFile::SetPosition(const Ogre::Vector3& position){
  54. position_ = position;
  55. }
  56. const Pixel& CameraMatrixFile::GetOffset() const{return offset_;}
  57. void CameraMatrixFile::SetOffset(const Pixel& offset){offset_ = offset;}
  58. const size_t& CameraMatrixFile::GetCount() const{return count_;}
  59. void CameraMatrixFile::SetCount(const size_t count){count_ = count;}
  60. const Ogre::Real& CameraMatrixFile::GetFocalLength() const{
  61. return focal_length_;
  62. }
  63. void CameraMatrixFile::SetFocalLength(const Ogre::Real focal_length){
  64. focal_length_ = focal_length;
  65. }
  66. Ogre::Radian CameraMatrixFile::GetFov(Ogre::Real width) const{
  67. return 2 * Ogre::Math::ATan(width / (2 * focal_length_));
  68. }
  69. }