Torque3D Documentation / _generateds / lightAnimData.h

lightAnimData.h

Engine/source/T3D/lightAnimData.h

More...

Classes:

class

A datablock which defines and performs light animation.

class

Helper class used to keyframe light parameters.

class

The light animation state required by LightAnimData.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  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
 24#ifndef _LIGHTANIMDATA_H_
 25#define _LIGHTANIMDATA_H_
 26
 27#ifndef _SIMDATABLOCK_H_
 28#include "console/simDatablock.h"
 29#endif
 30#ifndef _CONSOLETYPES_H_
 31#include "console/consoleTypes.h"
 32#endif
 33#ifndef _MMATRIX_H_
 34#include "math/mMatrix.h"
 35#endif
 36#ifndef _MPOINT3_H_
 37#include "math/mPoint3.h"
 38#endif
 39#ifndef _COLOR_H_
 40#include "core/color.h"
 41#endif
 42
 43class LightInfo;
 44
 45
 46/// The light animation state required by LightAnimData.
 47struct LightAnimState
 48{  
 49   /// Constructor.
 50   LightAnimState()
 51      :  active( false ),
 52         animationPhase( 1.0f ),
 53         animationPeriod( 1.0f ),
 54         brightness( 1.0f ),
 55         transform( true ),
 56         color( 0, 0, 0, 0 )
 57   {
 58   }
 59
 60   /// If true light animation should be performed.
 61   bool active;
 62
 63   /// The phase used to offset the animation start 
 64   /// time to vary the animation of nearby lights.
 65   F32 animationPhase;
 66
 67   /// The length of time in seconds for a single playback
 68   /// of the light animation.
 69   F32 animationPeriod;   
 70
 71   /// The set light brightness before animation occurs.
 72   F32 brightness;
 73
 74   /// The set light transform before animation occurs.
 75   MatrixF transform;
 76
 77   /// The set light color before animation occurs.
 78   LinearColorF color;
 79};
 80
 81
 82/// A datablock which defines and performs light animation.
 83/// @see LightBase, LightDescription
 84class LightAnimData : public SimDataBlock
 85{
 86   typedef SimDataBlock Parent;
 87
 88protected:
 89
 90   /// Called internally to update the key data.
 91   void _updateKeys();
 92
 93public:
 94
 95   LightAnimData();
 96   virtual ~LightAnimData();
 97
 98   DECLARE_CONOBJECT( LightAnimData );
 99
100   // SimObject
101   static void initPersistFields();
102   virtual void inspectPostApply();
103
104   // SimDataBlock
105   virtual bool preload( bool server, String &errorStr );
106   virtual void packData( BitStream *stream );
107   virtual void unpackData( BitStream *stream );
108
109   /// Animates parameters on the passed Light's LightInfo object.
110   virtual void animate( LightInfo *light, LightAnimState *state );
111
112   /// Helper class used to keyframe light parameters.  It is templatized
113   /// on the number of parameters to store.
114   template<U32 COUNT>
115   struct AnimValue
116   {
117      /// Constructor.
118      AnimValue()
119      {
120         dMemset( value1, 0, sizeof( value1 ) );
121         dMemset( value2, 0, sizeof( value2 ) );
122         dMemset( period, 0, sizeof( period ) );
123         dMemset( keys, 0, sizeof( keys ) );
124         dMemset( smooth, 0, sizeof( smooth ) );
125         dMemset( keyLen, 0, sizeof( keyLen ) );
126         dMemset( timeScale, 0, sizeof( timeScale ) );
127      }
128
129      /// The first value associated with the A keyframe.
130      F32 value1[COUNT];
131
132      /// The second value associated with the Z keyframe.
133      F32 value2[COUNT];
134
135      /// The period of the full keyframe sequence.
136      F32 period[COUNT];
137
138      /// The keyframe keys as a string of letters A to Z.
139      StringTableEntry keys[COUNT];
140
141      /// If true the transition between keyframes will be smooth.
142      bool smooth[COUNT];
143
144      /// The calculated length of the keyframe string.
145      /// @see updateKey
146      U32 keyLen[COUNT];
147
148      /// The scale used to convert time into a keyframe position.
149      /// @see updateKey
150      F32 timeScale[COUNT];
151
152      /// Performs the animation returning the results in the output if
153      /// the time scale is greater than zero.
154      /// @return Returns true if the animation was performed.
155      bool animate(F32 time, F32 *output, bool multiply = false);
156
157      /// Called when the key string is changed to update the
158      /// key length and time scale.
159      void updateKey();
160
161      /// Write the animation data to the bitstream.
162      void write( BitStream *stream ) const;
163
164      /// Read the animation data from the bitstream.
165      void read( BitStream *stream );
166   };
167
168   /// The positional animation parameters for x, y, and z.
169   AnimValue<3> mOffset;
170
171   /// The rotational animation parameters for x, y, and z.
172   AnimValue<3> mRot;
173
174   /// The color animation parameters for r, g, and b.
175   AnimValue<3> mColor;
176
177   /// The brightness animation parameter.
178   AnimValue<1> mBrightness;
179};
180
181#endif // _LIGHTANIMDATA_H_
182