Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grieverheart/46b0f66add9404e82f353e6d8d106e3d to your computer and use it in GitHub Desktop.
Save Grieverheart/46b0f66add9404e82f353e6d8d106e3d to your computer and use it in GitHub Desktop.
GJK API v2
#include <stdio.h>
typedef void (*support_t)(const void* data, const double* dir, double* point);
typedef struct{
support_t support;
double min[3], max[3];
}box_t;
typedef struct{
support_t support;
}sphere_t;
void box_support(const void* data, const double* dir, double* point){
const box_t* box = data;
printf("Hello from box: %f, %f, %f\n", box->min[0], box->min[1], box->min[2]);
}
void sphere_support(const void* data, const double* dir, double* point){
printf("Hello from sphere\n");
}
void init_box(box_t* box, const double* min, const double* max){
box->support = box_support;
for(int i = 0; i < 3; ++i){
box->min[i] = min[i];
box->max[i] = max[i];
}
}
void init_sphere(sphere_t* sphere){
sphere->support = sphere_support;
}
typedef struct{
double pos[3];
double rot[4];
double size;
}transform_t;
int gjk_boolean(
const void* sa, const transform_t* ta,
const void* sb, const transform_t* tb
){
double dir[3], point[3];
support_t ca = *(const support_t*)sa;
support_t cb = *(const support_t*)sb;
ca(sa, dir, point);
cb(sb, dir, point);
return 0;
}
int main(int argc, char* argv[]){
double min[] = {-11.0, -7.0, -113.0};
double max[] = {1.0, 1.0, 1.0};
box_t box;
sphere_t sphere;
init_sphere(&sphere);
init_box(&box, min, max);
transform_t ta = {
{0.0, 0.0, 0.0},
{1.0, 0.0, 0.0, 1.0},
1.0
};
gjk_boolean(&box, &ta, &sphere, &ta);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment