コード例 #1
0
ファイル: LeapApp.cpp プロジェクト: gaborpapp/Cinder-LeapSdk
// Set up
void LeapApp::setup()
{
	// Set up OpenGL
	gl::enable( GL_LINE_SMOOTH );
	glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); 
	gl::enable( GL_POLYGON_SMOOTH );
	glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );

	// Set up camera
	mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 0.01f, 1000.0f );
	mCamera.lookAt( Vec3f( 0.0f, 125.0f, 500.0f ), Vec3f( 0.0f, 250.0f, 0.0f ) );
	
	// Start device
	mLeap = Device::create();
	mLeap->addCallback( &LeapApp::onFrame, this );

	// Params
	mFrameRate	= 0.0f;
	mFullScreen	= false;
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 105 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,						"", true );
	mParams.addParam( "Full screen",	&mFullScreen,						"key=f"		);
	mParams.addButton( "Screen shot",	bind( &LeapApp::screenShot, this ), "key=space" );
	mParams.addButton( "Quit",			bind( &LeapApp::quit, this ),		"key=q" );
}
コード例 #2
0
// Set up
void TracerApp::setup()
{
	// Set up camera
	mCamera		= CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 0.01f, 1000.0f );
	mCamera.lookAt( Vec3f( 0.0f, 93.75f, 250.0f ), Vec3f( 0.0f, 250.0f, 0.0f ) );
	
	// Start device
	mDevice = Device::create();
	mDevice->connectEventHandler( &TracerApp::onFrame, this );

	// Load shaders
	try {
		mShader[ 0 ]	= gl::GlslProg( loadResource( RES_GLSL_PASS_THROUGH_VERT ), loadResource( RES_GLSL_BLUR_X_FRAG ) );
	} catch ( gl::GlslProgCompileExc ex ) {
		console() << "Unable to compile blur X shader: \n" << string( ex.what() ) << "\n";
		quit();
	}
	try {
		mShader[ 1 ]	= gl::GlslProg( loadResource( RES_GLSL_PASS_THROUGH_VERT ), loadResource( RES_GLSL_BLUR_Y_FRAG ) );
	} catch ( gl::GlslProgCompileExc ex ) {
		console() << "Unable to compile blur Y shader: \n" << string( ex.what() ) << "\n";
		quit();
	}

	// Params
	mFrameRate	= 0.0f;
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 105 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,							"", true );
	mParams.addButton( "Screen shot",	bind( &TracerApp::screenShot, this ),	"key=space" );
	mParams.addButton( "Quit",			bind( &TracerApp::quit, this ),			"key=q" );

	// Enable polygon smoothing
	gl::enable( GL_POLYGON_SMOOTH );
	glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
	
	// Set up FBOs
	gl::Fbo::Format format;
#if defined( CINDER_MSW )
	format.setColorInternalFormat( GL_RGBA32F );
#else
	format.setColorInternalFormat( GL_RGBA32F_ARB );
#endif
	format.setMinFilter( GL_LINEAR );
	format.setMagFilter( GL_LINEAR );
	format.setWrap( GL_CLAMP, GL_CLAMP );
	for ( size_t i = 0; i < 3; ++i ) {
		mFbo[ i ]	= gl::Fbo( getWindowWidth(), getWindowHeight(), format );
		mFbo[ i ].bindFramebuffer();
		gl::setViewport( mFbo[ i ].getBounds() );
		gl::clear();
		mFbo[ i ].unbindFramebuffer();
	}
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
}
コード例 #3
0
// Render
void TracerApp::draw()
{
	// Add to accumulation buffer
	mFbo[ 0 ].bindFramebuffer();
	gl::setViewport( mFbo[ 0 ].getBounds() );
	gl::setMatricesWindow( mFbo[ 0 ].getSize() );
	gl::enableAlphaBlending();

	// Dim last frame
	gl::color( ColorAf( Colorf::black(), 0.03f ) );
	gl::drawSolidRect( Rectf( mFbo[ 0 ].getBounds() ) );

	// Draw finger tips into the accumulation buffer
	gl::setMatrices( mCamera );
	gl::enableAdditiveBlending();
	for ( RibbonMap::const_iterator iter = mRibbons.begin(); iter != mRibbons.end(); ++iter ) {
		iter->second.draw();
	}
	mFbo[ 0 ].unbindFramebuffer();

	// Blur the accumulation buffer
	gl::enable( GL_TEXTURE_2D );
	gl::enableAlphaBlending();
	gl::color( ColorAf::white() );
	Vec2f pixel	= Vec2f::one() / Vec2f( mFbo[ 0 ].getSize() );
	pixel		*= 3.0f;
	for ( size_t i = 0; i < 2; ++i ) {
		mFbo[ i + 1 ].bindFramebuffer();
		gl::clear();
		
		mShader[ i ].bind();
		mShader[ i ].uniform( "size",	pixel );
		mShader[ i ].uniform( "tex",	0 );
				
		gl::Texture& texture = mFbo[ i ].getTexture();
		texture.bind();
		gl::drawSolidRect( Rectf( mFbo[ i ].getBounds() ) );
		texture.unbind();
		
		mShader[ i ].unbind();
		mFbo[ i + 1 ].unbindFramebuffer();
	}

	// Draw blurred image
	gl::setMatricesWindow( getWindowSize(), false );
	gl::color( ColorAf::white() );
	mFbo[ 0 ].bindTexture();
	gl::drawSolidRect( Rectf( getWindowBounds() ) );
	mFbo[ 0 ].unbindTexture();
	
	gl::color( ColorAf( Colorf::white(), 0.8f ) );
	mFbo[ 2 ].bindTexture();
	gl::drawSolidRect( Rectf( getWindowBounds() ) );
	mFbo[ 2 ].unbindTexture();
	gl::disableAlphaBlending();
	gl::disable( GL_TEXTURE_2D );

	// Draw the interface
	mParams.draw();
}
コード例 #4
0
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();	
}
コード例 #5
0
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();	
}
コード例 #6
0
void BulletTestApp::setup()
{
	mDragging	= false;
	mFrameRate	= 0.0f;
	mTest		= 9;
	mTestPrev	= mTest;

	// Set up lighting
	mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
	mLight->setAmbient( ColorAf( 0.2f, 0.2f, 0.2f, 1.0f ) );
	mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
	mLight->enable();

	// Load meshes
	loadModels();

	// Create a Bullet dynamics world
	mWorld = bullet::createWorld();

	// Load texture
	mTexSquare	= gl::Texture( loadImage( loadResource( RES_TEX_SQUARE ) ) );
	mTexSphere	= gl::Texture( loadImage( loadResource( RES_TEX_SPHERE ) ) );
	mTexTerrain	= gl::Texture( loadImage( loadResource( RES_TEX_TERRAIN ) ) );
	mTexTerrain.setWrap( GL_REPEAT, GL_REPEAT );
	mTexTerrain.unbind();

	// Init terrain pointer
	mTerrain = 0;

	// Parameters
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 120 ) );
	mParams.addParam( "Frame Rate",		&mFrameRate,								"", true );
	mParams.addParam( "Test",			&mTest,										"min=0 max=9 step=1 keyDecr=t keyIncr=T" ); 
	mParams.addButton( "Drop",			bind( &BulletTestApp::drop, this ),			"key=space" );
	mParams.addButton( "Screen shot",	bind( &BulletTestApp::screenShot, this ),	"key=s" );
	mParams.addButton( "Quit",			bind( &BulletTestApp::quit, this ),			"key=q" );

	// Initialize
	initTest();

	// Run first resize to initialize view
	resize( ResizeEvent( getWindowSize() ) );

}
コード例 #7
0
ファイル: UiApp.cpp プロジェクト: imclab/Cinder-LeapMotion
// Render
void UiApp::draw()
{
	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( Colorf::white() );
	gl::setMatricesWindow( getWindowSize() );
	gl::color( ColorAf::white() );
	
	// Make PNG backgrounds transparent
	gl::enableAlphaBlending();
	gl::disableDepthRead();
	gl::disableDepthWrite();
	
	// Master offset
	gl::pushMatrices();
	
	// Draw buttons
	for ( size_t i = 0; i < 3; ++i ) {
		bool pressed = mButtonState[ i ];
		gl::pushMatrices();
		gl::translate( mButtonPosition[ i ] );
		gl::draw( mButton[ pressed ? 1 : 0 ] );
		gl::popMatrices();
	}
	
	// Draw slider
	gl::pushMatrices();
	gl::translate( mTrackPosition );
	gl::draw( mTrack );
	gl::popMatrices();
	gl::pushMatrices();
	gl::translate( mSliderPosition );
	gl::draw( mSlider );
	gl::popMatrices();
	
	// Draw cursor
	if ( mCursorType != CursorType::NONE ) {
		gl::color( ColorAf::white() );
		gl::pushMatrices();
		gl::translate( mCursorPosition );
		gl::draw( mTexture[ (size_t)mCursorType ] );
		gl::popMatrices();
	}
	
	gl::popMatrices();
	
	// Draw finger position for pressing buttons
	if ( mCursorType == CursorType::TOUCH )
	{
		gl::color( ColorAf( 1.0f, 0.7f, 0.0f ) );
		gl::drawSolidCircle( mFingerTipPosition, 20.0f );
		gl::drawStrokedCircle( mFingerTipPosition, 40.0f );
	}
	
	// Draw the interface
	mParams.draw();
}
コード例 #8
0
void BulletTestApp::setup()
{

	// Set test mode
	mTest = 0;
	mTestPrev = mTest;

	// Set up lighting
	mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
	mLight->setAmbient( ColorAf( 0.2f, 0.2f, 0.2f, 1.0f ) );
	mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
	mLight->enable();

	// Load meshes
	loadModels();

	// Create a Bullet dynamics world
	mWorld = bullet::createWorld();

	// Load texture
	mTexSquare = gl::Texture( loadImage( loadResource( RES_TEX_SQUARE ) ) );
	mTexSphere = gl::Texture( loadImage( loadResource( RES_TEX_SPHERE ) ) );
	mTexTerrain = gl::Texture( loadImage( loadResource( RES_TEX_TERRAIN ) ) );
	mTexTerrain.setWrap( GL_REPEAT, GL_REPEAT );
	mTexTerrain.unbind();

	// Init terrain pointer
	mTerrain = 0;

	// Parameters
	mFrameRate = 0.0f;
	mParams = params::InterfaceGl( "Params", Vec2i( 150, 100) );
	mParams.addParam( "Frame Rate", &mFrameRate, "", true );
	mParams.addParam( "Test", &mTest, "min=0 max=7 step=1 keyDecr=d keyIncr=D" ); 

	// Initialize
	initTest();

	// Run first resize to initialize view
	resize( ResizeEvent( getWindowSize() ) );

}
コード例 #9
0
ファイル: UiApp.cpp プロジェクト: gaborpapp/Cinder-LeapSdk
// Render
void UiApp::draw()
{
	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( Colorf::white() );
	gl::setMatrices( mCamera );
	
	// Make PNG backgrounds transparent
	gl::enableAlphaBlending();
	gl::disableDepthRead();
	gl::disableDepthWrite();
	
	// Master offset
	gl::pushMatrices();
	gl::translate( mOffset );
	
	// Draw buttons
	for ( size_t i = 0; i < 3; ++i ) {
		bool pressed = mButtonState[ i ];
		gl::pushMatrices();
		gl::translate( mButtonPosition[ i ] );
		gl::draw( mButton[ pressed ? 1 : 0 ] );
		gl::popMatrices();
	}
	
	// Draw slider
	gl::pushMatrices();
	gl::translate( mTrackPosition );
	gl::draw( mTrack );
	gl::popMatrices();
	gl::pushMatrices();
	gl::translate( mSliderPosition );
	gl::draw( mSlider );
	gl::popMatrices();
	
	// Draw cursor
	if ( mCursorType != CursorType::NONE ) {
		gl::color( ColorAf::white() );
		gl::pushMatrices();
		gl::translate( mCursorPosition );
		gl::draw( mTexture[ (size_t)mCursorType ] );
		gl::popMatrices();
	}
	
	gl::popMatrices();
	
	// Draw the interface
	mParams.draw();
}
コード例 #10
0
void BulletTestApp::setup()
{
    // Set up lighting
    mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
    mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
    mLight->setAmbient( ColorAf( 0.2f, 0.2f, 0.2f, 1.0f ) );
    mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
    mLight->enable();

    // Load meshes
    loadModels();

    // Create a Bullet dynamics world
    mWorld = bullet::createWorld();

    // Load texture
    mTexGround     = gl::Texture( loadImage( loadResource( RES_TEX_GROUND     )));
    mTexBackBoard  = gl::Texture( loadImage( loadResource( RES_TEX_BACKBOARD  )));
    mTexRing       = gl::Texture( loadImage( loadResource( RES_TEX_RING       )));
    mTexBasketBall = gl::Texture( loadImage( loadResource( RES_TEX_BASKETBALL )));

    // Parameters
    mFrameRate      = 0.0f;
    mPoint          = 0;
    mViewX          = -27;
    mViewY          = -64;
    mViewZ          = 0;
    mStrengthX      = 0;
    mStrengthY      = 44;
    mStrengthZ      = 33;
// 	mStrengthY      = 0;
// 	mStrengthZ      = 0;
    mParams = params::InterfaceGl( "Params", Vec2i( 200, 250) );
    mParams.addParam( "Frame Rate", &mFrameRate, "", true );
    mParams.addParam( "Point"     , &mPoint    , "", true );
    mParams.addText ( "View" );
    mParams.addParam( "view_x"             , &mViewX, "min=-100 max=100 step=1 keyIncr=7 keyDecr=4" );
    mParams.addParam( "view_y"             , &mViewY, "min=-100 max=100 step=1 keyIncr=8 keyDecr=5" );
    mParams.addParam( "view_z"             , &mViewZ, "min=-100 max=100 step=1 keyIncr=9 keyDecr=6" );
    mParams.addText ( "Strength" );
    mParams.addParam( "strength_x"         , &mStrengthX, "min=-100 max=100 step=1 keyIncr=q keyDecr=a" );
    mParams.addParam( "strength_y"         , &mStrengthY, "min=-100 max=100 step=1 keyIncr=w keyDecr=s" );
    mParams.addParam( "strength_z"         , &mStrengthZ, "min=-100 max=100 step=1 keyIncr=e keyDecr=d" );

    // Initialize
    initTest();

    // Run first resize to initialize view
    resize( ResizeEvent( getWindowSize() ) );
}
コード例 #11
0
ファイル: Fluid2DRGBApp.cpp プロジェクト: andrewfb/CinderFx
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();
}
コード例 #12
0
void BulletTestApp::draw()
{
	gl::enableDepthRead();
	gl::enableDepthWrite();

	gl::setViewport( getWindowBounds() );
	gl::clear( ColorAf::black() );
	gl::setMatrices( mCamera );
	gl::pushMatrices();
	gl::rotate( Vec3f( -45.0f, 0.0f, 0.0f ) );
	uint32_t i = 0;

	for ( bullet::Iter iter = mWorld->begin(); iter != mWorld->end(); ++iter, ++i ) {
		gl::pushMatrices();
		glMultMatrixf( iter->getTransformMatrix() );
		bindTexture( i );
		
		switch ( iter->getPrimitiveType() ) {
		case CollisionObject::PRIMITIVE_BOX:
			gl::draw( mCube );
			break;
		case CollisionObject::PRIMITIVE_CONE:
			gl::draw( mCone );
			break;
		case CollisionObject::PRIMITIVE_CYLINDER:
			gl::draw( mCylinder );
			break;
		case CollisionObject::PRIMITIVE_SPHERE:
			gl::draw( mSphere );
			break;
		default:
			if ( iter->isMeshBody() ) {
				gl::draw( bullet::calcTriMesh( iter ) );
			}
			break;
		}

		unbindTexture( i );
		gl::popMatrices();
	}
	gl::popMatrices();

	mParams.draw();
}
コード例 #13
0
void BulletTestApp::draw()
{
	gl::setViewport( getWindowBounds() );
	gl::clear( ColorAf::black() );
	gl::setMatrices( mCamera );
	gl::pushMatrices();
	gl::rotate( Vec3f( -45.0f, 0.0f, 0.0f ) );
	uint32_t i = 0;
	for ( bullet::Iter object = mWorld->begin(); object != mWorld->end(); ++object, i++ ) {
		gl::pushMatrices();
		glMultMatrixf( object->getTransformMatrix() );
		bindTexture( i );
		gl::draw( object->getVboMesh() );
		unbindTexture( i );
		gl::popMatrices();
	}
	gl::popMatrices();

	mParams.draw();
}
コード例 #14
0
void cinderFFmpegApp::draw()
{
	Rectf imgRect;
	int posX;
	int posY;

	gl::clear();
	
	for(int i=0; i<m_Players.size(); i++)
	{
		if(m_Players[i]->hasVideo()) //&& m_Players[i]->isNewFrame())
		{	
		//	m_Players[i]->update();
			unsigned char* pImg = m_Players[i]->getVideoData().m_pData;
			if(pImg != nullptr)
			{		
				m_VideoTextures[i] = gl::Texture(ci::Surface(pImg, m_Players[i]->getWidth(), m_Players[i]->getHeight(), m_Players[i]->getWidth() * 3, ci::SurfaceChannelOrder::RGB) );
			}
		}
		posX = (i % m_iTilesDivisor) * m_iTileWidth;
		posY = ((int(float(i) / float(m_iTilesDivisor))) % m_iTilesDivisor) * m_iTileHeight;
		Rectf imgRect = Rectf(posX, posY, posX + m_iTileWidth, posY + m_iTileHeight);
		if(m_VideoTextures[i])
			ci::gl::draw( m_VideoTextures[i] , imgRect);
	}
	
	// draw green selection frame
	if(m_Players.size()>0)
	{
		posX = (m_iCurrentVideo % m_iTilesDivisor) * m_iTileWidth;
		posY = ((int(float(m_iCurrentVideo) / float(m_iTilesDivisor))) % m_iTilesDivisor) * m_iTileHeight;
		gl::color(0,1,0,1);
		glLineWidth(3);
		gl::drawStrokedRect(Rectf(posX, posY, posX + m_iTileWidth, posY + m_iTileHeight));
		gl::color(1,1,1,1);
	}
			
	// draw fps and gui
	gl::drawString( toString(getAverageFps()), Vec2f( float(getWindowWidth() - 240), 10.0 ), Color(1,0,0), m_Font);
	m_Gui.draw();
}
コード例 #15
0
void Fluid2DCamAppApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	gl::color( Colorf::white() );
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );
	
	if( mTexCam ) {
		gl::draw( mTexCam, Rectf( 0*kDrawScale*mFluid2DResX, 0*kDrawScale*mFluid2DResY, 1*kDrawScale*mFluid2DResX, 1*kDrawScale*mFluid2DResY ) );
	}

	gl::draw( mTexVel0, Rectf( 0*kDrawScale*mFluid2DResX, 1*kDrawScale*mFluid2DResY, 1*kDrawScale*mFluid2DResX, 2*kDrawScale*mFluid2DResY ) );
	gl::draw( mTexVel1, Rectf( 1*kDrawScale*mFluid2DResX, 1*kDrawScale*mFluid2DResY, 2*kDrawScale*mFluid2DResX, 2*kDrawScale*mFluid2DResY ) );
	gl::draw( mTexDen0, Rectf( 2*kDrawScale*mFluid2DResX, 1*kDrawScale*mFluid2DResY, 3*kDrawScale*mFluid2DResX, 2*kDrawScale*mFluid2DResY ) );
	gl::draw( mTexDen1, Rectf( 3*kDrawScale*mFluid2DResX, 1*kDrawScale*mFluid2DResY, 4*kDrawScale*mFluid2DResX, 2*kDrawScale*mFluid2DResY ) );

	gl::draw( mTexDiv,     Rectf( 0*kDrawScale*mFluid2DResX, 2*kDrawScale*mFluid2DResY, 1*kDrawScale*mFluid2DResX, 4*kDrawScale*mFluid2DResY ) );
	gl::draw( mTexPrs,     Rectf( 1*kDrawScale*mFluid2DResX, 2*kDrawScale*mFluid2DResY, 2*kDrawScale*mFluid2DResX, 4*kDrawScale*mFluid2DResY ) );
	gl::draw( mTexCurl,    Rectf( 2*kDrawScale*mFluid2DResX, 2*kDrawScale*mFluid2DResY, 3*kDrawScale*mFluid2DResX, 4*kDrawScale*mFluid2DResY ) );
	gl::draw( mTexCurlLen, Rectf( 3*kDrawScale*mFluid2DResX, 2*kDrawScale*mFluid2DResY, 4*kDrawScale*mFluid2DResX, 4*kDrawScale*mFluid2DResY ) );

	mTexCurlLen.unbind();

	gl::color( Color( 1, 0, 0 ) );
	glLineWidth( 0.5f );
	glBegin( GL_LINES );
		glVertex2f( Vec2f( 0, 1*kDrawScale*mFluid2DResY ) );
		glVertex2f( Vec2f( (float)getWindowWidth(), 1*kDrawScale*mFluid2DResY ) );
		glVertex2f( Vec2f( 0, 2*kDrawScale*mFluid2DResY ) );
		glVertex2f( Vec2f( (float)getWindowWidth(), 2*kDrawScale*mFluid2DResY ) );

		glVertex2f( Vec2f( 1*kDrawScale*mFluid2DResX, 0 ) );
		glVertex2f( Vec2f( 1*kDrawScale*mFluid2DResX, (float)getWindowHeight() ) );
		glVertex2f( Vec2f( 2*kDrawScale*mFluid2DResX, 0 ) );
		glVertex2f( Vec2f( 2*kDrawScale*mFluid2DResX, (float)getWindowHeight() ) );
		glVertex2f( Vec2f( 3*kDrawScale*mFluid2DResX, 0 ) );
		glVertex2f( Vec2f( 3*kDrawScale*mFluid2DResX, (float)getWindowHeight() ) );
	glEnd();
	mParams.draw();
}
コード例 #16
0
// Render
void GestureApp::draw()
{
	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( mBackgroundColor + Colorf::gray( mBackgroundBrightness ) );
	gl::setMatricesWindow( getWindowSize() );
	gl::enableAlphaBlending();
	gl::color( Colorf::white() );
	
	// Draw everything
	gl::pushMatrices();
	gl::translate( mOffset );
	
	drawUi();
	drawGestures();
	drawPointables();
	
	gl::popMatrices();
	
	// Draw the interface
	mParams.draw();
}
コード例 #17
0
void BulletTestApp::draw()
{
    gl::setViewport( getWindowBounds() );
    gl::clear( ColorAf::black() );
    gl::setMatrices( mCamera );
    gl::pushMatrices();
    gl::rotate( Vec3f( (float)mViewX, (float)mViewY, (float)mViewZ ) );
    uint32_t i = 0;
    for( bullet::Iter object = mWorld->begin(); object != mWorld->end(); ++object, i++ )
    {
        TextureType type = TT_GROUND;

        if( i == 0 )
            type = TT_GROUND;
        else if( i == 1 )
            type = TT_BACKBOARD;
        else if( i == 2 || i == 3 )
            type = TT_RING;
        else
            type = TT_BASKETBALL;

        gl::pushMatrices();
        glMultMatrixf( object->getTransformMatrix() );
        bindTexture( type );
        gl::draw( object->getVboMesh() );
        unbindTexture( type );
        gl::popMatrices();
    }

    // draw the same torus
//	gl::translate( Vec3f( 0.0f, 13.0f, 0.0f ));
//	gl::rotate( Quatf( 0.0f, 0.0f, 1.14f, 1.0f ));
//	gl::drawTorus( 20, 3, 200, 200 );

    gl::popMatrices();

    mParams.draw();
}
コード例 #18
0
void Fluid2DParticleSoupApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );
	gl::enableAdditiveBlending();
	
	gl::color( 1.0f, 1.0f, 1.0f, 1.0f );

	// Uncomment to see underlining density
	/*
	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( surf );
	} else {
		mTex.update( surf );
	}
	gl::draw( mTex, getWindowBounds() );
	mTex.unbind();
	*/

	mParticleSoup.draw();
	mParams.draw();
}
コード例 #19
0
void cinderFFmpegApp::setupGui()
{
	std::stringstream strTmp;
	m_Gui = ci::params::InterfaceGl("FFmpeg Player", ci::Vec2i(300,340));

	// Video / Audio Infos
	m_Gui.addButton( "open", std::bind( &cinderFFmpegApp::open, this ) );
	m_Gui.addButton( "clear all", std::bind( &cinderFFmpegApp::clearAll, this ) );

	m_Gui.addSeparator();
	strTmp << "label='file: '";
	m_Gui.addText("file", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='video codec: '";
	m_Gui.addText("video codec", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='audio codec: '";
	m_Gui.addText("audio codec", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='width: '";
	m_Gui.addText("width", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='height: '";
	m_Gui.addText("height", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='fps: '";
	m_Gui.addText("fps", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='bitrate: '";
	m_Gui.addText("bitrate", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='audio channels: '";
	m_Gui.addText("audio channels", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='audio sample rate: '";
	m_Gui.addText("audio sample rate", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='frame: '";
	m_Gui.addText("frame", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='time: '";
	m_Gui.addText("time", strTmp.str());
	m_Gui.addSeparator();
	m_Gui.addButton( "play/pause", std::bind( &cinderFFmpegApp::pause, this ) );
	m_Gui.addButton( "stop", std::bind( &cinderFFmpegApp::stop, this ) );
	m_Gui.addButton( "toggle direction", std::bind( &cinderFFmpegApp::toggleDirection, this ) );
	m_Gui.addSeparator();
	m_Gui.addParam("speed", &m_fSpeed, "min=0 max=8.0 step=0.05");
	m_Gui.addParam("0..none, 1..loop, 2..loopBidi", &m_iLoopMode, "min=0 max=2 step=1");
	m_Gui.addParam("seek frame", &m_fSeekPos, "min=0.0 max=1.0 step=0.01");
}
コード例 #20
0
void cinderFFmpegApp::updateGui()
{
	// Video / Audio Infos
	// update dynamic info of video/audio
	std::stringstream strTmp;
	strTmp << "label='file:  " << m_Players[m_iCurrentVideo]->getFileName() << "'";
	m_Gui.setOptions( "file", strTmp.str() );
	strTmp.clear();	strTmp.str("");
	strTmp << "label='frame:  " << m_Players[m_iCurrentVideo]->getCurrentFrameNumber() << "/" << m_Players[m_iCurrentVideo]->getDurationInFrames() << "'";
	m_Gui.setOptions( "frame", strTmp.str() );
	strTmp.clear();	strTmp.str("");
	strTmp << "label='time:  " << m_Players[m_iCurrentVideo]->getCurrentTimeInMs() << ":" << m_Players[m_iCurrentVideo]->getDurationInMs() << "'";
	m_Gui.setOptions( "time", strTmp.str() );
	strTmp.clear();	strTmp.str("");
	strTmp << "label='video codec: " << m_Players[m_iCurrentVideo]->getVideoCodecName() << "'";
	m_Gui.setOptions("video codec", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='audio codec: " << m_Players[m_iCurrentVideo]->getAudioCodecName() << "'";
	m_Gui.setOptions("audio codec", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='width: " << m_Players[m_iCurrentVideo]->getWidth() << "'";
	m_Gui.setOptions("width", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='height: " << m_Players[m_iCurrentVideo]->getHeight() << "'";
	m_Gui.setOptions("height", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='fps: " << m_Players[m_iCurrentVideo]->getFps() << "'";
	m_Gui.setOptions("fps", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='bitrate:  " << m_Players[m_iCurrentVideo]->getBitrate() << "'";
	m_Gui.setOptions("bitrate", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='audio channels:  " << m_Players[m_iCurrentVideo]->getAudioChannels() << "'";
	m_Gui.setOptions("audio channels", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='audio sample rate:  " << m_Players[m_iCurrentVideo]->getAudioSampleRate() << "'";
	m_Gui.setOptions("audio sample rate", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='frame:  " << m_Players[m_iCurrentVideo]->getCurrentFrameNumber() << "/" << m_Players[m_iCurrentVideo]->getDurationInFrames() << "'";
	m_Gui.setOptions("frame", strTmp.str());
	strTmp.clear();	strTmp.str("");
	strTmp << "label='time:  " << m_Players[m_iCurrentVideo]->getCurrentTimeInMs() << "/" << m_Players[m_iCurrentVideo]->getDurationInMs() << "'";
	m_Gui.setOptions("time", strTmp.str());
}
コード例 #21
0
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;
}
コード例 #22
0
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;
	}
}
コード例 #23
0
ファイル: UiApp.cpp プロジェクト: gaborpapp/Cinder-LeapSdk
// Set up
void UiApp::setup()
{
	glShadeModel( GL_FLAT );
	
	// Set up camera
	mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 45.0f, 0.01f, 1000.0f );
	mOffset = Vec3f( 240.0f, -480.0f, 0.0f );
	
	// Start device
	mLeap = Device::create();
	mLeap->addCallback( &UiApp::onFrame, this );
	
	// Load cursor textures
	for ( size_t i = 0; i < 3; ++i ) {
		switch ( (CursorType)i ) {
			case CursorType::GRAB:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_GRAB ) ) );
				break;
			case CursorType::HAND:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_HAND ) ) );
				break;
			case CursorType::TOUCH:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_TOUCH ) ) );
				break;
			case NONE:
				break;
		}
		mTexture[ i ].setFlipped( true );
		mTexture[ i ].setMagFilter( GL_NEAREST );
		mTexture[ i ].setMinFilter( GL_NEAREST );
	}
	
	// Initialize cursor
	mCursorType				= CursorType::NONE;
	mCursorPosition			= Vec3f::zero();
	mCursorPositionTarget	= Vec3f::zero();
	
	// Load UI textures
	mButton[ 0 ]	= gl::Texture( loadImage( loadResource( RES_TEX_BUTTON_OFF ) ) );
	mButton[ 1 ]	= gl::Texture( loadImage( loadResource( RES_TEX_BUTTON_ON ) ) );
	mSlider			= gl::Texture( loadImage( loadResource( RES_TEX_SLIDER ) ) );
	mTrack			= gl::Texture( loadImage( loadResource( RES_TEX_TRACK ) ) );

	// Flip textures
	mButton[ 0 ].setFlipped( true );
	mButton[ 1 ].setFlipped( true );
	mSlider.setFlipped( true );
	mTrack.setFlipped( true );
	
	// Disable anti-aliasing
	mButton[ 0 ].setMagFilter( GL_NEAREST );
	mButton[ 0 ].setMinFilter( GL_NEAREST );
	mButton[ 1 ].setMagFilter( GL_NEAREST );
	mButton[ 1 ].setMinFilter( GL_NEAREST );
	mSlider.setMagFilter( GL_NEAREST );
	mSlider.setMinFilter( GL_NEAREST );
	mTrack.setMagFilter( GL_NEAREST );
	mTrack.setMinFilter( GL_NEAREST );
	
	// Initialize buttons
	Vec3f position( -120.0f, 950.0f, 0.0f );
	for ( size_t i = 0; i < 3; ++i, position.x += 320.0f ) {
		mButtonPosition[ i ]	= position;
		mButtonState[ i ]		= false;
	}
	
	// Initialize sliider
	mTrackPosition		= Vec3f( 0.0f, 700.0f, 0.0f );
	mSliderPosition		= mTrackPosition;
	mSliderPosition.y	-= 45.0f;
	
	// Params
	mFrameRate	= 0.0f;
	mFullScreen	= false;
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 105 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,						"", true );
	mParams.addParam( "Full screen",	&mFullScreen,						"key=f"		);
	mParams.addButton( "Screen shot",	bind( &UiApp::screenShot, this ),	"key=space" );
	mParams.addButton( "Quit",			bind( &UiApp::quit, this ),			"key=q" );
}
コード例 #24
0
void Fluid2DParticleSoupApp::setup()
{
	glEnable( GL_TEXTURE_2D );

	mDenScale = 50;
	mRgbScale = 40;

	mFluid2D.set( 192, 192 );
   	mFluid2D.setDensityDissipation( 0.99f );
	mFluid2D.setRgbDissipation( 0.99f ); 
	mVelScale = 3.0f*std::max( mFluid2D.resX(), mFluid2D.resY() );
	
	mParams = params::InterfaceGl( "Params", Vec2i( 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.addParam( "Rgb Input Scale", &mRgbScale, "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( "Rgb Dissipation", mFluid2D.rgbDissipationAddr(), "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( "Rgb Viscosity", mFluid2D.rgbViscosityAddr(), "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" );
	
	mFluid2D.setRgbDissipation( 0.9930f );
	mFluid2D.enableDensity();
	mFluid2D.enableRgb();
	mFluid2D.enableVorticityConfinement();
	mFluid2D.initSimData();

	mParticleSoup.setup( &mFluid2D );

	mColor = Colorf( 0.98f, 0.7f, 0.4f );
}
コード例 #25
0
ファイル: LeapApp.cpp プロジェクト: gaborpapp/Cinder-LeapSdk
// Render
void LeapApp::draw()
{
	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( Colorf::white() );
	gl::setMatrices( mCamera );

	// Enable depth
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();
	
	// Iterate through hands
	float headLength = 6.0f;
	float headRadius = 3.0f;
	for ( const auto& handIter : mHands ) {
		const Hand& hand = handIter.second;

		// Hand sphere
		gl::enableWireframe();
		gl::color( ColorAf( Colorf::gray( 0.9f ), 0.5f ) );
		gl::drawSphere( hand.getSpherePosition(), hand.getSphereRadius(), 16 );
		gl::disableWireframe();

		// Hand plane
		gl::color( ColorAf( 0.75f, 0.0f, 0.75f, 0.25f ) );
		gl::pushMatrices();
		gl::translate( hand.getPosition() );
		gl::rotate( Quatf( hand.getPosition(), hand.getDirection() ) );
		for ( float i = 0.25f; i <= 1.0f; i += 0.25f ) {
			gl::drawStrokedCircle( Vec2f::zero(), hand.getSphereRadius() * i, 16 );
		}
		gl::popMatrices();

		// Hand direction
		gl::color( 1.0f, 0.0f, 1.0f, 0.5f );
		gl::drawVector( hand.getPosition(), hand.getPosition() + hand.getDirection() * 30.0f, headLength, headRadius );

		// Hand normal
		gl::color( 0.0f, 0.0f, 1.0f, 0.5f );
		gl::drawVector( hand.getPosition(), hand.getPosition() + hand.getNormal() * 30.0f, headLength, headRadius );

		// Hand velocity
		gl::color( 0.0f, 1.0f, 0.0f, 0.5f );
		gl::drawVector( hand.getPosition(), hand.getPosition() + hand.getVelocity() * 0.05f, headLength, headRadius );

		// Fingers
		const FingerMap& fingers = hand.getFingers();
		for ( const auto& fingerIter : fingers ) {
			const Finger& finger = fingerIter.second;

			// Finger
			Vec3f position = finger.getPosition() + finger.getDirection() * finger.getLength();
			gl::color( ColorAf::gray( 0.3f ) );
			gl::drawLine( finger.getPosition(), position );

			// Finger tip
			gl::color( ColorAf::black() );
			gl::pushMatrices();
			gl::translate( position );
			gl::drawStrokedCircle( Vec2f::zero(), finger.getWidth(), 16 );
			gl::popMatrices();

			// Finger velocity
			gl::color( 0.0f, 1.0f, 0.0f, 0.5f );
			gl::drawVector( position, position + finger.getVelocity() * 0.05f, headLength, headRadius );
		}
		
		// Tools
		const ToolMap& tools = hand.getTools();
		for ( const auto& toolIter : tools ) {
			const Finger& tool = toolIter.second;
			
			// Tool
			Vec3f position = tool.getPosition() + tool.getDirection() * tool.getLength();
			gl::color( ColorAf( 1.0f, 0.0f, 0.0f, 0.3f ) );
			gl::drawLine( tool.getPosition(), position );
			
			// Tool tip
			gl::color( ColorAf( 1.0f, 0.0f, 0.0f, 1.0f ) );
			gl::pushMatrices();
			gl::translate( position );
			gl::drawStrokedCircle( Vec2f::zero(), tool.getWidth(), 16 );
			gl::popMatrices();
			
			// Tool velocity
			gl::color( 0.0f, 1.0f, 0.0f, 0.5f );
			gl::drawVector( position, position + tool.getVelocity() * 0.05f, headLength, headRadius );
		}
	}
	
	// Draw the interface
	mParams.draw();
}
コード例 #26
0
void VboMeshSampleApp::setup()
{
	// Setting an unrealistically high frame rate effectively
	// disables frame rate limiting
	setFrameRate( 10000.0f );
	setWindowSize( 800, 600 );

	// Set up OpenGL to work with default lighting
	glShadeModel( GL_SMOOTH );
	gl::enable( GL_POLYGON_SMOOTH );
	glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
	gl::enable( GL_NORMALIZE );
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();

	// Load the texture map
	mTexture = gl::Texture( loadImage( loadResource( RES_TEXTURE ) ) );

	// Define properties
	mFrameRate			= 0.0f;
	mFullScreen			= false;
	mLightEnabled		= true;
	mMeshIndex			= 0;
	mNumSegments		= 48;
	mNumSegmentsPrev	= mNumSegments;
	mScale				= Vec3f::one();
	mTextureEnabled		= true;
	mWireframe			= false;
	
	// Set up the arcball
	mArcball = Arcball( getWindowSize() );
	mArcball.setRadius( (float)getWindowHeight() * 0.5f );
	
	// Set up the camera
	mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 0.0001f, 10.0f );
	mCamera.lookAt( Vec3f( 0.0f, 0.0f, -5.0f ), Vec3f::zero() );

	// Set up the light
	mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLight->setAmbient( ColorAf::white() );
	mLight->setDiffuse( ColorAf::white() );
	mLight->setDirection( Vec3f::one() );
	mLight->setPosition( Vec3f::one() * -1.0f );
	mLight->setSpecular( ColorAf::white() );
	mLight->enable();

	// Define the mesh titles for the params GUI
	mMeshTitles.push_back( "Cube" );
	mMeshTitles.push_back( "Sphere" );
	mMeshTitles.push_back( "Cylinder" );
	mMeshTitles.push_back( "Cone" );
	mMeshTitles.push_back( "Circle" );
	mMeshTitles.push_back( "Square" );
	mMeshTitles.push_back( "Ring" );
	mMeshTitles.push_back( "Custom" );

	// Set up the params GUI
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 320 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,									"", true									);
	mParams.addSeparator();
	mParams.addParam( "Enable light",	&mLightEnabled,									"key=l"										);
	mParams.addParam( "Enable texture",	&mTextureEnabled,								"key=t"										);
	mParams.addParam( "Mesh type",		mMeshTitles, &mMeshIndex,						"keyDecr=m keyIncr=M"						);
	mParams.addParam( "Scale",			&mScale																						);
	mParams.addParam( "Segments",		&mNumSegments,									"keyDecr=s keyIncr=S min=3 max=1024 step=1"	);
	mParams.addParam( "Wireframe",		&mWireframe,									"key=w"										);
	mParams.addSeparator();
	mParams.addParam( "Full screen",	&mFullScreen,									"key=f"										);
	mParams.addButton( "Screen shot",	bind( &VboMeshSampleApp::screenShot, this ),	"key=space"									);
	mParams.addButton( "Quit",			bind( &VboMeshSampleApp::quit, this ),			"key=q"										);

	// Generate meshes
	createMeshes();
}
コード例 #27
0
// Set up
void KinectApp::setup()
{

	// Set up OpenGL
	glLineWidth( 2.0f );
	gl::color( ColorAf::white() );

	// Set up camera
	mCamera.lookAt( Vec3f( 0.0f, 0.0f, -3.0f ), Vec3f::zero() );
	mCamera.setPerspective( 45.0f, getWindowAspectRatio(), 1.0f, 1000.0f );

	// Define drawing body
	defineBody();

	// Initialize parameters
	mBinaryMode = false;
	mBinaryModePrev = mBinaryMode;
	mCapture = true;
	mCapturePrev = mCapture;
	mDeviceCount = 0;
	mEnabledAudio = true;
	mEnabledAudioPrev = true;
	mEnabledDepth = true;
	mEnabledDepthPrev = mEnabledDepth;
	mEnabledNearMode = false;
	mEnabledNearModePrev = mEnabledNearMode;
	mEnabledSkeletons = true;
	mEnabledSkeletonsPrev = mEnabledSkeletons;
	mEnabledStats = true;
	mEnabledVideo = true;
	mEnabledVideoPrev = mEnabledVideo;
	mFrameRateApp = 0.0f;
	mFrameRateDepth = 0.0f;
	mFrameRateSkeletons = 0.0f;
	mFrameRateVideo = 0.0f;
	mFullScreen = isFullScreen();
	mInverted = false;
	mInvertedPrev = mInverted;
	mRemoveBackground = false;
	mRemoveBackgroundPrev = mRemoveBackground;
	mUserCount = 0;

	// Start image capture
	startKinect();

	// Start audio capture
	startAudio();

	// Setup the parameters
	mParams = params::InterfaceGl( "Parameters", Vec2i( 245, 500 ) );
	mParams.addText( "DEVICE" );
	mParams.addParam( "Device count", & mDeviceCount, "", true );
	mParams.addParam( "Device angle", & mCameraAngle, "min=-" + toString( Kinect::MAXIMUM_TILT_ANGLE ) + 
		" max=" + toString( Kinect::MAXIMUM_TILT_ANGLE ) + " step=1" );
	mParams.addSeparator();
	mParams.addText( "STATISTICS");
	mParams.addParam( "Collect statistics", & mEnabledStats, "key=t" );
	mParams.addParam( "App frame rate", & mFrameRateApp, "", true );
	mParams.addParam( "Depth frame rate", & mFrameRateDepth, "", true );
	mParams.addParam( "Skeleton frame rate", & mFrameRateSkeletons, "", true );
	mParams.addParam( "Video frame rate", & mFrameRateVideo, "", true );
	mParams.addParam( "User count", & mUserCount, "", true );
	mParams.addSeparator();
	mParams.addText( "CAPTURE" );
	mParams.addParam( "Capture", & mCapture, "key=c" );
	mParams.addParam( "Audio", & mEnabledAudio, "key=a" );
	mParams.addParam( "Depth", & mEnabledDepth, "key=d" );
	mParams.addParam( "Skeletons", & mEnabledSkeletons, "key=k" );
	mParams.addParam( "Video", & mEnabledVideo, "key=v" );
	mParams.addSeparator();
	mParams.addText( "DEPTH IMAGE");
	mParams.addParam( "Remove background", & mRemoveBackground, "key=b" );
	mParams.addParam( "Binary depth mode", & mBinaryMode, "key=w" );
	mParams.addParam( "Invert binary image", & mInverted, "key=i" );
	mParams.addParam( "Near mode", & mEnabledNearMode, "key=n" );
	mParams.addSeparator();
	mParams.addText( "APPLICATION" );
	mParams.addParam( "Full screen", & mFullScreen, "key=f" );
	mParams.addButton( "Screen shot", std::bind(& KinectApp::screenShot, this ), "key=s" );
	mParams.addButton( "Quit", std::bind( & KinectApp::quit, this ), "key=esc" );

}
コード例 #28
0
void Fluid2DParticlesApp::setup()
{
    glEnable( GL_TEXTURE_2D );
    gl::enableAlphaBlending();
    gl::enableAdditiveBlending();

    mRgbScale = 50;
    mDenScale = 50;

    mFluid2D.set( 192, 192 );
    mFluid2D.setDensityDissipation( 0.99f );
    mFluid2D.setRgbDissipation( 0.99f );
    mVelScale = 3.0f*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.addParam( "Rgb Input Scale", &mRgbScale, "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( "Rgb Dissipation", mFluid2D.rgbDissipationAddr(), "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( "Rgb Viscosity", mFluid2D.rgbViscosityAddr(), "min=0.000001 max=10 step=0.000001" );
    mParams.addSeparator();
    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" );

    mFluid2D.setDt( 0.1f );
    mFluid2D.enableDensity();
    mFluid2D.enableRgb();
    mFluid2D.enableVorticityConfinement();

    mParticles.setup( getWindowBounds(), &mFluid2D );
}
コード例 #29
0
ファイル: MeshApp.cpp プロジェクト: Asteral/Cinder-KinectSdk
// Set up
void MeshApp::setup()
{

	// Start Kinect
	mKinect = Kinect::create();
	mKinect->enableUserColor( false );
	mKinect->removeBackground();
	mKinect->start();

	// Add callbacks
	mCallbackDepthId	= mKinect->addDepthCallback(& MeshApp::onDepthData, this );
	mCallbackSkeletonId	= mKinect->addSkeletonTrackingCallback(& MeshApp::onSkeletonData, this );
	mCallbackColorId	= mKinect->addColorCallback(& MeshApp::onColorData, this );

	// Set up the light. This application does not actually use OpenGL 
	// lighting. Instead, it passes a light position and color 
	// values to the shader. Per fragment lighting is calculated in GLSL.
	mLightAmbient	= ColorAf( 0.0f, 0.0f, 0.0f, 1.0f );
	mLightDiffuse	= ColorAf( 0.5f, 0.5f, 0.5f, 1.0f );
	mLightPosition	= Vec3f( 0.0f, -600.0f, 180.0f );
	mLightShininess	= 2.0f;
	mLightSpecular	= ColorAf( 1.0f, 1.0f, 1.0f, 1.0f );

	// Set default properties
	mBrightTolerance		= 0.2f;
	mFrameRate				= 0.0f;
	mFullScreen				= isFullScreen();
	mFullScreenPrev			= mFullScreen;
	mMeshUvMix				= 0.2f;
	mRemoveBackground		= true;
	mRemoveBackgroundPrev	= mRemoveBackground;
	mScale					= Vec3f( 1.0f, 1.0f, 500.0f );
	mShowColor				= false;
	mColorOffsetX			= 0.0f;
	mColorOffsetY			= 0.0f;

	// Create the parameters bar
	mParams = params::InterfaceGl( "Parameters", Vec2i( 250, 500 ) );
	mParams.addSeparator( "" );
	mParams.addParam( "Bright tolerance",	&mBrightTolerance,					"min=0.000 max=1.000 step=0.001 keyDecr=b keyIncr=B"		);
	mParams.addParam( "Remove background",	&mRemoveBackground,					"key=c"														);
	mParams.addParam( "Scale",				&mScale																							);
	mParams.addSeparator();
	mParams.addParam( "Eye point",			&mEyePoint																						);
	mParams.addParam( "Look at",			&mLookAt																						);
	mParams.addParam( "Rotation",			&mRotation																						);
	mParams.addSeparator();
	mParams.addParam( "Show Color",			&mShowColor,						"key=d"														);
	mParams.addParam( "Color offset X",		&mColorOffsetX,						"min=0.000 max=1.000 step=0.001 keyDecr=e keyIncr=E"		);
	mParams.addParam( "Color offset Y",		&mColorOffsetY,						"min=0.000 max=1.000 step=0.001 keyDecr=f keyIncr=F"		);
	mParams.addSeparator();
	mParams.addParam( "Light position",		&mLightPosition																					);
	mParams.addParam( "Light shininess",	&mLightShininess,					"min=0.000 max=10000.000 step=0.001 keyDecr=g keyIncr=G"	);
	mParams.addSeparator();
	mParams.addParam( "Frame rate",			&mFrameRate,						"", true													);
	mParams.addParam( "Full screen",		&mFullScreen,						"key=h"														);
	mParams.addButton( "Save screen shot",	bind(& MeshApp::screenShot, this ),	"key=space"													);
	mParams.addButton( "Quit",				bind(& MeshApp::quit, this ),		"key=esc"													);

	// Initialize texture
	mTextureFormat.setInternalFormat( GL_RGBA_FLOAT32_ATI );
	mTextureDepth = gl::Texture( Surface32f( kMeshWidth, kMeshHeight, false, SurfaceChannelOrder::RGBA ), mTextureFormat );

	// Initialize mesh
	initMesh();

	// Run first window resize
	resize();

}
コード例 #30
0
ファイル: UiApp.cpp プロジェクト: imclab/Cinder-LeapMotion
// Set up
void UiApp::setup()
{
	glShadeModel( GL_FLAT );
		
	// Start device
	mDevice 		= Device::create();
	mDevice->connectEventHandler( &UiApp::onFrame, this );
	
	// Load cursor textures
	for ( size_t i = 0; i < 3; ++i ) {
		switch ( (CursorType)i ) {
			case CursorType::GRAB:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_GRAB ) ) );
				break;
			case CursorType::HAND:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_HAND ) ) );
				break;
			case CursorType::TOUCH:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_TOUCH ) ) );
				break;
			case NONE:
				break;
		}
		mTexture[ i ].setMagFilter( GL_NEAREST );
		mTexture[ i ].setMinFilter( GL_NEAREST );
	}
	
	// Initialize cursor
	mCursorType				= CursorType::NONE;
	mCursorPosition			= Vec2f::zero();
	mCursorPositionTarget	= Vec2f::zero();
	mFingerTipPosition		= Vec2i::zero();
	
	// Load UI textures
	mButton[ 0 ]	= gl::Texture( loadImage( loadResource( RES_TEX_BUTTON_OFF ) ) );
	mButton[ 1 ]	= gl::Texture( loadImage( loadResource( RES_TEX_BUTTON_ON ) ) );
	mSlider			= gl::Texture( loadImage( loadResource( RES_TEX_SLIDER ) ) );
	mTrack			= gl::Texture( loadImage( loadResource( RES_TEX_TRACK ) ) );
	
	// Disable anti-aliasing
	mButton[ 0 ].setMagFilter( GL_NEAREST );
	mButton[ 0 ].setMinFilter( GL_NEAREST );
	mButton[ 1 ].setMagFilter( GL_NEAREST );
	mButton[ 1 ].setMinFilter( GL_NEAREST );
	mSlider.setMagFilter( GL_NEAREST );
	mSlider.setMinFilter( GL_NEAREST );
	mTrack.setMagFilter( GL_NEAREST );
	mTrack.setMinFilter( GL_NEAREST );
	
	// Params
	mFrameRate	= 0.0f;
	mFullScreen	= false;
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 105 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,						"", true );
	mParams.addParam( "Full screen",	&mFullScreen,						"key=f"		);
	mParams.addButton( "Screen shot",	bind( &UiApp::screenShot, this ),	"key=space" );
	mParams.addButton( "Quit",			bind( &UiApp::quit, this ),			"key=q" );
	
	// Run resize to initialize layout
	resize();
}