VCameraGroup.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  4. //
  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
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #include "Verve/Extension/Camera/VCameraGroup.h"
  24. #include "Verve/Extension/Camera/VCameraTrack.h"
  25. //-----------------------------------------------------------------------------
  26. IMPLEMENT_CONOBJECT( VCameraGroup );
  27. //-----------------------------------------------------------------------------
  28. VCameraGroup *VCameraGroup::mActiveGroup = NULL;
  29. VCameraGroup::CameraChangeSignal VCameraGroup::mCameraChangeSignal;
  30. //-----------------------------------------------------------------------------
  31. VCameraGroup::VCameraGroup( void )
  32. {
  33. setLabel( "CameraGroup" );
  34. };
  35. //-----------------------------------------------------------------------------
  36. //
  37. // Tree Methods.
  38. //
  39. //-----------------------------------------------------------------------------
  40. //-----------------------------------------------------------------------------
  41. //
  42. // VCameraGroup::onAttach();
  43. //
  44. // This callback subscribes this object to the controller's event signal.
  45. //
  46. //-----------------------------------------------------------------------------
  47. void VCameraGroup::onAttach( void )
  48. {
  49. Parent::onAttach();
  50. // Valid Controller?
  51. if ( getController() )
  52. {
  53. // Subscribe to Events.
  54. getController()->getControllerEventSignal().notify( this, &VCameraGroup::onControllerEvent );
  55. }
  56. }
  57. //-----------------------------------------------------------------------------
  58. //
  59. // VCameraGroup::onAttach();
  60. //
  61. // This callback removes this object from the controller's event signal
  62. // notification list.
  63. //
  64. //-----------------------------------------------------------------------------
  65. void VCameraGroup::onDetach( void )
  66. {
  67. // Valid Controller?
  68. if ( getController() )
  69. {
  70. // Remove Event Notification.
  71. getController()->getControllerEventSignal().remove( this, &VCameraGroup::onControllerEvent );
  72. }
  73. Parent::onDetach();
  74. }
  75. //-----------------------------------------------------------------------------
  76. //
  77. // Controller Methods.
  78. //
  79. //-----------------------------------------------------------------------------
  80. //-----------------------------------------------------------------------------
  81. //
  82. // VCameraGroup::onControllerEvent( pEvent );
  83. //
  84. // When the controller's state changes, this method is called.
  85. //
  86. // For a full list of possible events, see the 'eControllerEventType'
  87. // declaration in VController.h.
  88. //
  89. //-----------------------------------------------------------------------------
  90. bool VCameraGroup::onControllerEvent( VController::eControllerEventType pEvent )
  91. {
  92. if ( !getController() )
  93. {
  94. AssertFatal( false, "VCameraGroup::onControllerEvent() - Invalid Controller." );
  95. return false;
  96. }
  97. // Enabled?
  98. if ( !isEnabled() )
  99. {
  100. // Continue Processing Events.
  101. return true;
  102. }
  103. switch( pEvent )
  104. {
  105. #ifdef VT_EDITOR
  106. case VController::k_EventPause :
  107. #endif
  108. case VController::k_EventStop :
  109. {
  110. // Clear the Camera.
  111. clearActiveGroup();
  112. } break;
  113. }
  114. return true;
  115. }
  116. //-----------------------------------------------------------------------------
  117. //
  118. // Camera Methods.
  119. //
  120. //-----------------------------------------------------------------------------
  121. //-----------------------------------------------------------------------------
  122. //
  123. // VCameraGroup::setActive();
  124. //
  125. // Set this Group to Active.
  126. //
  127. //-----------------------------------------------------------------------------
  128. void VCameraGroup::setActive( void )
  129. {
  130. // Set Active.
  131. setActiveGroup( this );
  132. }
  133. //-----------------------------------------------------------------------------
  134. //
  135. // VCameraGroup::clearActiveGroup();
  136. //
  137. // Clear the Active Camera.
  138. //
  139. //-----------------------------------------------------------------------------
  140. void VCameraGroup::clearActiveGroup( void )
  141. {
  142. if ( mActiveGroup )
  143. {
  144. // Deactivate Signal.
  145. mActiveGroup->getCameraEventSignal().trigger( k_EventDeactivate );
  146. }
  147. // Store.
  148. mActiveGroup = NULL;
  149. // Clear Camera Object.
  150. VTorque::setCamera( NULL );
  151. // Change Signal.
  152. getCameraChangeSignal().trigger( NULL );
  153. }
  154. //-----------------------------------------------------------------------------
  155. //
  156. // VCameraGroup::setActiveGroup( pCameraGroup );
  157. //
  158. // Change the current camera group. The actual camera object is the object that
  159. // the group references.
  160. //
  161. // A NULL value of pCameraGroup will clear the active camera, which generally
  162. // reverts to the connection's control object. The camera is also cleared when
  163. // the Controller stops playing.
  164. //
  165. //-----------------------------------------------------------------------------
  166. void VCameraGroup::setActiveGroup( VCameraGroup *pCameraGroup )
  167. {
  168. // Change Camera?
  169. if ( pCameraGroup == mActiveGroup ||
  170. pCameraGroup && !pCameraGroup->isEnabled() )
  171. {
  172. // Invalid Target.
  173. return;
  174. }
  175. if ( mActiveGroup )
  176. {
  177. // Deactivate Signal.
  178. mActiveGroup->getCameraEventSignal().trigger( k_EventDeactivate );
  179. }
  180. // Store.
  181. mActiveGroup = pCameraGroup;
  182. if ( mActiveGroup )
  183. {
  184. // Set Camera Object.
  185. VTorque::setCamera( mActiveGroup->getSceneObject() );
  186. // Activate Signal.
  187. mActiveGroup->getCameraEventSignal().trigger( k_EventActivate );
  188. }
  189. else
  190. {
  191. // Clear Camera Object.
  192. VTorque::setCamera( NULL );
  193. }
  194. // Change Signal.
  195. getCameraChangeSignal().trigger( mActiveGroup );
  196. }