Added unit cube generation and get_support queries.

master
Martin Felis 2021-05-28 21:43:37 +02:00
parent 0c53f3fd8b
commit e93a659daf
1 changed files with 78 additions and 0 deletions

View File

@ -121,6 +121,8 @@ int sch_hull_connect_face_edges(const sch_hull* hull, int face_index);
void sch_create_face(int num_vert, simd4f* vertices, sch_face* out_face); void sch_create_face(int num_vert, simd4f* vertices, sch_face* out_face);
void sch_create_unitbox(sch_hull* out_hull);
// //
// sconvcol Implementation // sconvcol Implementation
// //
@ -337,6 +339,26 @@ sch_edge* sch_hull_find_edge (const sch_hull* hull, const simd4f v0, const simd4
return NULL; return NULL;
} }
void sch_hull_get_support(const sch_hull* hull, simd4f normal, simd4f* out_vert) {
sch_edge* edge = hull->faces[0].edge;
sch_edge* last_edge = edge;
float normal_dot_edge = -1.;
do {
simd4f dir = simd4f_normalize3(simd4f_sub (edge->next->vert->p, edge->vert->p));
normal_dot_edge = simd4f_dot3_scalar(dir, normal);
if (normal_dot_edge <= 0.) {
edge = edge->twin->next;
} else {
edge = edge->next;
last_edge = edge;
}
} while (last_edge != edge || normal_dot_edge > 0);
*out_vert = edge->vert->p;
}
int sch_hull_is_vertex_concave(const sch_hull* hull, const simd4f v) { int sch_hull_is_vertex_concave(const sch_hull* hull, const simd4f v) {
sch_plane plane; sch_plane plane;
for (int i = 0; i < hull->num_faces; i++) { for (int i = 0; i < hull->num_faces; i++) {
@ -407,6 +429,62 @@ int sch_hull_is_closed (const sch_hull* hull) {
return SchHullResultOK; return SchHullResultOK;
} }
void sch_create_unitbox(sch_hull* out_hull) {
sch_hull_builder builder;
sch_builder_reset(&builder);
// +x
sch_builder_face_begin(&builder);
sch_builder_face_vertex(&builder, simd4f_create (0.5f, -0.5f, 0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( 0.5f, -0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( 0.5f, 0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create (0.5f, 0.5f, 0.5f, 1.f));
sch_builder_face_end(&builder);
// -x
sch_builder_face_begin(&builder);
sch_builder_face_vertex(&builder, simd4f_create (-0.5f, -0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( -0.5f, -0.5f, 0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( -0.5f, 0.5f, 0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create (-0.5f, 0.5f, -0.5f, 1.f));
sch_builder_face_end(&builder);
// +y
sch_builder_face_begin(&builder);
sch_builder_face_vertex(&builder, simd4f_create (0.5f, 0.5f, 0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( 0.5f, 0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( -0.5f, 0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create (-0.5f, 0.5f, 0.5f, 1.f));
sch_builder_face_end(&builder);
// +y
sch_builder_face_begin(&builder);
sch_builder_face_vertex(&builder, simd4f_create (-0.5f, -0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( 0.5f, -0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( 0.5f, -0.5f, 0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create (-0.5f, -0.5f, 0.5f, 1.f));
sch_builder_face_end(&builder);
// +z
sch_builder_face_begin(&builder);
sch_builder_face_vertex(&builder, simd4f_create (-0.5f, -0.5f, 0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( 0.5f, -0.5f, 0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create ( 0.5f, 0.5f, 0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create (-0.5f, 0.5f, 0.5f, 1.f));
sch_builder_face_end(&builder);
// -z
sch_builder_face_begin(&builder);
sch_builder_face_vertex(&builder, simd4f_create(0.5f, -0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create(-0.5f, -0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create(-0.5f, 0.5f, -0.5f, 1.f));
sch_builder_face_vertex(&builder, simd4f_create(0.5f, 0.5f, -0.5f, 1.f));
sch_builder_face_end(&builder);
int hull_result = sch_builder_create_hull(&builder, out_hull);
assert (hull_result == SchHullResultOK);
}
#endif /* SCONVCOL_IMPLEMENTATION */ #endif /* SCONVCOL_IMPLEMENTATION */
#ifdef __cplusplus #ifdef __cplusplus