当前位置: 首页>>代码示例>>C++>>正文


C++ Perlin::dfBm方法代码示例

本文整理汇总了C++中Perlin::dfBm方法的典型用法代码示例。如果您正苦于以下问题:C++ Perlin::dfBm方法的具体用法?C++ Perlin::dfBm怎么用?C++ Perlin::dfBm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Perlin的用法示例。


在下文中一共展示了Perlin::dfBm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

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() ) ) );
	}
}
开发者ID:AaronMeyers,项目名称:Cinder,代码行数:31,代码来源:BasicParticleApp.cpp

示例2: scopeStencil

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();
    
}
开发者ID:Craigson,项目名称:100days,代码行数:60,代码来源:Day59App.cpp

示例3: update

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;
    }
}
开发者ID:stdmtb,项目名称:uf_0.8.6,代码行数:23,代码来源:cApp.cpp

示例4: findPerlin

void Particle::findPerlin()
{
	Vec3f noise = sPerlin.dfBm( loc[0] * 0.01f + Vec3f( 0, 0, counter / 100.0f ) );
	perlin = noise.normalized() * 0.5f;
}
开发者ID:CinimodStudio,项目名称:Cinder,代码行数:5,代码来源:Particle.cpp

示例5: setup

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;
    
}
开发者ID:stdmtb,项目名称:uf_0.8.6,代码行数:86,代码来源:cApp.cpp

示例6: update

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);
    }
}
开发者ID:stdmtb,项目名称:uf_0.9.0,代码行数:74,代码来源:cApp.cpp


注:本文中的Perlin::dfBm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。