camera.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // camera.cpp
  19. // Project: Nostril (aka Postal)
  20. //
  21. // This module impliments the CCamara class
  22. //
  23. // History:
  24. // 01/09/96 MJR Started.
  25. //
  26. // 02/13/97 JMI Now passes m_pHood to CScene::Render().
  27. //
  28. // 02/28/97 JMI The Snap that takes many parameters was not using the
  29. // passed in CScene*, now it is.
  30. // Snap() now accepts a CHood* as well.
  31. //
  32. // 07/05/97 MJR Changed to RSP_BLACK_INDEX instead of 0.
  33. //
  34. // 07/31/97 JMI Added m_bClip to allow us to disable clipping to realm
  35. // edges.
  36. //
  37. ////////////////////////////////////////////////////////////////////////////////
  38. #define CAMERA_CPP
  39. #include "RSPiX.h"
  40. #include "camera.h"
  41. ////////////////////////////////////////////////////////////////////////////////
  42. // Macros/types/etc.
  43. ////////////////////////////////////////////////////////////////////////////////
  44. ////////////////////////////////////////////////////////////////////////////////
  45. // Default constructor
  46. ////////////////////////////////////////////////////////////////////////////////
  47. CCamera::CCamera()
  48. {
  49. // Clear these for testing/debugging
  50. m_pScene = 0;
  51. m_pimFilm = 0;
  52. m_pHood = 0;
  53. // Default to clipping to realm edges.
  54. m_bClip = true;
  55. }
  56. ////////////////////////////////////////////////////////////////////////////////
  57. // Destructor
  58. ////////////////////////////////////////////////////////////////////////////////
  59. CCamera::~CCamera()
  60. {
  61. }
  62. ////////////////////////////////////////////////////////////////////////////////
  63. // Set camera's scene
  64. ////////////////////////////////////////////////////////////////////////////////
  65. void CCamera::SetScene(
  66. CScene* pScene) // In: Scene to take picture of
  67. {
  68. // Save specified values
  69. m_pScene = pScene;
  70. }
  71. ////////////////////////////////////////////////////////////////////////////////
  72. // Set camera's hood
  73. ////////////////////////////////////////////////////////////////////////////////
  74. void CCamera::SetHood(
  75. CHood* pHood) // In: Hood to use for camera control
  76. {
  77. // Save specified values
  78. m_pHood = pHood;
  79. }
  80. ////////////////////////////////////////////////////////////////////////////////
  81. // Set camera's view of the scene
  82. ////////////////////////////////////////////////////////////////////////////////
  83. void CCamera::SetView(
  84. short sSceneViewX, // In: View's upper left x (in scene coords)
  85. short sSceneViewY, // In: View's upper left y (in scene coords)
  86. short sViewW, // In: View's width
  87. short sViewH) // In: View's height
  88. {
  89. // Save specified values
  90. m_sSceneViewX = sSceneViewX;
  91. m_sSceneViewY = sSceneViewY;
  92. m_sViewW = sViewW;
  93. m_sViewH = sViewH;
  94. // Update state
  95. Update();
  96. }
  97. ////////////////////////////////////////////////////////////////////////////////
  98. // Set camera's view position (assumes the view's size will be or was set separately)
  99. ////////////////////////////////////////////////////////////////////////////////
  100. void CCamera::SetViewPos(
  101. short sSceneViewX, // In: View's upper left x (in scene coords)
  102. short sSceneViewY) // In: View's upper left y (in scene coords)
  103. {
  104. // Save specified values
  105. m_sSceneViewX = sSceneViewX;
  106. m_sSceneViewY = sSceneViewY;
  107. // Update state
  108. Update();
  109. }
  110. ////////////////////////////////////////////////////////////////////////////////
  111. // Set camera's view size (assumes the view's position will be or was set separately)
  112. ////////////////////////////////////////////////////////////////////////////////
  113. void CCamera::SetViewSize(
  114. short sViewW, // In: View's width
  115. short sViewH) // In: View's height
  116. {
  117. // Save specified values
  118. m_sViewW = sViewW;
  119. m_sViewH = sViewH;
  120. // Update state
  121. Update();
  122. }
  123. ////////////////////////////////////////////////////////////////////////////////
  124. // Set camera's film (the RImage in which to put pictures of the scene). The view
  125. // can be put anywhere on the film and is clipped as required to fit the film.
  126. ////////////////////////////////////////////////////////////////////////////////
  127. void CCamera::SetFilm(
  128. RImage* pimFilm, // In: Film (where the picture ends up)
  129. short sFilmViewX, // In: View's upper left x (in film coords)
  130. short sFilmViewY) // In: View's upper left y (in film coords)
  131. {
  132. // Save specified values
  133. m_pimFilm = pimFilm;
  134. m_sFilmViewX = sFilmViewX;
  135. m_sFilmViewY = sFilmViewY;
  136. // Update state
  137. Update();
  138. }
  139. ////////////////////////////////////////////////////////////////////////////////
  140. // Snap a picture with the lens cover on (i.e. - set film's view area to black)
  141. ////////////////////////////////////////////////////////////////////////////////
  142. void CCamera::SnapWithLensCoverOn(void)
  143. {
  144. ASSERT(m_pimFilm != NULL);
  145. // Draw black rectangle (automatically clips to image size)
  146. rspRect(RSP_BLACK_INDEX, m_pimFilm, m_sFilmViewX, m_sFilmViewY, m_sViewW, m_sViewH);
  147. }
  148. ////////////////////////////////////////////////////////////////////////////////
  149. // Snap a picture using the preset parameters (scene, view, and film)
  150. ////////////////////////////////////////////////////////////////////////////////
  151. void CCamera::Snap(void)
  152. {
  153. ASSERT(m_pScene != NULL);
  154. ASSERT(m_pimFilm != NULL);
  155. /*
  156. // Init film clipping rect to view's location on the film
  157. RRect rFilmClip(m_sFilmViewX, m_sFilmViewY, m_sViewW, m_sViewH);
  158. // Clip the clipping rect to the film size
  159. RRect rFilmSize(0, 0, m_pimFilm->m_sWidth, m_pimFilm->m_sHeight);
  160. rFilmClip.ClipTo(&rFilmSize);
  161. // Tell scene to render itself onto film
  162. m_pScene->Render(m_sScene2FilmX, m_sScene2FilmY, m_pimFilm, &rFilmClip);
  163. */
  164. // Tell scene to render itself onto film (scene handles clipping)
  165. m_pScene->Render(m_sSceneViewX, m_sSceneViewY, m_sViewW, m_sViewH, m_pimFilm, m_sFilmViewX, m_sFilmViewY, m_pHood);
  166. }
  167. ////////////////////////////////////////////////////////////////////////////////
  168. // Snap a picture using the specified parameters. These parameters are
  169. // temporary -- they do not affect any of the preset parameters!
  170. ////////////////////////////////////////////////////////////////////////////////
  171. void CCamera::Snap(
  172. short sViewW, // In: View's width
  173. short sViewH, // In: View's height
  174. CScene* pScene, // In: Scene to take picture of
  175. CHood* phood, // In: Hood for this scene.
  176. short sSceneViewX, // In: View's upper left x (in scene coords)
  177. short sSceneViewY, // In: View's upper left y (in scene coords)
  178. RImage* pimFilm, // In: Film (where the picture ends up)
  179. short sFilmViewX, // In: View's upper left x (in film coords)
  180. short sFilmViewY) // In: View's upper left y (in film coords)
  181. {
  182. /*
  183. // Init film clipping rect to view's location on the film
  184. RRect rFilmClip(sFilmViewX, sFilmViewY, sViewW, sViewH);
  185. // Clip the clipping rect to the film size
  186. RRect rFilmSize(0, 0, pimFilm->m_sWidth, pimFilm->m_sHeight);
  187. rFilmClip.ClipTo(&rFilmSize);
  188. // Calculate mapping from scene to film coords
  189. short sScene2FilmX = sSceneViewX - sFilmViewX;
  190. short sScene2FilmY = sSceneViewY - sFilmViewY;
  191. // Tell scene to render itself onto film
  192. pScene->Render(sScene2FilmX, sScene2FilmY, pimFilm, &rFilmClip);
  193. */
  194. // Tell scene to render itself onto film (scene handles clipping)
  195. pScene->Render(sSceneViewX, sSceneViewY, sViewW, sViewH, pimFilm, sFilmViewX, sFilmViewY, phood);
  196. }
  197. ////////////////////////////////////////////////////////////////////////////////
  198. // Update internal state after setting new values
  199. ////////////////////////////////////////////////////////////////////////////////
  200. void CCamera::Update(void)
  201. {
  202. // If clipping is on . . .
  203. if (m_bClip == true)
  204. {
  205. // Limit to left edge of scene
  206. if (m_sSceneViewX < 0)
  207. m_sSceneViewX = 0;
  208. // Limit to top edge of scene
  209. if (m_sSceneViewY < 0)
  210. m_sSceneViewY = 0;
  211. // Limit to right edge of scene
  212. if (m_pHood != 0)
  213. {
  214. short sClipX = (m_sSceneViewX + m_sViewW) - m_pHood->GetWidth();
  215. if (sClipX > 0)
  216. m_sSceneViewX -= sClipX;
  217. // Limit to bottom edge of scene
  218. short sClipY = (m_sSceneViewY + m_sViewH) - m_pHood->GetHeight();
  219. if (sClipY > 0)
  220. m_sSceneViewY -= sClipY;
  221. }
  222. }
  223. // Calculate mapping from scene to film coords
  224. m_sScene2FilmX = m_sSceneViewX - m_sFilmViewX;
  225. m_sScene2FilmY = m_sSceneViewY - m_sFilmViewY;
  226. }
  227. ////////////////////////////////////////////////////////////////////////////////
  228. // EOF
  229. ////////////////////////////////////////////////////////////////////////////////