particle.h

Engine/source/T3D/fx/particle.h

More...

Classes:

Public Defines

define

Detailed Description

Public Defines

MaxParticleSize() 50.0
  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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28
 29#ifndef _PARTICLE_H_
 30#define _PARTICLE_H_
 31
 32#ifndef _GAMEBASE_H_
 33#include "T3D/gameBase/gameBase.h"
 34#endif
 35#ifndef _GFXTEXTUREHANDLE_H_
 36#include "gfx/gfxTextureHandle.h"
 37#endif
 38
 39#define MaxParticleSize 50.0
 40
 41struct Particle;
 42
 43//*****************************************************************************
 44// Particle Data
 45//*****************************************************************************
 46class ParticleData : public SimDataBlock
 47{
 48   typedef SimDataBlock Parent;
 49
 50  public:
 51   enum PDConst
 52   {
 53      // This increase the keyframes from 4 to 8. Especially useful for premult-alpha blended particles
 54      // for which 4 keyframes is often not enough.
 55      PDC_NUM_KEYS = 8,
 56   };
 57
 58   F32   dragCoefficient;
 59   F32   windCoefficient;
 60   F32   gravityCoefficient;
 61
 62   F32   inheritedVelFactor;
 63   F32   constantAcceleration;
 64
 65   S32   lifetimeMS;
 66   S32   lifetimeVarianceMS;
 67
 68   F32   spinSpeed;        // degrees per second
 69   F32   spinRandomMin;
 70   F32   spinRandomMax;
 71
 72   bool  useInvAlpha;
 73
 74   bool  animateTexture;
 75   U32   numFrames;
 76   U32   framesPerSec;
 77
 78   LinearColorF colors[ PDC_NUM_KEYS ];
 79   F32    sizes[ PDC_NUM_KEYS ];
 80   F32    times[ PDC_NUM_KEYS ];
 81
 82   Point2F*          animTexUVs;
 83   Point2F           texCoords[4];   // default: {{"{"}}0.0,0.0}, {0.0,1.0}, {1.0,1.0}, {1.0,0.0}} 
 84   Point2I           animTexTiling;
 85   StringTableEntry  animTexFramesString;
 86   Vector<U8>        animTexFrames;
 87   StringTableEntry  textureName;
 88   GFXTexHandle      textureHandle;
 89
 90   static bool protectedSetSizes( void *object, const char *index, const char *data );
 91   static bool protectedSetTimes( void *object, const char *index, const char *data );
 92
 93  public:
 94   ParticleData();
 95   ~ParticleData();
 96
 97   // move this procedure to Particle
 98   void initializeParticle(Particle*, const Point3F&);
 99
100   void packData(BitStream* stream);
101   void unpackData(BitStream* stream);
102   bool onAdd();
103   bool preload(bool server, String &errorStr);
104   DECLARE_CONOBJECT(ParticleData);
105   static void  initPersistFields();
106
107   bool reload(char errorBuffer[256]);
108  public:
109   /*C*/  ParticleData(const ParticleData&, bool = false);
110   virtual void onPerformSubstitutions();
111   virtual bool allowSubstitutions() const { return true; }
112  protected:
113   F32   spinBias;
114   bool  randomizeSpinDir;
115   StringTableEntry  textureExtName;
116  public:
117   GFXTexHandle      textureExtHandle;
118   bool   constrain_pos;
119   F32    start_angle;
120   F32    angle_variance;
121   F32    sizeBias; 
122  public:
123   bool loadParameters();  
124   bool reload(String &errorStr);
125};
126
127//*****************************************************************************
128// Particle
129// 
130// This structure should be as small as possible.
131//*****************************************************************************
132struct Particle
133{
134   Point3F  pos;     // current instantaneous position
135   Point3F  vel;     //   "         "         velocity
136   Point3F  acc;     // Constant acceleration
137   Point3F  orientDir;  // direction particle should go if using oriented particles
138
139   U32           totalLifetime;   // Total ms that this instance should be "live"
140   ParticleData* dataBlock;       // datablock that contains global parameters for
141                                  //  this instance
142   U32       currentAge;
143
144
145   // are these necessary to store here? - they are interpolated in real time
146   LinearColorF           color;
147   F32              size;
148
149   F32              spinSpeed;
150   Particle *       next;
151   Point3F  pos_local;
152   F32      t_last;
153   Point3F  radial_v;   // radial vector for concentric effects
154   // note -- for non-oriented particles, we use orientDir.x to store the billboard start angle.
155};
156
157
158#endif // _PARTICLE_H_
159