Esempio n. 1
0
const AxisAlignedBoundingBox PolygonalDrawable::boundingBox(glm::mat4 transform) const
{
    AxisAlignedBoundingBox aabb = AxisAlignedBoundingBox();
    glm::mat4 newTransform;
    
    if( m_geometry == nullptr ) {
        return aabb;
    }

    if (m_rf == RF_Absolute) {
        newTransform = transform;
    } else {
        newTransform = this->transform() * transform;
    }


    t_VertexListP myVList = m_geometry->vertices();
    myVList->foreachVertexAttribute<glm::vec3>(0, myVList->size(), "position", nullptr,
        [&aabb, &newTransform](int i, const glm::vec3 & pos)
        {
            aabb.extend( glm::vec3(newTransform * glm::vec4(pos, 1.0f)) );
        }
    );

    return aabb;
}
Esempio n. 2
0
const AxisAlignedBoundingBox TriangleObject::boundingBox(glm::mat4 transform) const
{
    AxisAlignedBoundingBox aabb = AxisAlignedBoundingBox();
    glm::mat4 newTransform;
    
    if ( m_triangles->size() == 0 )
        return aabb;
    
    if (m_rf == RF_Absolute) {
        newTransform = transform;
    } else {
        newTransform = this->transform() * transform;
    }

    for ( auto vertex : *m_triangles ) {
        glm::vec4 transformedVertex = newTransform * glm::vec4(vertex, 1.0f);
        aabb.extend( transformedVertex.xyz * (1.0f / transformedVertex.w) );
    }
    return aabb;
}
Esempio n. 3
0
AxisAlignedBoundingBox AssimpScene::retrieveAxisAlignedBoundingBox(const aiScene * scene)
{
    AxisAlignedBoundingBox aabb;

    for (unsigned int m = 0; m < scene->mNumMeshes; ++m)
    {
        aiMesh * mesh = scene->mMeshes[m];

        for (unsigned int v = 0; v < mesh->mNumVertices; ++v)
        {
            const QVector3D vec3(
                mesh->mVertices[v].x
            ,   mesh->mVertices[v].y
            ,   mesh->mVertices[v].z);

            aabb.extend(vec3);
        }
    }
    return aabb;
}