source: trunk/packages/vizservers/nanovis/NvParticleRenderer.h @ 2870

Last change on this file since 2870 was 2870, checked in by ldelgass, 13 years ago

remove global.h header. Move global Cg context handle into NvShader? as a
static member. Move LoadCgSourceProgram? to NvShader?.cpp, but make shader
classes use the methods NvShader::loadVertex/FragmentProgram instead.
There are still some users of LoadCgSourceProgram? left that need the context
handle.

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