Changeset 5481
- Timestamp:
- May 9, 2015, 1:37:21 PM (9 years ago)
- Location:
- nanovis/branches/1.2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
nanovis/branches/1.2/ParticleRenderer.cpp
r5397 r5481 13 13 #include <GL/glew.h> 14 14 15 #include <vrmath/Vector3f.h> 15 16 #include <vrmath/Color4f.h> 16 17 17 18 #include "ParticleRenderer.h" 19 #include "Volume.h" 18 20 #include "define.h" 19 21 #include "Trace.h" 20 22 23 using namespace vrmath; 21 24 using namespace nv; 22 23 ParticleAdvectionShader *ParticleRenderer::_advectionShader = NULL;24 ParticleAdvectionShaderInstance shaderInstance;25 25 26 26 ParticleRenderer::ParticleRenderer(int w, int h) : 27 27 _initPosTex(0), 28 28 _data(NULL), 29 _psysFrame(0 U),29 _psysFrame(0), 30 30 _reborn(true), 31 31 _flip(true), 32 _maxLife(500 U),32 _maxLife(500), 33 33 _particleSize(1.2), 34 34 _vertexArray(NULL), … … 43 43 { 44 44 _data = new Particle[w * h]; 45 memset(_data, 0, sizeof(Particle) * w * h);46 45 47 46 _vertexArray = new RenderVertexArray(_psysWidth * _psysHeight, 3, GL_FLOAT); … … 104 103 #endif 105 104 106 if (_advectionShader == NULL) { 107 _advectionShader = new ParticleAdvectionShader(); 108 } 105 _advectionShader = new ParticleAdvectionShader(); 109 106 } 110 107 … … 121 118 glDeleteFramebuffersEXT(2, _psysFbo); 122 119 120 delete _advectionShader; 123 121 delete _vertexArray; 124 122 delete [] _data; … … 128 126 ParticleRenderer::initializeDataArray() 129 127 { 130 size_t n = _psysWidth * _psysHeight * 4; 131 memset(_data, 0, sizeof(float)* n); 132 133 int index; 134 bool particle; 135 float *p = (float *)_data; 128 TRACE("Enter axis: %d pos: %g", _sliceAxis, _slicePos); 129 130 memset(_data, 0, sizeof(Particle) * _psysWidth * _psysHeight); 131 132 bool hasParticle; 136 133 for (int i = 0; i < _psysWidth; i++) { 137 134 for (int j = 0; j < _psysHeight; j++) { 138 index = i + _psysHeight*j;139 particle = (rand() % 256) > 150;140 if ( particle) {135 Particle *p = &_data[i + _psysHeight*j]; 136 hasParticle = (rand() % 256) > 150; 137 if (hasParticle) { 141 138 //assign any location (x,y,z) in range [0,1] 142 139 switch (_sliceAxis) { 143 140 case AXIS_X: 144 p [4*index]= _slicePos;145 p [4*index+1]= j/float(_psysHeight);146 p [4*index+2]= i/float(_psysWidth);141 p->x = _slicePos; 142 p->y = j/float(_psysHeight); 143 p->z = i/float(_psysWidth); 147 144 break; 148 145 case AXIS_Y: 149 p [4*index]= j/float(_psysHeight);150 p [4*index+1]= _slicePos;151 p [4*index+2]= i/float(_psysWidth);146 p->x = j/float(_psysHeight); 147 p->y = _slicePos; 148 p->z = i/float(_psysWidth); 152 149 break; 153 150 case AXIS_Z: 154 p [4*index]= j/float(_psysHeight);155 p [4*index+1]= i/float(_psysWidth);156 p [4*index+2]= _slicePos;151 p->x = j/float(_psysHeight); 152 p->y = i/float(_psysWidth); 153 p->z = _slicePos; 157 154 break; 158 155 default: 159 p[4*index] = 0; 160 p[4*index+1] = 0; 161 p[4*index+2] = 0; 162 p[4*index+3] = 0; 156 ERROR("Unknown axis"); 163 157 } 164 165 158 //shorter life span, quicker iterations 166 p[4*index+3] = rand() / ((float) RAND_MAX) * 0.5 + 0.5f; 167 } else { 168 p[4*index] = 0; 169 p[4*index+1] = 0; 170 p[4*index+2] = 0; 171 p[4*index+3] = 0; 159 p->life = rand() / ((float) RAND_MAX) * 0.5 + 0.5f; 172 160 } 173 161 } … … 178 166 ParticleRenderer::initialize() 179 167 { 168 TRACE("Enter"); 169 180 170 initializeDataArray(); 181 171 … … 192 182 _flip = true; 193 183 _reborn = false; 184 _psysFrame = 0; 194 185 195 186 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _initPosTex); … … 220 211 _flip = true; 221 212 _reborn = false; 222 _psysFrame = 0 U;213 _psysFrame = 0; 223 214 } 224 215 … … 226 217 ParticleRenderer::advect() 227 218 { 219 TRACE("Enter"); 220 228 221 if (_reborn) 229 222 reset(); … … 281 274 _psysFrame++; 282 275 if (_psysFrame == _maxLife) { 283 _psysFrame = 0U;284 // 276 //_psysFrame = 0; 277 //_reborn = true; 285 278 } 286 279 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig); … … 293 286 { 294 287 _vertexArray->read(_psysWidth, _psysHeight); 295 296 //_vertexArray->loadData(vert); //does not work??297 //assert(glGetError()==0);298 288 } 299 289 … … 301 291 ParticleRenderer::render() 302 292 { 293 if (_psysFrame == 0) { 294 TRACE("Initializing vertex array"); 295 advect(); 296 } 297 303 298 glPushAttrib(GL_ENABLE_BIT); 304 299 glDisable(GL_TEXTURE_2D); … … 340 335 ParticleRenderer::setSliceAxis(FlowSliceAxis axis) 341 336 { 342 _sliceAxis = axis; 343 initializeDataArray(); 337 if (axis != _sliceAxis) { 338 _sliceAxis = axis; 339 initialize(); 340 } 344 341 } 345 342 … … 347 344 ParticleRenderer::setSlicePosition(float pos) 348 345 { 349 _slicePos = pos; 350 initializeDataArray(); 351 } 346 if (pos != _slicePos) { 347 _slicePos = pos; 348 initialize(); 349 } 350 } -
nanovis/branches/1.2/ParticleRenderer.h
r4904 r5481 15 15 16 16 #include "FlowTypes.h" 17 #include "Volume.h" 17 18 #include "ParticleAdvectionShader.h" 18 19 #include "RenderVertexArray.h" … … 94 95 } 95 96 96 static ParticleAdvectionShader *_advectionShader;97 98 97 private: 99 98 void initializeDataArray(); 100 99 101 100 void updateVertexBuffer(); 101 102 ParticleAdvectionShader *_advectionShader; 102 103 103 104 /// frame buffer objects: two are defined, flip them as input output every step … … 143 144 }; 144 145 145 class ParticleAdvectionShaderInstance146 {147 public :148 ParticleAdvectionShaderInstance()149 {}150 151 ~ParticleAdvectionShaderInstance()152 {153 if (ParticleRenderer::_advectionShader) {154 delete ParticleRenderer::_advectionShader;155 }156 }157 };158 159 146 } 160 147
Note: See TracChangeset
for help on using the changeset viewer.