Ejemplo n.º 1
0
void GLC_Viewport::setDistMinAndMax(const GLC_BoundingBox& bBox)
{
	if(!bBox.isEmpty())
	{
		// The scene is not empty
		GLC_Matrix4x4 matComp(m_pViewCam->modelViewMatrix());

		// The bounding Box in Camera coordinate
		GLC_BoundingBox boundingBox(bBox);
		boundingBox.transform(matComp);

		// Increase size of the bounding box
		const double increaseFactor= 1.1;
		// Convert box distance in sphere distance
		const double center= fabs(boundingBox.center().z());
		const double radius= boundingBox.boundingSphereRadius();
		const double min= center - radius * increaseFactor;
		const double max= center + radius * increaseFactor;

		GLC_Point3d camEye(m_pViewCam->eye());
		camEye= matComp * camEye;

		if (min > 0.0)
		{
			// Outside bounding Sphere
			m_dDistanceMini= min;
			m_DistanceMax= max;
			//qDebug() << "distmin" << m_dCamDistMin;
			//qDebug() << "distmax" << m_dCamDistMax;
		}
		else
		{
			// Inside bounding Sphere
			m_dDistanceMini= qMin(0.01 * radius, m_pViewCam->distEyeTarget() / 4.0);
			m_DistanceMax= max;
			//qDebug() << "inside distmin" << m_dCamDistMin;
			//qDebug() << "inside distmax" << m_dCamDistMax;
		}
	}
	else
	{
		// The scene is empty
		m_dDistanceMini= m_pViewCam->distEyeTarget() / 2.0;
		m_DistanceMax= m_pViewCam->distEyeTarget();
	}

	// Update OpenGL projection matrix
	updateProjectionMat();
}
Ejemplo n.º 2
0
void GLC_Viewport::reframe(const GLC_BoundingBox& box)
{
	Q_ASSERT(!box.isEmpty());

	// Center view on the BoundingBox
	const GLC_Vector3d deltaVector(box.center() - m_pViewCam->target());
	m_pViewCam->translate(deltaVector);

	double cameraCover= box.boundingSphereRadius() * 2.0;

	// Compute Camera distance
	const double distance = cameraCover / m_ViewTangent;

	// Update Camera position
	m_pViewCam->setDistEyeTarget(distance);
}
Ejemplo n.º 3
0
void GLC_OctreeNode::addInstance(GLC_3DViewInstance* pInstance, int depth)
{
    m_Empty= false;
    const GLC_BoundingBox instanceBox= pInstance->boundingBox();
    // Check if the instance's bounding box intersect this node bounding box
    if (!instanceBox.isEmpty() && intersect(instanceBox))
    {
        if (0 == depth)
        {
            m_3DViewInstanceSet.insert(pInstance);
        }
        else
        {
            if (m_Children.isEmpty())
            {
                // Create children
                addChildren();
            }
            QVector<bool> childIntersect(8);
            bool allIntersect= true;
            bool currentIntersect= false;
            for (int i= 0; i < 8; ++i)
            {
                currentIntersect= m_Children.at(i)->intersect(instanceBox);
                allIntersect= allIntersect && currentIntersect;
                childIntersect[i]= currentIntersect;
            }
            if (allIntersect)
            {
                m_3DViewInstanceSet.insert(pInstance);
            }
            else
            {
                for (int i= 0; i < 8; ++i)
                {
                    if (childIntersect[i])
                    {
                        m_Children[i]->addInstance(pInstance, depth - 1);
                    }
                }
            }
        }

    }
}
Ejemplo n.º 4
0
GLC_Camera GLC_Viewport::reframedCamera(const GLC_BoundingBox &box, double coverFactor) const
{
    Q_ASSERT(!box.isEmpty());
    GLC_Camera subject(*m_pViewCam);

    // Center view on the BoundingBox
    const GLC_Vector3d deltaVector(box.center() - m_pViewCam->target());
    subject.translate(deltaVector);

    if (coverFactor > 0.0) {
        double cameraCover= box.boundingSphereRadius() * coverFactor;

        // Compute Camera distance
        const double distance = cameraCover / m_ViewTangent;

        // Update Camera position
        subject.setDistEyeTarget(distance);
    }

    return subject;
}