void gim_trimesh_get_triangle_data(GIM_TRIMESH * trimesh, GUINT32 triangle_index, GIM_TRIANGLE_DATA * tri_data) { vec3f * transformed_vertices = GIM_BUFFER_ARRAY_POINTER(vec3f,trimesh->m_transformed_vertex_buffer,0); GUINT32 * triangle_indices = GIM_BUFFER_ARRAY_POINTER(GUINT32,trimesh->m_tri_index_buffer,triangle_index*3); //Copy the vertices VEC_COPY(tri_data->m_vertices[0],transformed_vertices[triangle_indices[0]]); VEC_COPY(tri_data->m_vertices[1],transformed_vertices[triangle_indices[1]]); VEC_COPY(tri_data->m_vertices[2],transformed_vertices[triangle_indices[2]]); //Get the planes GIM_TRIPLANES_CACHE * planes = GIM_DYNARRAY_POINTER(GIM_TRIPLANES_CACHE,trimesh->m_planes_cache_buffer); planes += triangle_index; //verify planes cache GUINT32 bit_eval; GIM_BITSET_GET(trimesh->m_planes_cache_bitset,triangle_index,bit_eval); if(bit_eval == 0)// Needs to calc the planes { //Calc the face plane TRIANGLE_PLANE(tri_data->m_vertices[0],tri_data->m_vertices[1],tri_data->m_vertices[2],planes->m_planes[0]); //Calc the edge 1 EDGE_PLANE(tri_data->m_vertices[0],tri_data->m_vertices[1],(planes->m_planes[0]),(planes->m_planes[1])); //Calc the edge 2 EDGE_PLANE(tri_data->m_vertices[1],tri_data->m_vertices[2],(planes->m_planes[0]),(planes->m_planes[2])); //Calc the edge 3 EDGE_PLANE(tri_data->m_vertices[2],tri_data->m_vertices[0],(planes->m_planes[0]), (planes->m_planes[3])); //mark GIM_BITSET_SET(trimesh->m_planes_cache_bitset,triangle_index); } VEC_COPY_4((tri_data->m_planes.m_planes[0]),(planes->m_planes[0]));//face plane VEC_COPY_4((tri_data->m_planes.m_planes[1]),(planes->m_planes[1]));//edge1 VEC_COPY_4((tri_data->m_planes.m_planes[2]),(planes->m_planes[2]));//edge2 VEC_COPY_4((tri_data->m_planes.m_planes[3]),(planes->m_planes[3]));//edge3 }
/*! */ SIMD_FORCE_INLINE GUINT clip_triangle( const btVector4 & tri_plane, const btVector3 * tripoints, const btVector3 * srcpoints, btVector3 * clip_points) { // edge 0 btVector4 edgeplane; EDGE_PLANE(tripoints[0],tripoints[1],tri_plane,edgeplane); GUINT clipped_count = PLANE_CLIP_TRIANGLE3D( edgeplane,srcpoints[0],srcpoints[1],srcpoints[2],temp_points); if(clipped_count == 0) return 0; // edge 1 EDGE_PLANE(tripoints[1],tripoints[2],tri_plane,edgeplane); clipped_count = PLANE_CLIP_POLYGON3D( edgeplane,temp_points,clipped_count,temp_points1); if(clipped_count == 0) return 0; // edge 2 EDGE_PLANE(tripoints[2],tripoints[0],tri_plane,edgeplane); clipped_count = PLANE_CLIP_POLYGON3D( edgeplane,temp_points1,clipped_count,clip_points); return clipped_count; /*GUINT i0 = (tri_plane.closestAxis()+1)%3; GUINT i1 = (i0+1)%3; // edge 0 btVector3 temp_points[MAX_TRI_CLIPPING]; btVector3 temp_points1[MAX_TRI_CLIPPING]; GUINT clipped_count= PLANE_CLIP_TRIANGLE_GENERIC( 0,srcpoints[0],srcpoints[1],srcpoints[2],temp_points, DISTANCE_EDGE(tripoints[0],tripoints[1],i0,i1)); if(clipped_count == 0) return 0; // edge 1 clipped_count = PLANE_CLIP_POLYGON_GENERIC( 0,temp_points,clipped_count,temp_points1, DISTANCE_EDGE(tripoints[1],tripoints[2],i0,i1)); if(clipped_count == 0) return 0; // edge 2 clipped_count = PLANE_CLIP_POLYGON_GENERIC( 0,temp_points1,clipped_count,clipped_points, DISTANCE_EDGE(tripoints[2],tripoints[0],i0,i1)); return clipped_count;*/ }