absence_thelab
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/3deng/particles.h Thu Oct 23 01:46:07 2014 +0300 1.3 @@ -0,0 +1,99 @@ 1.4 +#ifndef _PARTICLES_H_ 1.5 +#define _PARTICLES_H_ 1.6 + 1.7 +#include <list> 1.8 +#include "n3dmath.h" 1.9 +#include "3dgeom.h" 1.10 +#include "objects.h" 1.11 + 1.12 +enum BlendingFactor; 1.13 + 1.14 +class Particle { 1.15 +public: 1.16 + Vector3 pos; 1.17 + Vector3 vel; 1.18 + unsigned int life; 1.19 + 1.20 + Particle(int life=0); 1.21 + Particle(const Vector3 &pos, int life=0); 1.22 + Particle(const Vector3 &pos, const Vector3 &vel, int life=0); 1.23 + 1.24 + void Update(const Vector3 &forces, float friction=0); 1.25 +}; 1.26 + 1.27 +class ParticleSystem { 1.28 +private: 1.29 + GraphicsContext *gc; 1.30 + bool FixedUpdateRate; 1.31 + float UpdateRate; 1.32 + float LastUpdate; 1.33 + 1.34 + BlendingFactor SourceBlend, DestBlend; 1.35 + 1.36 + Vector3 pos, prevpos; // position of the emmiter (world space) 1.37 + Vector3 ShootDirection; // an initial velocity vector for the particles 1.38 + std::list<Particle> particles; // a list of particles 1.39 + Vertex pquad[4]; // the basic particle quad vertices 1.40 + Triangle ptris[2]; // the basic particle quad triangles 1.41 + float size; // size of the particles 1.42 + float friction; // friction impeding particle movement 1.43 + int SpawnRate; // rate of particle generation 1.44 + float SpawnRadius; // spawning radius around the emmiter 1.45 + float GravForce; // Gravitual force 1.46 + float DispRads; 1.47 + int life; // particle life 1.48 + bool EmmiterAffectsParticleTrajectory; // ehm ... yeah 1.49 + float SpawnDiffDispersion; 1.50 + int SpawnRateChange; // if 0 then spawn rate constant 1.51 + 1.52 + float StartRed, StartGreen, StartBlue; 1.53 + float EndRed, EndGreen, EndBlue; 1.54 + 1.55 + int VertsToRender, TrianglesToRender; 1.56 + int vbsize, ibsize, maxprimitives; 1.57 + Texture *texture; // the particles' texture 1.58 + Object *obj; // the particles' mesh object (if present don't render quads) 1.59 + Vertex *varray; // secondary vertex array (ease of development) 1.60 + Triangle *tarray; // the triangles 1.61 + 1.62 + int VertexCount, IndexCount, TriCount, ParticleCount; 1.63 + 1.64 +public: 1.65 + Matrix4x4 Translation, OrbitRot; 1.66 + 1.67 + ParticleSystem(GraphicsContext *gc); 1.68 + ~ParticleSystem(); 1.69 + 1.70 + void SetGraphicsContext(GraphicsContext *gc); 1.71 + void SetParticleSize(float psize); 1.72 + void SetParticleLife(int life); 1.73 + void SetFriction(float friction); 1.74 + void SetSpawnRate(float spawnrate); 1.75 + void SetSpawnRadius(float radius); 1.76 + void SetTexture(Texture *texture); 1.77 + void SetObject(Object *obj); 1.78 + void SetPosition(const Vector3 &pos); 1.79 + void SetShootDirection(const Vector3 &dir); 1.80 + void SetGravitualForce(float grav); 1.81 + void SetEmmiterDependence(bool dep); 1.82 + void SetMaxDispersionAngle(float maxdisp); 1.83 + void SetInitialColor(float r, float g, float b); 1.84 + void SetDeathColor(float r, float g, float b); 1.85 + void SetBlendingMode(BlendingFactor src, BlendingFactor dest); 1.86 + void SetSpawningDifferenceDispersion(float val); 1.87 + void SetSpawnRateChange(int change); 1.88 + 1.89 + void Translate(float x, float y, float z); 1.90 + void Rotate(float x, float y, float z); 1.91 + void Rotate(const Vector3 &axis, float angle); 1.92 + void ResetTranslation(); 1.93 + void ResetRotation(); 1.94 + 1.95 + int CountParticles(); 1.96 + 1.97 + void Update(float t = 0.0f); 1.98 + void Render(); 1.99 +}; 1.100 + 1.101 + 1.102 +#endif // _PARTICLES_H_