VCameraShakeEvent.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/Core/VGroup.h"
  24. #include "Verve/Extension/Camera/VCameraGroup.h"
  25. #include "Verve/Extension/Camera/VCameraShakeEvent.h"
  26. #include "console/consoleTypes.h"
  27. //-----------------------------------------------------------------------------
  28. IMPLEMENT_CONOBJECT( VCameraShakeEvent );
  29. //-----------------------------------------------------------------------------
  30. VCameraShakeEvent::VCameraShakeEvent( void ) :
  31. mAmplitude( Point3F::Zero ),
  32. mFalloff( 10.f ),
  33. mFrequency( Point3F::Zero )
  34. {
  35. // Clear Label.
  36. setLabel( "CameraShakeEvent" );
  37. }
  38. void VCameraShakeEvent::initPersistFields( void )
  39. {
  40. Parent::initPersistFields();
  41. addField( "Amplitude", TypePoint3F, Offset( mAmplitude, VCameraShakeEvent ), "Amplitude of the Camera Shake event." );
  42. addField( "Falloff", TypeF32, Offset( mFalloff, VCameraShakeEvent ), "Falloff of the Camera Shake event." );
  43. addField( "Frequency", TypePoint3F, Offset( mFrequency, VCameraShakeEvent ), "Frequency of the Camera Shake event." );
  44. }
  45. //-----------------------------------------------------------------------------
  46. //
  47. // Controller Methods.
  48. //
  49. //-----------------------------------------------------------------------------
  50. //-----------------------------------------------------------------------------
  51. //
  52. // VCameraShakeEvent::onTrigger( pTime, pDelta );
  53. //
  54. // Start shaking the camera. Also account for any offet in playtime, and
  55. // timescale.
  56. //
  57. //-----------------------------------------------------------------------------
  58. void VCameraShakeEvent::onTrigger( const S32 &pTime, const S32 &pDelta )
  59. {
  60. Parent::onTrigger( pTime, pDelta );
  61. // Fetch Group.
  62. VCameraGroup *group;
  63. if ( !getGroup( group ) || !group->isActive() )
  64. {
  65. // Inactive.
  66. return;
  67. }
  68. // Duration.
  69. //const F32 duration = ( mDuration - mAbs( pTime - getStartTime() ) ) / ( 1000.f * mFabs( getControllerTimeScale() ) );
  70. const F32 duration = ( mDuration - mAbs( pTime - getStartTime() ) ) / 1000.f;
  71. // Shake Camera.
  72. VTorque::startCameraShake( duration, mFalloff, mAmplitude, mFrequency );
  73. }