Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
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 00025 #include "csextern.h" 00026 00027 #include "csgfx/shadervarcontext.h" 00028 #include "cstool/framedataholder.h" 00029 #include "cstool/meshobjtmpl.h" 00030 #include "cstool/rendermeshholder.h" 00031 #include "csutil/cscolor.h" 00032 #include "csutil/dirtyaccessarray.h" 00033 #include "csutil/weakref.h" 00034 00035 #include "iengine/lightmgr.h" 00036 #include "imesh/partsys.h" 00037 #include "ivideo/rendermesh.h" 00038 00046 const int CS_PARTICLE_AUTODELETE = 1; 00047 00049 const int CS_PARTICLE_SCALE = 2; 00050 00052 const int CS_PARTICLE_ROTATE = 4; 00053 00055 const int CS_PARTICLE_AXIS = 8; 00056 00058 const int CS_PARTICLE_ALIGN_Y = 512; 00059 00069 class CS_CRYSTALSPACE_EXPORT csNewParticleSystem : public csMeshObject 00070 { 00071 protected: 00073 iMeshObjectFactory *Factory; 00074 csRef<iLightManager> light_mgr; 00075 00076 bool initialized; 00077 00078 csRenderMeshHolder rmHolder; 00079 struct PerFrameData 00080 { 00081 csRef<csRenderBufferHolder> bufferHolder; 00082 csRef<iRenderBuffer> vertex_buffer; 00083 }; 00084 csFrameDataHolder<PerFrameData> perFrameHolder; 00085 uint lastDataUpdateFrame; 00086 00087 int VertexCount; 00088 int TriangleCount; 00089 csRef<iRenderBuffer> texel_buffer; 00090 csRef<iRenderBuffer> normal_buffer; 00091 csRef<iRenderBuffer> color_buffer; 00092 csRef<iRenderBuffer> index_buffer; 00093 00094 csWeakRef<iGraphics3D> g3d; 00095 00096 csTriangle* triangles; 00097 csVector2* texels; 00098 csColor* colors; 00099 00101 int StorageCount; 00102 00104 int ParticleFlags; 00105 00107 int ParticleCount; 00108 00110 csVector3 *PositionArray; 00111 00113 csVector2 Scale; 00114 00116 float Angle; 00117 00119 csColor Color; 00120 00122 uint MixMode; 00123 00125 csRef<iMaterialWrapper> Material; 00126 00128 csVector3 Axis; 00129 00131 csTicks PrevTime; 00132 00133 // bounding box 00134 csBox3 Bounds; 00135 00136 // clipping flags (passed from DrawTest to Draw) 00137 int ClipPortal, ClipPlane, ClipZ; 00138 00139 // use lighting ? 00140 bool Lighting; 00141 00142 // lighting data 00143 csColor *LitColors; 00144 00146 bool self_destruct; 00147 csTicks time_to_live; // msec 00148 00150 bool change_color; csColor colorpersecond; 00152 bool change_size; float scalepersecond; 00154 bool change_alpha; float alphapersecond; float alpha_now; 00156 bool change_rotation; float anglepersecond; 00157 00163 virtual void Allocate (int newsize, int copysize); 00164 00165 virtual void SetupObject (); 00166 00170 void SetupParticles (const csReversibleTransform&, csVector3* vertices); 00171 00172 public: 00174 csNewParticleSystem (iEngine *, iMeshObjectFactory *, int ParticleFlags); 00175 00177 virtual ~csNewParticleSystem (); 00178 00179 SCF_DECLARE_IBASE_EXT (csMeshObject); 00180 00182 void SetCount (int num); 00183 00185 void Compact (); 00186 00188 void UpdateBounds (); 00189 00191 virtual void Update (csTicks passedTime); 00192 00194 virtual iMeshObjectFactory* GetFactory () const; 00195 00196 virtual csRenderMesh** GetRenderMeshes (int& n, iRenderView* rview, 00197 iMovable* movable, uint32 frustum_mask); 00198 00200 void UpdateLighting (const csArray<iLight*>&, iMovable*); 00201 00203 virtual void NextFrame (csTicks current_time, const csVector3& pos); 00204 00206 virtual bool SetColor (const csColor& color); 00207 00209 virtual void AddColor (const csColor& color); 00210 00212 virtual const csColor& GetColor () const; 00213 00215 virtual bool SetMaterialWrapper (iMaterialWrapper* material); 00216 00218 virtual iMaterialWrapper* GetMaterialWrapper () const; 00219 00221 virtual bool GetLighting () const; 00222 00224 virtual void SetLighting (bool enable); 00225 00226 virtual void GetObjectBoundingBox (csBox3& bbox) 00227 { 00228 SetupObject (); 00229 bbox = Bounds; 00230 } 00231 virtual void SetObjectBoundingBox (const csBox3& bbox) 00232 { 00233 Bounds = bbox; 00234 scfiObjectModel.ShapeChanged (); 00235 } 00236 00238 inline void SetSelfDestruct (csTicks t) 00239 { self_destruct=true; time_to_live = t; }; 00241 inline void UnSetSelfDestruct () { self_destruct=false; } 00243 inline bool GetSelfDestruct () const { return self_destruct; } 00245 inline csTicks GetTimeToLive () const { return time_to_live; } 00246 00248 inline void SetChangeColor(const csColor& col) 00249 {change_color = true; colorpersecond = col;} 00251 inline void UnsetChangeColor() {change_color=false;} 00253 inline bool GetChangeColor (csColor& col) const 00254 { if(!change_color) return false; col = colorpersecond; return true; } 00255 00257 inline void SetChangeSize(float factor) 00258 {change_size = true; scalepersecond = factor;} 00260 inline void UnsetChangeSize() {change_size=false;} 00262 inline bool GetChangeSize (float& factor) const 00263 { if(!change_size) return false; factor = scalepersecond; return true; } 00264 00266 inline void SetAlpha(float alpha) 00267 {alpha_now = alpha; MixMode = CS_FX_SETALPHA (alpha); } 00269 inline float GetAlpha() const {return alpha_now;} 00271 inline void SetChangeAlpha(float factor) 00272 {change_alpha = true; alphapersecond = factor;} 00274 inline void UnsetChangeAlpha() {change_alpha=false;} 00276 inline bool GetChangeAlpha (float& factor) const 00277 { if(!change_alpha) return false; factor = alphapersecond; return true; } 00278 00280 inline void SetChangeRotation(float angle) 00281 { 00282 change_rotation = true; 00283 anglepersecond = angle; 00284 // @@@??? Ok? 00285 ParticleFlags |= CS_PARTICLE_ROTATE; 00286 } 00288 inline void UnsetChangeRotation() { change_rotation=false; } 00290 inline bool GetChangeRotation (float& angle) const 00291 { if(!change_rotation) return false; angle = anglepersecond; return true; } 00292 00293 00294 struct eiParticleState : public iParticleState 00295 { 00296 SCF_DECLARE_EMBEDDED_IBASE (csNewParticleSystem); 00297 virtual void SetMaterialWrapper (iMaterialWrapper* material) 00298 { 00299 scfParent->SetMaterialWrapper (material); 00300 } 00301 virtual iMaterialWrapper* GetMaterialWrapper () const 00302 { 00303 return scfParent->GetMaterialWrapper (); 00304 } 00305 virtual void SetMixMode (uint mode) 00306 { 00307 scfParent->MixMode = mode; 00308 } 00309 virtual uint GetMixMode () const 00310 { 00311 return scfParent->MixMode; 00312 } 00313 virtual void SetColor (const csColor& color) 00314 { 00315 scfParent->SetColor (color); 00316 } 00317 virtual const csColor& GetColor () const 00318 { 00319 return scfParent->GetColor (); 00320 } 00321 virtual void SetAlpha(float alpha) { scfParent->SetAlpha(alpha); } 00322 virtual float GetAlpha() const { return scfParent->GetAlpha (); } 00323 virtual void SetChangeColor (const csColor& color) 00324 { 00325 scfParent->SetChangeColor (color); 00326 } 00327 virtual void UnsetChangeColor () 00328 { 00329 scfParent->UnsetChangeColor (); 00330 } 00331 virtual bool GetChangeColor (csColor& col) const 00332 { 00333 return scfParent->GetChangeColor(col); } 00334 virtual void SetChangeSize (float factor) 00335 { 00336 scfParent->SetChangeSize (factor); 00337 } 00338 virtual void UnsetChangeSize () 00339 { 00340 scfParent->UnsetChangeSize (); 00341 } 00342 virtual bool GetChangeSize (float& factor) const 00343 { 00344 return scfParent->GetChangeSize(factor); 00345 } 00346 virtual void SetChangeRotation (float angle) 00347 { 00348 scfParent->SetChangeRotation (angle); 00349 } 00350 virtual void UnsetChangeRotation () 00351 { 00352 scfParent->UnsetChangeRotation (); 00353 } 00354 virtual bool GetChangeRotation (float& angle) const 00355 { 00356 return scfParent->GetChangeRotation(angle); 00357 } 00358 virtual void SetChangeAlpha (float factor) 00359 { 00360 scfParent->SetChangeAlpha (factor); 00361 } 00362 virtual void UnsetChangeAlpha () 00363 { 00364 scfParent->UnsetChangeAlpha (); 00365 } 00366 virtual bool GetChangeAlpha (float& factor) const 00367 { 00368 return scfParent->GetChangeAlpha(factor); 00369 } 00370 virtual void SetSelfDestruct (csTicks t) 00371 { 00372 scfParent->SetSelfDestruct (t); 00373 } 00374 virtual void UnSetSelfDestruct () 00375 { 00376 scfParent->UnSetSelfDestruct (); 00377 } 00378 } scfiParticleState; 00379 friend struct eiParticleState; 00380 }; 00381 00384 #endif // __CS_CSPLUGINCOMMON_PARTICLESYS_PARTICLE_H__
Generated for Crystal Space by doxygen 1.4.4