Beispiel #1
0
	void Frustum::RecalculatePlanesEx(glm::mat4x4& p_view, glm::mat4x4& p_proj)
	{
		glm::mat4 matrix;

		float a = -(m_far + m_near) / (m_far - m_near);
		float b = -(2 * m_far * m_near) / (m_far - m_near);

		float c = p_proj[2][2];
		float d = p_proj[3][2];

		matrix = p_proj * p_view;

		m_planesEx[NEARP].a = matrix[0][3] + matrix[0][2];
		m_planesEx[NEARP].b = matrix[1][3] + matrix[1][2];
		m_planesEx[NEARP].c = matrix[2][3] + matrix[2][2];
		m_planesEx[NEARP].d = matrix[3][3] + matrix[3][2];
		NormalizePlane(m_planesEx[NEARP]);

		m_planesEx[FARP].a = matrix[0][3] - matrix[0][2];
		m_planesEx[FARP].b = matrix[1][3] - matrix[1][2];
		m_planesEx[FARP].c = matrix[2][3] - matrix[2][2];
		m_planesEx[FARP].d = matrix[3][3] - matrix[3][2];
		NormalizePlane(m_planesEx[FARP]);

		m_planesEx[LEFT].a = matrix[0][3] + matrix[0][0];
		m_planesEx[LEFT].b = matrix[1][3] + matrix[1][0];
		m_planesEx[LEFT].c = matrix[2][3] + matrix[2][0];
		m_planesEx[LEFT].d = matrix[3][3] + matrix[3][0];
		NormalizePlane(m_planesEx[LEFT]);

		m_planesEx[RIGHT].a = matrix[0][3] - matrix[0][0];
		m_planesEx[RIGHT].b = matrix[1][3] - matrix[1][0];
		m_planesEx[RIGHT].c = matrix[2][3] - matrix[2][0];
		m_planesEx[RIGHT].d = matrix[3][3] - matrix[3][0];
		NormalizePlane(m_planesEx[RIGHT]);

		m_planesEx[TOP].a = matrix[0][3] - matrix[0][1];
		m_planesEx[TOP].b = matrix[1][3] - matrix[1][1];
		m_planesEx[TOP].c = matrix[2][3] - matrix[2][1];
		m_planesEx[TOP].d = matrix[3][3] - matrix[3][1];
		NormalizePlane(m_planesEx[TOP]);
		
		m_planesEx[BOTTOM].a = matrix[0][3] + matrix[0][1];
		m_planesEx[BOTTOM].b = matrix[1][3] + matrix[1][1];
		m_planesEx[BOTTOM].c = matrix[2][3] + matrix[2][1];
		m_planesEx[BOTTOM].d = matrix[3][3] + matrix[3][1];
		NormalizePlane(m_planesEx[BOTTOM]);

		ftl = Intersect3Planes(m_planesEx[LEFT], m_planesEx[TOP], m_planesEx[FARP]);
		fbl = Intersect3Planes(m_planesEx[LEFT], m_planesEx[BOTTOM], m_planesEx[FARP]);

		fbr = Intersect3Planes(m_planesEx[RIGHT], m_planesEx[BOTTOM], m_planesEx[FARP]);
		ftr = Intersect3Planes(m_planesEx[RIGHT], m_planesEx[TOP], m_planesEx[FARP]);

		ntl = Intersect3Planes(m_planesEx[LEFT], m_planesEx[TOP], m_planesEx[NEARP]);
		nbl = Intersect3Planes(m_planesEx[LEFT], m_planesEx[BOTTOM], m_planesEx[NEARP]);

		nbr = Intersect3Planes(m_planesEx[RIGHT], m_planesEx[BOTTOM], m_planesEx[NEARP]);
		ntr = Intersect3Planes(m_planesEx[RIGHT], m_planesEx[TOP], m_planesEx[NEARP]);
	}
Beispiel #2
0
void FrustumPlanes::GetPoints(VEC3* points) const
{
	assert(points);

	Intersect3Planes(Planes[4], Planes[0], Planes[3], &points[0]);
	Intersect3Planes(Planes[4], Planes[1], Planes[3], &points[1]);
	Intersect3Planes(Planes[4], Planes[0], Planes[2], &points[2]);
	Intersect3Planes(Planes[4], Planes[1], Planes[2], &points[3]);
	Intersect3Planes(Planes[5], Planes[0], Planes[3], &points[4]);
	Intersect3Planes(Planes[5], Planes[1], Planes[3], &points[5]);
	Intersect3Planes(Planes[5], Planes[0], Planes[2], &points[6]);
	Intersect3Planes(Planes[5], Planes[1], Planes[2], &points[7]);
}