Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | 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 #include "cstool/meshobjtmpl.h" 00027 #include "cstool/rendermeshholder.h" 00028 #include "imesh/partsys.h" 00029 #include "ivideo/rendermesh.h" 00030 #include "iengine/lightmgr.h" 00031 #include "csgfx/shadervarcontext.h" 00032 #include "csutil/dirtyaccessarray.h" 00033 #include "csutil/weakref.h" 00034 00042 const int CS_PARTICLE_AUTODELETE = 1; 00043 00045 const int CS_PARTICLE_SCALE = 2; 00046 00048 const int CS_PARTICLE_ROTATE = 4; 00049 00051 const int CS_PARTICLE_AXIS = 8; 00052 00054 const int CS_PARTICLE_ALIGN_Y = 512; 00055 00065 class CS_CSPLUGINCOMMON_EXPORT csNewParticleSystem : public csMeshObject 00066 { 00067 protected: 00069 iMeshObjectFactory *Factory; 00070 csRef<iLightManager> light_mgr; 00071 00072 bool initialized; 00073 00074 csRenderMeshHolderSingle rmHolder; 00075 csRef<csRenderBufferHolder> bufferHolder; 00076 00077 int VertexCount; 00078 int TriangleCount; 00079 csVector3* vertices; 00080 csRef<iRenderBuffer> vertex_buffer; 00081 csRef<iRenderBuffer> texel_buffer; 00082 csRef<iRenderBuffer> normal_buffer; 00083 csRef<iRenderBuffer> color_buffer; 00084 csRef<iRenderBuffer> index_buffer; 00085 00086 csWeakRef<iGraphics3D> g3d; 00087 00088 csTriangle* triangles; 00089 csVector2* texels; 00090 csColor* colors; 00091 00093 int StorageCount; 00094 00096 int ParticleFlags; 00097 00099 int ParticleCount; 00100 00102 csVector3 *PositionArray; 00103 00105 csVector2 Scale; 00106 00108 float Angle; 00109 00111 csColor Color; 00112 00114 uint MixMode; 00115 00117 csRef<iMaterialWrapper> Material; 00118 00120 csVector3 Axis; 00121 00123 csTicks PrevTime; 00124 00125 // bounding box 00126 csBox3 Bounds; 00127 00128 // clipping flags (passed from DrawTest to Draw) 00129 int ClipPortal, ClipPlane, ClipZ; 00130 00131 // use lighting ? 00132 bool Lighting; 00133 00134 // lighting data 00135 csColor *LitColors; 00136 00138 bool self_destruct; 00139 csTicks time_to_live; // msec 00140 00142 bool change_color; csColor colorpersecond; 00144 bool change_size; float scalepersecond; 00146 bool change_alpha; float alphapersecond; float alpha_now; 00148 bool change_rotation; float anglepersecond; 00149 00155 virtual void Allocate (int newsize, int copysize); 00156 00157 virtual void SetupObject (); 00158 00162 void SetupParticles (const csReversibleTransform&, csVector3* vertices); 00163 00164 public: 00166 csNewParticleSystem (iEngine *, iMeshObjectFactory *, int ParticleFlags); 00167 00169 virtual ~csNewParticleSystem (); 00170 00171 SCF_DECLARE_IBASE_EXT (csMeshObject); 00172 00174 void SetCount (int num); 00175 00177 void Compact (); 00178 00180 void UpdateBounds (); 00181 00183 virtual void Update (csTicks passedTime); 00184 00186 virtual iMeshObjectFactory* GetFactory () const; 00187 00188 virtual csRenderMesh** GetRenderMeshes (int& n, iRenderView* rview, 00189 iMovable* movable, uint32 frustum_mask); 00190 00192 void UpdateLighting (const csArray<iLight*>&, iMovable*); 00193 00195 virtual void NextFrame (csTicks current_time, const csVector3& pos); 00196 00198 virtual bool SetColor (const csColor& color); 00199 00201 virtual void AddColor (const csColor& color); 00202 00204 virtual const csColor& GetColor () const; 00205 00207 virtual bool SetMaterialWrapper (iMaterialWrapper* material); 00208 00210 virtual iMaterialWrapper* GetMaterialWrapper () const; 00211 00213 virtual bool GetLighting () const; 00214 00216 virtual void SetLighting (bool enable); 00217 00218 virtual void GetObjectBoundingBox (csBox3& bbox) 00219 { 00220 SetupObject (); 00221 bbox = Bounds; 00222 } 00223 virtual void SetObjectBoundingBox (const csBox3& bbox) 00224 { 00225 Bounds = bbox; 00226 scfiObjectModel.ShapeChanged (); 00227 } 00228 00230 inline void SetSelfDestruct (csTicks t) 00231 { self_destruct=true; time_to_live = t; }; 00233 inline void UnSetSelfDestruct () { self_destruct=false; } 00235 inline bool GetSelfDestruct () const { return self_destruct; } 00237 inline csTicks GetTimeToLive () const { return time_to_live; } 00238 00240 inline void SetChangeColor(const csColor& col) 00241 {change_color = true; colorpersecond = col;} 00243 inline void UnsetChangeColor() {change_color=false;} 00245 inline bool GetChangeColor (csColor& col) const 00246 { if(!change_color) return false; col = colorpersecond; return true; } 00247 00249 inline void SetChangeSize(float factor) 00250 {change_size = true; scalepersecond = factor;} 00252 inline void UnsetChangeSize() {change_size=false;} 00254 inline bool GetChangeSize (float& factor) const 00255 { if(!change_size) return false; factor = scalepersecond; return true; } 00256 00258 inline void SetAlpha(float alpha) 00259 {alpha_now = alpha; MixMode = CS_FX_SETALPHA (alpha); } 00261 inline float GetAlpha() const {return alpha_now;} 00263 inline void SetChangeAlpha(float factor) 00264 {change_alpha = true; alphapersecond = factor;} 00266 inline void UnsetChangeAlpha() {change_alpha=false;} 00268 inline bool GetChangeAlpha (float& factor) const 00269 { if(!change_alpha) return false; factor = alphapersecond; return true; } 00270 00272 inline void SetChangeRotation(float angle) 00273 { 00274 change_rotation = true; 00275 anglepersecond = angle; 00276 // @@@??? Ok? 00277 ParticleFlags |= CS_PARTICLE_ROTATE; 00278 } 00280 inline void UnsetChangeRotation() { change_rotation=false; } 00282 inline bool GetChangeRotation (float& angle) const 00283 { if(!change_rotation) return false; angle = anglepersecond; return true; } 00284 00285 00286 struct eiParticleState : public iParticleState 00287 { 00288 SCF_DECLARE_EMBEDDED_IBASE (csNewParticleSystem); 00289 virtual void SetMaterialWrapper (iMaterialWrapper* material) 00290 { 00291 scfParent->SetMaterialWrapper (material); 00292 } 00293 virtual iMaterialWrapper* GetMaterialWrapper () const 00294 { 00295 return scfParent->GetMaterialWrapper (); 00296 } 00297 virtual void SetMixMode (uint mode) 00298 { 00299 scfParent->MixMode = mode; 00300 } 00301 virtual uint GetMixMode () const 00302 { 00303 return scfParent->MixMode; 00304 } 00305 virtual void SetColor (const csColor& color) 00306 { 00307 scfParent->SetColor (color); 00308 } 00309 virtual const csColor& GetColor () const 00310 { 00311 return scfParent->GetColor (); 00312 } 00313 virtual void SetAlpha(float alpha) { scfParent->SetAlpha(alpha); } 00314 virtual float GetAlpha() const { return scfParent->GetAlpha (); } 00315 virtual void SetChangeColor (const csColor& color) 00316 { 00317 scfParent->SetChangeColor (color); 00318 } 00319 virtual void UnsetChangeColor () 00320 { 00321 scfParent->UnsetChangeColor (); 00322 } 00323 virtual bool GetChangeColor (csColor& col) const 00324 { 00325 return scfParent->GetChangeColor(col); } 00326 virtual void SetChangeSize (float factor) 00327 { 00328 scfParent->SetChangeSize (factor); 00329 } 00330 virtual void UnsetChangeSize () 00331 { 00332 scfParent->UnsetChangeSize (); 00333 } 00334 virtual bool GetChangeSize (float& factor) const 00335 { 00336 return scfParent->GetChangeSize(factor); 00337 } 00338 virtual void SetChangeRotation (float angle) 00339 { 00340 scfParent->SetChangeRotation (angle); 00341 } 00342 virtual void UnsetChangeRotation () 00343 { 00344 scfParent->UnsetChangeRotation (); 00345 } 00346 virtual bool GetChangeRotation (float& angle) const 00347 { 00348 return scfParent->GetChangeRotation(angle); 00349 } 00350 virtual void SetChangeAlpha (float factor) 00351 { 00352 scfParent->SetChangeAlpha (factor); 00353 } 00354 virtual void UnsetChangeAlpha () 00355 { 00356 scfParent->UnsetChangeAlpha (); 00357 } 00358 virtual bool GetChangeAlpha (float& factor) const 00359 { 00360 return scfParent->GetChangeAlpha(factor); 00361 } 00362 virtual void SetSelfDestruct (csTicks t) 00363 { 00364 scfParent->SetSelfDestruct (t); 00365 } 00366 virtual void UnSetSelfDestruct () 00367 { 00368 scfParent->UnSetSelfDestruct (); 00369 } 00370 } scfiParticleState; 00371 friend struct eiParticleState; 00372 }; 00373 00376 #endif // __CS_CSPLUGINCOMMON_PARTICLESYS_PARTICLE_H__
Generated for Crystal Space by doxygen 1.3.9.1