示例#1
0
bool NavigationMath::boundaryVisible(
    const QMatrix4x4 & mvp
,   const AxisAlignedBoundingBox & b)
{
	const QVector3D box[8] = 
	{
	// front
		QVector3D(b.llf().x(),  b.llf().y(), b.urb().z())
	,	QVector3D(b.urb().x(),  b.llf().y(), b.urb().z())
	,	QVector3D(b.urb().x(),  b.urb().y(), b.urb().z())
	,	QVector3D(b.llf().x(),  b.urb().y(), b.urb().z())
	// back
	,	QVector3D(b.llf().x(),  b.llf().y(), b.llf().z())
	,	QVector3D(b.urb().x(),  b.llf().y(), b.llf().z())
	,	QVector3D(b.urb().x(),  b.urb().y(), b.llf().z())
	,	QVector3D(b.llf().x(),  b.urb().y(), b.llf().z())
	};

	// transform bounds and check if any point is outside NDC (Normalized Device 
    // Coordinates) space 

	for(int i = 0; i < 8; ++i)
	{
		const QVector3D t = mvp * box[i];

		if(qAbs<float>(t.x()) > 1.0 || qAbs<float>(t.y()) > 1.0)
			return false;
	}
	return true;
}
示例#2
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

}