Beispiel #1
0
Frus calcFrus(const Matrix& M, float aspect, float fov)
{
	float x = tanf(fov/2);
	float y = x / aspect;
	Vector v[4] = {
		M.origin - M.axes.z - M.axes.y * y - M.axes.x * x,
		M.origin - M.axes.z + M.axes.y * y - M.axes.x * x,
		M.origin - M.axes.z + M.axes.y * y + M.axes.x * x,
		M.origin - M.axes.z - M.axes.y * y + M.axes.x * x,
	};
	Frus f;
	f.p[0] = Plane(-M.axes.z, dot(-M.axes.z, M.origin));
	for(int i=0; i<4; i++){
		f.p[i+1] = planeFromPoints(v[i], v[(i+1)%4], M.origin);
	}
	return f;
}
Beispiel #2
0
void LLCamera::calcAgentFrustumPlanes(LLVector3* frust)
{

	for (int i = 0; i < 8; i++)
	{
		mAgentFrustum[i] = frust[i];
	}

	//frust contains the 8 points of the frustum, calculate 6 planes

	//order of planes is important, keep most likely to fail in the front of the list

	//near - frust[0], frust[1], frust[2]
	mAgentPlanes[2] = planeFromPoints(frust[0], frust[1], frust[2]);

	//far  
	mAgentPlanes[5] = planeFromPoints(frust[5], frust[4], frust[6]);

	//left  
	mAgentPlanes[0] = planeFromPoints(frust[4], frust[0], frust[7]);

	//right  
	mAgentPlanes[1] = planeFromPoints(frust[1], frust[5], frust[6]);

	//top  
	mAgentPlanes[4] = planeFromPoints(frust[3], frust[2], frust[6]);

	//bottom  
	mAgentPlanes[3] = planeFromPoints(frust[1], frust[0], frust[4]);

	//cache plane octant facing mask for use in AABBInFrustum
	for (int i = 0; i < 6; i++)
	{
		U8 mask = 0;
		LLPlane p = mAgentPlanes[i];
		LLVector3 n = LLVector3(p);

		if (n.mV[0] >= 0)
		{
			mask |= 1;
		}
		if (n.mV[1] >= 0)
		{
			mask |= 2;
		}
		if (n.mV[2] >= 0)
		{
			mask |= 4;
		}
		mAgentPlaneMask[i] = mask;
	}
}
Beispiel #3
0
void LLCamera::calcAgentFrustumPlanes(LLVector3* frust)
{

	for (int i = 0; i < 8; i++)
	{
		mAgentFrustum[i] = frust[i];
	}

	mFrustumCornerDist = (frust[5] - getOrigin()).magVec();

	//frust contains the 8 points of the frustum, calculate 6 planes

	//order of planes is important, keep most likely to fail in the front of the list

	//near - frust[0], frust[1], frust[2]
	mAgentPlanes[2].p = planeFromPoints(frust[0], frust[1], frust[2]);

	//far  
	mAgentPlanes[5].p = planeFromPoints(frust[5], frust[4], frust[6]);

	//left  
	mAgentPlanes[0].p = planeFromPoints(frust[4], frust[0], frust[7]);

	//right  
	mAgentPlanes[1].p = planeFromPoints(frust[1], frust[5], frust[6]);

	//top  
	mAgentPlanes[4].p = planeFromPoints(frust[3], frust[2], frust[6]);

	//bottom  
	mAgentPlanes[3].p = planeFromPoints(frust[1], frust[0], frust[4]);

	//cache plane octant facing mask for use in AABBInFrustum
	for (U32 i = 0; i < mPlaneCount; i++)
	{
		mAgentPlanes[i].mask = calcPlaneMask(mAgentPlanes[i].p);
	}
}