DRW: Add plane culling test.
Usefull to see if the view frustum is totally behind a plane.
This commit is contained in:
		@@ -462,6 +462,7 @@ void DRW_state_clip_planes_reset(void);
 | 
			
		||||
/* Culling, return true if object is inside view frustum. */
 | 
			
		||||
bool DRW_culling_sphere_test(BoundSphere *bsphere);
 | 
			
		||||
bool DRW_culling_box_test(BoundBox *bbox);
 | 
			
		||||
bool DRW_culling_plane_test(float plane[4]);
 | 
			
		||||
 | 
			
		||||
/* Selection */
 | 
			
		||||
void DRW_select_load_id(unsigned int id);
 | 
			
		||||
 
 | 
			
		||||
@@ -320,6 +320,7 @@ typedef struct DRWManager {
 | 
			
		||||
 | 
			
		||||
	struct {
 | 
			
		||||
		float frustum_planes[6][4];
 | 
			
		||||
		BoundBox frustum_corners;
 | 
			
		||||
		BoundSphere frustum_bsphere;
 | 
			
		||||
		bool updated;
 | 
			
		||||
	} clipping;
 | 
			
		||||
 
 | 
			
		||||
@@ -461,6 +461,8 @@ static void draw_clipping_setup_from_view(void)
 | 
			
		||||
		mul_m4_v3(viewinv, bbox.vec[i]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	memcpy(&DST.clipping.frustum_corners, &bbox, sizeof(BoundBox));
 | 
			
		||||
 | 
			
		||||
	/* Compute clip planes using the world space frustum corners. */
 | 
			
		||||
	for (int p = 0; p < 6; p++) {
 | 
			
		||||
		int q, r;
 | 
			
		||||
@@ -640,6 +642,22 @@ bool DRW_culling_box_test(BoundBox *bbox)
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Return True if the current view frustum is inside or intersect the given plane */
 | 
			
		||||
bool DRW_culling_plane_test(float plane[4])
 | 
			
		||||
{
 | 
			
		||||
	draw_clipping_setup_from_view();
 | 
			
		||||
 | 
			
		||||
	/* Test against the 8 frustum corners. */
 | 
			
		||||
	for (int c = 0; c < 8; c++) {
 | 
			
		||||
		float dist = plane_point_side_v3(plane, DST.clipping.frustum_corners.vec[c]);
 | 
			
		||||
		if (dist < 0.0f) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** \} */
 | 
			
		||||
 | 
			
		||||
/* -------------------------------------------------------------------- */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user