Esempio n. 1
0
int main(int argc, char* argv[]) {
	int i;
	int j;
	int n;

	if (argc < 2) {
		n = 10000;
	} else {
		n = atoi(argv[1]);
	}
	printf("Number of iterations: %d\n", n);

	float* xyz = (float*)malloc(n * 6 * 3 * sizeof (float));
	int* y = (int*)malloc(n * sizeof (int));

	if(xyz == NULL) {
		printf("Cannot allocate memory for the triangle coordinates!");
		return -1;
	}

	for (i = 0; i < n * 6 * 3; ++i) {
		xyz[i] = ((float)rand())/RAND_MAX;
	}

	for (i = 0, j = 0; i < (n * 6 * 3); i += 6 * 3, j++) {
		y[j] = tri_tri_intersect(
			xyz + i + 0 * 3, xyz + i + 1 * 3, xyz + i + 2 * 3,
			xyz + i + 3 * 3, xyz + i + 4 * 3, xyz + i + 5 * 3
		);
	}

	for (j = 0; j < n; j++) {
		putchar('0' + (char)y[j]);
	}
	putchar('\n');

	free(xyz);
	xyz = NULL;

	return 0;
}
Esempio n. 2
0
bool Triangles_Intersect(const EERIE_TRI & v, const EERIE_TRI & u)
{
	EERIE_3D_BBOX bb1 = Triangle_ComputeBoundingBox(v);
	EERIE_3D_BBOX bb2 = Triangle_ComputeBoundingBox(u);

	if (bb1.max.y < bb2.min.y) return false;

	if (bb1.min.y > bb2.max.y) return false;

	if (bb1.max.x < bb2.min.x) return false;

	if (bb1.min.x > bb2.max.x) return false;

	if (bb1.max.z < bb2.min.z) return false;

	if (bb1.min.z > bb2.max.z) return false;

	if (tri_tri_intersect(v, u)) 
		return true;

	return false;
}