csplugincommon/particlesys/particle.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003 by Martin Geisse <mgeisse@gmx.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSPLUGINCOMMON_PARTICLESYS_PARTICLE_H__ 00020 #define __CS_CSPLUGINCOMMON_PARTICLESYS_PARTICLE_H__ 00021 00026 #include "csextern.h" 00027 00028 #include "csgfx/shadervarcontext.h" 00029 #include "cstool/framedataholder.h" 00030 #include "cstool/meshobjtmpl.h" 00031 #include "cstool/rendermeshholder.h" 00032 #include "csutil/cscolor.h" 00033 #include "csutil/dirtyaccessarray.h" 00034 #include "csutil/weakref.h" 00035 00036 #include "iengine/lightmgr.h" 00037 #include "imesh/partsys.h" 00038 #include "ivideo/rendermesh.h" 00039 00047 const int CS_PARTICLE_AUTODELETE = 1; 00048 00050 const int CS_PARTICLE_SCALE = 2; 00051 00053 const int CS_PARTICLE_ROTATE = 4; 00054 00056 const int CS_PARTICLE_AXIS = 8; 00057 00059 const int CS_PARTICLE_ALIGN_Y = 512; 00060 00070 class CS_CRYSTALSPACE_EXPORT csNewParticleSystem : 00071 public scfImplementationExt1<csNewParticleSystem, 00072 csMeshObject, iParticleState> 00073 { 00074 protected: 00076 iMeshObjectFactory *Factory; 00077 csRef<iLightManager> light_mgr; 00078 00079 bool initialized; 00080 00081 csRenderMeshHolder rmHolder; 00082 struct PerFrameData 00083 { 00084 csRef<csRenderBufferHolder> bufferHolder; 00085 csRef<iRenderBuffer> vertex_buffer; 00086 }; 00087 csFrameDataHolder<PerFrameData> perFrameHolder; 00088 uint lastDataUpdateFrame; 00089 00090 int VertexCount; 00091 int TriangleCount; 00092 csRef<iRenderBuffer> texel_buffer; 00093 csRef<iRenderBuffer> normal_buffer; 00094 csRef<iRenderBuffer> color_buffer; 00095 csRef<iRenderBuffer> index_buffer; 00096 00097 csWeakRef<iGraphics3D> g3d; 00098 00099 csTriangle* triangles; 00100 csVector2* texels; 00101 csColor* colors; 00102 00104 int StorageCount; 00105 00107 int ParticleFlags; 00108 00110 int ParticleCount; 00111 00113 csVector3 *PositionArray; 00114 00116 csVector2 Scale; 00117 00119 float Angle; 00120 00122 csColor Color; 00123 00125 uint MixMode; 00126 00128 csRef<iMaterialWrapper> Material; 00129 00131 csVector3 Axis; 00132 00134 csTicks PrevTime; 00135 00136 // bounding box 00137 csBox3 Bounds; 00138 00139 // clipping flags (passed from DrawTest to Draw) 00140 int ClipPortal, ClipPlane, ClipZ; 00141 00142 // use lighting ? 00143 bool Lighting; 00144 00145 // lighting data 00146 csColor *LitColors; 00147 00149 bool self_destruct; 00150 csTicks time_to_live; // msec 00151 00153 bool change_color; csColor colorpersecond; 00155 bool change_size; float scalepersecond; 00157 bool change_alpha; float alphapersecond; float alpha_now; 00159 bool change_rotation; float anglepersecond; 00160 00166 virtual void Allocate (int newsize, int copysize); 00167 00168 virtual void SetupObject (); 00169 00173 void SetupParticles (const csReversibleTransform&, csVector3* vertices); 00174 00175 public: 00177 csNewParticleSystem (iEngine *, iMeshObjectFactory *, int ParticleFlags); 00178 00180 virtual ~csNewParticleSystem (); 00181 00183 void SetCount (int num); 00184 00186 void Compact (); 00187 00189 void UpdateBounds (); 00190 00192 virtual void Update (csTicks passedTime); 00193 00195 virtual iMeshObjectFactory* GetFactory () const; 00196 00197 virtual csRenderMesh** GetRenderMeshes (int& n, iRenderView* rview, 00198 iMovable* movable, uint32 frustum_mask); 00199 00201 void UpdateLighting (const csArray<iLightSectorInfluence*>&, iMovable*); 00202 00204 virtual void NextFrame (csTicks current_time, const csVector3& pos); 00205 00207 virtual bool SetColor (const csColor& color); 00208 00210 virtual void AddColor (const csColor& color); 00211 00213 virtual const csColor& GetColor () const; 00214 00216 virtual bool SetMaterialWrapper (iMaterialWrapper* material); 00217 00219 virtual iMaterialWrapper* GetMaterialWrapper () const; 00220 00222 virtual bool GetLighting () const; 00223 00225 virtual void SetLighting (bool enable); 00226 00227 virtual void GetObjectBoundingBox (csBox3& bbox) 00228 { 00229 SetupObject (); 00230 bbox = Bounds; 00231 } 00232 virtual void SetObjectBoundingBox (const csBox3& bbox) 00233 { 00234 Bounds = bbox; 00235 ShapeChanged (); 00236 } 00237 00239 inline void SetSelfDestruct (csTicks t) 00240 { self_destruct=true; time_to_live = t; }; 00242 inline void UnSetSelfDestruct () { self_destruct=false; } 00244 inline bool GetSelfDestruct () const { return self_destruct; } 00246 inline csTicks GetTimeToLive () const { return time_to_live; } 00247 00249 inline void SetChangeColor(const csColor& col) 00250 {change_color = true; colorpersecond = col;} 00252 inline void UnsetChangeColor() {change_color=false;} 00254 inline bool GetChangeColor (csColor& col) const 00255 { if(!change_color) return false; col = colorpersecond; return true; } 00256 00258 inline void SetChangeSize(float factor) 00259 {change_size = true; scalepersecond = factor;} 00261 inline void UnsetChangeSize() {change_size=false;} 00263 inline bool GetChangeSize (float& factor) const 00264 { if(!change_size) return false; factor = scalepersecond; return true; } 00265 00267 inline void SetAlpha(float alpha) 00268 {alpha_now = alpha; MixMode = CS_FX_SETALPHA (alpha); } 00270 inline float GetAlpha() const {return alpha_now;} 00272 inline void SetChangeAlpha(float factor) 00273 {change_alpha = true; alphapersecond = factor;} 00275 inline void UnsetChangeAlpha() {change_alpha=false;} 00277 inline bool GetChangeAlpha (float& factor) const 00278 { if(!change_alpha) return false; factor = alphapersecond; return true; } 00279 00281 inline void SetChangeRotation(float angle) 00282 { 00283 change_rotation = true; 00284 anglepersecond = angle; 00285 // @@@??? Ok? 00286 ParticleFlags |= CS_PARTICLE_ROTATE; 00287 } 00289 inline void UnsetChangeRotation() { change_rotation=false; } 00291 inline bool GetChangeRotation (float& angle) const 00292 { if(!change_rotation) return false; angle = anglepersecond; return true; } 00293 00294 virtual void SetMixMode (uint mode) { MixMode = mode; } 00295 virtual uint GetMixMode () const { return MixMode; } 00296 }; 00297 00300 #endif // __CS_CSPLUGINCOMMON_PARTICLESYS_PARTICLE_H__
Generated for Crystal Space by doxygen 1.4.6