void kinectPointCloudApp::createVbo()
{
	gl::VboMesh::Layout layout;
	
	layout.setStaticPositions();
	layout.setStaticTexCoords2d();
	layout.setStaticIndices();
	
	std::vector<Vec3f> positions;
	std::vector<Vec2f> texCoords;
	std::vector<uint32_t> indices; 
	
	int numVertices = VBO_X_RES * VBO_Y_RES;
	int numShapes	= ( VBO_X_RES - 1 ) * ( VBO_Y_RES - 1 );

	mVboMesh		= gl::VboMesh( numVertices, numShapes, layout, GL_POINTS );
	
	for( int x=0; x<VBO_X_RES; ++x ){
		for( int y=0; y<VBO_Y_RES; ++y ){
			indices.push_back( x * VBO_Y_RES + y );

			float xPer	= x / (float)(VBO_X_RES-1);
			float yPer	= y / (float)(VBO_Y_RES-1);
			
			positions.push_back( Vec3f( ( xPer * 2.0f - 1.0f ) * VBO_X_RES, ( yPer * 2.0f - 1.0f ) * VBO_Y_RES, 0.0f ) );
			texCoords.push_back( Vec2f( xPer, yPer ) );			
		}
	}
	
	mVboMesh.bufferPositions( positions );
	mVboMesh.bufferIndices( indices );
	mVboMesh.bufferTexCoords2d( 0, texCoords );
}
Example #2
0
void Controller::createSphere( gl::VboMesh &vbo, int res )
{
	float X = 0.525731112119f; 
	float Z = 0.850650808352f;
	
	static Vec3f verts[12] = {
		Vec3f( -X, 0.0f, Z ), Vec3f( X, 0.0f, Z ), Vec3f( -X, 0.0f, -Z ), Vec3f( X, 0.0f, -Z ),
		Vec3f( 0.0f, Z, X ), Vec3f( 0.0f, Z, -X ), Vec3f( 0.0f, -Z, X ), Vec3f( 0.0f, -Z, -X ),
		Vec3f( Z, X, 0.0f ), Vec3f( -Z, X, 0.0f ), Vec3f( Z, -X, 0.0f ), Vec3f( -Z, -X, 0.0f ) };
	
	static GLuint triIndices[20][3] = { 
		{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1}, {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
		{7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6}, {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
	
	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	layout.setStaticNormals();
	
	mPosCoords.clear();
	mNormals.clear();
	for( int i=0; i<20; i++ ){
		drawSphereTri( verts[triIndices[i][0]], verts[triIndices[i][1]], verts[triIndices[i][2]], res );
	}
	vbo = gl::VboMesh( mPosCoords.size(), 0, layout, GL_TRIANGLES );	
	vbo.bufferPositions( mPosCoords );
	vbo.bufferNormals( mNormals );
}
void BouncingBallsApp::setup()
{
	// randomize the random generator
	Rand::randSeed( clock() );

	//
	mUseMotionBlur = true;

	// set some kind of sensible maximum to the frame rate
	setFrameRate(100.0f);

	// initialize simulator
	mStepsPerSecond = 60;
	mStepsPerformed = 0;

	// create a single ball
	mBalls.push_back( BallRef( new Ball() ) );

	// create ball mesh ( much faster than using gl::drawSolidCircle() )
	size_t slices = 20;

	std::vector<Vec3f> positions;
	std::vector<Vec2f> texcoords;
	std::vector<uint32_t> indices;

	indices.push_back( positions.size() );
	texcoords.push_back( Vec2f(0.5f, 0.5f) );
	positions.push_back( Vec3f::zero() );

	for(size_t i=0;i<=slices;++i) {	
		float angle = i / (float) slices * 2.0f * (float) M_PI;
		Vec2f v(sinf(angle), cosf(angle));

		indices.push_back( positions.size() );
		texcoords.push_back( Vec2f(0.5f, 0.5f) + 0.5f * v );
		positions.push_back( Ball::RADIUS * Vec3f(v, 0.0f) );
	}

	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	layout.setStaticTexCoords2d();
	layout.setStaticIndices();

	mMesh = gl::VboMesh( (size_t) (slices + 2), (size_t) (slices + 2), layout, GL_TRIANGLE_FAN );
	mMesh.bufferPositions( &positions.front(), positions.size() );
	mMesh.bufferTexCoords2d(0, texcoords);
	mMesh.bufferIndices( indices );

	// load texture
	mTexture = gl::Texture( loadImage( loadAsset("ball.png") ) );

	// start simulation
	mTimer.start();
}
Example #4
0
void VboSampleApp::update()
{
    // mCamera.lookAt(Vec3f(0, 0, 5.0f), Vec3f(0, 0, 0));
	gl::setMatrices( mCamera );

    vector<Vec3f> positions;
    positions.push_back(Vec3f(-1.0f+0.2f*sin(getElapsedSeconds()), 1.0f, 0));
    positions.push_back(Vec3f(-1.0f, -1.0f, 0));
    positions.push_back(Vec3f(1.0f, -1.0f, 0));
    positions.push_back(Vec3f(1.0f, 1.0f, 0));
    mVboMesh.bufferPositions(positions);
}
void GeometryShaderApp::update()
{
	// brute-force method: recreate mesh if anything changed
	if( !mVboMesh ) {
		if( mPoints.size() > 1 ) {
			// create a new vector that can contain 3D vertices
			std::vector<Vec3f> vertices;

			// to improve performance, make room for the vertices + 2 adjacency vertices
			vertices.reserve( mPoints.size() + 2);

			// first, add an adjacency vertex at the beginning
			vertices.push_back( 2.0f * Vec3f(mPoints[0]) - Vec3f(mPoints[1]) );

			// next, add all 2D points as 3D vertices
			std::vector<Vec2f>::iterator itr;
			for(itr=mPoints.begin();itr!=mPoints.end();++itr)
				vertices.push_back( Vec3f( *itr ) );

			// next, add an adjacency vertex at the end
			size_t n = mPoints.size();
			vertices.push_back( 2.0f * Vec3f(mPoints[n-1]) - Vec3f(mPoints[n-2]) );

			// now that we have a list of vertices, create the index buffer
			n = vertices.size() - 2;
			std::vector<uint32_t> indices;
			indices.reserve( n * 4 );

			for(size_t i=1;i<vertices.size()-2;++i) {
				indices.push_back(i-1);
				indices.push_back(i);
				indices.push_back(i+1);
				indices.push_back(i+2);
			}

			// finally, create the mesh
			gl::VboMesh::Layout layout;
			layout.setStaticPositions();
			layout.setStaticIndices();

			mVboMesh = gl::VboMesh( vertices.size(), indices.size(), layout, GL_LINES_ADJACENCY_EXT );
			mVboMesh.bufferPositions( &(vertices.front()), vertices.size() );
			mVboMesh.bufferIndices( indices );
		}
		else
			mVboMesh = gl::VboMesh();
	}
}
Example #6
0
void RepulsionApp::createSphere( gl::VboMesh &vbo, int res )
{
	float X = 0.525731112119f; 
	float Z = 0.850650808352f;
	
	static Vec3f verts[12] = {
		Vec3f( -X, 0.0f, Z ), Vec3f( X, 0.0f, Z ), Vec3f( -X, 0.0f, -Z ), Vec3f( X, 0.0f, -Z ),
		Vec3f( 0.0f, Z, X ), Vec3f( 0.0f, Z, -X ), Vec3f( 0.0f, -Z, X ), Vec3f( 0.0f, -Z, -X ),
		Vec3f( Z, X, 0.0f ), Vec3f( -Z, X, 0.0f ), Vec3f( Z, -X, 0.0f ), Vec3f( -Z, -X, 0.0f ) };
	
	static GLuint triIndices[20][3] = { 
		{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1}, {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
		{7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6}, {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
	
	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	layout.setStaticNormals();
	layout.setStaticColorsRGB();
	
	mPosCoords.clear();
	mNormals.clear();
	mColors.clear();
	
	float invWidth = 1.0f/(float)FBO_WIDTH;
	float invHeight = 1.0f/(float)FBO_HEIGHT;
	for( int x = 0; x < FBO_WIDTH; ++x ) {
		for( int y = 0; y < FBO_HEIGHT; ++y ) {
			float u = ( (float)x + 0.5f ) * invWidth;
			float v = ( (float)y + 0.5f ) * invHeight;
			Colorf c = Colorf( u, v, 0.0f );
			
			for( int i=0; i<20; i++ ){
				drawSphereTri( verts[triIndices[i][0]], verts[triIndices[i][1]], verts[triIndices[i][2]], res, c );
			}
		}
	}
	vbo = gl::VboMesh( mPosCoords.size(), 0, layout, GL_TRIANGLES );	
	vbo.bufferPositions( mPosCoords );
	vbo.bufferNormals( mNormals );
	vbo.bufferColorsRGB( mColors );
	vbo.unbindBuffers();
}
Example #7
0
void CatalogApp::initFaintVbo()
{
	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	layout.setStaticColorsRGB();
	
	int numFaintStars	= mFaintStars.size();
	mFaintVbo			= gl::VboMesh( numFaintStars, 0, layout, GL_POINTS );
	vector<Vec3f> positions;
	vector<Color> colors;

	for( int i=0; i<numFaintStars; i++ ){
		positions.push_back( mFaintStars[i]->mPos );
		colors.push_back( Color( mFaintStars[i]->mColor, 0.0f, 0.0f ) );
	}
	
	mFaintVbo.bufferPositions( positions );
	mFaintVbo.bufferColorsRGB( colors );
	mFaintVbo.unbindBuffers();
}
Example #8
0
void VboSampleApp::setup()
{
    mCamera.setAspectRatio(getWindowAspectRatio());

    mTexture = bluegin::getTextureAsset("cinder_logo.png");
    mTexture.setMinFilter(GL_LINEAR);
    mTexture.setMagFilter(GL_LINEAR);

	gl::VboMesh::Layout layout;
	layout.setStaticIndices();
	layout.setStaticPositions();
    layout.setStaticTexCoords2d();

    const int vertexCount = 4;
    const int indexCount  = 6;

	mVboMesh = gl::VboMesh( vertexCount, indexCount, layout, GL_TRIANGLES );

    vector<Vec3f> positions;
    positions.push_back(Vec3f(-1.0f, 1.0f, 0));
    positions.push_back(Vec3f(-1.0f, -1.0f, 0));
    positions.push_back(Vec3f(1.0f, -1.0f, 0));
    positions.push_back(Vec3f(1.0f, 1.0f, 0));
    mVboMesh.bufferPositions(positions);

    vector<Vec2f> texcoords;
    texcoords.push_back(Vec2f(0, 0));
    texcoords.push_back(Vec2f(0, 1.0f));
    texcoords.push_back(Vec2f(1.0f, 1.0f));
    texcoords.push_back(Vec2f(1.0f, 0));
    mVboMesh.bufferTexCoords2d(0, texcoords);

    vector<index_t> indices;
    indices.push_back(index_t(0));
    indices.push_back(index_t(1));
    indices.push_back(index_t(2));
    indices.push_back(index_t(2));
    indices.push_back(index_t(3));
    indices.push_back(index_t(0));
    mVboMesh.bufferIndices(indices);
}
Example #9
0
void FolApp::createVbo()
{
    gl::VboMesh::Layout layout;

    layout.setStaticPositions();
    layout.setStaticTexCoords2d();
    layout.setStaticIndices();

    std::vector<Vec3f> positions;
    std::vector<Vec2f> texCoords;
    std::vector<uint32_t> indices;

    int numVertices = VBO_X_SIZE * VBO_Y_SIZE;
    int numShapes = ( VBO_X_SIZE - 1 ) * ( VBO_Y_SIZE - 1 );

    mVboMesh = gl::VboMesh( numVertices, numShapes, layout, GL_POINTS );

    for ( int x = 0; x < VBO_X_SIZE; x++ )
    {
        for ( int y = 0; y < VBO_Y_SIZE; y++ )
        {
            indices.push_back( x * VBO_Y_SIZE + y );
            float xPer = x / (float)( VBO_X_SIZE - 1 );
            float yPer = y / (float)( VBO_Y_SIZE - 1 );

            /*
            positions.push_back( Vec3f( ( xPer * 2.0f - 1.0f ) * VBO_X_SIZE,
            							( yPer * 2.0f - 1.0f ) * VBO_Y_SIZE,
            							0.0f ) );
            */
            positions.push_back( Vec3f( x, y, 0 ) );
            texCoords.push_back( Vec2f( xPer, yPer ) );
        }
    }

    mVboMesh.bufferPositions( positions );
    mVboMesh.bufferIndices( indices );
    mVboMesh.bufferTexCoords2d( 0, texCoords );
    //mVboMesh.unbindBuffers();
}
void AudioVisualizerApp::setup()
{
	// initialize signals
	signalChannelEnd = false;

	// make a list of valid audio file extensions and initialize audio variables
	const char* extensions[] = {"mp3", "wav", "ogg"};
	mAudioExtensions = vector<string>(extensions, extensions+2);
	mAudioPath = getAssetPath("");
	mIsAudioPlaying = false;

	// setup camera
	mCamera.setPerspective(50.0f, 1.0f, 1.0f, 10000.0f);
	mCamera.setEyePoint( Vec3f(-kWidth/4, kHeight/2, -kWidth/8) );
	mCamera.setCenterOfInterestPoint( Vec3f(kWidth/4, -kHeight/8, kWidth/4) );

	// create channels from which we can construct our textures
	mChannelLeft = Channel32f(kBands, kHistory);
	mChannelRight = Channel32f(kBands, kHistory);
	memset(	mChannelLeft.getData(), 0, mChannelLeft.getRowBytes() * kHistory );
	memset(	mChannelRight.getData(), 0, mChannelRight.getRowBytes() * kHistory );

	// create texture format (wrap the y-axis, clamp the x-axis)
	mTextureFormat.setWrapS( GL_CLAMP );
	mTextureFormat.setWrapT( GL_REPEAT );
	mTextureFormat.setMinFilter( GL_LINEAR );
	mTextureFormat.setMagFilter( GL_LINEAR );

	// compile shader
	try {
		mShader = gl::GlslProg( loadAsset("shaders/spectrum.vert"), loadAsset("shaders/spectrum.frag") );
	}
	catch( const std::exception& e ) {
		console() << e.what() << std::endl;
		quit();
		return;
	}

	// create static mesh (all animation is done in the vertex shader)
	std::vector<Vec3f>	vertices;
	std::vector<Colorf>	colors;
	std::vector<Vec2f>	coords;
	std::vector<size_t>	indices;
	
	for(size_t h=0;h<kHeight;++h)
	{
		for(size_t w=0;w<kWidth;++w)
		{
			// add polygon indices
			if(h < kHeight-1 && w < kWidth-1)
			{
				size_t offset = vertices.size();

				indices.push_back(offset);
				indices.push_back(offset+kWidth);
				indices.push_back(offset+kWidth+1);
				indices.push_back(offset);
				indices.push_back(offset+kWidth+1);
				indices.push_back(offset+1);
			}

			// add vertex
			vertices.push_back( Vec3f(float(w), 0, float(h)) );

			// add texture coordinates
			// note: we only want to draw the lower part of the frequency bands,
			//  so we scale the coordinates a bit
			const float part = 0.5f;
			float s = w / float(kWidth-1);
			float t = h / float(kHeight-1);
			coords.push_back( Vec2f(part - part * s, t) );

			// add vertex colors
			colors.push_back( Color(CM_HSV, s, 0.5f, 0.75f) );
		}
	}

	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	layout.setStaticColorsRGB();
	layout.setStaticIndices();
	layout.setStaticTexCoords2d();

	mMesh = gl::VboMesh(vertices.size(), indices.size(), layout, GL_TRIANGLES);
	mMesh.bufferPositions(vertices);
	mMesh.bufferColorsRGB(colors);
	mMesh.bufferIndices(indices);
	mMesh.bufferTexCoords2d(0, coords);

	// play audio using the Cinder FMOD block
	FMOD::System_Create( &mFMODSystem );
	mFMODSystem->init( 32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL );
	mFMODSound = nullptr;
	mFMODChannel = nullptr;

	playAudio( findAudio( mAudioPath ) );
	
	mIsMouseDown = false;
	mMouseUpDelay = 30.0;
	mMouseUpTime = getElapsedSeconds() - mMouseUpDelay;

	// the texture offset has two purposes:
	//  1) it tells us where to upload the next spectrum data
	//  2) we use it to offset the texture coordinates in the shader for the scrolling effect
	mOffset = 0;
}
Example #11
0
void CatalogApp::initBrightVbo()
{
	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	layout.setStaticTexCoords2d();
	layout.setStaticColorsRGB();
	
	int numVertices = FBO_WIDTH * FBO_HEIGHT;
	// 1 quad per particle
	// 2 triangles make up the quad
	// 3 points per triangle
	mBrightVbo		= gl::VboMesh( numVertices * 2 * 3, 0, layout, GL_TRIANGLES );
	
	float s = 0.5f;
	Vec3f p0( -s, -s, 0.0f );
	Vec3f p1( -s,  s, 0.0f );
	Vec3f p2(  s,  s, 0.0f );
	Vec3f p3(  s, -s, 0.0f );
	
	Vec2f t0( 0.0f, 0.0f );
	Vec2f t1( 0.0f, 1.0f );
	Vec2f t2( 1.0f, 1.0f );
	Vec2f t3( 1.0f, 0.0f );
	
	vector<Vec3f>		positions;
	vector<Vec2f>		texCoords;
	vector<Color>		colors;
	
	for( int x = 0; x < FBO_WIDTH; ++x ) {
		for( int y = 0; y < FBO_HEIGHT; ++y ) {
			float u = (float)x/(float)FBO_WIDTH;
			float v = (float)y/(float)FBO_HEIGHT;
			Color c = Color( u, v, 0.0f );
			
			positions.push_back( p0 );
			positions.push_back( p1 );
			positions.push_back( p2 );
			texCoords.push_back( t0 );
			texCoords.push_back( t1 );
			texCoords.push_back( t2 );
			colors.push_back( c );
			colors.push_back( c );
			colors.push_back( c );
			
			positions.push_back( p0 );
			positions.push_back( p2 );
			positions.push_back( p3 );
			texCoords.push_back( t0 );
			texCoords.push_back( t2 );
			texCoords.push_back( t3 );
			colors.push_back( c );
			colors.push_back( c );
			colors.push_back( c );
		}
	}
	
	mBrightVbo.bufferPositions( positions );
	mBrightVbo.bufferTexCoords2d( 0, texCoords );
	mBrightVbo.bufferColorsRGB( colors );
	mBrightVbo.unbindBuffers();
}
Example #12
0
void Controller::createSphere( gl::VboMesh &vbo, int res )
{
	float X = 0.525731112119f; 
	float Z = 0.850650808352f;
	
	static Vec3f verts[12] = {
		Vec3f( -X, 0.0f, Z ), Vec3f( X, 0.0f, Z ), Vec3f( -X, 0.0f, -Z ), Vec3f( X, 0.0f, -Z ),
		Vec3f( 0.0f, Z, X ), Vec3f( 0.0f, Z, -X ), Vec3f( 0.0f, -Z, X ), Vec3f( 0.0f, -Z, -X ),
		Vec3f( Z, X, 0.0f ), Vec3f( -Z, X, 0.0f ), Vec3f( Z, -X, 0.0f ), Vec3f( -Z, -X, 0.0f ) };
	
	static GLuint triIndices[20][3] = { 
		{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1}, {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
		{7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6}, {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
	
	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	layout.setStaticNormals();
	
	mPosCoords.clear();
	mNormals.clear();
	for( int i=0; i<20; i++ ){
		drawSphereTri( verts[triIndices[i][0]], verts[triIndices[i][1]], verts[triIndices[i][2]], res );
	}
	
	float z = 0.0f;
	float s = 0.05f;
	float y1 = -0.975f;
	float y2 = -1.1f;
	
	Vec3f v0 = Vec3f( z, y1, z );
	Vec3f v1 = Vec3f( s, y2, s );
	Vec3f v2 = Vec3f(-s, y2, s );
	Vec3f v3 = Vec3f(-s, y2,-s );
	Vec3f v4 = Vec3f( s, y2,-s );
	
	mPosCoords.push_back( v1 );	// back
	mPosCoords.push_back( v2 );
	mPosCoords.push_back( v0 );
	
	mPosCoords.push_back( v4 ); // right
	mPosCoords.push_back( v1 );
	mPosCoords.push_back( v0 );
	
	mPosCoords.push_back( v3 ); // front
	mPosCoords.push_back( v4 );
	mPosCoords.push_back( v0 );
	
	mPosCoords.push_back( v2 ); // left
	mPosCoords.push_back( v3 );
	mPosCoords.push_back( v0 );
	
	mPosCoords.push_back( v1 ); // bottom
	mPosCoords.push_back( v2 );
	mPosCoords.push_back( v3 );
	
	mPosCoords.push_back( v1 ); // bottom
	mPosCoords.push_back( v3 );
	mPosCoords.push_back( v4 );

	mNormals.push_back( Vec3f::zAxis() );	// back
	mNormals.push_back( Vec3f::zAxis() );
	mNormals.push_back( Vec3f::zAxis() );
	
	mNormals.push_back( Vec3f::xAxis() );	// right
	mNormals.push_back( Vec3f::xAxis() );
	mNormals.push_back( Vec3f::xAxis() );
	
	mNormals.push_back(-Vec3f::zAxis() );	// front
	mNormals.push_back(-Vec3f::zAxis() );
	mNormals.push_back(-Vec3f::zAxis() );
	
	mNormals.push_back( Vec3f::xAxis() );	// left
	mNormals.push_back( Vec3f::xAxis() );
	mNormals.push_back( Vec3f::xAxis() );
	
	mNormals.push_back( Vec3f::yAxis() );	// bottom
	mNormals.push_back( Vec3f::yAxis() );
	mNormals.push_back( Vec3f::yAxis() );
	
	mNormals.push_back( Vec3f::yAxis() );	// bottom
	mNormals.push_back( Vec3f::yAxis() );
	mNormals.push_back( Vec3f::yAxis() );
	
	vbo = gl::VboMesh( mPosCoords.size(), 0, layout, GL_TRIANGLES );	
	vbo.bufferPositions( mPosCoords );
	vbo.bufferNormals( mNormals );
}