CrystalSpace

Public API Reference

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 
00254 struct iParticleEmitter : public virtual iBase
00255 {
00256   SCF_INTERFACE(iParticleEmitter,1,0,0);
00257 
00262   virtual void SetEnabled (bool enabled) = 0;
00263 
00267   virtual bool GetEnabled () const = 0;
00268 
00275   virtual void SetStartTime (float time) = 0;
00276 
00280   virtual float GetStartTime () const = 0;
00281 
00289   virtual void SetDuration (float time) = 0;
00290 
00294   virtual float GetDuration () const = 0;
00295 
00299   virtual void SetEmissionRate (float particlesPerSecond) = 0;
00300 
00304   virtual float GetEmissionRate () const = 0;
00305 
00310   virtual void SetInitialTTL (float min, float max) = 0;
00311 
00315   virtual void GetInitialTTL (float& min, float& max) const= 0;
00316 
00321   virtual void SetInitialMass (float min, float max) = 0;
00322 
00326   virtual void GetInitialMass (float& min, float& max) const = 0;
00327 
00331   virtual csPtr<iParticleEmitter> Clone () const = 0;
00332 
00336   virtual size_t ParticlesToEmit (iParticleSystemBase* system,
00337     float dt, float totalTime) = 0;
00338 
00342   virtual void EmitParticles (iParticleSystemBase* system,
00343     const csParticleBuffer& particleBuffer, float dt, float totalTime,
00344     const csReversibleTransform* const emitterToParticle = 0) = 0;
00345 
00346 };
00347 
00353 struct iParticleEffector : public virtual iBase
00354 {
00355   SCF_INTERFACE(iParticleEffector,1,0,0);
00356 
00360   virtual csPtr<iParticleEffector> Clone () const = 0;
00361 
00365   virtual void EffectParticles (iParticleSystemBase* system,
00366     const csParticleBuffer& particleBuffer, float dt, float totalTime) = 0;
00367 };
00368 
00369 
00376 struct iParticleSystemBase : public virtual iBase
00377 {
00378   SCF_INTERFACE(iParticleSystemBase, 1,0,0);
00379 
00381   virtual void SetParticleRenderOrientation (csParticleRenderOrientation o) = 0;
00382 
00384   virtual csParticleRenderOrientation GetParticleRenderOrientation () const = 0;
00385 
00387   virtual void SetRotationMode (csParticleRotationMode mode) = 0;
00388 
00390   virtual csParticleRotationMode GetRotationMode () const = 0;
00391 
00393   virtual void SetSortMode (csParticleSortMode mode) = 0;
00394 
00396   virtual csParticleSortMode GetSortMode () const = 0;
00397 
00399   virtual void SetIntegrationMode (csParticleIntegrationMode mode) = 0;
00400 
00402   virtual csParticleIntegrationMode GetIntegrationMode () = 0;
00403 
00405   virtual void SetCommonDirection (const csVector3& direction) = 0;
00406 
00408   virtual const csVector3& GetCommonDirection () const = 0;
00409 
00411   virtual void SetTransformMode (csParticleTransformMode mode) = 0;
00412 
00414   virtual csParticleTransformMode GetTransformMode () const = 0;
00415 
00417   virtual void SetUseIndividualSize (bool individual) = 0;
00418 
00420   virtual bool GetUseIndividualSize () const = 0;
00421 
00423   virtual void SetParticleSize (const csVector2& size) = 0;
00424 
00426   virtual const csVector2& GetParticleSize () const = 0;
00427 
00429   virtual void SetMinBoundingBox (const csBox3& box) = 0;
00430   
00432   virtual const csBox3& GetMinBoundingBox () const = 0;
00433 
00435   virtual void AddEmitter (iParticleEmitter* emitter) = 0;
00436 
00438   virtual iParticleEmitter* GetEmitter (size_t index) const = 0;
00439 
00441   virtual void RemoveEmitter (size_t index) = 0;
00442 
00444   virtual size_t GetEmitterCount () const = 0;
00445 
00447   virtual void AddEffector (iParticleEffector* effector) = 0;
00448 
00450   virtual iParticleEffector* GetEffector (size_t index) const = 0;
00451 
00453   virtual void RemoveEffector (size_t index) = 0;
00454 
00456   virtual size_t GetEffectorCount () const = 0;
00457 
00458 };
00459 
00460 
00464 struct iParticleSystemFactory : public iParticleSystemBase
00465 {
00466   SCF_INTERFACE(iParticleSystemFactory,1,0,0);
00467 
00472   virtual void SetDeepCreation (bool deep) = 0;
00473 
00475   virtual bool GetDeepCreation () const = 0;
00476 };
00477 
00478 
00482 struct iParticleSystem : public iParticleSystemBase
00483 {
00484   SCF_INTERFACE(iParticleSystem,1,0,1);
00485 
00487   virtual size_t GetParticleCount () const = 0;
00488 
00490   virtual csParticle* GetParticle (size_t index) = 0;
00491 
00493   virtual csParticleAux* GetParticleAux (size_t index) = 0;
00494 
00501   virtual csParticleBuffer* LockForExternalControl (size_t maxParticles) = 0;
00502   
00510   virtual void Advance (csTicks time) = 0;
00511 };
00512 
00518 
00519 enum csParticleBuiltinEmitterPlacement
00520 {
00522   CS_PARTICLE_BUILTIN_CENTER,
00524   CS_PARTICLE_BUILTIN_VOLUME,
00526   CS_PARTICLE_BUILTIN_SURFACE
00527 };
00528 
00529 struct iParticleBuiltinEmitterBase : public iParticleEmitter
00530 {
00531   SCF_INTERFACE(iParticleBuiltinEmitterBase,1,0,0);
00532 
00538   virtual void SetPosition (const csVector3& position) = 0;
00539 
00541   virtual const csVector3& GetPosition () const = 0;
00542 
00544   virtual void SetParticlePlacement (csParticleBuiltinEmitterPlacement place) = 0;
00545 
00547   virtual csParticleBuiltinEmitterPlacement GetParticlePlacement () const = 0;
00548 
00561   virtual void SetUniformVelocity (bool uniform) = 0;
00562 
00564   virtual bool GetUniformVelocity () const = 0;
00565 
00567   virtual void SetInitialVelocity (const csVector3& linear, 
00568     const csVector3& angular) = 0;
00569 
00571   virtual void GetInitialVelocity (csVector3& linear, 
00572     csVector3& angular) const = 0;
00573 };
00574 
00575 struct iParticleBuiltinEmitterSphere : public iParticleBuiltinEmitterBase
00576 {
00577   SCF_INTERFACE(iParticleBuiltinEmitterSphere,1,0,0);
00578 
00580   virtual void SetRadius (float radius) = 0;
00581 
00583   virtual float GetRadius () const = 0;
00584 };
00585 
00586 struct iParticleBuiltinEmitterCone : public iParticleBuiltinEmitterBase
00587 {
00588   SCF_INTERFACE(iParticleBuiltinEmitterCone,1,0,0);
00589 
00591   virtual void SetExtent (const csVector3& extent) = 0;
00592 
00594   virtual const csVector3& GetExtent () const = 0;
00595 
00600   virtual void SetConeAngle (float angle) = 0;
00601 
00603   virtual float GetConeAngle () const = 0;
00604 };
00605 
00606 struct iParticleBuiltinEmitterBox : public iParticleBuiltinEmitterBase
00607 {
00608   SCF_INTERFACE(iParticleBuiltinEmitterBox,1,0,0);
00609 
00611   virtual void SetBox (const csOBB& box) = 0;
00612 
00614   virtual const csOBB& GetBox () const = 0;
00615 };
00616 
00617 struct iParticleBuiltinEmitterCylinder : public iParticleBuiltinEmitterBase
00618 {
00619   SCF_INTERFACE(iParticleBuiltinEmitterCylinder,1,0,0);
00620 
00622   virtual void SetRadius (float radius) = 0;
00623 
00625   virtual float GetRadius () const = 0;
00626 
00628   virtual void SetExtent (const csVector3& extent) = 0;
00629 
00631   virtual const csVector3& GetExtent () const = 0;
00632 };
00633 
00637 struct iParticleBuiltinEmitterFactory : public virtual iBase
00638 {
00639   SCF_INTERFACE(iParticleBuiltinEmitterFactory,1,0,0);
00640 
00641   virtual csPtr<iParticleBuiltinEmitterSphere> CreateSphere () const = 0;
00642   virtual csPtr<iParticleBuiltinEmitterCone> CreateCone () const = 0;
00643   virtual csPtr<iParticleBuiltinEmitterBox> CreateBox () const = 0;
00644   virtual csPtr<iParticleBuiltinEmitterCylinder> CreateCylinder () const = 0;
00645 };
00646 
00665 struct iParticleBuiltinEffectorForce : public iParticleEffector
00666 {
00667   SCF_INTERFACE(iParticleBuiltinEffectorForce,2,0,0);
00668   
00670   virtual void SetAcceleration (const csVector3& acceleration) = 0;
00671 
00673   virtual const csVector3& GetAcceleration () const = 0;
00674 
00676   virtual void SetForce (const csVector3& force) = 0;
00677 
00679   virtual const csVector3& GetForce () const = 0;
00680 
00682   virtual void SetRandomAcceleration (const csVector3& magnitude) = 0;
00683 
00685   virtual const csVector3& GetRandomAcceleration () const = 0;
00686 };
00687 
00696 struct iParticleBuiltinEffectorLinColor : public iParticleEffector
00697 {
00698   SCF_INTERFACE(iParticleBuiltinEffectorLinColor,1,0,0);
00699 
00704   virtual size_t AddColor (const csColor4& color, float endTTL) = 0;
00705 
00709   virtual void SetColor (size_t index, const csColor4& color) = 0;
00710 
00714   virtual void GetColor (size_t index, csColor4& color, float& endTTL) const = 0;
00715 
00719   virtual size_t GetColorCount () const = 0;
00720 };
00721 
00727 enum csParticleBuiltinEffectorVFType
00728 {
00736   CS_PARTICLE_BUILTIN_SPIRAL,
00737 
00744   CS_PARTICLE_BUILTIN_RADIALPOINT
00745 };
00746 
00758 struct iParticleBuiltinEffectorVelocityField : public iParticleEffector
00759 {
00760   SCF_INTERFACE(iParticleBuiltinEffectorVelocityField,1,0,0);
00761 
00765   virtual void SetType (csParticleBuiltinEffectorVFType type) = 0;
00766 
00770   virtual csParticleBuiltinEffectorVFType GetType () const = 0;
00771 
00775   virtual void SetFParameter (size_t parameterNumber, float value) = 0;
00776   
00780   virtual float GetFParameter (size_t parameterNumber) const = 0;
00781 
00785   virtual size_t GetFParameterCount () const = 0;
00786 
00790   virtual void SetVParameter (size_t parameterNumber, const csVector3& value) = 0;
00791   
00795   virtual csVector3 GetVParameter (size_t parameterNumber) const = 0;
00796 
00800   virtual size_t GetVParameterCount () const = 0;
00801 };
00802 
00806 struct iParticleBuiltinEffectorFactory : public virtual iBase
00807 {
00808   SCF_INTERFACE(iParticleBuiltinEffectorFactory,1,0,0);
00809 
00810   virtual csPtr<iParticleBuiltinEffectorForce> CreateForce () const = 0;
00811   virtual csPtr<iParticleBuiltinEffectorLinColor> CreateLinColor () const = 0;
00812   virtual csPtr<iParticleBuiltinEffectorVelocityField> CreateVelocityField () const = 0;
00813 };
00814 
00820 #endif // __CS_IMESH_PARTICLES_H__

Generated for Crystal Space 1.2.1 by doxygen 1.5.3