Exemplo n.º 1
0
void Choreo3DApp::draw()
{
  
    //gl::clear( ColorA::gray( background ) );
    gl::clear(ColorAf(testBK));
    
    //THIS MAY NEED TO BE CLEANED UP
    vector<std::string> dataVector = {"CCL_JOINT_CCL3_00_skip10.json"};
    
    if( CURRENT_DATA_SET != LOADED_DATA_SET){
       // paused = true;
        
        
        //   jointList = {};
        jointList = ccl::loadMotionCaptureFromJson(getAssetPath(dataVector[CURRENT_DATA_SET]));
        
        FRAME_COUNT = 0;
        TOTAL_FRAMES = jointList[0].jointPositions.size(); //SHOULD PROBABLY PUT A TRY/CATCH HERE
        
        std::cout << "total frames: " << TOTAL_FRAMES << ", total joints:"<< jointList.size() << std::endl;
        
        gl::VboMeshRef body = gl::VboMesh::create( geom::Sphere().subdivisions( 16 ).radius(4) );
        
        //CREATE A CONTAINER TO STORE THE INITIAL POSITIONS FOR INITIALISING THE JOINTS
        std::vector<glm::vec3> positions;
        
        // CREATE THE SPHERES AT THE INITIAL JOINT LOCATIONS
        for ( int i = 0; i < jointList.size(); ++i ) {
            glm::vec3 jointAt = jointList[i].jointPositions[i];
            float instanceX = jointAt.x;
            float instanceY = jointAt.y;
            float instanceZ = jointAt.z;
            // float instanceZ = 0;
            
            positions.push_back( vec3( instanceX, instanceY, instanceZ));
        }
        //std::cout << "positions: " << positions[0] << std::endl;
        
        // create the VBO which will contain per-instance (rather than per-vertex) data
        mInstanceDataVbo = gl::Vbo::create( GL_ARRAY_BUFFER, positions.size() * sizeof(vec3), positions.data(), GL_DYNAMIC_DRAW );
        
        // we need a geom::BufferLayout to describe this data as mapping to the CUSTOM_0 semantic, and the 1 (rather than 0) as the last param indicates per-instance (rather than per-vertex)
        geom::BufferLayout instanceDataLayout;
        
        instanceDataLayout.append( geom::Attrib::CUSTOM_0, 3, 0, 0, 1 /* per instance */ );
        
        //NOW ADD IT TO THE VBO MESH THAT WE INITIAL CREATED FOR THE BODY / SKELETON
        body->appendVbo( instanceDataLayout, mInstanceDataVbo );
        
        //FINALLY, BUILD THE BATCH, AND MAP THE CUSTOM_0 ATTRIBUTE TO THE "vInstancePosition" GLSL VERTEX ATTRIBUTE
        mSphereBatch = gl::Batch::create( body, mGlsl, { { geom::Attrib::CUSTOM_0, "vInstancePosition" } } );
        
        LOADED_DATA_SET = CURRENT_DATA_SET;
        
    }
    
    
    
    gl::setMatrices( mCamera );
    
    if (showGrid)renderScene();
    
    Color( dancerColor[0], dancerColor[1], dancerColor[2] );
    //gl::ScopedModelMatrix modelScope;
    
    if(markersActive)mSphereBatch->drawInstanced( jointList.size() );
    
    if(skeletonActive)skeleton.renderSkeleton();
    
    if(ribbonsActive)drawRibbons();
    
    if(trailsActive)handTrail.render(dancerColor);
    
    
}