Exemplo n.º 1
0
//static
void LLViewerCamera::updateFrustumPlanes(LLCamera& camera, BOOL ortho, BOOL zflip, BOOL no_hacks)
{
	GLint* viewport = (GLint*) gGLViewport;
	GLdouble* model = gGLModelView;
	GLdouble* proj = gGLProjection;
	GLdouble objX,objY,objZ;

	LLVector3 frust[8];

	if (no_hacks)
	{
		gluUnProject(viewport[0],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[0].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[1].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[2].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[3].setVec((F32)objX,(F32)objY,(F32)objZ);

		gluUnProject(viewport[0],viewport[1],1,model,proj,viewport,&objX,&objY,&objZ);
		frust[4].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1],1,model,proj,viewport,&objX,&objY,&objZ);
		frust[5].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],1,model,proj,viewport,&objX,&objY,&objZ);
		frust[6].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0],viewport[1]+viewport[3],1,model,proj,viewport,&objX,&objY,&objZ);
		frust[7].setVec((F32)objX,(F32)objY,(F32)objZ);
	}
	else if (zflip)
	{
		gluUnProject(viewport[0],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[0].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[1].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[2].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[3].setVec((F32)objX,(F32)objY,(F32)objZ);

		gluUnProject(viewport[0],viewport[1]+viewport[3],1,model,proj,viewport,&objX,&objY,&objZ);
		frust[4].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],1,model,proj,viewport,&objX,&objY,&objZ);
		frust[5].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1],1,model,proj,viewport,&objX,&objY,&objZ);
		frust[6].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0],viewport[1],1,model,proj,viewport,&objX,&objY,&objZ);
		frust[7].setVec((F32)objX,(F32)objY,(F32)objZ);

		for (U32 i = 0; i < 4; i++)
		{
			frust[i+4] = frust[i+4]-frust[i];
			frust[i+4].normVec();
			frust[i+4] = frust[i] + frust[i+4]*camera.getFar();
		}
	}
	else
	{
		gluUnProject(viewport[0],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[0].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[1].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[2].setVec((F32)objX,(F32)objY,(F32)objZ);
		gluUnProject(viewport[0],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
		frust[3].setVec((F32)objX,(F32)objY,(F32)objZ);
		
		if (ortho)
		{
			LLVector3 far_shift = camera.getAtAxis()*camera.getFar()*2.f; 
			for (U32 i = 0; i < 4; i++)
			{
				frust[i+4] = frust[i] + far_shift;
			}
		}
		else
		{
			for (U32 i = 0; i < 4; i++)
			{
				LLVector3 vec = frust[i] - camera.getOrigin();
				vec.normVec();
				frust[i+4] = camera.getOrigin() + vec*camera.getFar();
			}
		}
	}

	camera.calcAgentFrustumPlanes(frust);
}
Exemplo n.º 2
0
//static
void LLViewerCamera::updateFrustumPlanes(LLCamera& camera, BOOL ortho, BOOL zflip, BOOL no_hacks)
{
	LLVector3 frust[8];

	LLRect view_port(gGLViewport[0],gGLViewport[1]+gGLViewport[3],gGLViewport[0]+gGLViewport[2],gGLViewport[1]);

	if (no_hacks)
	{
		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mBottom,0.f),gGLModelView,gGLProjection,view_port,frust[0]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mBottom,0.f),gGLModelView,gGLProjection,view_port,frust[1]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mTop,0.f),gGLModelView,gGLProjection,view_port,frust[2]);
		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mTop,0.f),gGLModelView,gGLProjection,view_port,frust[3]);

		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mBottom,1.f),gGLModelView,gGLProjection,view_port,frust[4]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mBottom,1.f),gGLModelView,gGLProjection,view_port,frust[5]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mTop,1.f),gGLModelView,gGLProjection,view_port,frust[6]);
		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mTop,1.f),gGLModelView,gGLProjection,view_port,frust[7]);
	}
	else if (zflip)
	{
		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mTop,0.f),gGLModelView,gGLProjection,view_port,frust[0]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mTop,0.f),gGLModelView,gGLProjection,view_port,frust[1]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mBottom,0.f),gGLModelView,gGLProjection,view_port,frust[2]);
		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mBottom,0.f),gGLModelView,gGLProjection,view_port,frust[3]);

		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mTop,1.f),gGLModelView,gGLProjection,view_port,frust[4]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mTop,1.f),gGLModelView,gGLProjection,view_port,frust[5]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mBottom,1.f),gGLModelView,gGLProjection,view_port,frust[6]);
		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mBottom,1.f),gGLModelView,gGLProjection,view_port,frust[7]);

		for (U32 i = 0; i < 4; i++)
		{
			frust[i+4] = frust[i+4]-frust[i];
			frust[i+4].normVec();
			frust[i+4] = frust[i] + frust[i+4]*camera.getFar();
		}
	}
	else
	{
		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mBottom,0.f),gGLModelView,gGLProjection,view_port,frust[0]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mBottom,0.f),gGLModelView,gGLProjection,view_port,frust[1]);
		gGL.unprojectf(LLVector3(view_port.mRight,view_port.mTop,0.f),gGLModelView,gGLProjection,view_port,frust[2]);
		gGL.unprojectf(LLVector3(view_port.mLeft,view_port.mTop,0.f),gGLModelView,gGLProjection,view_port,frust[3]);
		
		if (ortho)
		{
			LLVector3 far_shift = camera.getAtAxis()*camera.getFar()*2.f; 
			for (U32 i = 0; i < 4; i++)
			{
				frust[i+4] = frust[i] + far_shift;
			}
		}
		else
		{
			for (U32 i = 0; i < 4; i++)
			{
				LLVector3 vec = frust[i] - camera.getOrigin();
				vec.normVec();
				frust[i+4] = camera.getOrigin() + vec*camera.getFar();
			}
		}
	}

	camera.calcAgentFrustumPlanes(frust);
}