VCameraShake.cpp
Engine/source/Verve/Torque3D/VCameraShake.cpp
Public Functions
DefineEngineFunction(ShakeCamera , void , (F32 duration, F32 falloff, VectorF amplitude, VectorF frequency) , (0, 0, VectorF::Zero, VectorF::Zero) , "( pDuration, pFalloff, pAmplitude, pFrequency )" )
Detailed Description
Public Functions
DefineEngineFunction(ShakeCamera , void , (F32 duration, F32 falloff, VectorF amplitude, VectorF frequency) , (0, 0, VectorF::Zero, VectorF::Zero) , "( pDuration, pFalloff, pAmplitude, pFrequency )" )
IMPLEMENT_CO_CLIENTEVENT_V1(VCameraShakeNetEvent )
1 2//----------------------------------------------------------------------------- 3// Verve 4// Copyright (C) 2014 - Violent Tulip 5// 6// Permission is hereby granted, free of charge, to any person obtaining a copy 7// of this software and associated documentation files (the "Software"), to 8// deal in the Software without restriction, including without limitation the 9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10// sell copies of the Software, and to permit persons to whom the Software is 11// furnished to do so, subject to the following conditions: 12// 13// The above copyright notice and this permission notice shall be included in 14// all copies or substantial portions of the Software. 15// 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22// IN THE SOFTWARE. 23//----------------------------------------------------------------------------- 24#include "Verve/Torque3D/VCameraShake.h" 25 26#include "T3D/gameBase/gameConnection.h" 27#include "core/stream/bitStream.h" 28 29//----------------------------------------------------------------------------- 30IMPLEMENT_CO_CLIENTEVENT_V1( VCameraShakeNetEvent ); 31//----------------------------------------------------------------------------- 32 33// ShakeCamera( 1, 10, "1 0 0", "1 0 0" ); 34DefineEngineFunction( ShakeCamera, void, (F32 duration, F32 falloff, VectorF amplitude, VectorF frequency), (0,0,VectorF::Zero, VectorF::Zero), "( pDuration, pFalloff, pAmplitude, pFrequency )" ) 35{ 36 // Shake Camera. 37 VTorque::startCameraShake( duration, falloff, amplitude, frequency ); 38} 39 40void VTorque::startCameraShake( const F32 &pDuration, const F32 &pFalloff, const VectorF &pAmplitude, const VectorF &pFrequency ) 41{ 42#ifdef VT_EDITOR 43 44 // Create FX Event 45 CameraShake *camShake = new CameraShake(); 46 47 // Set Duration. 48 camShake->setDuration( pDuration ); 49 50 // Set Falloff. 51 camShake->setFalloff( pFalloff ); 52 53 // Set Amplitude. 54 VectorF amp = pAmplitude; 55 camShake->setAmplitude( amp ); 56 57 // Set Frequency. 58 VectorF freq = pFrequency; 59 camShake->setFrequency( freq ); 60 61 // Initialise. 62 camShake->init(); 63 64 // Add to Manager. 65 gCamFXMgr.addFX( camShake ); 66 67#else 68 69 // Fetch Client Group. 70 SimGroup* clientGroup = Sim::getClientGroup(); 71 72 for ( SimGroup::iterator itr = clientGroup->begin(); itr != clientGroup->end(); itr++ ) 73 { 74 NetConnection *connection = static_cast<NetConnection*>( *itr ); 75 if ( connection ) 76 { 77 // Create Event. 78 VCameraShakeNetEvent *event = new VCameraShakeNetEvent(); 79 80 // Setup Event. 81 event->mEventType |= ( VCameraShakeNetEvent::k_TypeClear | VCameraShakeNetEvent::k_TypeMake ); 82 event->mDuration = pDuration; 83 event->mFalloff = pFalloff; 84 event->mAmplitude = pAmplitude; 85 event->mFrequency = pFrequency; 86 87 // Post Event. 88 connection->postNetEvent( event ); 89 } 90 } 91 92#endif 93} 94 95void VTorque::stopCameraShake( void ) 96{ 97#ifdef VT_EDITOR 98 99 // Clear Manager. 100 gCamFXMgr.clear(); 101 102#else 103 104 // Fetch Client Group. 105 SimGroup* clientGroup = Sim::getClientGroup(); 106 107 for ( SimGroup::iterator itr = clientGroup->begin(); itr != clientGroup->end(); itr++ ) 108 { 109 NetConnection *connection = static_cast<NetConnection*>( *itr ); 110 if ( connection ) 111 { 112 // Create Event. 113 VCameraShakeNetEvent *event = new VCameraShakeNetEvent(); 114 115 // Setup Event. 116 event->mEventType |= VCameraShakeNetEvent::k_TypeClear; 117 118 // Post Event. 119 connection->postNetEvent( event ); 120 } 121 } 122 123#endif 124} 125 126//----------------------------------------------------------------------------- 127 128VCameraShakeNetEvent::VCameraShakeNetEvent( void ) : mEventType( 0 ), 129 mDuration( 0.f ), 130 mFalloff( 10.f ), 131 mAmplitude( Point3F::Zero ), 132 mFrequency( Point3F::Zero ) 133{ 134 // Void. 135} 136 137void VCameraShakeNetEvent::write( NetConnection *pConnection, BitStream *pStream ) 138{ 139 // Void. 140} 141 142void VCameraShakeNetEvent::pack( NetConnection *pConnection, BitStream *pStream ) 143{ 144 // Clear Manager? 145 pStream->write( mEventType & k_TypeClear ); 146 147 // Make Event? 148 if ( pStream->write( mEventType & k_TypeMake ) ) 149 { 150 // Duration. 151 pStream->write( mDuration ); 152 153 // Falloff. 154 pStream->write( mFalloff ); 155 156 // Amplitude. 157 pStream->write( mAmplitude.x ); 158 pStream->write( mAmplitude.y ); 159 pStream->write( mAmplitude.z ); 160 161 // Frequency. 162 pStream->write( mFrequency.x ); 163 pStream->write( mFrequency.y ); 164 pStream->write( mFrequency.z ); 165 } 166} 167 168void VCameraShakeNetEvent::unpack( NetConnection *pConnection, BitStream *pStream ) 169{ 170 // Clear Manager? 171 if ( pStream->readFlag() ) 172 { 173 // Update State. 174 mEventType |= k_TypeClear; 175 } 176 177 // Make Event? 178 if ( pStream->readFlag() ) 179 { 180 // Update State. 181 mEventType |= k_TypeMake; 182 183 // Duration. 184 pStream->read( &mDuration ); 185 186 // Falloff. 187 pStream->read( &mFalloff ); 188 189 // Amplitude. 190 pStream->read( &mAmplitude.x ); 191 pStream->read( &mAmplitude.y ); 192 pStream->read( &mAmplitude.z ); 193 194 // Frequency. 195 pStream->read( &mFrequency.x ); 196 pStream->read( &mFrequency.y ); 197 pStream->read( &mFrequency.z ); 198 } 199} 200 201void VCameraShakeNetEvent::process( NetConnection *pConnection ) 202{ 203 if ( mEventType & k_TypeClear ) 204 { 205 // Clear Manager. 206 gCamFXMgr.clear(); 207 } 208 209 if ( mEventType & k_TypeMake ) 210 { 211 // Create FX Event 212 CameraShake *camShake = new CameraShake(); 213 214 // Set Duration. 215 camShake->setDuration( mDuration ); 216 217 // Set Falloff. 218 camShake->setFalloff( mFalloff ); 219 220 // Set Amplitude. 221 camShake->setAmplitude( mAmplitude ); 222 223 // Set Frequency. 224 camShake->setFrequency( mFrequency ); 225 226 // Initialise. 227 camShake->init(); 228 229 // Add to Manager. 230 gCamFXMgr.addFX( camShake ); 231 } 232} 233