Beispiel #1
0
/** This method is called in the main rendering loop everytime the OpenGL windows has to be refreshed. */
void render(GLFWwindow* window)
{
    // clear the buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear all buffers

    //Draw PointCloud
    mBlinn.activate();

    glUniformMatrix4fv(mBlinn.getUniformLocation("projection_matrix"),1,false,mCamera.computeProjectionMatrix().data());
    glUniformMatrix4fv(mBlinn.getUniformLocation("modelview_matrix"),1,false,mCamera.computeViewMatrix().data());
    Vector4f light_pos;
    light_pos << mLightPos , 1.0f;
    Vector4f light_pos2;
    light_pos2 << mLightPos2 , 1.0f;
    glUniform4fv(mBlinn.getUniformLocation("light_pos"),1,light_pos.data());
    glUniform4fv(mBlinn.getUniformLocation("light_pos2"),1,light_pos2.data());

    glUniformMatrix4fv(mBlinn.getUniformLocation("object_matrix"),1,false,/*pc*//*mesh*/mMeshes[mCurrentMesh]->getTransformationMatrix().data());
    Matrix3f normal_matrix = (mCamera.computeViewMatrix()*/*pc*//*mesh*/mMeshes[mCurrentMesh]->getTransformationMatrix()).linear().inverse().transpose();
    glUniformMatrix3fv(mBlinn.getUniformLocation("normal_matrix"),1,false,normal_matrix.data());


    mMeshes[mCurrentMesh]->draw(&mBlinn/*,true*/);

    //pc->draw(&mBlinn);


//    Vector4f light_pos_mesh;

//    mMesh.activate();
//    glUniformMatrix4fv(mMesh.getUniformLocation("projection_matrix"),1,false,mCamera.computeProjectionMatrix().data());
//    glUniformMatrix4fv(mMesh.getUniformLocation("modelview_matrix"),1,false,mCamera.computeViewMatrix().data());

//    light_pos_mesh << mLightPos , 1.0f;
//    glUniform4fv(mMesh.getUniformLocation("light_pos"),1,light_pos_mesh.data());

//    glUniformMatrix4fv(mMesh.getUniformLocation("object_matrix"),1,false,mesh->getTransformationMatrix().data());
//    Matrix3f normal_matrix = (mCamera.computeViewMatrix()*mesh->getTransformationMatrix()).linear().inverse().transpose();
//    glUniformMatrix3fv(mMesh.getUniformLocation("normal_matrix"),1,false,normal_matrix.data());



//    mesh->draw(&mMesh);

    //Draw Octree
    if(octreeVisu >= 0)
    {
        mSimple.activate();
        glUniformMatrix4fv(mSimple.getUniformLocation("projection_matrix"),1,false,mCamera.computeProjectionMatrix().data());
        glUniformMatrix4fv(mSimple.getUniformLocation("modelview_matrix"),1,false,mCamera.computeViewMatrix().data());
        std::vector<AlignedBox3f> aabbs = octree->getAABBs(octreeVisu);
        for(unsigned i=0; i<aabbs.size(); ++i)
        {
            Affine3f object_matrix;
            object_matrix = Translation3f(aabbs[i].center()) * Scaling((aabbs[i].max() - aabbs[i].min())/2.0);
            glUniformMatrix4fv(mSimple.getUniformLocation("object_matrix"),1,false, object_matrix.data());
            wirecube->draw(&mSimple);
        }
    }

    mHole.activate();
    glUniformMatrix4fv(mHole.getUniformLocation("object_matrix"),1,false,/*mesh*/mMeshes[mCurrentMesh]->getTransformationMatrix().data());
    glUniformMatrix3fv(mHole.getUniformLocation("normal_matrix"),1,false,normal_matrix.data());
    //mesh->drawEdges(&mHole);

    // check OpenGL errors
    GL_TEST_ERR;

    glfwSwapBuffers(window);
}
Beispiel #2
0
/** This method is called in the main rendering loop everytime the OpenGL windows has to be refreshed. */
void render(GLFWwindow* window)
{
    // clear the buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear all buffers

    //Draw PointCloud
    mBlinn.activate();

    glUniformMatrix4fv(mBlinn.getUniformLocation("projection_matrix"),1,false,mCamera.computeProjectionMatrix().data());
    glUniformMatrix4fv(mBlinn.getUniformLocation("modelview_matrix"),1,false,mCamera.computeViewMatrix().data());
    Vector4f light_pos;
    light_pos << mLightPos , 1.0f;
    glUniform4fv(mBlinn.getUniformLocation("light_pos"),1,light_pos.data());

    glUniformMatrix4fv(mBlinn.getUniformLocation("object_matrix"),1,false,pc->getTransformationMatrix().data());
    Matrix3f normal_matrix = (mCamera.computeViewMatrix()*pc->getTransformationMatrix()).linear().inverse().transpose();
    glUniformMatrix3fv(mBlinn.getUniformLocation("normal_matrix"),1,false,normal_matrix.data());

    pc->draw(&mBlinn);



    //Draw Octree
//    mSimple.activate();
    //mCamera.updateViewMatrix();

//     glUniformMatrix4fv(mSimple.getUniformLocation("projection_matrix"),1,false,mCamera.computeProjectionMatrix().data());
//     glUniformMatrix4fv(mSimple.getUniformLocation("modelview_matrix"),1,false,mCamera.computeViewMatrix().data());
     glUniformMatrix4fv(mBlinn.getUniformLocation("object_matrix"),1,false, ball->getTransformationMatrix().data());
     glUniform3f(mBlinn.getUniformLocation("colorV"),1.f,1.f,1.f);
        ball->draw();
     glUniform3f(mBlinn.getUniformLocation("colorV"),0.2,0.3,0.8);

     mSimple.activate();


       glUniformMatrix4fv(mSimple.getUniformLocation("projection_matrix"),1,false,mCamera.computeProjectionMatrix().data());
       glUniformMatrix4fv(mSimple.getUniformLocation("modelview_matrix"),1,false,mCamera.computeViewMatrix().data());
       glUniformMatrix4fv(mSimple.getUniformLocation("object_matrix"),1,false, surface->getTransformationMatrix().data());
        glUniform3f(mSimple.getUniformLocation("color"),1.,0.,0.);
       surface->draw();
       // glUniform3f(mBlinn.getUniformLocation("colorV"),0.2,0.3,0.8);


    if(octreeVisu >= 0)
    {
        //mSimple.activate();
//        glUniformMatrix4fv(mSimple.getUniformLocation("projection_matrix"),1,false,mCamera.computeProjectionMatrix().data());
//        glUniformMatrix4fv(mSimple.getUniformLocation("modelview_matrix"),1,false,mCamera.computeViewMatrix().data());
        std::vector<AlignedBox3f> aabbs = octree->getAABBs(octreeVisu);
        for(unsigned i=0; i<aabbs.size(); ++i)
        {
            Affine3f object_matrix;
            object_matrix = Translation3f(aabbs[i].center()) * Scaling((aabbs[i].max() - aabbs[i].min())/2.0);
            glUniformMatrix4fv(mSimple.getUniformLocation("object_matrix"),1,false, object_matrix.data());
            wirecube->draw(&mSimple);
        }
    }




    //draw faces

//     glUniformMatrix4fv(mSimple.getUniformLocation("projection_matrix"),1,false,mCamera.computeProjectionMatrix().data());
//     glUniformMatrix4fv(mSimple.getUniformLocation("modelview_matrix"),1,false,mCamera.computeViewMatrix().data());
//     glUniformMatrix4fv(mSimple.getUniformLocation("object_matrix"),1,false, surface->getTransformationMatrix().data());
//     glUniform3f(mSimple.getUniformLocation("color"),1.f,0.f,0.f);
//     surface->draw();
//     glUniform3f(mSimple.getUniformLocation("color"),1.f,1.f,1.f);


    // check OpenGL errors
    GL_TEST_ERR;

    glfwSwapBuffers(window);
}