Exemplo n.º 1
0
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()] ) );
        }

    }
}
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();
}
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 ) {
		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.splatRgb( x, y, mRgbScale*mColor );
		if( mFluid2D.isBuoyancyEnabled() ) {
			mFluid2D.splatDensity( x, y, mDenScale );
		}
	}
}
Exemplo n.º 4
0
void Fluid2DRGBApp::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 ) {
		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 );
		}
	}
}
Exemplo n.º 5
0
void Fluid2DParticlesApp::mouseDrag( MouseEvent event )
{
    float x = (event.getX()/(float)getWindowWidth())*mFluid2D.resX();
    float y = (event.getY()/(float)getWindowHeight())*mFluid2D.resY();
    float s = 10;

    if( event.isLeftDown() ) {
        vec2 dv = vec2( event.getPos() ) - mPrevPos;
        mFluid2D.splatVelocity( x, y, mVelScale*dv );
        mFluid2D.splatRgb( x, y, mRgbScale*mColor );
        if( mFluid2D.isBuoyancyEnabled() ) {
            mFluid2D.splatDensity( x, y, mDenScale );
        }
        //
        for( int i = 0; i < 10; ++i ) {
            vec2 partPos = vec2( event.getPos() ) + vec2( Rand::randFloat( -s, s ), Rand::randFloat( -s, s ) );
            float life = Rand::randFloat( 2.0f, 4.0f );
            mParticles.append( Particle( partPos, life, mColor ) );
        }
    }

    mPrevPos = event.getPos();
}