예제 #1
0
// gets called at every program start and when a new file is opened in the viewer
void AbstractNavigation::sceneChanged(Group * scene)
{
    AxisAlignedBoundingBox bb = scene->boundingBox();

    m_BBRadius = bb.radius();

    m_frontView = glm::lookAt(bb.center() + glm::vec3(0.f, 0.f, bb.radius()*2.5), bb.center(), glm::vec3(0.f, 1.f, 0.f));
    setFromMatrix(topRightView());
    updateCamera();
}
예제 #2
0
// Workaround to avoid invisible objects due to wrong clipping planes
// all scenes are scaled to a radius of 5
void AbstractNavigation::rescaleScene( Group * scene )
{
    AxisAlignedBoundingBox bb = scene->boundingBox();
    glm::mat4 scale_matrix = glm::scale(glm::vec3(5.0f / bb.radius()));
    m_sceneTransform = scale_matrix * scene->transform();
    scene->setTransform(m_sceneTransform);
}
예제 #3
0
void PathTracingBVH::addToGeometry(Node *node) {
    
    AxisAlignedBoundingBox aabb = node->boundingBox();
    int aabbIndex = m_geometry->size();
    m_geometry->push_back(glm::vec4()); //llf dummy
    m_geometry->push_back(glm::vec4()); //urb dummy

    //add triangles
    for (auto child : node->children()) {
        if (child->children().size() == 0) { //the current child is a leaf ==> it is a triangle object
            TriangleObject *triangleObject = dynamic_cast<TriangleObject *>(child);
            if (triangleObject == nullptr) { //we have to be safe because it could also be an empty Group
                qDebug() << "PathTracingBVH : addToGeometry(Node *) : dynamic cast to TriangleObject * failed";
                continue;
            }
            p_TriangleList triangles = triangleObject->triangles();
            for (int i = 2; i < triangles->size(); i += 3) {
                m_geometry->push_back(glm::vec4(triangles->at(i - 2), 3.0f)); // data1
                m_geometry->push_back(glm::vec4(triangles->at(i - 1), 0.0f)); // data2
                m_geometry->push_back(glm::vec4(triangles->at(i    ), 0.0f)); // data3
            }
        } else { //internal node
            addToGeometry(child);
        }
    }
    glm::vec3 aabbEnlargement = aabb.radius() * glm::vec3(0.000001f, 0.000001f, 0.000001f);
    m_geometry->at(aabbIndex) = glm::vec4(
        aabb.llf() - aabbEnlargement, //llf
        0.0f //we are a bounding box
    ); //data1
    m_geometry->at(aabbIndex + 1) = glm::vec4(
        aabb.urb() + aabbEnlargement, //urb 
        float(m_geometry->size()) // points to one behind the last entry in geometry list, 
        // that is the next object on the same hierarchy level (or a higher hierarchy level 
        // if there is none on the same)
    ); //data2

}