void particleTriangleRender::update(){
    if(opacity == 0) {
        return;
    }
    
    if(isDirty) {
        updateVbo();
    }
    
    // reset visible count
    visibleCount = 0;
    
    // update data
    for(int j=0; j<particleData.size(); j++) {
        const ParticleData* pd = particleData[j];
        
        int firstId = 0;
        int lastId = pd->countAlive;
        for(int i=firstId; i<lastId; i++){
            const Particle& p = pd->particles[i];
            
            positions[visibleCount].set(p.pos);
            sizes[visibleCount]     = p.size;
            lifes[visibleCount]     = p.elapsedLife / p.maxLife;
            rotations[visibleCount] = p.angle;
            
            visibleCount++;
        }
    }
}
Esempio n. 2
0
bool PointCloudVBO::loadData(text file, text sep, int xi, int yi, int zi,
                             float colorScale,
                             float ri, float gi, float bi, float ai,
                             bool async)
// ----------------------------------------------------------------------------
//   Load points from a file
// ----------------------------------------------------------------------------
{
    bool changed = PointCloud::loadData(file, sep, xi, yi, zi, colorScale,
                                        ri, gi, bi, ai, async);
    if (useVbo() && changed)
    {
        updateVbo();

        noOptimize = false;
        this->sep = sep;
        this->xi = xi;
        this->yi = yi;
        this->zi = zi;
        this->colorScale = colorScale;
        this->ri = ri;
        this->gi = gi;
        this->bi = bi;
        this->ai = ai;
    }
    return changed;
}
Esempio n. 3
0
void PointCloudVBO::removePoints(unsigned n)
// ----------------------------------------------------------------------------
//   Drop n points from the cloud
// ----------------------------------------------------------------------------
{
    XL_ASSERT(!optimized);

    PointCloud::removePoints(n);
    if (useVbo())
        updateVbo();
    noOptimize = true;
}
Esempio n. 4
0
void PointCloudVBO::checkGLContext()
// ----------------------------------------------------------------------------
//   Do what's needed if GL context has changed
// ----------------------------------------------------------------------------
{
    if (QGLContext::currentContext() != context)
    {
        IFTRACE(pointcloud)
            debug() << "GL context changed\n";

        // Re-create VBO(s)
        genPointBuffer();
        if (colored())
            genColorBuffer();

        if (optimized)
        {
            IFTRACE(pointcloud)
                debug() << "GL context changed on optimized cloud\n";

            XL_ASSERT(file != "" || nbRandom != 0);

            if (file != "")
            {
                IFTRACE(pointcloud)
                    debug() << "Reloading file\n";
                text f = file;
                clear();
                loadData(f, sep, xi, yi, zi, colorScale, ri, gi, bi, ai);
            }
            else if (nbRandom != 0)
            {
                IFTRACE(pointcloud)
                    debug() << "Re-creating random points\n";
                unsigned n = nbRandom;
                clear();
                randomPoints(n, coloredRandom);
            }

            optimized = false;
            XL_ASSERT(!dirty);
        }
        else
            updateVbo();

        context = QGLContext::currentContext();
    }
}
Esempio n. 5
0
bool PointCloudVBO::optimize()
// ----------------------------------------------------------------------------
//   Optimize point cloud data
// ----------------------------------------------------------------------------
{
    if (optimized || dontOptimize())
        return optimized;

    if (useVbo())
    {
        if (dirty)
            updateVbo();
        nbPoints = points.size();
        points.clear();
        optimized = true;
        IFTRACE(pointcloud)
            debug() << "Cloud optimized\n";
    }

    return true;
}
Esempio n. 6
0
void PointCloudVBO::clear()
// ----------------------------------------------------------------------------
//   Remove all points
// ----------------------------------------------------------------------------
{
    if (size() == 0)
        return;

    if (optimized)
    {
        nbPoints = 0;
        optimized = false;
    }
    else
    {
        PointCloud::clear();
        if (useVbo())
            updateVbo();
    }
    file = "";
    nbRandom = 0;
}
Esempio n. 7
0
void PointCloudVBO::draw()
// ----------------------------------------------------------------------------
//   Draw cloud
// ----------------------------------------------------------------------------
{
    if (!useVbo())
        return PointCloud::draw();

    PointCloudFactory * fact = PointCloudFactory::instance();

    checkGLContext();

    if (size() == 0)
        return;

    if (dirty)
        updateVbo();

    if (colored())
    {
        GL.EnableClientState(GL_COLOR_ARRAY);
        GL.BindBuffer(GL_ARRAY_BUFFER, colorVbo);
        GL.ColorPointer(4, GL_FLOAT, sizeof(Color), 0);
    }
    else
    {
        // Activate current document color
        fact->tao->SetFillColor();
    }

    if (pointSize > 0)
    {
        glPushAttrib(GL_POINT_BIT);
        GL.PointSize(pointSize * fact->tao->DevicePixelRatio());
    }
    if (pointSprites)
    {
        GL.Enable(GL_POINT_SPRITE);
        GL.TexEnv(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
        GL.PointParameter(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
        fact->tao->SetTextures();
    }
    if (pointProgrammableSize)
        GL.Enable(GL_VERTEX_PROGRAM_POINT_SIZE);

    GL.EnableClientState(GL_VERTEX_ARRAY);
    GL.BindBuffer(GL_ARRAY_BUFFER, vbo);
    GL.VertexPointer(3, GL_FLOAT, sizeof(Point), 0);
    GL.DrawArrays(GL_POINTS, 0, size());
    GL.BindBuffer(GL_ARRAY_BUFFER, 0);
    GL.DisableClientState(GL_VERTEX_ARRAY);
    if (colored())
        GL.DisableClientState(GL_COLOR_ARRAY);

    if (pointProgrammableSize)
        GL.Disable(GL_VERTEX_PROGRAM_POINT_SIZE);
    if (pointSprites)
    {
        GL.Disable(GL_POINT_SPRITE);
        GL.TexEnv(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);
        GL.PointParameter(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);
    }
    if (pointSize > 0)
        glPopAttrib();

}
void CloudsVisualSystemFireworks::selfUpdate()
{
	float t = ofGetElapsedTimef();
	
	//camera
	if(bAnimateCamera)
	{
		ofVec3f eul = getCameraRef().getOrientationEuler();
		float xDamp = ofMap( abs(eul.x), 70, 90, 1, 0, true );
		
		float noiseTimeScl = .1;
		float noiseOffsetScl = 800;
		
		float panScl = -5;
		
		float noiseValX = ofSignedNoise( ofGetElapsedTimef() * noiseTimeScl + 1. ) * noiseOffsetScl;
		float noiseValY = ofSignedNoise( ofGetElapsedTimef() * noiseTimeScl ) * noiseOffsetScl;
		
		//pan and tilt with mouse
        //MA: changed ofGetWidth() to getCanvasWidth() and ofGetHeight() to getCanvasHeight()
		float pan = ofMap(GetCloudsInputX() + noiseValX, 0, getCanvasWidth(), cameraMotionScl, -cameraMotionScl);
		float tilt = ofMap(GetCloudsInputY() + noiseValY, 0, getCanvasHeight(), cameraMotionScl, -cameraMotionScl) * xDamp;

		if(abs(eul.x) < 90) getCameraRef().tilt( tilt );
		getCameraRef().pan( pan );
		
		//roll it when we move left to right
		float roll = abs(pan) * pan * panScl;
		getCameraRef().roll( -roll );
		getCameraRef().move(0, abs(roll), 0);
		
		//move it
		ofVec3f vel = getCameraRef().getLookAtDir();
		getCameraRef().move( vel * camSpeed );
		
		//use this to determine where to explode fireworks
		float targetDistance = 300;
		camTarget = vel * targetDistance + getCameraRef().getPosition();
	}
	
	
	//emitters
	ofVec3f p0, nScl;
	float nx, ny, nz;
	ofVec3f relativeDown = getCameraRef().getUpDir() * gravity.y;
	for (int i=emitters.size()-1; i>=0; i--)
	{
		emitters[i].update( t );
		
		if( emitters[i].bStarted )
		{
			emitters[i].pos += relativeDown * emitters[i].span * CubicIn(emitters[i].age);
			
			p0 = emitters[i].pos;
			nScl = p0 * .01;
			nx = ofSignedNoise(nScl.x + emitters[i].age, nScl.y, nScl.z);
			ny = ofSignedNoise(nScl.x, nScl.y + emitters[i].age, nScl.z);
			nz = ofSignedNoise(nScl.x, nScl.y, nScl.z + emitters[i].age);
			p0 += ofVec3f( nx, ny, nz ) * 10. * emitters[i].age;
			
			trailPoint( p0, emitters[i].vel, emissonRate, emitters[i].textureIndex, emitters[i].colorIndex );
		}
		
		if(emitters[i].bEnded)
		{
			emitters.erase( emitters.begin() + i );
		}
	}
	
	//particles
	bool updateIndices = false;
	
	indexCount = 0;
	for(int i=0; i<FIREWORKS_NUM_PARTICLES; i++){
		//if the age + lifespan is less then the current time we want to draw it. otherwise? it is dead to us.
		if(lifeData[i].r + lifeData[i].g / speed > t){
			indices[indexCount] = i;
			indexCount++;
			updateIndices = true;
		}
	}
	
	if(updateIndices){
		vbo.updateIndexData( &indices[0], indexCount );
	}
	
	if(	bUpdateVbo )
	{
		updateVbo();
	}
	
	if( nextFireworkExplosionTime < t )
	{
		explodeFireWorkAtRandom();
	}
	
}
void CloudsVisualSystemFireworks::selfUpdate()
{
	float t = ofGetElapsedTimef();
	for (int i=emitters.size()-1; i>=0; i--) {
		emitters[i].update( t );
		
		if( emitters[i].bStarted )
		{
			
			emitters[i].pos += fireworkGravity * emitters[i].span * emitters[i].age * 10;

			ofVec3f p0 = emitters[i].pos;
			ofVec3f nScl = p0 * .01;
			float nx = ofSignedNoise(nScl.x + emitters[i].age, nScl.y, nScl.z);
			float ny = ofSignedNoise(nScl.x, nScl.y + emitters[i].age, nScl.z);
			float nz = ofSignedNoise(nScl.x, nScl.y, nScl.z + emitters[i].age);
			p0 += ofVec3f( nx, ny, nz ) * 10. * emitters[i].age;

			trailPoint( p0, emitters[i].vel, 4 );
		}
		if(emitters[i].bEnded)
		{
			emitters.erase( emitters.begin() + i );
		}
	}
	
//	for (int i=rockets.size()-1; i>=0; i--)
//	{
//		rockets[i].update( t );
//
//		if(rockets[i].bEnded)
//		{
//			rockets.erase( rockets.begin() + i );
//		}
//	}
	
	
	//camera
	ofVec3f eul = camera.getOrientationEuler();
	float xDamp = ofMap( abs(eul.x), 70, 90, 1, 0, true );
	
	float noiseTimeScl = .1;
	float noiseOffsetScl = 800;
	float mouseScl = .25;
	float panScl = -5;
	
	float noiseValX = ofSignedNoise( ofGetElapsedTimef() * noiseTimeScl + 1. ) * noiseOffsetScl;
	float noiseValY = ofSignedNoise( ofGetElapsedTimef() * noiseTimeScl ) * noiseOffsetScl;
	
	float pan = ofMap(ofGetMouseX() + noiseValX, 0, ofGetWidth(), mouseScl, -mouseScl);
	float tilt = ofMap(ofGetMouseY() + noiseValY, 0, ofGetHeight(), -mouseScl, mouseScl) * xDamp;
	if(abs(eul.x) < 90) camera.tilt( tilt );
	camera.pan( pan );
	
	float roll = abs(pan) * pan * panScl;
	camera.roll( roll );
	
	camera.move(0, abs(roll), 0);
	
	ofVec3f vel = camera.getLookAtDir();
	camera.move( vel * camSpeed );
	
	float targetDistance = 300;
	camTarget = vel * targetDistance + camera.getPosition();
	
	
	//particles
	bool updateIndices = false;
	
	indexCount = 0;
	for(int i=0; i<FIREWORKS_NUM_PARTICLES; i++){
		//if the age + lifespan is less then the current time we want to draw
		if(lifeData[i].r + lifeData[i].g > t){
			indices[indexCount] = i;
			indexCount++;
			updateIndices = true;
		}
	}
	
	if(updateIndices){
		vbo.updateIndexData( indices, indexCount );
	}
	
	
	//fireworks...
	for (int i = spawnTime.size()-1; i>=0; i--) {
		//if it's alive apply gravity
		if(spawnTime[i] + 2 > t ){
			spawnPos[i] += spawnVel[i];
			spawnVel[i] += fireworkGravity;
			spawnVel[i] *= .99;
			
			trailPoint( spawnPos[i], spawnVel[i].normalized() );
		}
		else
		{
			spawnPos.erase( spawnPos.begin()+i );
			spawnVel.erase( spawnVel.begin()+i );
			spawnTime.erase( spawnTime.begin()+i );
		}
	}
	
	if(	bUpdateVbo )
	{
		updateVbo();
	}
	
	if( nextFireworkExplosionTime < t )
	{
		explodeFireWorkAtRandom();
	}
	
}