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 _PARTICLE_SYSTEM_H_
|
---|
18 | #define _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 "NvParticleAdvectionShader.h"
|
---|
32 |
|
---|
33 | typedef struct Particle {
|
---|
34 | float x;
|
---|
35 | float y;
|
---|
36 | float z;
|
---|
37 | float aux;
|
---|
38 |
|
---|
39 | Particle(){};
|
---|
40 | Particle(float _x, float _y, float _z, float _life) :
|
---|
41 | x(_x), y(_y), z(_z), aux(_life){}
|
---|
42 | };
|
---|
43 |
|
---|
44 |
|
---|
45 | class NvParticleRenderer : public Renderable {
|
---|
46 | /**
|
---|
47 | * @brief frame buffer objects: two are defined, flip them as input output every step
|
---|
48 | */
|
---|
49 | NVISid psys_fbo[2];
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * @brief color textures attached to frame buffer objects
|
---|
53 | */
|
---|
54 | NVISid psys_tex[2];
|
---|
55 |
|
---|
56 | Particle* data;
|
---|
57 |
|
---|
58 | /**
|
---|
59 | *@brief Count the frame number of particle system iteration
|
---|
60 | */
|
---|
61 | int psys_frame;
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * @brief Reinitiate particles
|
---|
65 | */
|
---|
66 | bool reborn;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * @brief flip the source and destination render targets
|
---|
70 | */
|
---|
71 | bool flip;
|
---|
72 |
|
---|
73 | float max_life;
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * @brief vertex array for display particles
|
---|
77 | */
|
---|
78 | RenderVertexArray* m_vertex_array;
|
---|
79 |
|
---|
80 | //Nvidia CG shaders and their parameters
|
---|
81 | /*
|
---|
82 | CGcontext m_g_context;
|
---|
83 | CGprogram m_pos_fprog;
|
---|
84 | CGparameter m_vel_tex_param, m_pos_tex_param, m_scale_param;
|
---|
85 | CGparameter m_pos_timestep_param, m_pos_spherePos_param;
|
---|
86 | */
|
---|
87 | NvParticleAdvectionShader* _advectionShader;
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * @brief scale of flow data
|
---|
91 | */
|
---|
92 | Vector3 scale;
|
---|
93 |
|
---|
94 | public:
|
---|
95 | int psys_width; //the storage of particles is implemented as a 2D array.
|
---|
96 | int psys_height;
|
---|
97 |
|
---|
98 | NvParticleRenderer(int w, int h, CGcontext context, NVISid vector_field,
|
---|
99 | float scalex, float scaley, float scalez);
|
---|
100 | ~NvParticleRenderer();
|
---|
101 | void initialize(Particle* data);
|
---|
102 | void advect();
|
---|
103 | void update_vertex_buffer();
|
---|
104 | void display_vertices();
|
---|
105 | void reset();
|
---|
106 | void render();
|
---|
107 | };
|
---|
108 |
|
---|
109 |
|
---|
110 | #endif
|
---|