Exemplo n.º 1
0
void BasicParticleApp::update()
{
	mAnimationCounter += 10.0f; // move ahead in time, which becomes the z-axis of our 3D noise

	// Save off the last position for drawing lines
	for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt )
		partIt->mLastPosition = partIt->mPosition;

	// Add some perlin noise to the velocity
	for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) {
		Vec3f deriv = mPerlin.dfBm( Vec3f( partIt->mPosition.x, partIt->mPosition.y, mAnimationCounter ) * 0.001f );
		partIt->mZ = deriv.z;
		Vec2f deriv2( deriv.x, deriv.y );
		deriv2.normalize();
		partIt->mVelocity += deriv2 * SPEED;
	}
		
	// Move the particles according to their velocities
	for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt )
		partIt->mPosition += partIt->mVelocity;

	// Dampen the velocities for the next frame
	for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt )
		partIt->mVelocity *= CONSERVATION_OF_VELOCITY;
		
	// Replace any particles that have gone offscreen with a random onscreen position
	for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) {
		if( isOffscreen( partIt->mPosition ) )
			*partIt = Particle( Vec2f( Rand::randFloat( getWindowWidth() ), Rand::randFloat( getWindowHeight() ) ) );
	}
}
Exemplo n.º 2
0
void Day59App::draw()
{
    gl::setMatrices(mCam);
    gl::clear( Color( 0.1, 0.1, 0.1 ) );
    gl::color(Color(0.,0.,0.));
    gl::clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
    mCam.setEyePoint(vec3(0.,0.,fabs(cos(omega) * 50.f)));
  mPerlin.setSeed(getElapsedFrames());
    
    // enable stencil test to be able to give the stencil buffers values.
    gl::ScopedState scopeStencil( GL_STENCIL_TEST, true );
  //  gl::rotate(angleAxis(theta/2, vec3(0.,1.,0.)));
    for (int i =0; i <NUM_OBJS; i++)
    {
        
        vec3 noise = mPerlin.dfBm(mRandomPositions[i]);
    
        gl::ScopedMatrices scpMtx;
        gl::translate(mRandomPositions[i]);
        
    
        {
            gl::ScopedMatrices push;
            gl::rotate(angleAxis(theta + mOffsets[i], vec3(1.0, 0., 0.)));
            gl::translate(mRandomPositions[i]);
            gl::scale(mScales[i]);
            
            //DRAW THE MAIN OBJECT (1ST RENDER PASS) AS NORMAL, FILL THE STENCIL BUFFER
            gl::stencilFunc(GL_ALWAYS, 1, 0xFF); //ALL FRAGMENTS MUST UPDATE THE STENCIL BUFFER
            gl::stencilMask(0xFF); //ENABLE WRITING TO THE STENCIL BUFFER
            mObject->draw();
        }
        
        //IF THE STENCIL TEST FAILS, KEEP THE FRAGMENT
        //IF STENCIL PASSES AND DEPTH FAILS, KEEP THE FRAGMENT
        //IF THE DEPTH TEST AND STENCIL TEST PASS, REPLACE THE FRAGMENT
        glStencilOp(GL_KEEP  , GL_KEEP, GL_REPLACE);
        
        //2ND RENDER PASS - DRAW OBJECT SLIGHTLY BIGGER, BUT DISABLE STENCIL WRITING.  BECAUSE THE STENCIL BUFFER IS FILLED WITH 1s (PARTICULARLY IN THE AREA OF THE ORIGINAL OBJECT), THE ONLY THING THAT WILL BE DRAWN IS THE AREA OF THE 2ND OBJECT, IE. THE SIZE DIFFERENCE
        
        gl::stencilFunc(GL_NOTEQUAL, 1, 0xFF); //don't update the stencil buffer
        gl::stencilMask(0x00);
        gl::disable(GL_DEPTH_TEST);
        {
            gl::ScopedMatrices push;
            gl::rotate(angleAxis(theta + mOffsets[i], vec3(1.0, 0., 0.)));
            gl::translate(mRandomPositions[i]);
            
            gl::scale(vec3(mScales[i] + vec3(0.1) ));
            
            mBorderObject->draw();
        }
    
    }
    
    gl::stencilMask(0xFF);
    gl::enable(GL_DEPTH_TEST);
  //  saveGif();
    
}
Exemplo n.º 3
0
void cApp::update(){
    if( !bStart )
        return;
    
    gl::VboMesh::VertexIter vitr( mPoints );
    for(int i=0; i<mPoints.getNumVertices(); i++ ){
        
        Vec3f &pos = ps[i];
        int x = pos.x;
        int y = pos.y;

        x = cinder::math<int>::clamp( x, 0, intensityW-1 );
        y = cinder::math<int>::clamp( y, 0, intensityH-1 );
        
        Vec3f vel( mVecMap[x][y].x, mVecMap[x][y].y, 0);
        Vec3f noise = mPln.dfBm(x, y, cs[i].a ) * 0.2;
        mVelocity[i] = mVelocity[i] + (vel + noise);
        
        vitr.setPosition( pos + mVelocity[i] );
        vitr.setColorRGBA( cs[i] );
        ++vitr;
    }
}
Exemplo n.º 4
0
void Particle::findPerlin()
{
	Vec3f noise = sPerlin.dfBm( loc[0] * 0.01f + Vec3f( 0, 0, counter / 100.0f ) );
	perlin = noise.normalized() * 0.5f;
}
Exemplo n.º 5
0
void cApp::setup(){
    
    setWindowPos( 0, 0 );
    setWindowSize( 1080*3*0.5, 1920*0.5 );
    mExp.setup( 1080*3, 1920, 3000, GL_RGB, mt::getRenderPath(), 0);
    
    CameraPersp cam(1080*3, 1920, 54.4f, 0.1, 10000 );
    cam.lookAt( Vec3f(0,0, 1600), Vec3f(0,0,0) );
    cam.setCenterOfInterestPoint( Vec3f(0,0,0) );
    camUi.setCurrentCam( cam );
    
    mPln.setSeed(123);
    mPln.setOctaves(4);
    
    fs::path assetPath = mt::getAssetPath();
    
    {
        // make VectorMap
        Surface32f sAspect( loadImage(assetPath/("img/00/halpha3000_aspect_32bit.tif")) );
        Surface32f sSlope( loadImage(assetPath/("img/00/halpha3000_slope1.tif")) );

        int w = sAspect.getWidth();
        int h = sAspect.getHeight();
        
        mVecMap.assign(w, vector<Vec2f>(h) );

        for( int i=0; i<sAspect.getWidth(); i++) {
            for( int j=0; j<sAspect.getHeight(); j++ ) {
                
                Vec2i pos(i, j);
                float aspect = *sAspect.getDataRed( pos );
                float slope = *sSlope.getDataRed( pos );
                if( slope!=0 && aspect!=-9999 ){

                    Vec2f vel( 0, slope*10.0 );
                    vel.rotate( toRadians(aspect) );
                    mVecMap[i][j] = vel;
                }else{
                    mVecMap[i][j] = Vec2f::zero();
                }
                
                mVelocity.push_back( Vec3f(mVecMap[i][j].x, mVecMap[i][j].y, 0) );
            }
        }
    }
    
    {
        // make point from intensity
        Surface32f sIntensity( loadImage(assetPath/("img/00/halpha3000-skv3264879915580.tiff")) );
        intensityW = sIntensity.getWidth();
        intensityH = sIntensity.getHeight();
        
        Surface32f::Iter itr = sIntensity.getIter();
        float threashold = 0.15;
        float extrusion = 300;
        while ( itr.line() ) {
            while( itr.pixel() ){
                float gray = itr.r();
                if( threashold < gray ){
                    Vec2i pos = itr.getPos();
                    Vec3f v(pos.x, pos.y, gray*extrusion );
                    Vec3f noise = mPln.dfBm( Vec3f(pos.x, pos.y, gray) ) * 2.0;
                    ps.push_back( v + noise );
                    float c = gray + 0.2f;
                    float a = lmap(c, 0.0f, 1.0f, 0.3f, 0.7f);
                    cs.push_back( ColorAf(c, c, c, a) );
                }
            }
        }
        
        
        mPoints = gl::VboMesh( ps.size(), 0, mt::getVboLayout(), GL_POINTS );
        gl::VboMesh::VertexIter vitr( mPoints );
        for(int i=0; i<ps.size(); i++ ){
            vitr.setPosition( ps[i] );
            vitr.setColorRGBA( cs[i] );

            ++vitr;
        }
    }
    
    
    mExp.startRender();
    bStart = true;
    
}
Exemplo n.º 6
0
void cApp::update(){

    if( !bStart ) return;
    
    parts.clear();
    vbo.resetAll();
    
    if(0){
        if(!mov){
            fs::path path = mt::getAssetPath()/"sim"/"supernova"/"2d"/"mov"/"7.1_simu_5_c_linear_rect.mov";
            mov = qtime::MovieSurface::create( path );
            mov->seekToStart();
            mov->play();
        }
        mov->seekToFrame(frame);
        sur = mov->getSurface();
    }else{
        fs::path path = mt::getAssetPath()/"sim"/"supernova"/"2d"/"img"/"simu_1"/"c"/"polar"/"linear"/"simu_1_idump100_c_linear_polar.png";
        //fs::path path = mt::getAssetPath()/"sim"/"supernova"/"2d"/"img"/"test.png";
        sur = Surface8u::create( loadImage(path) );
    }
    
    if(sur){
        frame++;

        Surface8u::Iter itr = sur->getIter();
        while (itr.line()) {
            while (itr.pixel()) {
                
                vec2 pos = itr.getPos();
                pos.x -= itr.getWidth()/2;
                pos.y -= itr.getHeight()/2;

                float val = itr.r()/255.0f;
                float min = 0.4f;
                float max = 0.99999f;
                if( min < val && val < max ){
                    float gray = lmap(val, min, max, 0.3f, 1.0f);
                    Particle pt;
                    pt.pos = vec3(pos.x, pos.y, gray*200.0f) + mPln.dfBm(frame*0.0001f, pos.x*0.001f, pos.y*0.001f)*0.3f;
                    pt.dist = glm::distance(eye, pt.pos);
                    pt.val = val;
                    
                    //pt.col = Colorf(gray,gray,gray);
                    pt.col = mt::getHeatmap( gray );
                    parts.push_back(pt);
                    
                    if(0){
                        for( int k=0; k<round(pt.pos.z); k+=5){
                            vec3 pp = pt.pos;
                            pp.z = k;
                            Particle pt;
                            pt.pos = pp + mPln.dfBm(frame*0.0001f, pos.x*0.001f, pos.y*0.001f)*0.3f;
                            pt.dist = glm::distance(eye, pp);
                            pt.val = val;
                            //pt.col = Colorf(gray,gray,gray);
                            pt.col = mt::getHeatmap( gray );
                            pt.col.a = k*0.01;
                            parts.push_back(pt);
                        }
                    }
                }
            }
        }
        
        std::sort(parts.begin(), parts.end(), [](const Particle&lp, const Particle&rp){ return lp.dist > rp.dist; } );
        
        for( int i=0; i<parts.size(); i++){
            vbo.addPos(parts[i].pos);
            vbo.addCol(parts[i].col);
        }
        vbo.init(GL_POINTS);
    }
}