Example #1
0
void GetRandPlane(Box3f &bb, Plane3f &plane)
{
    Point3f planeCenter = bb.Center();
    Point3f planeDir = Point3f(-0.5f+float(rand())/RAND_MAX,-0.5f+float(rand())/RAND_MAX,-0.5f+float(rand())/RAND_MAX);
    planeDir.Normalize();

    plane.Init(planeCenter+planeDir*0.3f*bb.Diag()*float(rand())/RAND_MAX,planeDir);
}
Example #2
0
void AmbientOcclusionPlugin::setCamera(Point3f camDir, Box3f &meshBBox)
{
	cameraDir = camDir;
	GLfloat d = (meshBBox.Diag()/2.0) * 1.1,
	        k = 0.1f;
	Point3f eye = meshBBox.Center() + camDir * (d+k);

	glViewport(0.0, 0.0, depthTexSize, depthTexSize);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-d, d, -d, d, k, k+(2.0*d) );

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(eye.X(), eye.Y(), eye.Z(),
			  meshBBox.Center().X(), meshBBox.Center().Y(), meshBBox.Center().Z(),
			  0.0, 1.0, 0.0);
}
Example #3
0
void SdfGpuPlugin::setCamera(Point3f camDir, Box3f &meshBBox)
{
    GLfloat d = (meshBBox.Diag()/2.0),
            k = 0.1f;
    Point3f eye = meshBBox.Center() + camDir * (d+k);

    mScale = 2*k+(2.0*d);

    glViewport(0.0, 0.0, mPeelingTextureSize, mPeelingTextureSize);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-d, d, -d, d, /*k*/0, mScale );

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(eye.X(), eye.Y(), eye.Z(),
                      meshBBox.Center().X(), meshBBox.Center().Y(), meshBBox.Center().Z(),
                      0.0, 1.0, 0.0);
}
void CQuadTree::AddReference( Box3f box, CEntity * pEntity, CQuadNode * node )  {

    assert( m_iLevels > 1 ); 

    int iNumInside = 0;

    Box3f boxTemp =  box;
    Box3f boxEnt = *pEntity->GetBoundingBox();

    // move box to the entity's height
    boxTemp.Center().Y() = boxEnt.Center().Y();
    boxTemp.Extent(1) = 100.0f; //extend this box infinitely

    bool bEntInQuad = false;

    Vector3f vBoxVerts[8];
    bool abValid[8] = { 1,1,1,1,1,1,1,1 };//{ 0,0,0,0,0,0,0,0 };
    bool bEntBoxInNode = false;
    bool bNodeInEntBox = false;

    //switch(TestIntersection( boxTemp,  boxEnt ) ) 
    switch(TestIntersection( boxEnt, boxTemp ) ) 
    {
        case true:  // box intersects
            node->m_EntMap[pEntity->GetId()] = pEntity; 
            bEntInQuad = true;  // find if the children intersect too
            break;

        case false:  // ent box is INSIDE or OUTSIDE the node
            // get vertices for the bounding box                
            boxEnt.ComputeVertices(vBoxVerts);

            // if entities box is contained in node box
            for (int j=0; j<8; j++ ) {
                if (InBox( vBoxVerts[j], boxTemp))  {
                    bEntBoxInNode = true;
                }
            }

            if (bEntBoxInNode == true)  {
            //if (ContOrientedBox (8, vBoxVerts, abValid, node->m_BBox))  {
                node->m_EntMap[pEntity->GetId()] = pEntity; //entity is in this node
                bEntInQuad = true;  // find out what child quads also contain this
                iNumInside++;                
            }
            else { // OUTSIDE or entities box contains the bounding box!
                boxTemp.ComputeVertices(vBoxVerts);
                
                // if node box  is contained in entities box
                for (int j=0; j<8; j++ ) {
                    if (InBox( vBoxVerts[j], boxEnt))  {
                        bNodeInEntBox = true;
                    }
                }

                if (bNodeInEntBox == true)  {
                //if (ContOrientedBox (8, vBoxVerts, abValid, boxTemp))  {
                    node->m_EntMap[pEntity->GetId()] = pEntity; //entity is in this node
                    bEntInQuad = true;  // find out what child quads also contain this

                }
                else {
                    // entity is outside, so don't add
                    bEntInQuad = false;
                    return;
                }
            }
            break;
    }

    // now this box will also intersect/be contained in the children as well
    if (bEntInQuad == true )  {
        //check if we need to subdivide even further
        if (iNumInside >= MAX_ENTS_PER_NODE)  {
            m_iLevels++;  //increase the number of levels
            SubDivide(node, m_iLevels-1);
        }

        if (node->m_pChildNode[NE] != NULL)  {
            AddReference( node->m_pChildNode[NE]->m_BBox, pEntity, node->m_pChildNode[NE]);
            //node->m_pChildNode[NE]->m_EntMap[pEntity->GetId()] = pEntity;
        }
        if (node->m_pChildNode[NW] != NULL)  {
            AddReference( node->m_pChildNode[NW]->m_BBox, pEntity, node->m_pChildNode[NW]);
            //node->m_pChildNode[NW]->m_EntMap[pEntity->GetId()] = pEntity;
        }
        if (node->m_pChildNode[SE] != NULL)  {
            AddReference( node->m_pChildNode[SE]->m_BBox, pEntity, node->m_pChildNode[SE]);
            //node->m_pChildNode[SE]->m_EntMap[pEntity->GetId()] = pEntity;
        }
        if (node->m_pChildNode[SW] != NULL)  {
            AddReference( node->m_pChildNode[SW]->m_BBox, pEntity, node->m_pChildNode[SW]);
            //node->m_pChildNode[SW]->m_EntMap[pEntity->GetId()] = pEntity;
        }        
    }

    return;
}