source: nanovis/branches/1.2/ParticleRenderer.h @ 5497

Last change on this file since 5497 was 5481, checked in by ldelgass, 9 years ago

Merge (manual) ParticleRenderer? changes from trunk

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