00001
00002
00003
00004
00005
00006 #ifndef PARTICLESYSTEM_H
00007 #define PARTICLESYSTEM_H
00008
00009 #include<Object.h>
00010
00011 #include<AABoundingBox.h>
00012 #include<Color4.h>
00013 #include<Vertex3.h>
00014
00015 #include<vector>
00016
00017 class RenderContext;
00018
00021 class ParticleSystem : public Object
00022 {
00023 public:
00026 class Particle {
00027 friend ParticleSystem;
00028
00029 Vertex3 position;
00030 Vertex3 velocity;
00031 real life;
00032 real size;
00033 };
00034 typedef enum BlendType {
00035 Smoke,
00036 Glow
00037 };
00038
00039 ParticleSystem(unsigned int maxSize = 100);
00040 ParticleSystem(const Vertex3 &pos, unsigned int maxSize = 100);
00041 virtual ~ParticleSystem();
00042
00043 unsigned int getSize() const {
00044 return maxSize;
00045 }
00046 void setSize(unsigned int maxSize);
00047 const Color4 &getColor() const {
00048 return color;
00049 }
00050 float getAngle() const {
00051 return angle;
00052 }
00053 void setAngle(float a) {
00054 angle = a;
00055 }
00056 float getLife() const {
00057 return maxLife;
00058 }
00059 void setLife(float life) {
00060 maxLife = life;
00061 }
00062 void setColor(const Color4 &c) {
00063 color = c;
00064 }
00065 bool getGravity() const {
00066 return gravity;
00067 }
00068 void setGravity(bool b) {
00069 gravity = b;
00070 }
00071 BlendType getBlendType() const {
00072 return blendType;
00073 }
00074 void setBlendType(BlendType b) {
00075 blendType = b;
00076 }
00077 const Vertex3 &getPosition() const {
00078 return position;
00079 }
00080 void setPosition(const Vertex3 &p) {
00081 position = p;
00082 }
00083 Vertex3 getDirection() const {
00084 return direction*speed;
00085 }
00086 void setDirection(const Vertex3 &d);
00087
00088
00089 bool update(World &world);
00090 void render(
00091 RenderContext &rc,
00092 RenderContext::Visibility visibility = RenderContext::PartlyVisible);
00093 void write(WDFFile &f);
00094 void read(WDFFile &f);
00095
00096 private:
00097 typedef vector<Particle> ParticleList;
00098
00099 void addParticle();
00100 void deleteParticle(unsigned int i);
00101
00102
00103 Vertex3 position;
00104 Vertex3 direction;
00105 Color4 color;
00106 float angle;
00107 float maxLife;
00108 unsigned int maxSize;
00109 bool gravity;
00110 BlendType blendType;
00111
00112 float speed;
00113 unsigned int size;
00114 ParticleList particle;
00115 };
00116 #endif