source: nanovis/tags/1.2.0/ParticleRenderer.h @ 6307

Last change on this file since 6307 was 4904, checked in by ldelgass, 9 years ago

Merge serveral changes from trunk. Does not include threading, world space
changes, etc.

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *  Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 *
5 *  Authors:
6 *    Wei Qiao <qiaow@purdue.edu>
7 */
8#ifndef NV_PARTICLE_RENDERER_H
9#define NV_PARTICLE_RENDERER_H
10
11#include <GL/glew.h>
12
13#include <vrmath/Vector3f.h>
14#include <vrmath/Color4f.h>
15
16#include "FlowTypes.h"
17#include "ParticleAdvectionShader.h"
18#include "RenderVertexArray.h"
19
20namespace nv {
21
22struct Particle {
23    float x;
24    float y;
25    float z;
26    float life;
27
28    Particle()
29    {}
30
31    Particle(float _x, float _y, float _z, float _life) :
32        x(_x),
33        y(_y),
34        z(_z),
35        life(_life)
36    {}
37};
38
39class ParticleRenderer
40{
41public:
42    ParticleRenderer(int w, int h);
43
44    ~ParticleRenderer();
45
46    void setVectorField(unsigned int texID, const vrmath::Vector3f& origin,
47                        float scaleX, float scaleY, float scaleZ, float max);
48
49    void initialize();
50
51    void advect();
52
53    void reset();
54
55    void render();
56
57    bool active() const
58    {
59        return _activate;
60    }
61
62    void active(bool state)
63    {
64        _activate = state;
65    }
66
67    void setColor(const vrmath::Color4f& color)
68    {
69        _color = color;
70    }
71
72    void setSliceAxis(FlowSliceAxis axis);
73
74    FlowSliceAxis getSliceAxis() const
75    {
76        return _sliceAxis;
77    }
78
79    void setSlicePosition(float pos);
80
81    float getSlicePosition() const
82    {
83        return _slicePos;
84    }
85
86    void particleSize(float size)
87    {
88        _particleSize = size;
89    }
90
91    float particleSize() const
92    {
93        return _particleSize;
94    }
95
96   static ParticleAdvectionShader *_advectionShader;
97
98private:
99    void initializeDataArray();
100
101    void updateVertexBuffer();
102
103    /// frame buffer objects: two are defined, flip them as input output every step
104    GLuint _psysFbo[2];
105
106    /// color textures attached to frame buffer objects
107    GLuint _psysTex[2];
108    GLuint _initPosTex;
109    Particle *_data;
110
111    /// Count the frame number of particle system iteration
112    unsigned int _psysFrame;
113
114    /// Reinitiate particles
115    bool _reborn;
116
117    /// flip the source and destination render targets
118    bool _flip;
119
120    unsigned int _maxLife;
121
122    /// Size of the particle: default is 1.2
123    float _particleSize;
124
125    /// vertex array for display particles
126    RenderVertexArray *_vertexArray;
127
128    /// scale of flow data
129    vrmath::Vector3f _scale;
130
131    vrmath::Vector3f _origin;
132
133    bool _activate;
134
135    float _slicePos;
136    FlowSliceAxis _sliceAxis;
137
138    vrmath::Color4f _color;
139
140    //the storage of particles is implemented as a 2D array.
141    int _psysWidth;
142    int _psysHeight;
143};
144
145class ParticleAdvectionShaderInstance
146{
147public :
148    ParticleAdvectionShaderInstance()
149    {}
150
151    ~ParticleAdvectionShaderInstance()
152    {
153        if (ParticleRenderer::_advectionShader) {
154            delete ParticleRenderer::_advectionShader;
155        }
156    }
157};
158
159}
160
161#endif
Note: See TracBrowser for help on using the repository browser.