void SpiderWebApp::reset() { mIterationIndex = 0; mPositionBufTexs[0].reset(); mPositionBufTexs[1].reset(); mPositionBufTexs[0] = nullptr; mPositionBufTexs[1] = nullptr; mVaos[0].reset(); mVaos[1].reset(); mVaos[0] = nullptr; mVaos[1] = nullptr; // mPositions[0] = nullptr; // with these, we only get movement the first time around // mPositions[1] = nullptr; // mVelocities[0] = nullptr; // mVelocities[1] = nullptr; // mConnections[0] = nullptr; // mConnections[1] = nullptr; // mConnectionLen[0] = nullptr; // mConnectionLen[1] = nullptr; // mLineIndices = nullptr; // adding this gives us 3 rounds of movement mPositions[0]->mapReplace(); mPositions[1]->mapReplace(); mVelocities[0]->mapReplace(); mVelocities[1]->mapReplace(); mConnections[0]->mapReplace(); mConnections[1]->mapReplace(); mConnectionLen[0]->mapReplace(); mConnectionLen[1]->mapReplace(); mLineIndices->mapReplace(); // RESET and generate web mWeb->reset(); mWeb = nullptr; generateWeb(); setupBuffers(); }
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(); }