Example #1
0
// Put the polygon in the the appropriate list
// and increment the counter assosiated with it.
// A polygon can end up in muliple lists, but not
// all of them.
int bsp_subdivide(poly_t *divider, poly_t *poly,
				  poly_t **coplanar_front, int *n_cp_front,
				  poly_t **coplanar_back,  int *n_cp_back,
				  poly_t **front,          int *n_front,
				  poly_t **back,           int *n_back) {
	switch(poly_classify_poly(divider, poly)) {
	case FRONT:
		front[*n_front] = poly;
		*n_front += 1;
		break;
	case BACK:
		back[*n_back] = poly;
		*n_back += 1;
		break;
	case COPLANAR:
		if(f3_dot(divider->normal, poly->normal) > 0) {
			coplanar_front[*n_cp_front] = poly;
			*n_cp_front += 1;
		}
		else {
			coplanar_back[*n_cp_back] = poly;
			*n_cp_back += 1;
		}
		break;
	case SPANNING: {
		poly_t *f = NULL;
		poly_t *b = NULL;
		check(poly_split(divider, poly, &f, &b) == 0,
			  "Failed to split polygon(%p) with divider(%p)", poly, divider);
		front[*n_front] = f;
		*n_front += 1;

		back[*n_back] = b;
		*n_back += 1;
		break;
	}
	}

	return 0;
error:
	return -1;
}
Example #2
0
float f3_distance2(float3 a, float3 b) {
	float3 diff = FLOAT3_INIT;
	f3_sub(&diff, a, b);
	return f3_dot(diff, diff);
}