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


C++ Fluid2D::splatVelocity方法代码示例

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


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

示例1: 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

示例2:

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

示例3:

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

示例4:

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

示例5:

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

示例6:

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

示例7: toOcv

void Fluid2DCamAppApp::update()
{
	
	if( mCapture && mCapture.checkNewFrame() ) {
		if( ! mTexCam ) {
			mTexCam = gl::Texture( mCapture.getSurface() );
		}

		// Flip the image
		if( ! mFlipped ) {
			Surface8u srcImg = mCapture.getSurface();
			mFlipped = Surface8u( srcImg.getWidth(), srcImg.getHeight(), srcImg.hasAlpha(), srcImg.getChannelOrder() );
		}
		Surface8u srcImg = mCapture.getSurface();
		mFlipped = Surface8u( srcImg.getWidth(), srcImg.getHeight(), srcImg.hasAlpha(), srcImg.getChannelOrder() );
		for( int y = 0; y < mCapture.getHeight(); ++y ) {
			const Color8u* src = (const Color8u*)(srcImg.getData() + (y + 1)*srcImg.getRowBytes() - srcImg.getPixelInc());
			Color8u* dst = (Color8u*)(mFlipped.getData() + y*mFlipped.getRowBytes());
			for( int x = 0; x < mCapture.getWidth(); ++x ) {
				*dst = *src;
				++dst;
				--src;
			} 
		}
		
		// Create scaled image
		if( ! mCurScaled  ) {
			mCurScaled = Surface8u( mFlipped.getWidth()/kFlowScale, mFlipped.getHeight()/kFlowScale, mFlipped.hasAlpha(), mFlipped.getChannelOrder() );
		}		
		ip::resize( mFlipped, &mCurScaled );

		// Optical flow 
		if( mCurScaled && mPrvScaled ) {
			mPrvCvData = mCurCvData;
			mCurCvData = cv::Mat( toOcv( Channel( mCurScaled ) ) );

			if( mPrvCvData.data && mCurCvData.data ) {
				int pyrLvels		= 3;
				int winSize			= 3;
				int iters			= 5;
				int poly_n			= 7;
				double poly_sigma	= 1.5;
				cv::calcOpticalFlowFarneback( mPrvCvData, mCurCvData, mFlow, 0.5, pyrLvels, 2*winSize + 1, iters, poly_n, poly_sigma, cv::OPTFLOW_FARNEBACK_GAUSSIAN );

				if( mFlow.data ) {
					if( mFlowVectors.empty() ) {
						mFlowVectors.resize( mCurScaled.getWidth()*mCurScaled.getHeight() );
					}
					
					//memset( &mFlowVectors[0], 0, mCurScaled.getWidth()*mCurScaled.getHeight()*sizeof( Vec2f ) );
					mNumActiveFlowVectors = 0;
					for( int j = 0; j < mCurScaled.getHeight(); ++j ) {
						for( int i = 0; i < mCurScaled.getWidth(); ++i ) {
							const float* fptr = reinterpret_cast<float*>(mFlow.data + j*mFlow.step + i*sizeof(float)*2);
							//
							Vec2f v = Vec2f( fptr[0], fptr[1] ); 
							if( v.lengthSquared() >= mVelThreshold ) {
								if( mNumActiveFlowVectors >= (int)mFlowVectors.size() ) {
									mFlowVectors.push_back( std::make_pair( Vec2i( i, j ), v ) );
								}
								else {
									mFlowVectors[mNumActiveFlowVectors] = std::make_pair( Vec2i( i, j ), v );
								}
								++mNumActiveFlowVectors;
							}
						}
					}
				}
			}
		}

		// Update texture
		mTexCam.update( mFlipped );

		// Save previous frame
		if( ! mPrvScaled ) {
			mPrvScaled = Surface8u( mCurScaled.getWidth(), mCurScaled.getHeight(), mCurScaled.hasAlpha(), mCurScaled.getChannelOrder() );
		}
		memcpy( mPrvScaled.getData(), mCurScaled.getData(), mCurScaled.getHeight()*mCurScaled.getRowBytes() );
	}

	// Update fluid
	float dx = (mFluid2DResX - 2)/(float)(640/kFlowScale);
	float dy = (mFluid2DResY - 2)/(float)(480/kFlowScale);
	for( int i = 0; i < mNumActiveFlowVectors; ++i ) {
		Vec2f P = mFlowVectors[i].first;
		const Vec2f& v = mFlowVectors[i].second;
		mFluid2D.splatDensity( P.x*dx + 1, P.y*dy + 1, mDenScale*v.lengthSquared() );
		mFluid2D.splatVelocity( P.x*dx + 1, P.y*dy + 1, v*mVelScale );
	}
	mFluid2D.step();

	// Update velocity
	const Vec2f* srcVel0 = mFluid2D.dbgVel0().data();
	const Vec2f* srcVel1 = mFluid2D.dbgVel1().data();
	Colorf* dstVel0 = (Colorf*)mSurfVel0.getData();
	Colorf* dstVel1 = (Colorf*)mSurfVel1.getData();
	for( int j = 0; j < mFluid2DResY; ++j ) {
		for( int i = 0; i < mFluid2DResX; ++i ) {
			*dstVel0 = Colorf( srcVel0->x, srcVel0->y, 0.0f );
//.........这里部分代码省略.........
开发者ID:fieldOfView,项目名称:CinderFx,代码行数:101,代码来源:Fluid2DCamApp.cpp


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