VAnimation.cpp

Engine/source/Verve/Torque3D/VAnimation.cpp

More...

Detailed Description

  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/Torque/TAnimation.h"
 25
 26#include "T3D/shapeBase.h"
 27
 28//-----------------------------------------------------------------------------
 29//
 30// Animation Methods.
 31//
 32//-----------------------------------------------------------------------------
 33
 34bool VTorque::isAnimationLooping( SceneObjectType *pObject, const char *pData )
 35{
 36    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
 37    if ( !shape || !shape->getShape() )
 38    {
 39        // Sanity!
 40        return false;
 41    }
 42
 43    // Find Sequence.
 44    const S32 sequenceIndex = shape->getShape()->findSequence( pData );
 45    if ( sequenceIndex == -1 )
 46    {
 47        // Invalid Sequence.
 48        return false;
 49    }
 50
 51    // Return Cyclic.
 52    return shape->getShape()->sequences[sequenceIndex].isCyclic();
 53}
 54
 55String VTorque::getAnimation( SceneObjectType *pObject, const U32 &pThreadIndex )
 56{
 57    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
 58    if ( !shape )
 59    {
 60        // Sanity!
 61        return "";
 62    }
 63
 64    // Return Name.
 65    return shape->getThreadSequenceName( pThreadIndex );
 66}
 67
 68F32 VTorque::getAnimationDuration( SceneObjectType *pObject, const char *pData )
 69{
 70    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
 71    if ( !shape || !shape->getShape() )
 72    {
 73        // Sanity!
 74        return 0.f;
 75    }
 76
 77    // Find Sequence.
 78    const S32 sequenceIndex = shape->getShape()->findSequence( pData );
 79    if ( sequenceIndex == -1 )
 80    {
 81        // Invalid Sequence.
 82        return 0.f;
 83    }
 84
 85    // Return Duration.
 86    return shape->getShape()->sequences[sequenceIndex].duration;
 87}
 88
 89void VTorque::setAnimationPosition( SceneObjectType *pObject, const U32 &pThreadIndex, const F32 &pPosition )
 90{
 91    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
 92    if ( !shape )
 93    {
 94        // Sanity!
 95        return;
 96    }
 97
 98    // Set Position.
 99    shape->setThreadPosition( 0, pPosition );
100}
101
102void VTorque::setAnimationTimeScale( SceneObjectType *pObject, const U32 &pThreadIndex, const F32 &pTimeScale )
103{
104    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
105    if ( !shape )
106    {
107        // Sanity!
108        return;
109    }
110
111    // Set TimeScale.
112    shape->setThreadTimeScale( pThreadIndex, pTimeScale );
113}
114
115void VTorque::playAnimation( SceneObjectType *pObject, const U32 &pThreadIndex, const char *pData )
116{
117    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
118    if ( !shape || !shape->getShape() )
119    {
120        // Sanity!
121        return;
122    }
123
124    // Find Sequence.
125    const S32 sequenceIndex = shape->getShape()->findSequence( pData );
126    if ( sequenceIndex == -1 )
127    {
128        // Invalid Sequence.
129        return;
130    }
131
132    // Play Sequence.
133    shape->setThreadSequence( pThreadIndex, sequenceIndex );
134}
135
136void VTorque::playAnimation( SceneObjectType *pObject, const U32 &pThreadIndex )
137{
138    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
139    if ( !shape )
140    {
141        // Sanity!
142        return;
143    }
144
145    // Play Sequence.
146    shape->playThread( pThreadIndex );
147}
148
149void VTorque::stopAnimation( SceneObjectType *pObject, const U32 &pThreadIndex )
150{
151    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
152    if ( !shape )
153    {
154        // Sanity!
155        return;
156    }
157
158    // Pause Thread.
159    shape->stopThread( pThreadIndex );
160}
161
162void VTorque::pauseAnimation( SceneObjectType *pObject, const U32 &pThreadIndex )
163{
164    ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
165    if ( !shape )
166    {
167        // Sanity!
168        return;
169    }
170
171    // Pause Thread.
172    shape->pauseThread( pThreadIndex );
173}
174