imesh/particles.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

imesh/particles.h
Go to the documentation of this file.

    00001 /*
    00002   Copyright (C) 2006 by Marten Svanfeldt
    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_IMESH_PARTICLES_H__
    00020 #define __CS_IMESH_PARTICLES_H__
    00021
    00022 #include "csutil/scf_interface.h"
    00023
    00024 #include "csgeom/obb.h"
    00025 #include "csgeom/vector2.h"
    00026 #include "csgeom/vector3.h"
    00027 #include "csgeom/quaternion.h"
    00028 #include "csutil/array.h"
    00029 #include "csutil/cscolor.h"
    00030 #include "csutil/ref.h"
    00031
    00036 struct iParticleSystemBase;
    00037
    00047 enum csParticleSortMode
    00048 {
    00050   CS_PARTICLE_SORT_NONE,
    00052   CS_PARTICLE_SORT_DISTANCE,
    00054   CS_PARTICLE_SORT_DOT
    00055 };
    00056
    00062 enum csParticleRenderOrientation
    00063 {
    00068   CS_PARTICLE_CAMERAFACE,
    00075   CS_PARTICLE_CAMERAFACE_APPROX,
    00080   CS_PARTICLE_ORIENT_COMMON,
    00087   CS_PARTICLE_ORIENT_COMMON_APPROX,
    00093   CS_PARTICLE_ORIENT_VELOCITY,
    00099   CS_PARTICLE_ORIENT_SELF,
    00107   CS_PARTICLE_ORIENT_SELF_FORWARD
    00108 };
    00109
    00114 enum csParticleRotationMode
    00115 {
    00117   CS_PARTICLE_ROTATE_NONE,
    00119   CS_PARTICLE_ROTATE_TEXCOORD,
    00121   CS_PARTICLE_ROTATE_VERTICES
    00122 };
    00123
    00129 enum csParticleIntegrationMode
    00130 {
    00132   CS_PARTICLE_INTEGRATE_NONE,
    00134   CS_PARTICLE_INTEGRATE_LINEAR,
    00139   CS_PARTICLE_INTEGRATE_BOTH
    00140 };
    00141
    00147 enum csParticleTransformMode
    00148 {
    00153   CS_PARTICLE_LOCAL_MODE,
    00161   CS_PARTICLE_LOCAL_EMITTER,
    00166   CS_PARTICLE_WORLD_MODE
    00167 };
    00168
    00172 struct csParticle
    00173 {
    00179   csVector3 position;
    00180
    00184   float mass;
    00185
    00192   csQuaternion orientation;
    00193
    00199   csVector3 linearVelocity;
    00200
    00204   float timeToLive;
    00205
    00209   csVector3 angularVelocity;
    00210
    00211   // Pad to make this struct 64 bytes
    00212   float pad;
    00213 };
    00214
    00218 struct csParticleAux
    00219 {
    00223   csColor4 color;
    00224
    00229   csVector2 particleSize;
    00230
    00231   // Pad to make this 32 bytes
    00232   float pad[2];
    00233 };
    00234
    00238 struct csParticleBuffer
    00239 {
    00241   csParticle* particleData;
    00242
    00244   csParticleAux* particleAuxData;
    00245
    00247   size_t particleCount;
    00248 };
    00249
    00255 struct iParticleEmitter : public virtual iBase
    00256 {
    00257   SCF_INTERFACE(iParticleEmitter,1,0,0);
    00258
    00263   virtual void SetEnabled (bool enabled) = 0;
    00264
    00268   virtual bool GetEnabled () const = 0;
    00269
    00276   virtual void SetStartTime (float time) = 0;
    00277
    00281   virtual float GetStartTime () const = 0;
    00282
    00290   virtual void SetDuration (float time) = 0;
    00291
    00295   virtual float GetDuration () const = 0;
    00296
    00300   virtual void SetEmissionRate (float particlesPerSecond) = 0;
    00301
    00305   virtual float GetEmissionRate () const = 0;
    00306
    00311   virtual void SetInitialTTL (float min, float max) = 0;
    00312
    00316   virtual void GetInitialTTL (float& min, float& max) const= 0;
    00317
    00322   virtual void SetInitialMass (float min, float max) = 0;
    00323
    00327   virtual void GetInitialMass (float& min, float& max) const = 0;
    00328
    00332   virtual csPtr<iParticleEmitter> Clone () const = 0;
    00333
    00343   virtual size_t ParticlesToEmit (iParticleSystemBase* system,
    00344     float dt, float totalTime) = 0;
    00345
    00360   virtual void EmitParticles (iParticleSystemBase* system,
    00361     const csParticleBuffer& particleBuffer, float dt, float totalTime,
    00362     const csReversibleTransform* const emitterToParticle = 0) = 0;
    00363
    00364 };
    00365
    00371 struct iParticleEffector : public virtual iBase
    00372 {
    00373   SCF_INTERFACE(iParticleEffector,1,0,0);
    00374
    00378   virtual csPtr<iParticleEffector> Clone () const = 0;
    00379
    00383   virtual void EffectParticles (iParticleSystemBase* system,
    00384     const csParticleBuffer& particleBuffer, float dt, float totalTime) = 0;
    00385 };
    00386
    00387
    00394 struct iParticleSystemBase : public virtual iBase
    00395 {
    00396   SCF_INTERFACE(iParticleSystemBase, 1,0,0);
    00397
    00399   virtual void SetParticleRenderOrientation (csParticleRenderOrientation o) = 0;
    00400
    00402   virtual csParticleRenderOrientation GetParticleRenderOrientation () const = 0;
    00403
    00405   virtual void SetRotationMode (csParticleRotationMode mode) = 0;
    00406
    00408   virtual csParticleRotationMode GetRotationMode () const = 0;
    00409
    00411   virtual void SetSortMode (csParticleSortMode mode) = 0;
    00412
    00414   virtual csParticleSortMode GetSortMode () const = 0;
    00415
    00417   virtual void SetIntegrationMode (csParticleIntegrationMode mode) = 0;
    00418
    00420   virtual csParticleIntegrationMode GetIntegrationMode () = 0;
    00421
    00423   virtual void SetCommonDirection (const csVector3& direction) = 0;
    00424
    00426   virtual const csVector3& GetCommonDirection () const = 0;
    00427
    00429   virtual void SetTransformMode (csParticleTransformMode mode) = 0;
    00430
    00432   virtual csParticleTransformMode GetTransformMode () const = 0;
    00433
    00435   virtual void SetUseIndividualSize (bool individual) = 0;
    00436
    00438   virtual bool GetUseIndividualSize () const = 0;
    00439
    00441   virtual void SetParticleSize (const csVector2& size) = 0;
    00442
    00444   virtual const csVector2& GetParticleSize () const = 0;
    00445
    00447   virtual void SetMinBoundingBox (const csBox3& box) = 0;
    00448
    00450   virtual const csBox3& GetMinBoundingBox () const = 0;
    00451
    00453   virtual void AddEmitter (iParticleEmitter* emitter) = 0;
    00454
    00456   virtual iParticleEmitter* GetEmitter (size_t index) const = 0;
    00457
    00459   virtual void RemoveEmitter (size_t index) = 0;
    00460
    00462   virtual size_t GetEmitterCount () const = 0;
    00463
    00465   virtual void AddEffector (iParticleEffector* effector) = 0;
    00466
    00468   virtual iParticleEffector* GetEffector (size_t index) const = 0;
    00469
    00471   virtual void RemoveEffector (size_t index) = 0;
    00472
    00474   virtual size_t GetEffectorCount () const = 0;
    00475
    00476 };
    00477
    00478
    00482 struct iParticleSystemFactory : public iParticleSystemBase
    00483 {
    00484   SCF_INTERFACE(iParticleSystemFactory,1,0,0);
    00485
    00490   virtual void SetDeepCreation (bool deep) = 0;
    00491
    00493   virtual bool GetDeepCreation () const = 0;
    00494 };
    00495
    00496
    00500 struct iParticleSystem : public iParticleSystemBase
    00501 {
    00502   SCF_INTERFACE(iParticleSystem,1,0,1);
    00503
    00505   virtual size_t GetParticleCount () const = 0;
    00506
    00508   virtual csParticle* GetParticle (size_t index) = 0;
    00509
    00511   virtual csParticleAux* GetParticleAux (size_t index) = 0;
    00512
    00521   virtual csParticleBuffer* LockForExternalControl (size_t maxParticles) = 0;
    00522
    00530   virtual void Advance (csTicks time) = 0;
    00531 };
    00532
    00538
    00539 enum csParticleBuiltinEmitterPlacement
    00540 {
    00542   CS_PARTICLE_BUILTIN_CENTER,
    00544   CS_PARTICLE_BUILTIN_VOLUME,
    00546   CS_PARTICLE_BUILTIN_SURFACE
    00547 };
    00548
    00552 struct iParticleBuiltinEmitterBase : public iParticleEmitter
    00553 {
    00554   SCF_INTERFACE(iParticleBuiltinEmitterBase,1,0,0);
    00555
    00561   virtual void SetPosition (const csVector3& position) = 0;
    00562
    00564   virtual const csVector3& GetPosition () const = 0;
    00565
    00567   virtual void SetParticlePlacement (csParticleBuiltinEmitterPlacement place) = 0;
    00568
    00570   virtual csParticleBuiltinEmitterPlacement GetParticlePlacement () const = 0;
    00571
    00584   virtual void SetUniformVelocity (bool uniform) = 0;
    00585
    00587   virtual bool GetUniformVelocity () const = 0;
    00588
    00590   virtual void SetInitialVelocity (const csVector3& linear,
    00591     const csVector3& angular) = 0;
    00592
    00594   virtual void GetInitialVelocity (csVector3& linear,
    00595     csVector3& angular) const = 0;
    00596 };
    00597
    00601 struct iParticleBuiltinEmitterSphere : public iParticleBuiltinEmitterBase
    00602 {
    00603   SCF_INTERFACE(iParticleBuiltinEmitterSphere,1,0,0);
    00604
    00606   virtual void SetRadius (float radius) = 0;
    00607
    00609   virtual float GetRadius () const = 0;
    00610 };
    00611
    00615 struct iParticleBuiltinEmitterCone : public iParticleBuiltinEmitterBase
    00616 {
    00617   SCF_INTERFACE(iParticleBuiltinEmitterCone,1,0,0);
    00618
    00620   virtual void SetExtent (const csVector3& extent) = 0;
    00621
    00623   virtual const csVector3& GetExtent () const = 0;
    00624
    00629   virtual void SetConeAngle (float angle) = 0;
    00630
    00632   virtual float GetConeAngle () const = 0;
    00633 };
    00634
    00638 struct iParticleBuiltinEmitterBox : public iParticleBuiltinEmitterBase
    00639 {
    00640   SCF_INTERFACE(iParticleBuiltinEmitterBox,1,0,0);
    00641
    00643   virtual void SetBox (const csOBB& box) = 0;
    00644
    00646   virtual const csOBB& GetBox () const = 0;
    00647 };
    00648
    00652 struct iParticleBuiltinEmitterCylinder : public iParticleBuiltinEmitterBase
    00653 {
    00654   SCF_INTERFACE(iParticleBuiltinEmitterCylinder,1,0,0);
    00655
    00657   virtual void SetRadius (float radius) = 0;
    00658
    00660   virtual float GetRadius () const = 0;
    00661
    00663   virtual void SetExtent (const csVector3& extent) = 0;
    00664
    00666   virtual const csVector3& GetExtent () const = 0;
    00667 };
    00668
    00672 struct iParticleBuiltinEmitterFactory : public virtual iBase
    00673 {
    00674   SCF_INTERFACE(iParticleBuiltinEmitterFactory,1,0,0);
    00675
    00677   virtual csPtr<iParticleBuiltinEmitterSphere> CreateSphere () const = 0;
    00678
    00680   virtual csPtr<iParticleBuiltinEmitterCone> CreateCone () const = 0;
    00681
    00683   virtual csPtr<iParticleBuiltinEmitterBox> CreateBox () const = 0;
    00684
    00686   virtual csPtr<iParticleBuiltinEmitterCylinder> CreateCylinder () const = 0;
    00687 };
    00688
    00707 struct iParticleBuiltinEffectorForce : public iParticleEffector
    00708 {
    00709   SCF_INTERFACE(iParticleBuiltinEffectorForce,2,0,0);
    00710
    00712   virtual void SetAcceleration (const csVector3& acceleration) = 0;
    00713
    00715   virtual const csVector3& GetAcceleration () const = 0;
    00716
    00718   virtual void SetForce (const csVector3& force) = 0;
    00719
    00721   virtual const csVector3& GetForce () const = 0;
    00722
    00724   virtual void SetRandomAcceleration (const csVector3& magnitude) = 0;
    00725
    00727   virtual const csVector3& GetRandomAcceleration () const = 0;
    00728 };
    00729
    00738 struct iParticleBuiltinEffectorLinColor : public iParticleEffector
    00739 {
    00740   SCF_INTERFACE(iParticleBuiltinEffectorLinColor,1,1,0);
    00741
    00746   virtual size_t AddColor (const csColor4& color, float endTTL) = 0;
    00747
    00751   virtual void RemoveColor (size_t index) = 0;
    00752
    00756   virtual void Clear () = 0;
    00757
    00761   virtual void SetColor (size_t index, const csColor4& color) = 0;
    00762
    00766   virtual void SetEndTTL (size_t index, float ttl) = 0;
    00767
    00771   virtual void GetColor (size_t index, csColor4& color, float& endTTL) const = 0;
    00772
    00776   virtual const csColor4& GetColor (size_t index) const = 0;
    00780   virtual float GetEndTTL (size_t index) const = 0;
    00781
    00785   virtual size_t GetColorCount () const = 0;
    00786 };
    00787
    00793 enum csParticleBuiltinEffectorVFType
    00794 {
    00802   CS_PARTICLE_BUILTIN_SPIRAL,
    00803
    00810   CS_PARTICLE_BUILTIN_RADIALPOINT
    00811 };
    00812
    00824 struct iParticleBuiltinEffectorVelocityField : public iParticleEffector
    00825 {
    00826   SCF_INTERFACE(iParticleBuiltinEffectorVelocityField,2,0,0);
    00827
    00831   virtual void SetType (csParticleBuiltinEffectorVFType type) = 0;
    00832
    00836   virtual csParticleBuiltinEffectorVFType GetType () const = 0;
    00837
    00841   virtual void SetFParameter (size_t parameterNumber, float value) = 0;
    00842
    00846   virtual float GetFParameter (size_t parameterNumber) const = 0;
    00847
    00851   virtual size_t GetFParameterCount () const = 0;
    00852
    00856   virtual void AddFParameter(float value) = 0;
    00857
    00861   virtual void RemoveFParameter(size_t index) = 0;
    00862
    00866   virtual void SetVParameter (size_t parameterNumber, const csVector3& value) = 0;
    00867
    00871   virtual csVector3 GetVParameter (size_t parameterNumber) const = 0;
    00872
    00876   virtual size_t GetVParameterCount () const = 0;
    00877
    00881   virtual void AddVParameter(const csVector3& value) = 0;
    00882
    00886   virtual void RemoveVParameter(size_t index) = 0;
    00887
    00888 };
    00889
    00894 enum csParticleParameterMask
    00895 {
    00897   CS_PARTICLE_MASK_MASS = 1,
    00899   CS_PARTICLE_MASK_LINEARVELOCITY = 2,
    00901   CS_PARTICLE_MASK_ANGULARVELOCITY = 4,
    00903   CS_PARTICLE_MASK_COLOR = 8,
    00905   CS_PARTICLE_MASK_PARTICLESIZE = 16,
    00906
    00908   CS_PARTICLE_MASK_ALL = CS_PARTICLE_MASK_MASS | CS_PARTICLE_MASK_LINEARVELOCITY |
    00909     CS_PARTICLE_MASK_ANGULARVELOCITY | CS_PARTICLE_MASK_COLOR | CS_PARTICLE_MASK_PARTICLESIZE
    00910 };
    00911
    00916 struct csParticleParameterSet
    00917 {
    00919   float mass;
    00921   csVector3 linearVelocity;
    00923   csVector3 angularVelocity;
    00925   csColor4 color;
    00927   csVector2 particleSize;
    00928
    00929   csParticleParameterSet ()
    00930   {
    00931     Clear ();
    00932   }
    00933
    00935   void Clear ()
    00936   {
    00937     mass = 0.0;
    00938     linearVelocity.Set (0, 0, 0);
    00939     angularVelocity.Set (0, 0, 0);
    00940     color.Set (0, 0, 0, 0);
    00941     particleSize.Set (0, 0);
    00942   }
    00943 };
    00944
    00953 struct iParticleBuiltinEffectorLinear : public iParticleEffector
    00954 {
    00955   SCF_INTERFACE(iParticleBuiltinEffectorLinear,1,1,0);
    00956
    00961   virtual void SetMask (int mask) = 0;
    00962
    00966   virtual int GetMask () const = 0;
    00967
    00972   virtual size_t AddParameterSet (const csParticleParameterSet& param, float endTTL) = 0;
    00973
    00977   virtual void RemoveParameterSet (size_t index) = 0;
    00978
    00982   virtual void Clear () = 0;
    00983
    00987   virtual void SetParameterSet (size_t index, const csParticleParameterSet& param) = 0;
    00988
    00992   virtual void SetEndTTL (size_t index, float ttl) = 0;
    00993
    00997   virtual void GetParameterSet (size_t index, csParticleParameterSet& param, float& endTTL) const = 0;
    00998
    01002   virtual const csParticleParameterSet& GetParameterSet (size_t index) const = 0;
    01003
    01007   virtual float GetEndTTL (size_t index) const = 0;
    01008
    01012   virtual size_t GetParameterSetCount () const = 0;
    01013 };
    01014
    01023 struct iParticleBuiltinEffectorLight : public iParticleEffector
    01024 {
    01025   SCF_INTERFACE(iParticleBuiltinEffectorLight,1,0,0);
    01026
    01032   virtual void SetInitialCutoffDistance (float distance) = 0;
    01033
    01035   virtual float GetInitialCutoffDistance () const = 0;
    01036 };
    01037
    01041 struct iParticleBuiltinEffectorFactory : public virtual iBase
    01042 {
    01043   SCF_INTERFACE(iParticleBuiltinEffectorFactory,1,0,2);
    01044
    01046   virtual csPtr<iParticleBuiltinEffectorForce> CreateForce () const = 0;
    01047
    01049   virtual csPtr<iParticleBuiltinEffectorLinColor> CreateLinColor () const = 0;
    01050
    01052   virtual csPtr<iParticleBuiltinEffectorVelocityField> CreateVelocityField () const = 0;
    01053
    01055   virtual csPtr<iParticleBuiltinEffectorLinear> CreateLinear () const = 0;
    01056
    01058   virtual csPtr<iParticleBuiltinEffectorLight> CreateLight () const = 0;
    01059 };
    01060
    01066 #endif // __CS_IMESH_PARTICLES_H__