absence_thelab

view src/3deng/particles.h @ 0:1cffe3409164

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Oct 2014 01:46:07 +0300
parents
children
line source
1 #ifndef _PARTICLES_H_
2 #define _PARTICLES_H_
4 #include <list>
5 #include "n3dmath.h"
6 #include "3dgeom.h"
7 #include "objects.h"
9 enum BlendingFactor;
11 class Particle {
12 public:
13 Vector3 pos;
14 Vector3 vel;
15 unsigned int life;
17 Particle(int life=0);
18 Particle(const Vector3 &pos, int life=0);
19 Particle(const Vector3 &pos, const Vector3 &vel, int life=0);
21 void Update(const Vector3 &forces, float friction=0);
22 };
24 class ParticleSystem {
25 private:
26 GraphicsContext *gc;
27 bool FixedUpdateRate;
28 float UpdateRate;
29 float LastUpdate;
31 BlendingFactor SourceBlend, DestBlend;
33 Vector3 pos, prevpos; // position of the emmiter (world space)
34 Vector3 ShootDirection; // an initial velocity vector for the particles
35 std::list<Particle> particles; // a list of particles
36 Vertex pquad[4]; // the basic particle quad vertices
37 Triangle ptris[2]; // the basic particle quad triangles
38 float size; // size of the particles
39 float friction; // friction impeding particle movement
40 int SpawnRate; // rate of particle generation
41 float SpawnRadius; // spawning radius around the emmiter
42 float GravForce; // Gravitual force
43 float DispRads;
44 int life; // particle life
45 bool EmmiterAffectsParticleTrajectory; // ehm ... yeah
46 float SpawnDiffDispersion;
47 int SpawnRateChange; // if 0 then spawn rate constant
49 float StartRed, StartGreen, StartBlue;
50 float EndRed, EndGreen, EndBlue;
52 int VertsToRender, TrianglesToRender;
53 int vbsize, ibsize, maxprimitives;
54 Texture *texture; // the particles' texture
55 Object *obj; // the particles' mesh object (if present don't render quads)
56 Vertex *varray; // secondary vertex array (ease of development)
57 Triangle *tarray; // the triangles
59 int VertexCount, IndexCount, TriCount, ParticleCount;
61 public:
62 Matrix4x4 Translation, OrbitRot;
64 ParticleSystem(GraphicsContext *gc);
65 ~ParticleSystem();
67 void SetGraphicsContext(GraphicsContext *gc);
68 void SetParticleSize(float psize);
69 void SetParticleLife(int life);
70 void SetFriction(float friction);
71 void SetSpawnRate(float spawnrate);
72 void SetSpawnRadius(float radius);
73 void SetTexture(Texture *texture);
74 void SetObject(Object *obj);
75 void SetPosition(const Vector3 &pos);
76 void SetShootDirection(const Vector3 &dir);
77 void SetGravitualForce(float grav);
78 void SetEmmiterDependence(bool dep);
79 void SetMaxDispersionAngle(float maxdisp);
80 void SetInitialColor(float r, float g, float b);
81 void SetDeathColor(float r, float g, float b);
82 void SetBlendingMode(BlendingFactor src, BlendingFactor dest);
83 void SetSpawningDifferenceDispersion(float val);
84 void SetSpawnRateChange(int change);
86 void Translate(float x, float y, float z);
87 void Rotate(float x, float y, float z);
88 void Rotate(const Vector3 &axis, float angle);
89 void ResetTranslation();
90 void ResetRotation();
92 int CountParticles();
94 void Update(float t = 0.0f);
95 void Render();
96 };
99 #endif // _PARTICLES_H_