Пример #1
0
void InitGL()
{
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(320,320);
	glutCreateWindow("Volume Raycasting 3D");

	glutDisplayFunc(renderScene);
	//glutIdleFunc(renderScene);
	//glutReshapeFunc(changeSize);

	glm::vec3 eyepos(66.5f, 30.0f, 0.0f);
	gDC.SetCamera(eyepos, -3.141592 / 2, 0);
	gDC.AllocateInput();

	glutKeyboardFunc(Keyboard);
	glutKeyboardUpFunc(KeyboardUp);
	glutSpecialFunc(Keyboard);
	glutMouseFunc(Mouse);
	glutMotionFunc(MouseMotion);
	glewInit();

	//glDisable(GL_CULL_FACE);
	//glCullFace(GL_FRONT);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
	//glEnable(GL_TEXTURE_3D);
	//glEnable(GL_TEXTURE_2D);

	glClearColor(0.0, 0.0, 0.0, 1.0);


}
Пример #2
0
Action::ResultE ShadingCallbacks::distanceLODRender(CNodePtr &pNode, 
                                                    Action   *action)
{
    DrawActionBase *da    = dynamic_cast<DrawActionBase *>(action);
    ShadingAction  *ra    = dynamic_cast<ShadingAction  *>(action);

    DistanceLOD    *pDLOD = dynamic_cast<DistanceLOD    *>(pNode.getCPtr());


    UInt32 numLevels = action->getNNodes ();
    UInt32 numRanges = pDLOD ->getMFRange()->size();

    UInt32 limit     = osgMin(numLevels, numRanges); 
    
    Int32  index     = -1;

    Pnt3f  eyepos(0.f, 0.f, 0.f);
    Pnt3f  objpos;

    da->getCameraToWorld().mult(eyepos);

    if(ra != NULL)
    {
        ra->top_matrix()              .mult(pDLOD->getCenter(), objpos);
    }
    else
    {
        da->getActNode()->getToWorld().mult(pDLOD->getCenter(), objpos);
    }
        
    Real32 dist = osgsqrt((eyepos[0] - objpos[0])*(eyepos[0] - objpos[0]) +
                          (eyepos[1] - objpos[1])*(eyepos[1] - objpos[1]) +
                          (eyepos[2] - objpos[2])*(eyepos[2] - objpos[2]));
    
    da->useNodeList();
    
    if(numRanges != 0 && numLevels!=0 )
    {
        if(dist < (*(pDLOD->getMFRange()))[0])
        {
            index = 0;
        } 
        else if(dist >= (*(pDLOD->getMFRange()))[numRanges-1])
        {
	    index = (numLevels > numRanges) ? numRanges : (limit-1); 
        }
        else
        {
            UInt32 i = 1;

            while( (i < numRanges) && 
                  !( ((*(pDLOD->getMFRange()))[i-1] <= dist) && 
                     (dist < (*(pDLOD->getMFRange()))[i]   )   ) )
            {
                i++;
            }
            
            index = osgMin(i, limit-1);
        } 
        
        if(da->isVisible(action->getNode(index).getCPtr()))
        {
            da->addNode(action->getNode(index));
        }
    }

    return Action::Continue;
}
Пример #3
0
void QuadTreeNode::GetVisibleMeshes(const ViewFrustum& frustum, const D3DXVECTOR4& viewsphere, VisibleSet& visible_set, bool inside)
{
    // Check if this node is fully outside the frustum.
    // If inside = true then that means it has already been determined that this entire branch is visible
    if(inside == false)
    {
        ViewFrustum::Containment result = frustum.ContainsSphere(sphere);

        if(result == ViewFrustum::OUTSIDE)
            return;

        if(result == ViewFrustum::INSIDE)
            inside = true;
    }

    // If this node has children, check them
    if(GetChildCount() > 0)
    {
        if(children[0])
            children[0]->GetVisibleMeshes(frustum, viewsphere, visible_set, inside);

        if(children[1])
            children[1]->GetVisibleMeshes(frustum, viewsphere, visible_set, inside);

        if(children[2])
            children[2]->GetVisibleMeshes(frustum, viewsphere, visible_set, inside);

        if(children[3])
            children[3]->GetVisibleMeshes(frustum, viewsphere, visible_set, inside);

        return;
    }

    // If this node has any meshes, check each of their visibility and add them to the list if they're not completely outside the frustum
    for(size_t i = 0, size = meshes.size(); i < size; ++i)
    {
        const QuadTreeMesh *mesh = meshes[i];

        if(inside == false)
        {
            ViewFrustum::Containment res = frustum.ContainsSphere(mesh->sphere);
            if(res == ViewFrustum::OUTSIDE)
                continue;

            if(res == ViewFrustum::INTERSECTS)
            {
                // The sphere intersects one of the edges of the screen, so try the box test
                res = frustum.ContainsBox(mesh->box);
                if(res == ViewFrustum::OUTSIDE)
                    continue;
            }
        }

        // Avoid camera rotation dependent clipping by using a spherical far clip plane
        // Test mesh against view sphere (eyepos.xyz, radius)
        D3DXVECTOR3 eyepos(viewsphere.x, viewsphere.y, viewsphere.z);
        D3DXVECTOR3 d = mesh->sphere.center - eyepos;
        float rangesquared = d.x*d.x + d.y*d.y + d.z*d.z;
        float viewlimit = viewsphere.w + mesh->sphere.radius;

        if(rangesquared <= viewlimit*viewlimit)
            visible_set.visible_set.push_back(mesh);
    }
}