void PURibbonTrailRender::render( Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem )
{
    if (!_isVisible || !_trail)
        return;

    bool needDraw = false;
    const ParticlePool &particlePool = particleSystem->getParticlePool();
    if (!particlePool.empty()){
        updateParticles(particlePool);
        needDraw = true;
    }

    const PUParticleSystem3D::ParticlePoolMap &emitterPool = static_cast<PUParticleSystem3D *>(particleSystem)->getEmittedEmitterParticlePool();
    if (!emitterPool.empty()){
        for (auto iter : emitterPool){
            updateParticles(iter.second);
            needDraw = true;
        }
    }

    const PUParticleSystem3D::ParticlePoolMap &systemPool = static_cast<PUParticleSystem3D *>(particleSystem)->getEmittedSystemParticlePool();
    if (!systemPool.empty()){
        for (auto iter : systemPool){
            updateParticles(iter.second);
            needDraw = true;
        }
    }
    ///lwwhb modify
    if (needDraw)
        _trail->render(renderer, transform, particleSystem->getBlendFunc());
    ///
}
Ejemplo n.º 2
0
void ParticleTrace :: update()
{
	if( !bImageLoaded )
		return;
	
	//---

	pfImage.setPixels( imgSrc.getPixels(), imgRect.width, imgRect.height, OF_IMAGE_COLOR );
	pfTrace.setPixels( imgTrace.getPixels(), imgRect.width, imgRect.height, OF_IMAGE_COLOR );
	
	//---
	
	updateParticles();
	
	//---

	ofPoint pos;
	if( testParticle )
	{
		pos.x = testParticle->posVec.x - imgRectCurrent.x;
		pos.y = testParticle->posVec.y - imgRectCurrent.y;
	}
	
	ofPoint mouse;
	mouse.x = ofClamp( mouseX - imgRectCurrent.x, 0, imgRect.width  - 1 );
	mouse.y = ofClamp( mouseY - imgRectCurrent.y, 0, imgRect.height - 1 );
	
	pfImage.getPixelsAt( pos, sampleRangeX, sampleRangeY, sampleImage0 );		// sample of image pixels around test particle.
	pfTrace.getPixelsAt( pos, sampleRangeX, sampleRangeY, sampleImage1 );		// sample of trace pixels around test particle.
	pfImage.getPixelsAt( mouse, sampleRangeX, sampleRangeY, sampleImage2 );		// sample of image pixels around mouse.
}
Ejemplo n.º 3
0
void ofxMSAPhysics::update(int frameNum) {
#ifdef MSAPHYSICS_USE_RECORDER
	if(frameNum < 0) frameNum = _frameCounter;
	if(_replayMode == OFX_MSA_DATA_LOAD) {
		load(frameNum);
	} else {
		updateParticles();
		updateAllConstraints();
		if(_replayMode == OFX_MSA_DATA_SAVE) _recorder.save(frameNum);
	}
	_frameCounter++;
#else
	updateParticles();
	updateAllConstraints();
#endif
}
//////////////////////////////////////////////////////////////////////////
// update
//virtual
void ScnParticleSystemComponent::update( BcReal Tick )
{
	///*
	// TEST CODE.
	for( BcU32 Idx = 0; Idx < 4; ++Idx )
	{
		ScnParticle* pParticle = NULL;
		if( allocParticle( pParticle ) )
		{
			pParticle->Position_ = BcVec3d( 0.0f, 0.0f, 0.0f );
			pParticle->Velocity_ = BcVec3d( BcRandom::Global.randReal() - 0.5f, BcRandom::Global.randReal() - 0.5f, BcRandom::Global.randReal() - 0.5f ).normal() * 16.0f;
			pParticle->Acceleration_ = -pParticle->Velocity_ * 0.5f;
			pParticle->RotationMultiplier_ = ( BcRandom::Global.randReal() - 0.5f ) * 4.0f;
			pParticle->MinScale_ = BcVec2d( 0.5f, 0.5f );
			pParticle->MaxScale_ = BcVec2d( 4.0f, 4.0f );
			pParticle->MinColour_ = RsColour( 1.0f, 0.0f, 1.0f, 0.1f );
			pParticle->MaxColour_ = RsColour( 0.0f, 1.0f, 1.0f, 0.0f );
			pParticle->UVBounds_ = BcVec4d( 0.0f, 0.0f, 1.0f, 1.0f );
			pParticle->CurrentTime_ = 0.0f;
			pParticle->MaxTime_ = 4.0f;
			pParticle->Alive_ = BcTrue;
		}
	}
	//*/
	

	// Allocate particles.
	updateParticles( Tick );
}
Ejemplo n.º 5
0
	//--------------------------------------------------------------
void BlackBoxApp::update()  {
	kinect.update();
	colorImage.setFromPixels(kinect.getPixels(), kinect.width, kinect.height);
	colorImage.flagImageChanged();
	
	blackAndWhite.setFromPixels(kinect.getPixels(), kinect.width,kinect.height);
	blackAndWhite.flagImageChanged();
	
	switch (drawMethod) {
		case 5:
		case 6:
		case 7:
		case 8:
		case 9:
			contourFinderUpdate();
			triangle.clear();
			for (int iT = 0; iT < contourFinder.nBlobs; iT++){
				triangle.triangulate(contourFinder.blobs[iT], max( 3.0f, (float)contourFinder.blobs[iT].nPts/triangleComplexity));
			}
			break;
			
		case 3:
			updateParticles();
			break;
	}
}
Ejemplo n.º 6
0
void main(void) {
  int gd = CUSTOM, gm = CUSTOM_MODE(1024,768);
  int page = 0;
  g_mousestate curState;
  g_mousestate oldState;
  int scrolling = 0;
  
  initgraph(&gd, &gm, "");
  
  initParticles(particles);
  
  while(!anykeypressed()) {
    getmousestate(&curState);
    if((curState.buttons & MOUSE_LEFTBUTTON) == 0) {
      scrolling = 0;
    } else {
      if(scrolling == 0) {
        scrolling = 1;
        getmousestate(&oldState);
      } else {
        orgX -= -curState.x + oldState.x;
        orgY += -curState.y + oldState.y;
        oldState = curState;
      }
    }
    updateParticles(particles, particles2);
	setactivepage(1 - page);
    clearviewport();
	drawParticles(particles);
	setvisualpage(1 - page);
    page = 1 - page;
	delay(4);
  }
  closegraph();
}
Ejemplo n.º 7
0
void wavesScene::update(){
    updateModeChange();
    updateParticles();
    updateInput();
    gradientWaves.update();
    stencilWaves.update();
    updateFade();
}
Ejemplo n.º 8
0
void ParticleSystem::update(UpdateInfo info)
{
	age += info.updateInterval;	
	
	updateParticles(info);
	cleanup();
	spawnCycle(info);
}
Ejemplo n.º 9
0
//--------------------------------------------------------------
void testApp::update(){
	
	
	panel.update();
	nIterations				= panel.getValueI("N_ITERATIONS"); 
	nNearestNeighborsK		= panel.getValueI("N_NEIGHBORS");
	nMaxPointsToVisit		= nNearestNeighborsK + 6;
	totalCycleDurationInIterations = nIterations * 6;
	
	if (!bPause && (iterationCount < nIterations)){
		
		int nToAddPerFrame  = panel.getValueI("ADD_PER_FRAME");
		//addPositionsProbabilisticallyBasedOnSourceImage (nToAddPerFrame);
		addPointsOnTooLongConnections();
		
		applyImageForces();
		
		IppiSize allBufRoi = {nParticles, 1};
		
		// add random forces to velocities
		unsigned int pSeed;
		float fmax = panel.getValueF("FORCE_NOISE");
		ippiAddRandUniform_Direct_32f_C1IR(velocityx, particleStep32f, allBufRoi, -fmax,fmax, &pSeed);
		ippiAddRandUniform_Direct_32f_C1IR(velocityy, particleStep32f, allBufRoi, -fmax,fmax, &pSeed);
		
		// multiply velocities by damping factor
		Ipp32f damping = panel.getValueF("DAMPING");
		Ipp32f progressiveDamping = ofMap(iterationCount, 0,nIterations, 1.0, 0.0, true);
		
		ippiMulC_32f_C1IR(progressiveDamping, velocityx, particleStep32f, allBufRoi);
		ippiMulC_32f_C1IR(progressiveDamping, velocityy, particleStep32f, allBufRoi);
		
		// add velocities to positions 
		ippiAdd_32f_C1IR(velocityx, particleStep32f, positionx, particleStep32f, allBufRoi);
		ippiAdd_32f_C1IR(velocityy, particleStep32f, positiony, particleStep32f, allBufRoi);
		

		// clamp positions to acceptable ranges
		ippiThreshold_LTValGTVal_32f_C1IR (positionx, particleStep32f, allBufRoi, bounds.x, bounds.x, bounds.x+bounds.width,  bounds.x+bounds.width);
		ippiThreshold_LTValGTVal_32f_C1IR (positiony, particleStep32f, allBufRoi, bounds.y, bounds.y, bounds.y+bounds.height, bounds.y+bounds.height);
	
		
		//----------------------------------
		updateNearestNeighbors();
		updateParticles();
		
	}
	iterationCount++;
	
	if (iterationCount == nIterations){
		saveFBO(); // DO IT!
	}
	if (bCycleAutomatically && (iterationCount > totalCycleDurationInIterations)){
		initialize(false); 
	}

	
}
void ParticleExplosionNode2::exeObjBehaviour(){

    emmiterLifetime+= 0.1;
    if(emmiterLifetime>=emmiterMaxLifetime){

        setDeadmark(true);
    }
    updateParticles( 0.1);
}
//-----------------------------------------------------------------------------------------
//
void ParticleSystemInstancedGeometryGPU::update( float _time, float _timeStep )
{
	particleMaterial.setAmbientColor( materialAmbient.get() );
	particleMaterial.setSpecularColor( materialSpecular.get() );
	particleMaterial.setEmissiveColor( materialEmissive.get() );
	particleMaterial.setShininess( materialShininess );
	
	updateParticles( _time, _timeStep );
}
Ejemplo n.º 12
0
void ParticleSystem::renderWithDT(float dt)
{
    time += (dt * 1000.0f);

    updateParticles(dt);
    renderParticles();

    currVB = currTFB;
    currTFB = (currTFB + 1) & 0x1;
}
Ejemplo n.º 13
0
void GvParticle::update(float dt) 
{

	updateParticles(dt);
 	createParticles(dt*rate);
	if (getNumParticles() > maxCount) 
	{
		deleteParticles(getNumParticles() - maxCount);
	}

}
void OpenCVMinimalParticle::update()
{
   
    OpenCVEngine::getInstance().update();

    updateParticles();
    
    
    backgroundFBO.begin();
        ofClear(0, 0, 0, 0);
        drawBackground();
    backgroundFBO.end();
    
    //Draw at full res
    OpenCVEngine::getInstance().contentLayerFBO.begin();
    ofClear(0, 0, 0, 0);
    
    ofPushStyle();
    
    for (int i=0; i<particleLayer->particles.size(); i++)
    {
        ofPushMatrix();
        ofTranslate(particleLayer->particles[i]->x,
                    particleLayer->particles[i]->y);
        ofEnableBlendMode(OF_BLENDMODE_ALPHA);
        particleTexture.draw(0, -100, 120, 1000);
        ofPopMatrix();
        ofDisableBlendMode();
        
        ofPopMatrix();
    }
    
    ofPopStyle();
    OpenCVEngine::getInstance().contentLayerFBO.end();
    
    contentFBO.begin();
    ofSetColor(0, 25);
    ofRect(0, 0, contentFBO.getWidth(), contentFBO.getHeight());
    ofSetColor(255);
    OpenCVEngine::getInstance().contentLayerFBO.draw(0,
                                                     0,
                                                     480,
                                                     120);
    contentFBO.end();
    
    fbo->begin();
    backgroundFBO.draw(0, 0);
    contentFBO.draw(0, 0);
    fbo->end();
    
    

}
Ejemplo n.º 15
0
void ParticleSystem::update(float milliseconds, Camera &camera)
{
	updateEmitters(milliseconds);
	updateParticles(milliseconds);

	const mat3 &cameraOrientation = camera.getOrientation();
	mat4 modl(camera.getPosition(),
	          cameraOrientation.getAxisX(),
	          cameraOrientation.getAxisY(),
	          cameraOrientation.getAxisZ());
	updateParticleBatches(modl);
}
Ejemplo n.º 16
0
Archivo: main.cpp Proyecto: puffski/SPH
void idle()
{
	glm::dvec3 colorFieldGradient;
	double colorFieldLaplacian;
	// Print OpenGL errors, if there are any (for debugging)
	if (GLenum err = glGetError())
	{
		std::cerr << "OpenGL ERROR: " << gluErrorString(err) << std::endl;
	}
	
	static double previous_time;
	static bool initialized = false;

	if (!initialized)
	{
		previous_time = double(clock()) / CLOCKS_PER_SEC;
		initialized = true;
	}

	double current_time = double(clock()) / CLOCKS_PER_SEC;
	double elapsed_time = current_time - previous_time;
	double dt = timestep;// elapsed_time;

	//reset force and density
	if (running)
		updateParticles(particles, partCount, h, eta, dt, sphereRadius, threshold, sigma);

	//check each particle for collision
	for (int i = 0; i < partCount; i++)
	{
		//if colliding
		if (isColliding(particles[i].x, sphereRadius)>0)
		{
			glm::dvec3 cp;
			double depth;
			glm::dvec3 normal;
			//get collision data
			collisionData(cp, depth, normal, particles[i].x, sphereRadius);

			//collision Response
			double slip = 0.0;
			particles[i].x = cp;
			particles[i].v = particles[i].v - (1.0 + slip*depth / (dt* glm::length(particles[i].v)))* glm::dot(particles[i].v, normal)*normal;		
		}
	}
	previous_time = current_time;

	if (running)
		glutSetWindowTitle("SPH running");
	else
		glutSetWindowTitle("SPH paused");
	glutPostRedisplay();
}
Ejemplo n.º 17
0
void idle(void)
{
    arg++;
    
    if (arg%argMod == frames) {
        updateParticles();
        
        glutPostRedisplay();
        
        arg = 1;
    }
}
Ejemplo n.º 18
0
//////////////////////////////////////////////////////////////////////////
// update
//virtual
void ScnParticleSystemComponent::postUpdate( BcF32 Tick )
{
	Super::postUpdate( Tick );

	UpdateFence_.increment();

	SysKernel::pImpl()->pushFunctionJob( 
		SysKernel::DEFAULT_JOB_QUEUE_ID, 
		[ this, Tick ]()
		{
			updateParticles( Tick );
		} );
}
Ejemplo n.º 19
0
//////////////////////////////////////////////////////////////////////////
// update
//virtual
void ScnParticleSystemComponent::postUpdate( BcF32 Tick )
{
	Super::postUpdate( Tick );

	UpdateFence_.increment();

#if 1
	typedef BcDelegate< void(*)( BcF32 ) > UpdateNodeDelegate;
	UpdateNodeDelegate Delegate = UpdateNodeDelegate::bind< ScnParticleSystemComponent, &ScnParticleSystemComponent::updateParticles >( this );
	SysKernel::pImpl()->enqueueDelegateJob( SysKernel::USER_WORKER_MASK, Delegate, Tick );
#else
	updateParticles( Tick );
#endif
}
Ejemplo n.º 20
0
PhysicsEngine::PhysicsEngine()
{
    // Create worker thread for particle engine
    m_particleEngine = new ParticleEngine;
    m_particleThread = new QThread;
    m_particleEngine->moveToThread(m_particleThread);
    connect(m_particleThread, SIGNAL(started()), m_particleEngine, SLOT(updateParticles()));
    connect(m_particleThread, SIGNAL(finished()), m_particleEngine, SLOT(deleteLater()));

    // Create worker thread for physics engine
    m_physicsThread = new QThread;
    moveToThread(m_physicsThread);
    connect(m_physicsThread, SIGNAL(started()), this, SLOT(process()));

    // Create sound management
    m_soundIO = new SoundIO;
}
Ejemplo n.º 21
0
void display (void) {
  int i;

  // update the particles
  updateParticles();

  // clear the buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // forces all translations to be local?
  glPushMatrix();

  // render the particles
  for (i=0; i<MAXPARTICLES; i++) {
    PARTICLE part = particles[i]; // convenience
   
    // skip "dead" or uncreated particles
    if (part.size == 0) {continue;}

    // render particle (reset coordinate system to 0,0,0 each time)

    if (SLOW) {
      // method 1 for rendering particles (slow)
      glPushMatrix();
      glTranslatef(part.x,part.y,part.z);
      glColor3f(part.r,part.g,part.b);
      glutSolidSphere(part.size,10,10);
      glPopMatrix();
    } else {
      glBegin(GL_POINTS);
      glColor3f(part.r,part.g,part.b);
      glVertex2f(part.x,part.y);
      // failed experiment w/ GL_POLYGON below (too slow)
      // glVertex2f(part.x+part.size,part.y);
      // glVertex2f(part.x+part.size,part.y+part.size);
      // glVertex2f(part.x,part.y+part.size);
      glEnd();
    }

  }

  glPopMatrix();
  glutSwapBuffers();
}
Ejemplo n.º 22
0
//--------------------------------------------------------------
void testApp::update() {
	kinect.update();
    int particleIndex;
    updateParticles();
	// there is a new frame and we are connected
	if(kinect.isFrameNew()) {
        ofColor particleColr = getParticleColor();
        particleIndex = 0;
        background.update(kinect);
        for(int y = 0; y < DEPTH_MAP_HEIGHT; y++) {
            for(int x = 0; x < DEPTH_MAP_WIDTH; x++) {
                if (particleIndex >= PARTICLE_COUNT) continue;
                int i = y * DEPTH_MAP_WIDTH + x;
                ofVec3f p = kinect.getWorldCoordinateAt(x, y);
                // camera gives us things upside down for some reason.
                p.y *= -1;
                if(background.isBackground(kinect, x, y))continue;
                if(ofRandom(0, RANDOM_THRESH) <= 1) {
                    makeParticleAt(p, particleColr);
                }
            }
        }
	}
    ofVec3f cameraPos = easyCam.getPosition();
    int speed = 20;
    switch (cameraDirection) {
        case OF_KEY_LEFT:
            cameraPos.x += speed;
            break;
        case OF_KEY_RIGHT:
            cameraPos.x -= speed;
            break;
        case OF_KEY_UP:
            cameraPos.y+=speed;
        case OF_KEY_DOWN:
            cameraPos.y-=speed;
        default:
            break;
    }
    easyCam.setPosition(cameraPos);

}
Ejemplo n.º 23
0
void updateGame(Game* game)
{
	int time = SDL_GetTicks();
	game->delta = (float)(time - game->lastTime) / 1000.0f;
	game->lastTime = time;
	
	for(int i = 0; i < MAX_KEYS; ++i)
		game->keysPressed[i] = game->keysReleased[i] = false;
	
	SDL_Event event;
	while (SDL_PollEvent(&event))
	{
		switch(event.type)
		{
			case SDL_QUIT:
				game->running = false;
				break;
			case SDL_KEYUP:
				game->keys[event.key.keysym.sym & 255] = false;
				game->keysPressed[event.key.keysym.sym & 255] = true;
				break;
			case SDL_KEYDOWN:
				game->keys[event.key.keysym.sym & 255] = true;
				game->keysReleased[event.key.keysym.sym & 255] = true;
				break;
			case SDL_MOUSEBUTTONDOWN:
				break;
			case SDL_MOUSEBUTTONUP:
				break;
		}
	}
	
	updateBackground(game);
	updateBehaviorPools(game, &game->behaviorPools);
			
	for(int i = 0; i < MAX_ENTITIES_PER_GAME; ++i)
		if(game->entities[i].alive)
			updateEntity(game, &game->entities[i]);
			
	updateParticles(game);
}
void ParticleInstance::update(float p_DeltaTime) 
{
	if (m_SysMaxLife > 0)
	{
		m_SysLife += p_DeltaTime;
		
		if (m_SysLife >= m_SysMaxLife)
		{
			setSeppuku(true);
		}	
	}
	
	killOldParticles();

	if (m_SysLife <= m_SysMaxLife || m_SysMaxLife == -1)
	{
		emitNewParticles(p_DeltaTime);
	}
	
	updateParticles(p_DeltaTime);
}
Bool
particlesPrePrepPaintScreen (CompWindow * w, int msSinceLastPaint)
{
    ANIMADDON_WINDOW (w);

    Bool particleAnimInProgress = FALSE;

    if (aw->eng.numPs)
    {
	int i;
	for (i = 0; i < aw->eng.numPs; i++)
	{
	    if (aw->eng.ps[i].active)
	    {
		updateParticles (&aw->eng.ps[i], msSinceLastPaint);
		particleAnimInProgress = TRUE;
	    }
	}
    }

    return particleAnimInProgress;
}
Ejemplo n.º 26
0
//--------------------------------------------------------------
void GrafPlayerApp::update(){

	dt  = ofGetElapsedTimef()-lastTime;
	lastTime  = ofGetElapsedTimef();
	
	
	bool bTrans = false;
	
	if( mode == PLAY_MODE_LOAD )
	{
		loadTags();
		if(bUseAudio)audio.update();
	}
	else if( mode == PLAY_MODE_PLAY && tags.size() > 0 )
	{
		
		//---- set drawing data for render
		if( drawer.bSetupDrawer )
			drawer.setup( &tags[currentTagID], tags[currentTagID].distMax );

		//---- update tag playing state
		if( !myTagPlayer.bDonePlaying )					
		{
			myTagPlayer.update(&tags[currentTagID]);	// normal play, update tag
		
		}else if( !myTagPlayer.bPaused && myTagPlayer.bDonePlaying && waitTimer > 0)			   
		{
			waitTimer -= dt;	// pause time after drawn, before fades out
		}
		else if ( !myTagPlayer.bPaused && myTagPlayer.bDonePlaying && (drawer.alpha > 0 || particleDrawer.alpha > 0))			  		
		{
			updateTransition(0);
			bTrans = true;
		}
		else if (  !myTagPlayer.bPaused && myTagPlayer.bDonePlaying )							
		{
			resetPlayer(1);	// setup for next tag
		}
	
		
		//---------- AUDIO applied
		if( bUseAudio) updateAudio();
		
		
		//--------- ARCHITECTURE
		if( bUseArchitecture ) updateArchitecture();
		
		
		//--------- PARTICLES
		updateParticles();
			
		
		//--------- TAG ROTATION + POSITION
		if(bRotating && !myTagPlayer.bPaused ) rotationY += panel.getValueF("ROT_SPEED")*dt;
		
		// update pos / vel
		tags[currentTagID].position.x += tagPosVel.x;
		tags[currentTagID].position.y += tagPosVel.y;
		
		tagPosVel.x -= .1*tagPosVel.x;
		tagPosVel.y -= .1*tagPosVel.y;
		
		if(!bTrans)
		{
		tags[currentTagID].rotation_o = tags[currentTagID].rotation;
		tags[currentTagID].position_o = tags[currentTagID].position;
		}

	}
	
	
	
	// controls
	if( bShowPanel ) updateControlPanel();
	
	
}
Ejemplo n.º 27
0
void ParticleField::Update() {
  updateForces();
  updateParticles();
  killParticles();
  spawnParticles();
}
Ejemplo n.º 28
0
int main(int argc, char ** argv)
{

	flowvr::Parallel::init(true);

	computeNodesCount = flowvr::Parallel::getNbProc();
	computeNodeRank = flowvr::Parallel::getRank();

	// Init FlowVR environment :
 	if (SetupFlowVR() != 0)
    		return -1;
	
	//Initialisation de la simulation
	initGrid();
	initParticles(1000 / computeNodesCount);

	int timePreviousCompute;	//Time in microsecond
	int timeCurrentCompute;
	int deltaT;

	timeval initialTime;
	gettimeofday(&initialTime, NULL);
	timePreviousCompute = (int)(initialTime.tv_sec*1000000 + initialTime.tv_usec);

	// Main loop :
  	int bLoop = 1;
  	while (bLoop)
  	{
    	// Compute a new set of prime numbers,
    	// mesuring the time elapsed during the computation :

	    timeval time;

	    gettimeofday(&time, NULL);
	    timeCurrentCompute = (int)(time.tv_sec*1000000 + time.tv_usec);

	    deltaT = timeCurrentCompute - timePreviousCompute;
	    if(deltaT < frequency)
	      usleep(frequency - deltaT);
	    timePreviousCompute = timeCurrentCompute;
	    
	    updateParticles(deltaT);


	    // Send these numbers to visualization node.
	    // Note that within the network, some modules must send messages before waiting in order to avoid deadlocks.
	    // Here, compute nodes send a set of prime numbers before the visualization node starts its rendering task.
	    SendPositions(deltaT);	   


	    // The module wait for notification from visualization node to know if it is ready to receive a new set of prime numbers.
	    // Note that there is no need to get the message as only the signal is useful in this case.
	    // Remember that the wait function blocks until every connected port receive a message, a behavior often taken in
	    // consideration for synchronization purpose.
	    bLoop = pFlowVRModule->wait();
	}

  // Clean up :
  CleanFlowVR();

  return 0;
}
Ejemplo n.º 29
0
void ParticleSystem::update(float timeElapsed) {
   setTimeElapsed(timeElapsed);
   keyboardActions();
   updateParticles();
   addParticlesToSystem();
}
Ejemplo n.º 30
0
/**
 * @brief draw particles
 */
void ParticleSystem::drawPoints() {
//    glEnable(GL_PROGRAM_POINT_SZE);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      updateParticles();

      // --------------------------------------------------
      //  transform feedback
      // --------------------------------------------------
      glUseProgram(program_transform);
      glEnable(GL_RASTERIZER_DISCARD);
            setUniforms();

              glBindBuffer(GL_ARRAY_BUFFER, vbo_position);
              glEnableVertexAttribArray(0);
              glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0,0);
              glBindBuffer(GL_ARRAY_BUFFER, vbo_speed);
              glEnableVertexAttribArray(1);
              glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,0);
              glBindBuffer(GL_ARRAY_BUFFER, vbo_ID);
              glEnableVertexAttribArray(2);
              glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 0,0);

              glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,0, vbo_draw);
              glBeginTransformFeedback(GL_POINTS);
                  glDrawArrays(GL_POINTS, 0, num_points);
              glEndTransformFeedback();

            glBindBuffer(GL_ARRAY_BUFFER, 0);


      glDisable(GL_RASTERIZER_DISCARD);
      glUseProgram(0);

      // --------------------------------------------------
      //  use the results from transformation to draw the particles
      // --------------------------------------------------
      srand (time(NULL));
      glm::vec3 r = glm::vec3(static_cast <float> (rand()) / static_cast <float> (RAND_MAX),
                                 static_cast <float> (rand()) / static_cast <float> (RAND_MAX),
                                 static_cast <float> (rand()) / static_cast <float> (RAND_MAX));
      shaderCtrlPoints.Bind();
      glUniform1f(shaderCtrlPoints.GetUniformLocation("pointSize"), (float)pointSize);
      glUniform3f(shaderCtrlPoints.GetUniformLocation("rand"), r.x, r.y, r.z);
      glUniformMatrix4fv(shaderCtrlPoints.GetUniformLocation("projMX"), 1, GL_FALSE,
                         glm::value_ptr(projMX));
      glUniformMatrix4fv(shaderCtrlPoints.GetUniformLocation("viewMX"), 1, GL_FALSE,
                         glm::value_ptr(viewMX));
      glUniform3f(shaderCtrlPoints.GetUniformLocation("translate"), 0.5f, 0.5f, 0.5f);
      currentTime+=deltaT;
      if(currentTime > 1000000.0f)
          currentTime = 0.0f;
      glUniform1f(shaderCtrlPoints.GetUniformLocation("time"), currentTime);

      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, randomTex);
      glUniform1i(shaderCtrlPoints.GetUniformLocation("randomtex"), 0);

          glBindBuffer(GL_ARRAY_BUFFER, vbo_draw);
          glEnableVertexAttribArray(0);
          glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0,0);

          glBindBuffer(GL_ARRAY_BUFFER, vbo_speed);
          glEnableVertexAttribArray(1);
          glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,0);

          glDrawArraysInstanced(GL_POINTS, 0, num_points, num_instances);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
  shaderCtrlPoints.Release();

  // --------------------------------------------------
  //  swap buffers for particles position (ping-pong update model)
  // --------------------------------------------------
  std::swap(vbo_position, vbo_draw);
}