VShapeAnimationTrack.cpp
Engine/source/Verve/Extension/Animation/VShapeAnimationTrack.cpp
Public Functions
Detailed Description
Public Functions
IMPLEMENT_CONOBJECT(VShapeAnimationTrack )
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/Extension/Animation/VShapeAnimationTrack.h" 25#include "Verve/Extension/Animation/VShapeAnimationEvent.h" 26#include "Verve/Core/VGroup.h" 27 28#include "console/consoleTypes.h" 29 30//----------------------------------------------------------------------------- 31IMPLEMENT_CONOBJECT( VShapeAnimationTrack ); 32//----------------------------------------------------------------------------- 33 34VShapeAnimationTrack::VShapeAnimationTrack( void ) : 35 mThreadIndex( 0 ) 36{ 37 setLabel( "AnimationTrack" ); 38} 39 40//----------------------------------------------------------------------------- 41 42void VShapeAnimationTrack::initPersistFields( void ) 43{ 44 Parent::initPersistFields(); 45 46 addField( "ThreadIndex", TypeS32, Offset( mThreadIndex, VShapeAnimationTrack ), "The index of the Animation Thread to play." ); 47} 48 49//----------------------------------------------------------------------------- 50// 51// Controller Methods. 52// 53//----------------------------------------------------------------------------- 54 55//----------------------------------------------------------------------------- 56// 57// VShapeAnimationTrack::onControllerEvent( pEvent ); 58// 59// When the controller's state changes, this method is called. If the 60// controller is paused, or stops playing, then the animation will cease to 61// play. If the controller resumes play, the animation will continue. 62// 63// For a full list of possible events, see the 'eControllerEventType' 64// declaration in VController.h. 65// 66//----------------------------------------------------------------------------- 67bool VShapeAnimationTrack::onControllerEvent( VController::eControllerEventType pEvent ) 68{ 69 if ( !Parent::onControllerEvent( pEvent ) ) 70 { 71 // Skip. 72 return false; 73 } 74 75 // Enabled? 76 if ( !isEnabled() ) 77 { 78 // Continue Processing Events. 79 return true; 80 } 81 82 switch ( pEvent ) 83 { 84 case VController::k_EventPlay : 85 { 86 87 // Play Animation. 88 VTorque::setAnimationTimeScale( getSceneObject(), mThreadIndex, ( ( isControllerPlayingForward() ) ? 1.f : -1.f ) ); 89 90 } break; 91 92 case VController::k_EventPause : 93 case VController::k_EventStop : 94 { 95 96 // Stop Animation. 97 VTorque::setAnimationTimeScale( getSceneObject(), mThreadIndex, 0.f ); 98 99 } break; 100 } 101 102 return true; 103} 104 105//----------------------------------------------------------------------------- 106// 107// VShapeAnimationTrack::onControllerReset( pTime, pForward ); 108// 109// Reset the animation state of the target object. If there is a Next Event, 110// then the animation is positioned accordingly. 111// 112//----------------------------------------------------------------------------- 113void VShapeAnimationTrack::onControllerReset( const S32 &pTime, const bool &pForward ) 114{ 115 VTorque::SceneObjectType *object = getSceneObject(); 116 if ( !object ) 117 { 118 // Parent Call. 119 Parent::onControllerReset( pTime, pForward ); 120 return; 121 } 122 123 VShapeAnimationEvent *event; 124 if ( getCurrentEvent( event ) ) 125 { 126 // Stop Animation. 127 VTorque::stopAnimation( object, mThreadIndex ); 128 } 129 130 // Parent Call. 131 Parent::onControllerReset( pTime, pForward ); 132 133 if ( getCurrentEvent( event ) ) 134 { 135 // Play Animation. 136 VTorque::playAnimation( object, mThreadIndex, event->mAnimationData ); 137 138 // Set Position. 139 VTorque::setAnimationPosition( object, mThreadIndex, event->getAnimationPosition( pTime ) ); 140 141 // Stop Animation. 142 VTorque::setAnimationTimeScale( object, mThreadIndex, 0.f ); 143 } 144} 145 146#ifdef VT_EDITOR 147//----------------------------------------------------------------------------- 148// 149// Debug Methods. 150// 151//----------------------------------------------------------------------------- 152 153DefineEngineMethod( VShapeAnimationTrack, updateTrack, void, (),, "( void ) - Update the Track.\n" 154 "@return No return value." ) 155{ 156 for ( ITreeNode *node = object->mChildNode; node != NULL; node = node->mSiblingNextNode ) 157 { 158 VShapeAnimationEvent *currEvent = ( VShapeAnimationEvent* )node; 159 VShapeAnimationEvent *nextEvent = ( VShapeAnimationEvent* )node->mSiblingNextNode; 160 if ( !currEvent->mAutoDuration ) 161 { 162 // Skip. 163 continue; 164 } 165 166 if ( VTorque::isAnimationLooping( object->getSceneObject(), currEvent->mAnimationData ) ) 167 { 168 if ( !nextEvent ) 169 { 170 // Update Duration. 171 currEvent->setDuration( object->getControllerDuration() - currEvent->getTriggerTime() ); 172 } 173 else 174 { 175 // Update Duration. 176 currEvent->setDuration( mAbs( nextEvent->getTriggerTime() - currEvent->getTriggerTime() ) ); 177 } 178 } 179 else 180 { 181 // Update Duration. 182 currEvent->setDuration( ( S32 )( 1000 * VTorque::getAnimationDuration( object->getSceneObject(), currEvent->mAnimationData ) ) ); 183 } 184 } 185} 186#endif 187