1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * NvParticleRenderer.h: particle system class |
---|
4 | * |
---|
5 | * ====================================================================== |
---|
6 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
7 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
8 | * |
---|
9 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
10 | * |
---|
11 | * See the file "license.terms" for information on usage and |
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | * ====================================================================== |
---|
14 | */ |
---|
15 | |
---|
16 | |
---|
17 | #ifndef _NV_PARTICLE_SYSTEM_H_ |
---|
18 | #define _NV_PARTICLE_SYSTEM_H_ |
---|
19 | |
---|
20 | #include "GL/glew.h" |
---|
21 | #include "Cg/cgGL.h" |
---|
22 | |
---|
23 | #include "define.h" |
---|
24 | #include "config.h" |
---|
25 | #include "global.h" |
---|
26 | |
---|
27 | #include "Renderable.h" |
---|
28 | #include "RenderVertexArray.h" |
---|
29 | #include "Vector3.h" |
---|
30 | |
---|
31 | #include <vector> |
---|
32 | |
---|
33 | #include "NvParticleAdvectionShader.h" |
---|
34 | |
---|
35 | struct Particle { |
---|
36 | float x; |
---|
37 | float y; |
---|
38 | float z; |
---|
39 | float aux; |
---|
40 | |
---|
41 | Particle(){}; |
---|
42 | Particle(float _x, float _y, float _z, float _life) : |
---|
43 | x(_x), y(_y), z(_z), aux(_life){} |
---|
44 | }; |
---|
45 | |
---|
46 | class NvParticleRenderer : public Renderable { |
---|
47 | public : |
---|
48 | /** |
---|
49 | * @brief frame buffer objects: two are defined, flip them as input output every step |
---|
50 | */ |
---|
51 | GLuint psys_fbo[2]; |
---|
52 | |
---|
53 | /** |
---|
54 | * @brief color textures attached to frame buffer objects |
---|
55 | */ |
---|
56 | GLuint psys_tex[2]; |
---|
57 | GLuint initPosTex; |
---|
58 | Particle* data; |
---|
59 | |
---|
60 | /** |
---|
61 | *@brief Count the frame number of particle system iteration |
---|
62 | */ |
---|
63 | int psys_frame; |
---|
64 | |
---|
65 | /** |
---|
66 | * @brief Reinitiate particles |
---|
67 | */ |
---|
68 | bool reborn; |
---|
69 | |
---|
70 | /** |
---|
71 | * @brief flip the source and destination render targets |
---|
72 | */ |
---|
73 | bool flip; |
---|
74 | |
---|
75 | float max_life; |
---|
76 | |
---|
77 | float _particleSize; // Size of the particle: default is 1.2 |
---|
78 | |
---|
79 | /** |
---|
80 | * @brief vertex array for display particles |
---|
81 | */ |
---|
82 | RenderVertexArray* m_vertex_array; |
---|
83 | |
---|
84 | //Nvidia CG shaders and their parameters |
---|
85 | /* |
---|
86 | CGcontext m_g_context; |
---|
87 | CGprogram m_pos_fprog; |
---|
88 | CGparameter m_vel_tex_param, m_pos_tex_param, m_scale_param; |
---|
89 | CGparameter m_pos_timestep_param, m_pos_spherePos_param; |
---|
90 | */ |
---|
91 | static NvParticleAdvectionShader* _advectionShader; |
---|
92 | |
---|
93 | /** |
---|
94 | * @brief scale of flow data |
---|
95 | */ |
---|
96 | Vector3 scale; |
---|
97 | |
---|
98 | Vector3 origin; |
---|
99 | |
---|
100 | bool _activate; |
---|
101 | |
---|
102 | float _slice_pos; |
---|
103 | int _slice_axis; |
---|
104 | Vector4 _color; |
---|
105 | |
---|
106 | public: |
---|
107 | int psys_width; //the storage of particles is implemented as a 2D array. |
---|
108 | int psys_height; |
---|
109 | |
---|
110 | NvParticleRenderer(int w, int h, CGcontext context); |
---|
111 | ~NvParticleRenderer(); |
---|
112 | void setVectorField(unsigned int texID, const Vector3& ori, float scaleX, float scaleY, float scaleZ, float max); |
---|
113 | void initialize(); |
---|
114 | void advect(); |
---|
115 | void update_vertex_buffer(); |
---|
116 | void display_vertices(); |
---|
117 | void reset(); |
---|
118 | void render(); |
---|
119 | |
---|
120 | bool active(void) { |
---|
121 | return _activate; |
---|
122 | } |
---|
123 | void active(bool state) { |
---|
124 | _activate = state; |
---|
125 | } |
---|
126 | void setColor(const Vector4& color) { |
---|
127 | _color = color; |
---|
128 | } |
---|
129 | void setAxis(int axis); |
---|
130 | void setPos(float pos); |
---|
131 | void draw_bounding_box(float x0, float y0, float z0, |
---|
132 | float x1, float y1, float z1, |
---|
133 | float r, float g, float b, float line_width); |
---|
134 | void initializeDataArray(); |
---|
135 | void particleSize(float size) { |
---|
136 | _particleSize = size; |
---|
137 | } |
---|
138 | float particleSize(void) { |
---|
139 | return _particleSize; |
---|
140 | } |
---|
141 | }; |
---|
142 | |
---|
143 | #endif |
---|