void ConstraintVisualizer::RenderPrismaticBoxes (IVRenderInterface* pRenderer, const hkvVec3& vStartPos, const hkvVec3& vEndPos)
{
  const VColorRef colorIB(0, 0, 200);
  const VColorRef colorOB(180, 180, 180);

  // Calculate the look at matrix
  hkvMat3 lookAtMat (hkvNoInitialization);
  lookAtMat.setLookInDirectionMatrix (vEndPos - vStartPos);

  // Compute box widths, so that they work for all world scales
  float fVecLen = (vStartPos - vEndPos).getLength();
  const float fWidthIB = fVecLen / 100.0f;
  const float fWidthOB = fWidthIB * 2.0f;

  // Setup the two boxes
  hkvAlignedBBox bBoxInner (hkvVec3 (0, fWidthIB, fWidthIB), hkvVec3 (fVecLen/2, -fWidthIB, -fWidthIB));
  hkvAlignedBBox bBoxOuter (hkvVec3 (fVecLen/2, fWidthOB, fWidthOB), hkvVec3 (fVecLen, -fWidthOB, -fWidthOB));

  // Render the two bounding boxes
  VSimpleRenderState_t state(VIS_TRANSP_ALPHA, RENDERSTATEFLAG_FRONTFACE);
  hkvVec3 corners[8];

  const hkvMat4 ThisIsALookAtMatrixYARLY (lookAtMat, vStartPos);

  bBoxInner.getCorners(corners);
  ThisIsALookAtMatrixYARLY.transformPositions(corners, 8);

  pRenderer->RenderBox(corners,sizeof(hkvVec3),colorIB,state);

  bBoxOuter.getCorners(corners);
  ThisIsALookAtMatrixYARLY.transformPositions(corners, 8);

  pRenderer->RenderBox(corners,sizeof(hkvVec3),colorOB,state);
}
示例#2
0
文件: renderer.cpp 项目: maxluzius/BA
void renderer::findBest(Camera &camera,Mesh* mesh, particle camPartikel, Shader* _likelihood, Shader* _meshProgram, glm::mat4 m, glm::mat4 v, glm::mat4 p, GLuint mLoc,GLuint vLoc,GLuint pLoc, GLuint handle, glm::vec3 &newCenter, glm::vec3 &newLookAt){

    max = 0.0;
    cv::Mat_<float> centerMat = camPartikel.getParticleCenterM();
    cv::Mat_<float> lookAtMat = camPartikel.getParticleLookAtM();
    //querys to count the pixels
    const int size = 400;
    GLuint queryArray[size];
    glGenQueries(size, queryArray);
    float meshsRelValue[size] = {0.0};

    //bind texture with edgepicture
    texLoc = glGetUniformLocation(handle,"tex");
    glActiveTexture(GL_TEXTURE0);
    glUniform1i(texLoc,0);
    glBindTexture(GL_TEXTURE_2D,handle);

    //bind likelihoodshader
    _likelihood->bind();

    m = mesh->computeModelMatrix();

    glUniformMatrix4fv(mLoc,1,GL_FALSE,glm::value_ptr(m));
    glUniformMatrix4fv(pLoc,1,GL_FALSE,glm::value_ptr(p));

    //funktioniert nicht
    //glm::mat4 * view = new glm::mat4[size];
    //view = camPartikel.getViewArray();
    for (int i = 0; i < centerMat.rows; i++) {
        cameraPos.x = centerMat(i,0);
        cameraPos.y = centerMat(i,1);
        cameraPos.z = centerMat(i,2);
        camera.setCenter(cameraPos);
        for (int j = 0; j < centerMat.rows; j++) {
            cameraLookAt.x = lookAtMat(i * centerMat.rows + j, 0);
            cameraLookAt.y = lookAtMat(i * centerMat.rows + j, 1);
            cameraLookAt.z = lookAtMat(i * centerMat.rows + j, 2);
            camera.setLookAt(cameraLookAt);

                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                v = camera.getViewMatrix();
                glUniformMatrix4fv(vLoc,1,GL_FALSE,glm::value_ptr(v));

                glBeginQuery(GL_SAMPLES_PASSED, queryArray[i]);
                if(mesh != nullptr)
                    mesh->draw(&cameraPos);
                glEndQuery(GL_SAMPLES_PASSED);
                glGetQueryObjectuiv(queryArray[i], GL_QUERY_RESULT, &PixelCountSet);

                meshsRelValue[i * centerMat.rows + j] = PixelCountSet;

                //cout << "PixelCount für " << i * centerMat.rows + j << ": " << PixelCountSet << endl;
                        }
                }

    glBindTexture(GL_TEXTURE_2D,0);
    _likelihood->unbind();

    //bind meshshader
    _meshProgram->bind();

    for (int i = 0; i < centerMat.rows; i++) {
        cameraPos.x = centerMat(i,0);
        cameraPos.y = centerMat(i,1);
        cameraPos.z = centerMat(i,2);
        camera.setCenter(cameraPos);
        for (int j = 0; j < centerMat.rows; j++) {
            cameraLookAt.x = lookAtMat(i * centerMat.rows + j, 0);
            cameraLookAt.y = lookAtMat(i * centerMat.rows + j, 1);
            cameraLookAt.z = lookAtMat(i * centerMat.rows + j, 2);
            camera.setLookAt(cameraLookAt);

                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                v = camera.getViewMatrix();
                glUniformMatrix4fv(vLoc,1,GL_FALSE,glm::value_ptr(v));

                glBeginQuery(GL_SAMPLES_PASSED, queryArray[i]);
                if(mesh != nullptr)
                    mesh->draw(&cameraPos);
                glEndQuery(GL_SAMPLES_PASSED);
                glGetQueryObjectuiv(queryArray[i], GL_QUERY_RESULT, &PixelCountSet);

                meshsRelValue[i * centerMat.rows + j] /= PixelCountSet;

                if(meshsRelValue[i * centerMat.rows + j] > max){
                    max = meshsRelValue[i * centerMat.rows + j];
                    newCenter.x = centerMat(i,0);
                    newCenter.y = centerMat(i,1);
                    newCenter.z = centerMat(i,2);
                    newLookAt.x = lookAtMat(i * centerMat.rows + j, 0);
                    newLookAt.y = lookAtMat(i * centerMat.rows + j, 1);
                    newLookAt.z = lookAtMat(i * centerMat.rows + j, 2);
                }

                //cout << "PixelCount für " << i * centerMat.rows + j << ": " << meshsRelValue[i * centerMat.rows + j] << endl;
        }
    }


    _meshProgram->unbind();
    glDeleteQueries(size, queryArray);

    //set camerapose of the best new position
    camera.setCenter(newCenter);
    camera.setLookAt(newLookAt);
}