#include #include #include "common.h" TEST(test_collision_trimesh_sphere_exact) { /* * This tests some extreme cases, where a sphere barely touches some triangles * with zero depth. */ #ifdef dTRIMESH_GIMPACT /* * Although GIMPACT is algorithmically able to handle this extreme case, * the numerical approximation used for the square root produces inexact results. */ return; #endif { const int VertexCount = 4; const int IndexCount = 2*3; // this is a square on the XY plane /* 3 2 +----+ | /| | / | | / | |/ | +----+ 0 1 */ float vertices[VertexCount * 3] = { -1,-1,0, 1,-1,0, 1,1,0, -1,1,0 }; dTriIndex indices[IndexCount] = { 0,1,2, 0,2,3 }; dTriMeshDataID data = dGeomTriMeshDataCreate(); dGeomTriMeshDataBuildSingle(data, vertices, 3 * sizeof(float), VertexCount, indices, IndexCount, 3 * sizeof(dTriIndex)); dGeomID trimesh = dCreateTriMesh(0, data, 0, 0, 0); const dReal radius = 4; dGeomID sphere = dCreateSphere(0, radius); dContactGeom cg[4]; int nc; dVector3 trinormal = { 0, 0, -1 }; // Test case: sphere touches the diagonal edge dGeomSetPosition(sphere, 0,0,radius); nc = dCollide(trimesh, sphere, 4, &cg[0], sizeof cg[0]); CHECK_EQUAL(2, nc); for (int i=0; i