ribbon.h

Engine/source/T3D/fx/ribbon.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2014 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 _RIBBON_H_
 25#define _RIBBON_H_
 26
 27#ifndef _GAMEBASE_H_
 28#include "T3D/gameBase/gameBase.h"
 29#endif
 30
 31#ifndef _GFXPRIMITIVEBUFFER_H_
 32#include "gfx/gfxPrimitiveBuffer.h"
 33#endif
 34
 35#ifndef _GFXVERTEXBUFFER_H_
 36#include "gfx/gfxVertexBuffer.h"
 37#endif
 38
 39#include "materials/materialParameters.h"
 40#include "math/util/matrixSet.h"
 41
 42//--------------------------------------------------------------------------
 43class RibbonData : public GameBaseData
 44{
 45   typedef GameBaseData Parent;
 46
 47protected:
 48   bool onAdd();
 49
 50public:
 51
 52   enum Constants
 53   {
 54      NumFields = 4
 55   };
 56
 57   F32 mSizes[NumFields];      ///< The radius for each keyframe.
 58   LinearColorF mColours[NumFields]; ///< The colour of the ribbon for each keyframe.
 59   F32 mTimes[NumFields];      ///< The relative time for each keyframe.
 60
 61   U32 mRibbonLength;      ///< The amount of segments that will make up the ribbon.
 62   S32 segmentsPerUpdate;  ///< Amount of segments to add each update.
 63   S32 mSegmentSkipAmount; ///< The amount of segments to skip each time segments are added.
 64
 65   bool mUseFadeOut;          ///< If true, the ribbon will fade away after deletion.
 66   F32 mFadeAwayStep;         ///< How quickly the ribbons is faded away after deletion.
 67   StringTableEntry mMatName; ///< The material for the ribbon.
 68   F32 mTileScale;            ///< A scalar to scale the texcoord.
 69   bool mFixedTexcoords;      ///< If true, texcoords will stay the same over the lifetime for each segment.
 70   bool mTexcoordsRelativeToDistance; ///< If true, texcoords will not be stretched if the distance between 2 segments are long.
 71
 72   RibbonData();
 73
 74   void packData(BitStream*);
 75   void unpackData(BitStream*);
 76   bool preload(bool server, String &errorBuffer);
 77
 78   static void initPersistFields();
 79   DECLARE_CONOBJECT(RibbonData);
 80};
 81
 82//--------------------------------------------------------------------------
 83class Ribbon : public GameBase
 84{
 85   typedef GameBase Parent;
 86
 87   RibbonData* mDataBlock;
 88
 89   bool mDeleteOnEnd;   ///< If true, the ribbon should delete itself as soon as the last segment is deleted
 90   bool mUseFadeOut;    ///< If true, the ribbon will fade away upon deletion
 91   F32 mFadeAwayStep;   ///< How quickly the ribbons is faded away after deletion.
 92   F32 mFadeOut;
 93   F32 mTravelledDistance; ///< How far the ribbon has travelled in it's lifetime.
 94
 95   Vector<Point3F> mSegmentPoints; ///< The points in space where the ribbon has spawned segments.
 96   U32 mSegmentOffset;
 97   U32 mSegmentIdx;
 98
 99   bool mUpdateBuffers; ///< If true, the vertex buffers need to be updated.
100   BaseMatInstance *mRibbonMat;
101   MaterialParameterHandle* mRadiusSC;
102   MaterialParameterHandle* mRibbonProjSC;
103   GFXPrimitiveBufferHandle mPrimBuffer;
104   GFXVertexBufferHandle<GFXVertexPCNTT> mVerts;
105
106protected:
107
108   bool onAdd();
109   void processTick(const Move*);
110   void advanceTime(F32);
111   void interpolateTick(F32 delta);
112
113   // Rendering
114   void prepRenderImage(SceneRenderState *state);
115   void setShaderParams();
116
117   ///Checks to see if ribbon is too long
118   U32 checkRibbonDistance(S32 segments);
119
120   /// Construct the vertex and primitive buffers
121   void createBuffers(SceneRenderState *state, GFXVertexBufferHandle<GFXVertexPCNTT> &verts, GFXPrimitiveBufferHandle &pb, U32 segments);
122
123public:
124   Ribbon();
125   ~Ribbon();
126
127   DECLARE_CONOBJECT(Ribbon);
128   static void initPersistFields();
129   bool onNewDataBlock(GameBaseData*,bool);
130   void onRemove();
131
132   /// Used to add another segment to the ribbon.
133   void addSegmentPoint(Point3F &point, MatrixF &mat);
134
135   /// Delete all segments.
136   void clearSegments() { mSegmentPoints.clear(); }
137
138   /// Delete the ribbon when all segments have been deleted.
139   void deleteOnEnd();
140};
141
142#endif // _H_RIBBON
143
144