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


C++ cinderfx::Fluid2D类代码示例

本文整理汇总了C++中cinderfx::Fluid2D的典型用法代码示例。如果您正苦于以下问题:C++ Fluid2D类的具体用法?C++ Fluid2D怎么用?C++ Fluid2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1:

void Fluid2DTextureApp::keyDown( KeyEvent event )
{
	switch( event.getCode() ) {
	case KeyEvent::KEY_r:
		mFluid2D.resetTexCoords();
		break;

	case KeyEvent::KEY_c:
		mFluid2D.clearAll();
		break;
	}
}
开发者ID:andrewfb,项目名称:CinderFx,代码行数:12,代码来源:Fluid2DTextureApp.cpp

示例2:

void Fluid2DBasicApp::touchesMoved( TouchEvent event )
{
	const std::vector<TouchEvent::Touch>& touches = event.getTouches();
	for( std::vector<TouchEvent::Touch>::const_iterator cit = touches.begin(); cit != touches.end(); ++cit ) {
		Vec2f prevPos = cit->getPrevPos();
		Vec2f pos = cit->getPos();
		float x = (pos.x/(float)getWindowWidth())*mFluid2D.resX();
		float y = (pos.y/(float)getWindowHeight())*mFluid2D.resY();	
		Vec2f dv = pos - prevPos;
		mFluid2D.splatVelocity( x, y, mVelScale*dv );
		mFluid2D.splatDensity( x, y, mDenScale );
	}
}
开发者ID:fieldOfView,项目名称:CinderFx,代码行数:13,代码来源:Fluid2DBasicApp.cpp

示例3:

void Fluid2DCamAppApp::mouseDrag( MouseEvent event )
{
	float x = (event.getX()/(float)getWindowWidth())*mFluid2D.resX();
	float y = (event.getY()/(float)getWindowHeight())*mFluid2D.resY();	
	
	if( event.isLeftDown() ) {
		Vec2f dv = event.getPos() - mPrevPos;
		mFluid2D.splatVelocity( x, y, mVelScale*dv );
		mFluid2D.splatDensity( x, y, mDenScale );
	}

	mPrevPos = event.getPos();
}
开发者ID:fieldOfView,项目名称:CinderFx,代码行数:13,代码来源:Fluid2DCamApp.cpp

示例4: chan

void Fluid2DBasicApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 

	Channel32f chan( mFluid2D.resX(), mFluid2D.resY(), mFluid2D.resX()*sizeof(float), 1, const_cast<float*>( mFluid2D.density().data() ) );

	if( ! mTex ) {
		mTex = gl::Texture( chan );
	} else {
		mTex.update( chan );
	}
	gl::color( Color( 1, 1, 1 ) );
	gl::draw( mTex, getWindowBounds() );

	mParams.draw();
}
开发者ID:fieldOfView,项目名称:CinderFx,代码行数:17,代码来源:Fluid2DBasicApp.cpp

示例5: switch

void Fluid2DParticlesApp::keyDown( KeyEvent event )
{
    switch( event.getCode() ) {
    case KeyEvent::KEY_r:
        mFluid2D.initSimData();
        break;
    }
}
开发者ID:roshan2010,项目名称:CinderFx,代码行数:8,代码来源:Fluid2DParticlesApp.cpp

示例6: surf

void Fluid2DRGBApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 

	//RenderFluidRgb( mFluid2D, getWindowBounds() );
	float* data = const_cast<float*>( (float*)mFluid2D.rgb().data() );
	Surface32f surf( data, mFluid2D.resX(), mFluid2D.resY(), mFluid2D.resX()*sizeof(Colorf), SurfaceChannelOrder::RGB );
	
	if ( ! mTex ) {
		mTex = gl::Texture::create( surf );
	} else {
		mTex->update( surf );
	}
	gl::draw( mTex, getWindowBounds() );
	
	mParams.draw();
}
开发者ID:andrewfb,项目名称:CinderFx,代码行数:18,代码来源:Fluid2DRGBApp.cpp

示例7: Particle

void Fluid2DParticlesApp::touchesMoved( TouchEvent event )
{
    float s = 10;

    const std::vector<TouchEvent::Touch>& touches = event.getTouches();
    for( std::vector<TouchEvent::Touch>::const_iterator cit = touches.begin(); cit != touches.end(); ++cit ) {
        if( mTouchColors.find( cit->getId() ) == mTouchColors.end() )
            continue;
        vec2 prevPos = cit->getPrevPos();
        vec2 pos = cit->getPos();
        float x = (pos.x/(float)getWindowWidth())*mFluid2D.resX();
        float y = (pos.y/(float)getWindowHeight())*mFluid2D.resY();
        vec2 dv = pos - prevPos;
        mFluid2D.splatVelocity( x, y, mVelScale*dv );
        mFluid2D.splatRgb( x, y, mRgbScale*mTouchColors[cit->getId()] );
        if( mFluid2D.isBuoyancyEnabled() ) {
            mFluid2D.splatDensity( x, y, mDenScale );
        }
        for( int i = 0; i < 5; ++i ) {
            vec2 partPos = pos + vec2( Rand::randFloat( -s, s ), Rand::randFloat( -s, s ) );
            float life = Rand::randFloat( 3.0f, 6.0f );
            mParticles.append( Particle( partPos, life, mTouchColors[cit->getId()] ) );
        }

    }
}
开发者ID:roshan2010,项目名称:CinderFx,代码行数:26,代码来源:Fluid2DParticlesApp.cpp

示例8: Color

void Fluid2DTextureApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );

	// Update the positions and tex coords
	Rectf drawRect = getWindowBounds();
	int limX = mFluid2D.resX() - 1;
	int limY = mFluid2D.resY() - 1;
	float dx = drawRect.getWidth()/(float)limX;
	float dy = drawRect.getHeight()/(float)limY;
	
	for( int j = 0; j < mFluid2D.resY(); ++j ) {
		for( int i = 0; i < mFluid2D.resX(); ++i ) {
			vec2 P = vec2( i*dx, j*dy );
			vec2 uv = mFluid2D.texCoordAt( i, j );

			int idx = j*mFluid2D.resX() + i;
			mTriMesh->getPositions<2>()[idx] = P;
			mTriMesh->getTexCoords0<2>()[idx] = uv;
			
		}
	}

	mTex->bind();
	gl::bindStockShader( gl::ShaderDef().color().texture() );
	gl::draw( gl::VboMesh::create(*mTriMesh) );
	mTex->unbind();
	
	mParams.draw();	
}
开发者ID:andrewfb,项目名称:CinderFx,代码行数:32,代码来源:Fluid2DTextureApp.cpp

示例9: Color

void Fluid2DTextureApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );

	// Update the positions and tex coords
	Rectf drawRect = getWindowBounds();
	int limX = mFluid2D.resX() - 1;
	int limY = mFluid2D.resY() - 1;
	float dx = drawRect.getWidth()/(float)limX;
	float dy = drawRect.getHeight()/(float)limY;
	
	for( int j = 0; j < mFluid2D.resY(); ++j ) {
		for( int i = 0; i < mFluid2D.resX(); ++i ) {
			Vec2f P = Vec2f( i*dx, j*dy );
			Vec2f uv = mFluid2D.texCoordAt( i, j );

			int idx = j*mFluid2D.resX() + i;
			mTriMesh.getVertices()[idx] = P;
			mTriMesh.getTexCoords()[idx] = uv;
			
		}
	}

	mTex.bind();
	gl::draw( mTriMesh ); 
	mTex.unbind();
	
	mParams.draw();	
}
开发者ID:fieldOfView,项目名称:CinderFx,代码行数:31,代码来源:Fluid2DTextureApp.cpp

示例10:

void Fluid2DParticleSoupApp::touchesMoved( TouchEvent event )
{
	const std::vector<TouchEvent::Touch>& touches = event.getTouches();
	for( std::vector<TouchEvent::Touch>::const_iterator cit = touches.begin(); cit != touches.end(); ++cit ) {
		vec2 prevPos = cit->getPrevPos();
		vec2 pos = cit->getPos();
		float x = (pos.x/(float)getWindowWidth())*mFluid2D.resX();
		float y = (pos.y/(float)getWindowHeight())*mFluid2D.resY();	
		vec2 dv = pos - prevPos;
		mFluid2D.splatVelocity( x, y, mVelScale*dv );
		mFluid2D.splatRgb( x, y, mRgbScale*mColor );
		if( mFluid2D.isBuoyancyEnabled() ) {
			mFluid2D.splatDensity( x, y, mDenScale );
		}
	}
}
开发者ID:chaoticbob,项目名称:CinderFx,代码行数:16,代码来源:Fluid2DParticleSoupApp.cpp

示例11:

void Fluid2DParticleSoupApp::mouseDrag( MouseEvent event )
{
	float x = (event.getX()/(float)getWindowWidth())*mFluid2D.resX();
	float y = (event.getY()/(float)getWindowHeight())*mFluid2D.resY();	
	
	if( event.isLeftDown() ) {
		Vec2f dv = event.getPos() - mPrevPos;
		mFluid2D.splatVelocity( x, y, mVelScale*dv );
		mFluid2D.splatRgb( x, y, mRgbScale*mColor );
		if( mFluid2D.isBuoyancyEnabled() ) {
			mFluid2D.splatDensity( x, y, mDenScale );
		}
	}
	
	mPrevPos = event.getPos();
}
开发者ID:fieldOfView,项目名称:CinderFx,代码行数:16,代码来源:Fluid2DParticleSoupApp.cpp

示例12: loadImage

void Fluid2DTextureApp::setup()
{
	mFrameRate = 0.0f;

	mTex = gl::Texture::create( loadImage( loadResource( RES_IMAGE ) ) );

	mFluid2D.enableTexCoord();
	mFluid2D.setTexCoordViscosity( 1.0f );

	mDenScale = 50;

	mFluid2D.set( 192, 192 );
   	mFluid2D.setDensityDissipation( 0.99f );
	mVelScale = 0.50f*std::max( mFluid2D.resX(), mFluid2D.resY() );
    
	mParams = params::InterfaceGl( "Params", ivec2( 300, 400 ) );
	mParams.addParam( "Stam Step", mFluid2D.stamStepAddr() );
	mParams.addSeparator();
	mParams.addParam( "Velocity Input Scale", &mVelScale, "min=0 max=10000 step=1" );
	mParams.addParam( "Density Input Scale", &mDenScale, "min=0 max=1000 step=1" );
	mParams.addSeparator();
	mParams.addParam( "Velocity Dissipation", mFluid2D.velocityDissipationAddr(), "min=0.0001 max=1 step=0.0001" );
	mParams.addParam( "Density Dissipation", mFluid2D.densityDissipationAddr(), "min=0.0001 max=1 step=0.0001" );
	mParams.addParam( "TexCoord Dissipation", mFluid2D.texCoordDissipationAddr(), "min=0.0001 max=1 step=0.0001" );
	mParams.addSeparator();
	mParams.addParam( "Velocity Viscosity", mFluid2D.velocityViscosityAddr(), "min=0.000001 max=10 step=0.000001" );
	mParams.addParam( "Density Viscosity", mFluid2D.densityViscosityAddr(), "min=0.000001 max=10 step=0.000001" );
	mParams.addParam( "TexCoord Viscosity", mFluid2D.texCoordViscosityAddr(), "min=0.000001 max=10 step=0.000001" );
	mParams.addSeparator();
	//mParams.addParam( "Vorticity Confinement", mFluid2D.enableVorticityConfinementAddr() );
	//mParams.addSeparator();
	std::vector<std::string> boundaries;
	boundaries.push_back( "None" ); boundaries.push_back( "Wall" ); boundaries.push_back( "Wrap" );
	mParams.addParam( "Boundary Type", boundaries, mFluid2D.boundaryTypeAddr() );
	mParams.addSeparator();
	mParams.addParam( "Enable Buoyancy", mFluid2D.enableBuoyancyAddr() );
	mParams.addParam( "Buoyancy Scale", mFluid2D.buoyancyScaleAddr(), "min=0 max=100 step=0.001" );
	mParams.addParam( "Vorticity Scale", mFluid2D.vorticityScaleAddr(), "min=0 max=1 step=0.001" );
	
	mTriMesh = ci::TriMesh::create( TriMesh::Format().positions(2).texCoords0(2) );

	// Points and texture coordinates
	for( int j = 0; j < mFluid2D.resY(); ++j ) {
		for( int i = 0; i < mFluid2D.resX(); ++i ) {
			mTriMesh->appendPosition( vec2( 0.0f, 0.0f ) );
			mTriMesh->appendTexCoord0( vec2( 0.0f, 0.0f ) );
		}
	}
	// Triangles
	for( int j = 0; j < mFluid2D.resY() - 1; ++j ) {
		for( int i = 0; i < mFluid2D.resX() - 1; ++i ) {
			int idx0 = (j + 0)*mFluid2D.resX() + (i + 0 );
			int idx1 = (j + 1)*mFluid2D.resX() + (i + 0 );
			int idx2 = (j + 1)*mFluid2D.resX() + (i + 1 );
			int idx3 = (j + 0)*mFluid2D.resX() + (i + 1 );
			mTriMesh->appendTriangle( idx0, idx1, idx2 );
			mTriMesh->appendTriangle( idx0, idx2, idx3 );
		}
	}
	
	//console() << mFluid2D << std::endl;
}
开发者ID:andrewfb,项目名称:CinderFx,代码行数:62,代码来源:Fluid2DTextureApp.cpp

示例13: getAverageFps

void Fluid2DTextureApp::update()
{
	mFluid2D.step();
	mFrameRate = getAverageFps();
}
开发者ID:andrewfb,项目名称:CinderFx,代码行数:5,代码来源:Fluid2DTextureApp.cpp

示例14:

void Fluid2DRGBApp::update()
{
	mFluid2D.step();
}
开发者ID:andrewfb,项目名称:CinderFx,代码行数:4,代码来源:Fluid2DRGBApp.cpp

示例15: defined

void Fluid2DCamAppApp::setup()
{
	glEnable( GL_TEXTURE_2D );
	
	mVelThreshold = 0.75f;
	mNumActiveFlowVectors = 0;
#if defined( CINDER_MSW )
	mVelScale = 0.5f;
	mDenScale = 0.0025f;
#elif defined( CINDER_MAC )
	mVelScale = 2.0f;
	mDenScale = 0.007f;
#endif

	mFluid2D.set( mFluid2DResX, mFluid2DResY );
	mFluid2D.enableDensity();
	mFluid2D.enableVorticityConfinement();
	mFluid2D.setNumPressureIters( 24 );
	mFluid2D.initSimData();
	
	// Create these so we can create the textures ahead of time
	mSurfVel0		= Surface32f( mFluid2DResX, mFluid2DResY, false, SurfaceChannelOrder::RGB );
	mSurfVel1		= Surface32f( mFluid2DResX, mFluid2DResY, false, SurfaceChannelOrder::RGB );
	mChanDen0		= Channel32f( mFluid2DResX, mFluid2DResY );
	mChanDen1		= Channel32f( mFluid2DResX, mFluid2DResY );
	mChanDiv		= Channel32f( mFluid2DResX, mFluid2DResY );
	mChanPrs		= Channel32f( mFluid2DResX, mFluid2DResY );
	mChanCurl		= Channel32f( mFluid2DResX, mFluid2DResY );
	mChanCurlLen	= Channel32f( mFluid2DResX, mFluid2DResY );
	mTexVel0		= gl::Texture( mSurfVel0 );
	mTexVel1		= gl::Texture( mSurfVel1 );
	mTexDen0		= gl::Texture( mChanDen0 );
	mTexDen1		= gl::Texture( mChanDen1 );
	mTexDiv			= gl::Texture( mChanDiv );
	mTexPrs			= gl::Texture( mChanPrs );
	mTexCurl		= gl::Texture( mChanCurl );
	mTexCurlLen		= gl::Texture( mChanCurlLen );
	
	mParams = params::InterfaceGl( "Params", Vec2i( 300, 400 ) );
	mParams.addParam( "Stam Step", mFluid2D.stamStepAddr() );
	mParams.addSeparator();
	mParams.addParam( "Velocity Threshold", &mVelThreshold, "min=0 max=2 step=0.001" );
	mParams.addSeparator();
	mParams.addParam( "Velocity Input Scale", &mVelScale, "min=0 max=10 step=0.001" );
	mParams.addParam( "Density Input Scale", &mDenScale, "min=0 max=1 step=0.0001" );
	mParams.addSeparator();
	mParams.addParam( "Velocity Dissipation", mFluid2D.velocityDissipationAddr(), "min=0 max=1 step=0.0001" );
	mParams.addParam( "Density Dissipation", mFluid2D.densityDissipationAddr(), "min=0 max=1 step=0.0001" );
	mParams.addSeparator();
	mParams.addParam( "Velocity Viscosity", mFluid2D.velocityViscosityAddr(), "min=0 max=10 step=0.000001" );
	mParams.addParam( "Density Viscosity", mFluid2D.densityViscosityAddr(), "min=0 max=10 step=0.000001" );
	mParams.addSeparator();
	mParams.addParam( "Vorticity Confinement", mFluid2D.enableVorticityConfinementAddr() );
	mParams.addSeparator();
	std::vector<std::string> boundaries;
	boundaries.push_back( "None" ); boundaries.push_back( "Wall" ); boundaries.push_back( "Wrap" );
	mParams.addParam( "Boundary Type", boundaries, mFluid2D.boundaryTypeAddr() );
	mParams.addSeparator();
	mParams.addParam( "Enable Buoyancy", mFluid2D.enableBuoyancyAddr() );
	mParams.addParam( "Buoyancy Scale", mFluid2D.buoyancyScaleAddr(), "min=0 max=100 step=0.001" );
	mParams.addParam( "Vorticity Scale", mFluid2D.vorticityScaleAddr(), "min=0 max=1 step=0.001" );
	
	// Camera
	try {
		mCapture = Capture( 640, 480 );
		mCapture.start();
	}
	catch( ... ) {
		console() << "Failed to initialize capture" << std::endl;
	}
}
开发者ID:fieldOfView,项目名称:CinderFx,代码行数:71,代码来源:Fluid2DCamApp.cpp


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