1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * ---------------------------------------------------------------------- |
---|
4 | * NvParticleRenderer.h: particle system class |
---|
5 | * |
---|
6 | * ====================================================================== |
---|
7 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
8 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
9 | * |
---|
10 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
11 | * |
---|
12 | * See the file "license.terms" for information on usage and |
---|
13 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
14 | * ====================================================================== |
---|
15 | */ |
---|
16 | #ifndef NVPARTICLERENDERER_H |
---|
17 | #define NVPARTICLERENDERER_H |
---|
18 | |
---|
19 | #include <GL/glew.h> |
---|
20 | |
---|
21 | #include "Renderable.h" |
---|
22 | #include "NvParticleAdvectionShader.h" |
---|
23 | #include "RenderVertexArray.h" |
---|
24 | #include "Vector3.h" |
---|
25 | #include "Vector4.h" |
---|
26 | |
---|
27 | struct Particle { |
---|
28 | float x; |
---|
29 | float y; |
---|
30 | float z; |
---|
31 | float aux; |
---|
32 | |
---|
33 | Particle() |
---|
34 | {} |
---|
35 | |
---|
36 | Particle(float _x, float _y, float _z, float _life) : |
---|
37 | x(_x), y(_y), z(_z), aux(_life) |
---|
38 | {} |
---|
39 | }; |
---|
40 | |
---|
41 | class NvParticleRenderer : public Renderable |
---|
42 | { |
---|
43 | public: |
---|
44 | NvParticleRenderer(int w, int h); |
---|
45 | |
---|
46 | ~NvParticleRenderer(); |
---|
47 | |
---|
48 | void setVectorField(unsigned int texID, const Vector3& origin, |
---|
49 | float scaleX, float scaleY, float scaleZ, float max); |
---|
50 | |
---|
51 | void initialize(); |
---|
52 | |
---|
53 | void advect(); |
---|
54 | |
---|
55 | void updateVertexBuffer(); |
---|
56 | |
---|
57 | void reset(); |
---|
58 | |
---|
59 | void render(); |
---|
60 | |
---|
61 | bool active() const |
---|
62 | { |
---|
63 | return _activate; |
---|
64 | } |
---|
65 | |
---|
66 | void active(bool state) |
---|
67 | { |
---|
68 | _activate = state; |
---|
69 | } |
---|
70 | |
---|
71 | void setColor(const Vector4& color) |
---|
72 | { |
---|
73 | _color = color; |
---|
74 | } |
---|
75 | |
---|
76 | void setAxis(int axis); |
---|
77 | |
---|
78 | void setPos(float pos); |
---|
79 | |
---|
80 | void initializeDataArray(); |
---|
81 | |
---|
82 | void particleSize(float size) |
---|
83 | { |
---|
84 | _particleSize = size; |
---|
85 | } |
---|
86 | |
---|
87 | float particleSize() const |
---|
88 | { |
---|
89 | return _particleSize; |
---|
90 | } |
---|
91 | |
---|
92 | static NvParticleAdvectionShader *_advectionShader; |
---|
93 | |
---|
94 | private: |
---|
95 | /// frame buffer objects: two are defined, flip them as input output every step |
---|
96 | GLuint _psysFbo[2]; |
---|
97 | |
---|
98 | /// color textures attached to frame buffer objects |
---|
99 | GLuint _psysTex[2]; |
---|
100 | GLuint _initPosTex; |
---|
101 | Particle *_data; |
---|
102 | |
---|
103 | /// Count the frame number of particle system iteration |
---|
104 | int _psysFrame; |
---|
105 | |
---|
106 | /// Reinitiate particles |
---|
107 | bool _reborn; |
---|
108 | |
---|
109 | /// flip the source and destination render targets |
---|
110 | bool _flip; |
---|
111 | |
---|
112 | float _maxLife; |
---|
113 | |
---|
114 | /// Size of the particle: default is 1.2 |
---|
115 | float _particleSize; |
---|
116 | |
---|
117 | /// vertex array for display particles |
---|
118 | RenderVertexArray *_vertexArray; |
---|
119 | |
---|
120 | /// scale of flow data |
---|
121 | Vector3 _scale; |
---|
122 | |
---|
123 | Vector3 _origin; |
---|
124 | |
---|
125 | bool _activate; |
---|
126 | |
---|
127 | float _slicePos; |
---|
128 | int _sliceAxis; |
---|
129 | |
---|
130 | Vector4 _color; |
---|
131 | |
---|
132 | //the storage of particles is implemented as a 2D array. |
---|
133 | int _psysWidth; |
---|
134 | int _psysHeight; |
---|
135 | }; |
---|
136 | |
---|
137 | #endif |
---|