void BulletSpheresApp::update()
{
	// update time
	// update bullet context
	updateTime(); 
	
	mContext->setGravity( vec3( 0 ) );
	mContext->update();

	// add attractive force
	mat4 * matrices = (mat4*)mMatrices->map( GL_WRITE_ONLY );
	for( auto &body : mRigidBodies ){
		body.update( mTimeElapsed );
		int index = body.getId();
		if( index >=2 ){		// small orbs
			for( int i=0; i<2; i++ ){
				vec3 pos		= mRigidBodies[i].getPos();
				float size		= mRigidBodies[i].getSize();
				float strength	= mRigidBodies[i].getStrength();
				body.attract( pos, size, strength );
			}
			matrices[index-2] = body.getMatrix();
		} else {				// big orbs
			float size			= mRigidBodies[index].getSize();
			body.attract( vec3( 0 ), size, 1.0f );
		}
	}
	mMatrices->unmap();
}
示例#2
0
void InstancedTeapotsApp::update()
{
	// move the camera up and down on Y
	mCam.lookAt( vec3( 0, CAMERA_Y_RANGE.first + abs(sin( getElapsedSeconds() / 4)) * (CAMERA_Y_RANGE.second - CAMERA_Y_RANGE.first), 0 ), vec3( 0 ) );
	
	// update our instance positions; map our instance data VBO, write new positions, unmap
	vec3 *positions = (vec3*)mInstanceDataVbo->mapWriteOnly( true );
	for( size_t potX = 0; potX < NUM_INSTANCES_X; ++potX ) {
		for( size_t potY = 0; potY < NUM_INSTANCES_Y; ++potY ) {
			float instanceX = potX / (float)NUM_INSTANCES_X - 0.5f;
			float instanceY = potY / (float)NUM_INSTANCES_Y - 0.5f;
			// just some nonsense math to move the teapots in a wave
			vec3 newPos(	instanceX * vec3( DRAW_SCALE, 0, 0 ) +
							instanceY * vec3( 0, 0, DRAW_SCALE ) +
							vec3( 0, 30, 0 ) * sinf( getElapsedSeconds() * 3 + instanceX * 3 + instanceY * 3 ) );
			*positions++ = newPos;
		}
	}
	mInstanceDataVbo->unmap();
}
示例#3
0
void Choreo3DApp::update()
{
    setFrameRate(frameRate);
    
    //DISABLE CAMERA INTERACTION IF MOUSE IS OVER UI REGION
    if (getMousePos().x > 3 * getWindowWidth()/4. && camActive)
    {
        camActive = false;
        mCamUi.disconnect();
        mCamUi.disable();
        cout << "disabling camera UI" << endl;
    } else {
        if (!camActive)
        {
            mCamUi.connect(getWindow());
            mCamUi.enable();
        }
        camActive = true;
        cout << "enabling camera UI" << endl;
    }
    
    mGlsl->uniform("uColor", markerColour );
    
    if (!paused)
    {
        
        
        //UPDATE POSITIONS
        //MAP INSTANCE DATA TO VBO
        //WRITE NEW POSITIONS
        //UNMAP
        
        glm::vec3 *newPositions = (glm::vec3*)mInstanceDataVbo->mapReplace();
        
        for( int i = 0; i < jointList.size(); ++i )
        {
            
            float instanceX = jointList[i].jointPositions[FRAME_COUNT].x;
            float instanceY = jointList[i].jointPositions[FRAME_COUNT].y;
            float instanceZ = jointList[i].jointPositions[FRAME_COUNT].z;
            
            vec3 newPos(vec3(instanceX,instanceY, instanceZ)); //CREATE A NEW VEC3 FOR UPDATING THE VBO
            
            framePositions[i] = newPos;
            
        }
        
        //REPLACE VEC3s IN VBO BY INCREMENTING THE POINTER
        for (int i = 0; i < framePositions.size(); i++){
            *newPositions++ = framePositions[i];
        }
        
        handTrail.update(framePositions[26], dancerColor);
        
        //    std::cout << framePositions[17] << std::endl;
        
        
        skeleton.update(framePositions);

        
        mInstanceDataVbo->unmap();
        // std::cout << "position: " << positions[0] << std::endl;
        
        if (ribbonsActive)updateRibbons();
        
        //MANUALLY INCREMENT THE FRAME, IF THE FRAME_COUNT EXCEEDS TOTAL FRAMES, RESET THE COUNTER
        if (FRAME_COUNT < TOTAL_FRAMES)
        {
            FRAME_COUNT += 1;
        } else {
            FRAME_COUNT = 0;
        }
        
        //std::cout << getAverageFps() << std:: endl;
        // std::cout << "frame rate: " << getAverageFps() << ", frame count: " << FRAME_COUNT << std::endl;
        
        //define changed color
      //  Color temp = Color(dancerColor[0],dancerColor[1],dancerColor[2]);
        
        
        mCurrentFrame++; //MANUALLY ADVANCE THE CURRENT FRAME - WITH RESPECT TO THE DANCERS
    
    }
    
    updateGui();
}
void SpiderWebApp::setupBuffers()
{
	
	// get all of the points from the spider web
	
	 // buffer the positions
	std::array<vec4, MAX_POINTS> positions;
	std::array<vec3, MAX_POINTS> velocities;
	std::array<ivec4, MAX_POINTS> connections;
	std::array<vec4, MAX_POINTS> connectionLen;
	std::array<vec4, MAX_POINTS> colors;
	
	vector<ParticleRef> webPoints = mWeb->getPoints();
	int n = 0;
	Perlin p = Perlin();
	for( auto iter = webPoints.begin(); iter != webPoints.end(); ++iter ) {
		auto point = (*iter);
		vec2 pos = point->getPosition();
		// create our initial positions
		positions[point->getId()] = vec4(
			pos.x, pos.y,
			0.0,
			1.0f );
		// zero out velocities
		velocities[point->getId()] = vec3( 0.0f );
		
		connections[n] = ivec4( -1 );
		connectionLen[n] = vec4( 0.0 );
		auto conn = point->getNeighbors();
		// use first 4 connections of there are more
		int max = min(int(conn.size()), 4);

		for( int i = 0; i < max; ++i ){
			auto connection = conn[i];
			connections[n][i] = connection->getId();
//			connectionLen[n][i] = distance( normalize(pos), normalize(connection->getPosition()) );
			connectionLen[n][i] = distance( pos, connection->getPosition() );
		}
		n++;
		
		// DEFINE alpha - helps make the line thickness look a bit varied
		float x = pos.x / getWindowWidth();
		float y = pos.y / getWindowHeight();
		float a = p.fBm( x, y ) * 2.0;
		a += 0.35;
		colors[point->getId()] = vec4( vec3( 1.0 ), a );
	}
	
	for ( int i = 0; i < 2; i++ ) {
		mVaos[i] = gl::Vao::create();
		gl::ScopedVao scopeVao( mVaos[i] );
		{
			// buffer the positions
			mPositions[i] = gl::Vbo::create( GL_ARRAY_BUFFER, positions.size() * sizeof(vec4), positions.data(), GL_STATIC_DRAW );
			{
				// bind and explain the vbo to your vao so that it knows how to distribute vertices to your shaders.
				gl::ScopedBuffer sccopeBuffer( mPositions[i] );
				gl::vertexAttribPointer( POSITION_INDEX, 4, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) 0 );
				gl::enableVertexAttribArray( POSITION_INDEX );
			}
			
			// buffer the velocities
			mVelocities[i] = gl::Vbo::create( GL_ARRAY_BUFFER, velocities.size() * sizeof(vec3), velocities.data(), GL_STATIC_DRAW );
			{
				// bind and explain the vbo to your vao so that it knows how to distribute vertices to your shaders.
				gl::ScopedBuffer scopeBuffer( mVelocities[i] );
				gl::vertexAttribPointer( VELOCITY_INDEX, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) 0 );
				gl::enableVertexAttribArray( VELOCITY_INDEX );
			}
			// buffer the connections
			mConnections[i] = gl::Vbo::create( GL_ARRAY_BUFFER, connections.size() * sizeof(ivec4), connections.data(), GL_STATIC_DRAW );
			{
				// bind and explain the vbo to your vao so that it knows how to distribute vertices to your shaders.
				gl::ScopedBuffer scopeBuffer( mConnections[i] );
				gl::vertexAttribIPointer( CONNECTION_INDEX, 4, GL_INT, 0, (const GLvoid*) 0 );
				gl::enableVertexAttribArray( CONNECTION_INDEX );
			}
			// buffer the connection lengths
			mConnectionLen[i] = gl::Vbo::create( GL_ARRAY_BUFFER, connectionLen.size() * sizeof(vec4), connectionLen.data(), GL_STATIC_DRAW );
			{
				// bind and explain the vbo to your vao so that it knows how to distribute vertices to your shaders.
				gl::ScopedBuffer scopeBuffer( mConnectionLen[i] );
				gl::vertexAttribPointer( CONNECTION_LEN_INDEX, 4, GL_FLOAT, GL_FLOAT, 0, (const GLvoid*) 0 );
				gl::enableVertexAttribArray( CONNECTION_LEN_INDEX );
			}
			
			// buffer the colors
			mColors[i] = gl::Vbo::create( GL_ARRAY_BUFFER, colors.size() * sizeof(vec4), colors.data(), GL_STATIC_DRAW );
			{
				// bind and explain the vbo to your vao so that it knows how to distribute vertices to your shaders.
				gl::ScopedBuffer scopeBuffer( mColors[i] );
				gl::vertexAttribPointer( COLOR_INDEX, 4, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) 0 );
				gl::enableVertexAttribArray( COLOR_INDEX );
			}
			
			// Create a TransformFeedbackObj, which is similar to Vao
			// It's used to capture the output of a glsl and uses the
			// index of the feedback's varying variable names.
			mFeedbackObj[i] = gl::TransformFeedbackObj::create();
			// Bind the TransformFeedbackObj and bind each corresponding buffer
			// to it's index.
			mFeedbackObj[i]->bind();
			gl::bindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, POSITION_INDEX, mPositions[i] );
			gl::bindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, VELOCITY_INDEX, mVelocities[i] );
			mFeedbackObj[i]->unbind();
		}
	}
	// create your two BufferTextures that correspond to your position buffers.
	mPositionBufTexs[0] = gl::BufferTexture::create( mPositions[0], GL_RGBA32F );
	mPositionBufTexs[1] = gl::BufferTexture::create( mPositions[1], GL_RGBA32F );
	
	auto strands = mWeb->getUniqueStrands();
	int lines = strands.size();
	mConnectionCount = lines;
	// create the indices to draw links between the cloth points
	mLineIndices = gl::Vbo::create( GL_ELEMENT_ARRAY_BUFFER, lines * 2 * sizeof(int), nullptr, GL_STATIC_DRAW );

	auto e = (int *) mLineIndices->mapReplace();
	for( auto iter = strands.begin(); iter != strands.end(); ++iter ){
		auto strand = *iter;
		*e++ = strand.first->getId();
		*e++ = strand.second->getId();
	}
	
	
	mLineIndices->unmap();
}