QGearsCameraMatrixFile.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-09-02 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #include "data/QGearsCameraMatrixFile.h"
  23. #include <OgreLogManager.h>
  24. #include "data/QGearsCameraMatrixFileSerializer.h"
  25. namespace QGears
  26. {
  27. //---------------------------------------------------------------------
  28. const String CameraMatrixFile::RESOURCE_TYPE( "QGearsCameraMatrixFile" );
  29. //---------------------------------------------------------------------
  30. CameraMatrixFile::CameraMatrixFile( Ogre::ResourceManager *creator
  31. ,const String &name, Ogre::ResourceHandle handle
  32. ,const String &group, bool isManual
  33. ,Ogre::ManualResourceLoader *loader ) :
  34. Resource( creator, name, handle, group, isManual, loader )
  35. {
  36. }
  37. //---------------------------------------------------------------------
  38. CameraMatrixFile::~CameraMatrixFile()
  39. {
  40. unload();
  41. }
  42. //---------------------------------------------------------------------
  43. void
  44. CameraMatrixFile::loadImpl()
  45. {
  46. CameraMatrixFileSerializer serializer;
  47. Ogre::DataStreamPtr stream( openResource() );
  48. serializer.importCameraMatrixFile( stream, this );
  49. }
  50. //---------------------------------------------------------------------
  51. void
  52. CameraMatrixFile::unloadImpl()
  53. {
  54. m_matrix = Ogre::Matrix3::ZERO;
  55. m_position = Ogre::Vector3::ZERO;
  56. m_offset.x = 0;
  57. m_offset.y = 0;
  58. m_focal_length = 0;
  59. m_count = 0;
  60. }
  61. //---------------------------------------------------------------------
  62. size_t
  63. CameraMatrixFile::calculateSize() const
  64. {
  65. return 0;
  66. }
  67. //---------------------------------------------------------------------
  68. Ogre::Quaternion
  69. CameraMatrixFile::getOrientation() const
  70. {
  71. return Ogre::Quaternion( m_matrix );
  72. }
  73. //---------------------------------------------------------------------
  74. const Ogre::Matrix3&
  75. CameraMatrixFile::getMatrix() const
  76. {
  77. return m_matrix;
  78. }
  79. //---------------------------------------------------------------------
  80. void
  81. CameraMatrixFile::setMatrix( const Ogre::Matrix3& matrix )
  82. {
  83. m_matrix = matrix;
  84. }
  85. //---------------------------------------------------------------------
  86. const Ogre::Vector3&
  87. CameraMatrixFile::getPosition() const
  88. {
  89. return m_position;
  90. }
  91. //---------------------------------------------------------------------
  92. void
  93. CameraMatrixFile::setPosition( const Ogre::Vector3& position )
  94. {
  95. m_position = position;
  96. }
  97. //---------------------------------------------------------------------
  98. const Pixel&
  99. CameraMatrixFile::getOffset() const
  100. {
  101. return m_offset;
  102. }
  103. //---------------------------------------------------------------------
  104. void
  105. CameraMatrixFile::setOffset( const Pixel& offset )
  106. {
  107. m_offset = offset;
  108. }
  109. //---------------------------------------------------------------------
  110. const size_t&
  111. CameraMatrixFile::getCount() const
  112. {
  113. return m_count;
  114. }
  115. //---------------------------------------------------------------------
  116. void
  117. CameraMatrixFile::setCount( const size_t count )
  118. {
  119. m_count = count;
  120. }
  121. //---------------------------------------------------------------------
  122. const Ogre::Real&
  123. CameraMatrixFile::getFocalLength() const
  124. {
  125. return m_focal_length;
  126. }
  127. //---------------------------------------------------------------------
  128. void
  129. CameraMatrixFile::setFocalLength( const Ogre::Real focal_length )
  130. {
  131. m_focal_length = focal_length;
  132. }
  133. //---------------------------------------------------------------------
  134. Ogre::Radian
  135. CameraMatrixFile::getFov( const Ogre::Real& width ) const
  136. {
  137. return 2 * Ogre::Math::ATan( width / (2 * m_focal_length ) );
  138. }
  139. //---------------------------------------------------------------------
  140. }