source: trunk/packages/vizservers/nanovis/ParticleRenderer.h @ 3628

Last change on this file since 3628 was 3627, checked in by ldelgass, 11 years ago

Use vrmath::Color4f for color where appropriate

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