llpartdata.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLPARTDATA_H
00033 #define LL_LLPARTDATA_H
00034 
00035 #include "lluuid.h"
00036 #include "v3math.h"
00037 #include "v3dmath.h"
00038 #include "v2math.h"
00039 #include "v4color.h"
00040 
00041 class LLMessageSystem;
00042 class LLDataPacker;
00043 
00044 const S32 PS_CUR_VERSION = 18;
00045 
00046 //
00047 // These constants are used by the script code, not by the particle system itself
00048 //
00049 
00050 enum LLPSScriptFlags
00051 {
00052         // Flags for the different parameters of individual particles
00053         LLPS_PART_FLAGS,
00054         LLPS_PART_START_COLOR,
00055         LLPS_PART_START_ALPHA,
00056         LLPS_PART_END_COLOR,
00057         LLPS_PART_END_ALPHA,
00058         LLPS_PART_START_SCALE,
00059         LLPS_PART_END_SCALE,
00060         LLPS_PART_MAX_AGE,
00061 
00062         // Flags for the different parameters of the particle source
00063         LLPS_SRC_ACCEL,
00064         LLPS_SRC_PATTERN,
00065         LLPS_SRC_INNERANGLE,
00066         LLPS_SRC_OUTERANGLE,
00067         LLPS_SRC_TEXTURE,
00068         LLPS_SRC_BURST_RATE,
00069         LLPS_SRC_BURST_DURATION,
00070         LLPS_SRC_BURST_PART_COUNT,
00071         LLPS_SRC_BURST_RADIUS,
00072         LLPS_SRC_BURST_SPEED_MIN,
00073         LLPS_SRC_BURST_SPEED_MAX,
00074         LLPS_SRC_MAX_AGE,
00075         LLPS_SRC_TARGET_UUID,
00076         LLPS_SRC_OMEGA,
00077         LLPS_SRC_ANGLE_BEGIN,
00078         LLPS_SRC_ANGLE_END
00079 };
00080 
00081 
00082 class LLPartData
00083 {
00084 public:
00085         LLPartData() :
00086                 mFlags(0),
00087                 mMaxAge(0.f),
00088                 mParameter(0.f)
00089         {
00090         }
00091         BOOL unpack(LLDataPacker &dp);
00092         BOOL pack(LLDataPacker &dp);
00093         LLSD asLLSD() const;
00094         operator LLSD() const {return asLLSD(); }
00095         bool fromLLSD(LLSD& sd);
00096 
00097         // Masks for the different particle flags
00098         enum
00099         {
00100                 LL_PART_INTERP_COLOR_MASK =             0x01,
00101                 LL_PART_INTERP_SCALE_MASK =             0x02,
00102                 LL_PART_BOUNCE_MASK =                   0x04,
00103                 LL_PART_WIND_MASK =                             0x08,
00104                 LL_PART_FOLLOW_SRC_MASK =               0x10,           // Follows source, no rotation following (expensive!)
00105                 LL_PART_FOLLOW_VELOCITY_MASK =  0x20,           // Particles orient themselves with velocity
00106                 LL_PART_TARGET_POS_MASK =               0x40,
00107                 LL_PART_TARGET_LINEAR_MASK =    0x80,           // Particle uses a direct linear interpolation
00108                 LL_PART_EMISSIVE_MASK =                 0x100,          // Particle is "emissive", instead of being lit
00109                 LL_PART_BEAM_MASK =                             0x200,          // Particle is a "beam" connecting source and target
00110 
00111                 // Not implemented yet!
00112                 //LL_PART_RANDOM_ACCEL_MASK =           0x100,          // Particles have random acceleration
00113                 //LL_PART_RANDOM_VEL_MASK =             0x200,          // Particles have random velocity shifts"
00114                 //LL_PART_TRAIL_MASK =                  0x400,          // Particles have historical "trails"
00115 
00116                 // Viewer side use only!
00117                 LL_PART_DEAD_MASK =                             0x80000000,
00118         };
00119 
00120         void setFlags(const U32 flags);
00121         void setMaxAge(const F32 max_age);
00122         void setStartScale(const F32 xs, F32 ys);
00123         void setEndScale(const F32 xs, F32 ys);
00124         void setStartColor(const LLVector3 &rgb);
00125         void setEndColor(const LLVector3 &rgb);
00126         void setStartAlpha(const F32 alpha);
00127         void setEndAlpha(const F32 alpha);
00128 
00129 
00130         friend class LLPartSysData;
00131         friend class LLViewerPartSourceScript;
00132 
00133         // These are public because I'm really lazy...
00134 public:
00135         U32                                     mFlags;                                         // Particle state/interpolators in effect
00136         F32                                     mMaxAge;                                        // Maximum age of the particle
00137         LLColor4                        mStartColor;                            // Start color
00138         LLColor4                        mEndColor;                                      // End color
00139         LLVector2                       mStartScale;                            // Start scale
00140         LLVector2                       mEndScale;                                      // End scale
00141 
00142         LLVector3                       mPosOffset;                                     // Offset from source if using FOLLOW_SOURCE
00143         F32                                     mParameter;                                     // A single floating point parameter
00144 };
00145 
00146 
00147 class LLPartSysData
00148 {
00149 public:
00150         LLPartSysData();
00151 
00152         BOOL unpack(LLDataPacker &dp);
00153         BOOL pack(LLDataPacker &dp);
00154 
00155         
00156         BOOL unpackBlock(const S32 block_num);
00157         BOOL packBlock();
00158 
00159         static BOOL packNull();
00160         static BOOL isNullPS(const S32 block_num); // Returns FALSE if this is a "NULL" particle system (i.e. no system)
00161 
00162         // Different masks for effects on the source
00163         enum
00164         {
00165                 LL_PART_SRC_OBJ_REL_MASK                =       0x01,           // Accel and velocity for particles relative object rotation
00166                 LL_PART_USE_NEW_ANGLE                   =       0x02,           // Particles uses new 'correct' angle parameters.
00167         };
00168 
00169         // The different patterns for how particles are created
00170         enum
00171         {
00172                 LL_PART_SRC_PATTERN_DROP =                              0x01,
00173                 LL_PART_SRC_PATTERN_EXPLODE =                   0x02,
00174                 // Not implemented fully yet
00175                 LL_PART_SRC_PATTERN_ANGLE =                             0x04,
00176                 LL_PART_SRC_PATTERN_ANGLE_CONE =                0x08,
00177                 LL_PART_SRC_PATTERN_ANGLE_CONE_EMPTY =  0x10,
00178         };
00179 
00180 
00181         void setBurstSpeedMin(const F32 spd) {  mBurstSpeedMin = llclamp(spd, -100.f, 100.f); }
00182         void setBurstSpeedMax(const F32 spd) {  mBurstSpeedMax = llclamp(spd, -100.f, 100.f); }
00183         void setBurstRadius(const F32 rad)       {      mBurstRadius = llclamp(rad, 0.f, 50.f); }
00184         void setPartAccel(const LLVector3 &accel);
00185         void setUseNewAngle()   { mFlags |=  LL_PART_USE_NEW_ANGLE; }
00186         void unsetUseNewAngle() { mFlags &= ~LL_PART_USE_NEW_ANGLE; }
00187 
00188         // Since the actual particle creation rate is
00189         // a combination of multiple parameters, we
00190         // need to clamp it using a separate method instead of an accessor.
00191         void clampSourceParticleRate();
00192         
00193         friend std::ostream&     operator<<(std::ostream& s, const LLPartSysData &data);                // Stream a
00194         
00195 public:
00196         // Public because I'm lazy....
00197 
00198         //
00199         // There are two kinds of data for the particle system
00200         // 1. Parameters which specify parameters of the source (mSource*)
00201         // 2. Parameters which specify parameters of the particles generated by the source (mPart*)
00202         //
00203 
00204         U32             mCRC;
00205         U32             mFlags;
00206 
00207         U8              mPattern;                                               // Pattern for particle velocity/output
00208         F32             mInnerAngle;                                    // Inner angle for PATTERN_ANGLE
00209         F32             mOuterAngle;                                    // Outer angle for PATTERN_ANGLE
00210         LLVector3 mAngularVelocity;                             // Angular velocity for emission axis (for PATTERN_ANGLE)
00211 
00212         F32             mBurstRate;                                             // How often to do a burst of particles
00213         U8              mBurstPartCount;                                // How many particles in a burst
00214         F32             mBurstRadius;
00215         F32             mBurstSpeedMin;                                 // Minimum particle velocity
00216         F32             mBurstSpeedMax;                                 // Maximum particle velocity
00217 
00218         F32             mMaxAge;                                                // Maximum lifetime of this particle source
00219 
00220         LLUUID  mTargetUUID;                                    // Target UUID for the particle system
00221 
00222         F32             mStartAge;                                              // Age at which to start the particle system (for an update after the
00223                                                                                         // particle system has started)
00224 
00225 
00226         //
00227         // These are actually particle properties, but can be mutated by the source,
00228         // so are stored here instead
00229         //
00230         LLVector3       mPartAccel;
00231         LLUUID          mPartImageID;
00232 
00233         //
00234         // The "template" partdata where we actually store the non-mutable particle parameters
00235         //
00236         LLPartData      mPartData;
00237 
00238 protected:
00239         S32             mNumParticles;                                  // Number of particles generated
00240 };
00241 
00242 #endif // LL_LLPARTDATA_H

Generated on Fri May 16 08:32:29 2008 for SecondLife by  doxygen 1.5.5