Example #1
0
void triMeshApp::setup(){
	// cam, lights material
	mCam = new CameraPersp(getWindowWidth(), getWindowHeight(), 45.0f);
	mCam->lookAt( Vec3f(300, 700, -600), Vec3f(0,0,0) );
	mCam->setPerspective( 60.0f, getWindowAspectRatio(), 0.1f, 5000.0f );
	yrot = 0;
	
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_LIGHTING);
	glEnable(GL_NORMALIZE);

	mLight = new gl::Light(gl::Light::DIRECTIONAL, 0);
	mLight->setDirection( Vec3f(0,0.1,0.3).normalized());
	mLight->setAmbient( Color( 0.2f, 0.2f, 0.2f ) );
	mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->update( *mCam );
	mLight->enable();
	
	mMaterial1.setSpecular( Color(0.5,0.5,0.5) );
	mMaterial1.setDiffuse( Color( 0.0f, 1.0f, 0.0f ) );
	mMaterial1.setAmbient( Color( 0.1f, 0.1f, 0.1f ) );
	mMaterial1.setShininess( 20.0f );
	mMaterial1.apply();
	
	mMaterial2.setSpecular( Color(0,0,0) );
	mMaterial2.setDiffuse( Color(1,0,0) );
	mMaterial2.setAmbient( Color( 0.4f, 0.0f, 0.0f ) );
	mMaterial2.setEmission(Color(1,0,0));
	
	initPhysics();
	
	
	ObjLoader loader( loadResource( RES_LOSPHERE )->createStream() );
	loader.load( &mConvex );
	mVBO = gl::VboMesh( mConvex );
	
	ObjLoader loader2( loadResource( RES_TORUS )->createStream() );
	loader2.load( &mConcave );
	mVBOTerrain = gl::VboMesh( mConcave );

	btConvexHullShape* shape = bullet::createConvexHullShape(mConvex, Vec3f(CONVEX_SCALE, CONVEX_SCALE, CONVEX_SCALE));
	m_convexRigidBody = bullet::createConvexHullBody(m_dynamicsWorld, shape, Vec3f(0,500,0), 10000);
	
	btBvhTriangleMeshShape* concaveShape = bullet::createStaticConcaveMeshShape(mConcave, Vec3f(CONCAVE_SCALE, CONCAVE_SCALE, CONCAVE_SCALE), 5.0f);
	m_concaveRigidBody = bullet::createStaticRigidBody(m_dynamicsWorld, concaveShape, Vec3f(0,255,0));
	
	m_hfImage = loadImage(loadResource(RES_HEIGHTMAP));
	m_hfChannel = new Channel32f(m_hfImage);
	// note that HF_HEIGHTSCALE is ignored since we are using float data. we adjust the y-scale with the local scaling parameter only!
	btHeightfieldTerrainShape* hfShape = bullet::createHeightfieldTerrainShape(m_hfChannel, 64, 64, HF_HEIGHTSCALE, -500, 500, 1, Vec3f(HF_SCALE,HF_SCALEY,HF_SCALE));
	m_hfRigidBody = bullet::createStaticRigidBody(m_dynamicsWorld, hfShape, Vec3f(0,0,0));
	
	gl::VboMesh::Layout layout;
	layout.setDynamicColorsRGB();
	layout.setDynamicPositions();
	mVBOHeightfield = gl::VboMesh( m_hfImage.getWidth() * m_hfImage.getHeight(), 0, layout, GL_POINTS );
	
	updateData( );		
}
void DelaunayMeshMaker::fileDrop( FileDropEvent event ){
	try {
		mSurface = loadImage( event.getFile( 0 ) );

		int width = mSurface.getWidth();
		int height = mSurface.getHeight();
		app::setWindowSize( width, height );

		mFbo = gl::Fbo( width, height, false );

		mBorderPoints.clear();
		mBorderPoints.push_back( Vec2f::zero() );
		mBorderPoints.push_back( Vec2f( (float)width, 0 ) );
		mBorderPoints.push_back( Vec2f( (float)width ,(float)height ) );
		mBorderPoints.push_back( Vec2f( 0 ,(float)height ) );

		mSteinerPoints.clear();
		mMesh.clear();

		tesselate();
	}
	catch( ... ) {
		console() << "unable to load the texture file!" << std::endl;
	};
	
}
void DelaunayMeshMaker::setup()
{
	mSurface = loadImage( app::loadAsset( "texture0.jpg" ) );
	
	int width = mSurface.getWidth();
	int height = mSurface.getHeight();
	app::setWindowSize( width, height );

	mFbo = gl::Fbo( width, height, false );

	mBorderPoints.push_back( Vec2f::zero() );
	mBorderPoints.push_back( Vec2f( (float)width, 0 ) );
	mBorderPoints.push_back( Vec2f( (float)width ,(float)height ) );
	mBorderPoints.push_back( Vec2f( 0 ,(float)height ) );

	mMesh.clear();

	mParams = params::InterfaceGl( "Parameters", Vec2i( 300, 250 ) );
	mParams.addParam( "Alpha", &mAlpha, "max=1.0 min=0.0 step=0.005" );
	mParams.addParam( "Blend", &mBlend );
	mParams.addParam( "Phong Shading", &mApplyPhongShading );
	mParams.addParam( "Depth Offset", &mDepthOffset, "step=0.1" );
	mParams.addParam( "Draw wireframe", &mDrawWireframe );
	
	mParams.addSeparator();
	mParams.addText("Edge detection");
	mParams.addParam( "Edge detection scale down", &mScaleDown, "min=1" );
	mParams.addParam( "Minimum threshold", &mCannyMinThreshold, "min=0.0f" );
	mParams.addParam( "Maximum threshold", &mCannyMaxThreshold, "min=0.0f" );

	mParams.addSeparator();
	mParams.addButton( "Tesselate", std::bind( &DelaunayMeshMaker::tesselate, this ) );

	mScaleDown			= 8;
	mScaleDownPrev		= mScaleDown;
	mCannyMinThreshold	= 60.0;
	mCannyMaxThreshold	= 70.0;
	mAlpha				= 0.0f;
	mBlend				= false;
	mApplyPhongShading	= false;
	mDrawWireframe		= false;
	mDepthOffset		= 0.0f;
	mPrevDepthOffset	= mDepthOffset;
	mPrevBlend			= mBlend;

	mPhongShader = gl::GlslProg( loadAsset("phong_vert.glsl"), loadAsset("phong_frag.glsl") );

	mEdgeDetectSurface = edgeDetect( Surface8u( mSurface ), mCannyMinThreshold, mCannyMaxThreshold, mScaleDownPrev );

	mTesselator = Tesselator::makeTesselator();
	mTesselator->sDone.connect( boost::bind( &DelaunayMeshMaker::onTesselationDone, this ) );
}
Example #4
0
void BasicApp::openFile()
{
	mImage = loadImage( loadAsset( "mona.jpg" ) );

	mWidth = mImage.getWidth();
	mHeight = mImage.getHeight();

	dx::VboMesh::Layout layout;
	layout.setDynamicColorsRGB();
	layout.setDynamicPositions();
	mVboMesh = dx::VboMesh( mWidth * mHeight, 0, layout, D3D_PRIMITIVE_TOPOLOGY_POINTLIST );

	updateData( kColor );		
}
void ImageHFApp::openFile()
{
	fs::path path = getOpenFilePath( "", ImageIo::getLoadExtensions() );
	if( ! path.empty() ) {
		mImage = loadImage( path );
	 
		mWidth = mImage.getWidth();
		mHeight = mImage.getHeight();

		mVboMesh = gl::VboMesh::create( mWidth * mHeight, GL_POINTS, { gl::VboMesh::Layout().usage(GL_STATIC_DRAW).attrib(geom::POSITION, 3).attrib(geom::COLOR, 3) } );
		mPointsBatch = gl::Batch::create( mVboMesh, gl::getStockShader( gl::ShaderDef().color() ) );

		updateData( kColor );		
	}
}
Example #6
0
Texture::Texture( const Surface32f &surface, Format format )
	: mObj( shared_ptr<Obj>( new Obj( surface.getWidth(), surface.getHeight() ) ) )
{
	if( format.mInternalFormat < 0 ) {
#if ! defined( CINDER_GLES )
		if( GLEE_ARB_texture_float )
			format.mInternalFormat = surface.hasAlpha() ? GL_RGBA32F_ARB : GL_RGB32F_ARB;
		else
			format.mInternalFormat = surface.hasAlpha() ? GL_RGBA : GL_RGB;
#else
		format.mInternalFormat = surface.hasAlpha() ? GL_RGBA : GL_RGB;
#endif	
	}
	mObj->mInternalFormat = format.mInternalFormat;
	mObj->mTarget = format.mTarget;

	init( surface.getData(), surface.hasAlpha()?GL_RGBA:GL_RGB, format );	
}
Example #7
0
void triMeshApp::updateData()
{
	Surface32f::Iter pixelIter = m_hfImage.getIter();
	gl::VboMesh::VertexIter vertexIter( mVBOHeightfield );
	
	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			Color color( pixelIter.r(), pixelIter.g(), pixelIter.b() );
			float height;

			height = color.dot( Color( 0.3333f, 0.3333f, 0.3333f ) );
         

			// the x and the z coordinates correspond to the pixel's x & y
			float x = (pixelIter.x() - m_hfImage.getWidth() / 2.0f);
			float z = (pixelIter.y() - m_hfImage.getHeight() / 2.0f);
			
            vertexIter.setPosition( x * HF_SCALE, height * HF_SCALEY, z * HF_SCALE);
			vertexIter.setColorRGB( color );
			++vertexIter;
		}
	}
}
Example #8
0
Texture::Texture( const Surface32f &surface, Format format )
	: mObj( shared_ptr<Obj>( new Obj( surface.getWidth(), surface.getHeight() ) ) )
{
#if defined( CINDER_MAC )
	bool supportsTextureFloat = gl::isExtensionAvailable( "GL_ARB_texture_float" );
#elif defined( CINDER_MSW )
	bool supportsTextureFloat = GLEE_ARB_texture_float != 0;
#endif

	if( format.mInternalFormat < 0 ) {
#if ! defined( CINDER_GLES )
		if( supportsTextureFloat )
			format.mInternalFormat = surface.hasAlpha() ? GL_RGBA32F_ARB : GL_RGB32F_ARB;
		else
			format.mInternalFormat = surface.hasAlpha() ? GL_RGBA : GL_RGB;
#else
		format.mInternalFormat = surface.hasAlpha() ? GL_RGBA : GL_RGB;
#endif	
	}
	mObj->mInternalFormat = format.mInternalFormat;
	mObj->mTarget = format.mTarget;

	init( surface.getData(), surface.hasAlpha()?GL_RGBA:GL_RGB, format );	
}