Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <float.h>
- #include <stdbool.h>
- #include "vector3.h"
- typedef struct TSimplex {
- TVec3 points[4];
- int size;
- } TSimplex;
- typedef struct TSphereShape {
- float radius;
- TVec3 position;
- } TSphereShape;
- typedef struct TConvexShape {
- TVec3 * points;
- int count;
- } TConvexShape;
- typedef struct TShape {
- TConvexShape * convex;
- TSphereShape * sphere;
- } TShape;
- typedef struct TEPATriangle {
- TVec3 a, b, c, normal;
- float dist;
- int numInPolytope;
- } TEPATriangle;
- typedef struct TEPAContact {
- TVec3 normal;
- float penetrationDepth;
- } TEPAContact;
- typedef struct TEPAFace {
- int a, b, c;
- } TEPAFace;
- typedef struct TEPAPolytope {
- TVec3 * vertices;
- int vertexCount;
- TEPAFace * faces;
- int faceCount;
- } TEPAPolytope;
- #ifndef M_PI
- #define M_PI 3.14159
- #endif
- void DrawPolytope( TEPAPolytope * polytope );
- TEPAPolytope * currentPolytope;
- TShape * currentShape1;
- TShape * currentShape2;
- // ===========================
- // HELPERS
- // ===========================
- bool Helper_SameDirection( TVec3 a, TVec3 b ) {
- return Vec3_Dot( a, b ) > 0;
- }
- // ===========================
- // SIMPLEX ROUTINE
- // ===========================
- void Simplex_RemovePoint( TSimplex * s, int num ) {
- if( s->size > 0 ) {
- if( num == 0 ) {
- s->points[0] = s->points[1];
- s->points[1] = s->points[2];
- s->points[2] = s->points[3];
- }
- if( num == 1 ) {
- s->points[1] = s->points[2];
- s->points[2] = s->points[3];
- }
- if( num == 2 ) {
- s->points[2] = s->points[3];
- }
- s->size--;
- }
- }
- void Simplex_AddPoint( TSimplex * s, TVec3 p ) {
- if( s->size < 4 ) {
- s->points[ s->size ] = p;
- s->size++;
- }
- }
- // ===========================
- // CONVEX SHAPE ROUTINE
- // ===========================
- TShape * ConvexShape_CreateTriangle( TVec3 a, TVec3 b, TVec3 c ) {
- TShape * shape = calloc( 1, sizeof( TShape ));
- shape->convex = calloc( 1, sizeof( TConvexShape ));
- shape->convex->count = 3;
- shape->convex->points = malloc( shape->convex->count * sizeof( TVec3 ));
- shape->convex->points[0] = a;
- shape->convex->points[1] = b;
- shape->convex->points[2] = c;
- return shape;
- }
- TShape * ConvexShape_CreateTetrahedron( TVec3 a, TVec3 b, TVec3 c, TVec3 d ) {
- TShape * shape = calloc( 1, sizeof( TShape ));
- shape->convex = calloc( 1, sizeof( TConvexShape ));
- shape->convex->count = 4;
- shape->convex->points = malloc( shape->convex->count * sizeof( TVec3 ));
- shape->convex->points[0] = a;
- shape->convex->points[1] = b;
- shape->convex->points[2] = c;
- shape->convex->points[3] = d;
- return shape;
- }
- TShape * ConvexShape_CreateSphere( TVec3 position, float radius ) {
- TShape * shape = calloc( 1, sizeof( TShape ));
- shape->sphere = calloc( 1, sizeof( TSphereShape ));
- shape->sphere->position = position;
- shape->sphere->radius = radius;
- return shape;
- }
- void ConvexShape_Delete( TShape * shape ) {
- if( shape->convex ) {
- free( shape->convex );
- }
- if( shape->sphere ) {
- free( shape->sphere );
- }
- free( shape );
- }
- TVec3 ConvexShape_GetFarthestPointInDirection( TShape * shape, TVec3 dir ) {
- const float eps = 0.000001;
- if( fabs( dir.x ) < eps && fabs( dir.y ) < eps && fabs( dir.z ) < eps ) {
- printf( "GJK Warning: Zero direction passed!\n" );
- }
- if( shape->convex ) {
- TVec3 farthest;
- float lastDot = -FLT_MAX;
- for( int i = 0; i < shape->convex->count; i++ ) {
- float dot = Vec3_Dot( dir, shape->convex->points[i] );
- if( dot > lastDot ) {
- farthest = shape->convex->points[i];
- lastDot = dot;
- }
- }
- return farthest;
- }
- if( shape->sphere ) {
- return Vec3_Add( shape->sphere->position, Vec3_Scale( Vec3_Normalize( dir ), shape->sphere->radius ));
- }
- return Vec3_Set( 0, 0, 0 );
- }
- // ===========================
- // GJK ALGORITHM ROUTINE
- // ===========================
- TVec3 GJK_GetSupport( TShape * shape1, TShape * shape2, TVec3 dir ) {
- return Vec3_Sub( ConvexShape_GetFarthestPointInDirection( shape1, dir ), ConvexShape_GetFarthestPointInDirection( shape2, Vec3_Negate( dir )));
- }
- bool GJK_ProcessLine( TSimplex * simplex, TVec3 * outDirection ) {
- TVec3 a = simplex->points[1];
- TVec3 b = simplex->points[0];
- TVec3 ab = Vec3_Sub( b, a );
- TVec3 aO = Vec3_Negate( a );
- if( Helper_SameDirection( ab, aO )) {
- *outDirection = Vec3_Cross( Vec3_Cross( ab, aO ), ab );
- } else {
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = aO;
- }
- return false;
- }
- bool GJK_ProcessTriangle( TSimplex * simplex, TVec3 * outDirection ) {
- TVec3 a = simplex->points[2];
- TVec3 b = simplex->points[1];
- TVec3 c = simplex->points[0];
- TVec3 aO = Vec3_Negate( a );
- TVec3 ab = Vec3_Sub( b, a );
- TVec3 ac = Vec3_Sub( c, a );
- TVec3 abc = Vec3_Cross( ab, ac );
- TVec3 acNormal = Vec3_Cross( abc, ac );
- TVec3 abNormal = Vec3_Cross( ab, abc );
- if( Helper_SameDirection( acNormal, aO )) {
- if( Helper_SameDirection( ac, aO )) {
- Simplex_RemovePoint( simplex, 1 );
- *outDirection = Vec3_Cross( Vec3_Cross(ac, aO), ac );
- } else {
- if( Helper_SameDirection( ab, aO )) {
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = Vec3_Cross( Vec3_Cross(ab, aO), ab);
- } else {
- Simplex_RemovePoint( simplex, 1 );
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = aO;
- }
- }
- } else {
- if( Helper_SameDirection( abNormal, aO )) {
- if( Helper_SameDirection( ab, aO )) {
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = Vec3_Cross( Vec3_Cross(ab, aO), ab);
- } else {
- Simplex_RemovePoint( simplex, 1 );
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = aO;
- }
- } else {
- if( Helper_SameDirection( abc, aO )) {
- *outDirection = Vec3_Cross(Vec3_Cross(abc, aO), abc);
- } else {
- *outDirection = Vec3_Cross(Vec3_Cross( Vec3_Negate( abc ), aO), Vec3_Negate( abc ) );
- }
- }
- }
- return false;
- }
- bool GJK_ProcessTetrahedron( TSimplex * simplex, TVec3 * outDirection ) {
- TVec3 a = simplex->points[3];
- TVec3 b = simplex->points[2];
- TVec3 c = simplex->points[1];
- TVec3 d = simplex->points[0];
- TVec3 ac = Vec3_Sub( c, a );
- TVec3 ab = Vec3_Sub( b, a );
- TVec3 ad = Vec3_Sub( d, a );
- TVec3 acd = Vec3_Cross( ad, ac );
- TVec3 abd = Vec3_Cross( ab, ad );
- TVec3 abc = Vec3_Cross( ac, ab );
- TVec3 aO = Vec3_Negate( a );
- if( Helper_SameDirection( abc, aO )) {
- if( Helper_SameDirection( Vec3_Cross( abc, ac ), aO )) {
- Simplex_RemovePoint( simplex, 2 );
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = Vec3_Cross( Vec3_Cross( ac, aO ), ac );
- } else if( Helper_SameDirection( Vec3_Cross( ab, abc ), aO )) {
- Simplex_RemovePoint( simplex, 1 );
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = Vec3_Cross( Vec3_Cross( ab, aO ), ab );
- } else {
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = abc;
- }
- } else if( Helper_SameDirection( acd, aO )) {
- if( Helper_SameDirection( Vec3_Cross( acd, ad ), aO )) {
- Simplex_RemovePoint( simplex, 2 );
- Simplex_RemovePoint( simplex, 1 );
- *outDirection = Vec3_Cross( Vec3_Cross( ad, aO ), ad );
- } else if ( Helper_SameDirection( Vec3_Cross( ac, acd ), aO )) {
- Simplex_RemovePoint( simplex, 2 );
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = Vec3_Cross( Vec3_Cross( ac, aO ), ac );
- } else {
- Simplex_RemovePoint( simplex, 2 );
- *outDirection = acd;
- }
- } else if( Helper_SameDirection( abd, aO )) {
- if( Helper_SameDirection( Vec3_Cross( abd, ab ), aO )) {
- Simplex_RemovePoint( simplex, 1 );
- Simplex_RemovePoint( simplex, 0 );
- *outDirection = Vec3_Cross( Vec3_Cross( ab, aO ), ab );
- } else if( Helper_SameDirection( Vec3_Cross( ad, abd ), aO )) {
- Simplex_RemovePoint( simplex, 2 );
- Simplex_RemovePoint( simplex, 1 );
- *outDirection = Vec3_Cross( Vec3_Cross( ad, aO ), ad );
- } else {
- Simplex_RemovePoint( simplex, 1 );
- *outDirection = abd;
- }
- } else {
- return true;
- }
- return false;
- }
- bool GJK_ProcessSimplex( TSimplex * simplex, TVec3 * outDirection ) {
- if( simplex->size == 2 ) {
- return GJK_ProcessLine( simplex, outDirection );
- } else if ( simplex->size == 3 ) {
- return GJK_ProcessTriangle( simplex, outDirection );
- } else {
- return GJK_ProcessTetrahedron( simplex, outDirection );
- }
- }
- bool GJK_IsIntersects( TShape * shape1, TShape * shape2, TSimplex * finalSimplex ) {
- TVec3 dir = Vec3_Set( 1, 1, 1 );
- TSimplex simplex = { 0 };
- Simplex_AddPoint( &simplex, GJK_GetSupport( shape1, shape2, dir ));
- dir = Vec3_Negate( dir );
- int convergenceLimit = 50;
- for( int i = 0; i < convergenceLimit; i++ ) {
- TVec3 lastSupport = GJK_GetSupport( shape1, shape2, dir );
- if( Helper_SameDirection( dir, lastSupport )) {
- Simplex_AddPoint( &simplex, lastSupport );
- if( GJK_ProcessSimplex( &simplex, &dir )) {
- printf( "GJK: Intersection! %d iteration(s)!\n", i );
- if( finalSimplex ) {
- *finalSimplex = simplex;
- }
- return true;
- }
- } else {
- printf( "GJK: No intersection! %d iteration(s)!\n", i );
- return false;
- }
- }
- printf( "GJK: No intersection! Convergence limit has reached!\n" );
- return false;
- }
- // ===========================
- // EPA ALGORITHM ROUTINE
- // ===========================
- void Polytope_SetFromSimplex( TEPAPolytope * polytope, TSimplex * simplex ) {
- polytope->vertexCount = 4;
- polytope->vertices = calloc( polytope->vertexCount, sizeof( TVec3 ));
- for( int i = 0; i < polytope->vertexCount; i++ ) {
- polytope->vertices[i] = simplex->points[i];
- }
- polytope->faceCount = 4;
- polytope->faces = calloc( polytope->faceCount, sizeof( TEPAFace ));
- polytope->faces[0] = (TEPAFace) { 0, 1, 2 };
- polytope->faces[1] = (TEPAFace) { 0, 3, 1 };
- polytope->faces[2] = (TEPAFace) { 0, 2, 3 };
- polytope->faces[3] = (TEPAFace) { 2, 1, 3 };
- }
- void Polytope_RemoveFaceAndPatchHole( TEPAPolytope * polytope, int n, TVec3 patchPoint ) {
- int a = polytope->faces[n].a;
- int b = polytope->faces[n].b;
- int c = polytope->faces[n].c;
- // add patch point to point list
- bool alreadyExist = false;
- int patchPointIndex;
- for( int i = 0; i < polytope->vertexCount; i++ ) {
- if( polytope->vertices[i].x == patchPoint.x && polytope->vertices[i].y == patchPoint.y && polytope->vertices[i].z == patchPoint.z ) {
- alreadyExist = true;
- patchPointIndex = i;
- break;
- }
- }
- if( !alreadyExist ) {
- polytope->vertexCount++;
- polytope->vertices = realloc( polytope->vertices, polytope->vertexCount * sizeof( TVec3 ));
- patchPointIndex = polytope->vertexCount - 1;
- polytope->vertices[ patchPointIndex ] = patchPoint;
- }
- // build new faces
- int lastFreeIndex = polytope->faceCount;
- polytope->faceCount += 2;
- polytope->faces = realloc( polytope->faces, polytope->faceCount * sizeof( TEPAFace ));
- polytope->faces[n] = (TEPAFace) { a, b, patchPointIndex };
- polytope->faces[lastFreeIndex] = (TEPAFace) { patchPointIndex, c, a };
- polytope->faces[lastFreeIndex+1] = (TEPAFace) { patchPointIndex, b, c };
- }
- void Polytope_RemoveNonconvexity( TEPAPolytope * polytope, TVec3 lastPoint ) {
- while( true ) {
- int seenNum = -1;
- bool foundSeen = false;
- for( int i = 0; i < polytope->faceCount; i++ ) {
- TVec3 a = polytope->vertices[ polytope->faces[ i ].a ];
- TVec3 b = polytope->vertices[ polytope->faces[ i ].b ];
- TVec3 c = polytope->vertices[ polytope->faces[ i ].c ];
- TVec3 normal = Vec3_Cross( Vec3_Sub( b, a ), Vec3_Sub( c, a ));
- if( Vec3_Dot( normal, Vec3_Sub( lastPoint, a )) > 0.0001 ) {
- seenNum = i;
- foundSeen = true;
- }
- }
- if( !foundSeen ) {
- break;
- } else {
- Polytope_RemoveFaceAndPatchHole( polytope, seenNum, lastPoint );
- }
- }
- }
- TVec3 EPA_ProjectOriginOntoPlane( TVec3 planePoint, TVec3 planeNormal ) {
- float t = -Vec3_Dot( planePoint, planeNormal );
- return Vec3_Negate( Vec3_Scale( planeNormal, t ));
- }
- float EPA_DistanceToOrigin( TVec3 normal, TVec3 point ) {
- return fabs( Vec3_Dot( normal, Vec3_Negate( point )));
- }
- TEPATriangle EPA_GetClosestTriangle( TEPAPolytope * polytope ) {
- TEPATriangle closest;
- float closestDistance = FLT_MAX;
- for( int i = 0; i < polytope->faceCount; i++ ) {
- TVec3 a = polytope->vertices[ polytope->faces[ i ].a ];
- TVec3 b = polytope->vertices[ polytope->faces[ i ].b ];
- TVec3 c = polytope->vertices[ polytope->faces[ i ].c ];
- TVec3 normal = Vec3_Cross( Vec3_Sub( b, a ), Vec3_Sub( c, a ) );
- float d = EPA_DistanceToOrigin( normal, a );
- if( d < closestDistance ) {
- closestDistance = d;
- closest = (TEPATriangle) { .a = a, .b = b, .c = c, .normal = normal, .dist = d, .numInPolytope = i };
- }
- }
- return closest;
- }
- bool EPA_ComputeContacts( TEPAPolytope * polytope, TShape * shape1, TShape * shape2 ) {
- const int convergenceLimit = 100;
- TEPATriangle lastClosest = { 0 };
- lastClosest.dist = FLT_MAX;
- for( int i = 0; i < convergenceLimit; i++ ) {
- TEPATriangle closestTriangle = EPA_GetClosestTriangle( polytope );
- if( closestTriangle.dist > lastClosest.dist ) {
- TVec3 proj = EPA_ProjectOriginOntoPlane( lastClosest.a, lastClosest.normal );
- printf( "EPA: Done in %d iteration(s)!\nClosest: %.3f, %.3f, %.3f\nPenetration depth: %.2f", i, proj.x, proj.y, proj.z, lastClosest.dist );
- return true;
- } else {
- TVec3 p = GJK_GetSupport( shape1, shape2, closestTriangle.normal );
- Polytope_RemoveFaceAndPatchHole( polytope, closestTriangle.numInPolytope, p );
- Polytope_RemoveNonconvexity( polytope, p );
- }
- lastClosest = closestTriangle;
- }
- printf( "EPA: Convergence limit has reached!\n" );
- return false;
- }
- // ===========================
- // RENDERING ROUTINE
- // ===========================
- #include <windows.h>
- #include "glut.h"
- #include "gl/gl.h"
- #define WINDOW_SIZE 800
- void DrawShape( TShape * shape ) {
- if( shape->convex ) {
- if( shape->convex->count == 4 ) { // tetrahedron
- TVec3 a = shape->convex->points[0];
- TVec3 b = shape->convex->points[1];
- TVec3 c = shape->convex->points[2];
- TVec3 d = shape->convex->points[3];
- glBegin(GL_TRIANGLES);
- glColor3ub( 255, 0, 0 );
- glVertex3f( a.x, a.y, a.z );
- glVertex3f( b.x, b.y, b.z );
- glVertex3f( c.x, c.y, c.z );
- glColor3ub( 0, 255, 0 );
- glVertex3f( a.x, a.y, a.z );
- glVertex3f( d.x, d.y, d.z );
- glVertex3f( b.x, b.y, b.z );
- glColor3ub( 0, 0, 255 );
- glVertex3f( a.x, a.y, a.z );
- glVertex3f( c.x, c.y, c.z );
- glVertex3f( d.x, d.y, d.z );
- glColor3ub( 255, 255, 0 );
- glVertex3f( c.x, c.y, c.z );
- glVertex3f( b.x, b.y, b.z );
- glVertex3f( d.x, d.y, d.z );
- glEnd();
- }
- } else {
- glPushMatrix();
- glColor3ub( 255, 0, 0 );
- glTranslatef( shape->sphere->position.x, shape->sphere->position.y, shape->sphere->position.z );
- glutSolidSphere( shape->sphere->radius, 10, 10 );
- glPopMatrix();
- }
- }
- void display() {
- static float a = 0;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt( 0, 0, 3, 0, 0, 0, 0, 1, 0 );
- glRotatef( a, 0, 1, 0 );
- a+=0.5;
- for( int i = 0; i < currentPolytope->faceCount; i++ ) {
- int ia = currentPolytope->faces[i].a;
- int ib = currentPolytope->faces[i].b;
- int ic = currentPolytope->faces[i].c;
- TVec3 a = currentPolytope->vertices[ ia ];
- TVec3 b = currentPolytope->vertices[ ib ];
- TVec3 c = currentPolytope->vertices[ ic ];
- glBegin(GL_TRIANGLES);
- glColor3ub( i * 8 + 50, i * 8 + 50, i * 8 + 50 );
- glVertex3f( a.x, a.y, a.z );
- glVertex3f( b.x, b.y, b.z );
- glVertex3f( c.x, c.y, c.z );
- glEnd();
- }
- DrawShape( currentShape1 );
- DrawShape( currentShape2 );
- glutSwapBuffers();
- glutPostRedisplay();
- }
- void init() {
- glClearColor(0.000, 0.110, 0.392, 0.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective( 80, 1, 0.01, 1024 );
- glClearDepth( 1.0f );
- glEnable( GL_DEPTH_TEST );
- glDepthFunc( GL_LEQUAL );
- glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
- glEnable( GL_TEXTURE_2D );
- glShadeModel( GL_SMOOTH );
- glEnable( GL_CULL_FACE );
- glDisable( GL_STENCIL_TEST );
- glCullFace( GL_BACK );
- glEnable( GL_ALPHA_TEST );
- glAlphaFunc( GL_GREATER, 0.025f );
- //currentShape1 = ConvexShape_CreateTetrahedron( Vec3_Set( -1, .5, 0 ), Vec3_Set( -1, 1.5, 0 ), Vec3_Set( 0.2, 0.5, 0 ), Vec3_Set( -1, 0.5, 1 ));
- //currentShape2 = ConvexShape_CreateTetrahedron( Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ), Vec3_Set( 0, 0, 1 ));
- currentShape1 = ConvexShape_CreateSphere( Vec3_Set( 1,0,0 ), 0.6 );
- currentShape2 = ConvexShape_CreateSphere( Vec3_Set( 0,0,0 ), 0.5 );
- TSimplex finalSimplex;
- GJK_IsIntersects( currentShape1, currentShape2, &finalSimplex );
- currentPolytope = calloc( 1, sizeof( TEPAPolytope ));
- Polytope_SetFromSimplex( currentPolytope, &finalSimplex );
- EPA_ComputeContacts( currentPolytope, currentShape1, currentShape2 );
- }
- // ===========================
- // TESTS
- // ===========================
- int main(int argc, char **argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
- glutInitWindowSize( 800, 800 );
- glutInitWindowPosition(0, 0);
- glutCreateWindow("Test");
- glutDisplayFunc(display);
- init();
- glutMainLoop();
- /*
- {
- printf( "Triangle-Triangle Intersection Test - " );
- TShape * shape1 = ConvexShape_CreateTriangle( Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ));
- TShape * shape2 = ConvexShape_CreateTriangle( Vec3_Set( 0, 0.5, 0 ), Vec3_Set( 0, 1.5, 1 ), Vec3_Set( 1, 0.5, 1 ));
- TSimplex finalSimplex;
- GJK_IsIntersects( shape1, shape2, &finalSimplex );
- EPA_ComputeContacts( &finalSimplex, shape1, shape2 );
- ConvexShape_Delete( shape1 );
- ConvexShape_Delete( shape2 );
- }
- {
- printf( "Triangle-Tetrahedron Intersection Test - " );
- TShape * shape1 = ConvexShape_CreateTriangle( Vec3_Set( 0, 0, 0.5 ), Vec3_Set( 0, 1, 0.5 ), Vec3_Set( 1, 0, 0.5 ));
- TShape * shape2 = ConvexShape_CreateTetrahedron( Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ), Vec3_Set( 0, 0, 1 ));
- TSimplex finalSimplex;
- GJK_IsIntersects( shape1, shape2, &finalSimplex );
- ConvexShape_Delete( shape1 );
- ConvexShape_Delete( shape2 );
- }
- {
- printf( "Sphere-Tetrahedron Intersection Test - " );
- TShape * shape1 = ConvexShape_CreateSphere( Vec3_Set( 0,0,0 ), 1 );
- TShape * shape2 = ConvexShape_CreateTetrahedron( Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ), Vec3_Set( 0, 0, 1 ));
- TSimplex finalSimplex;
- GJK_IsIntersects( shape1, shape2, &finalSimplex );
- ConvexShape_Delete( shape1 );
- ConvexShape_Delete( shape2 );
- }
- {
- printf( "Tetrahedron-Tetrahedron Intersection Test - " );
- TShape * shape1 = ConvexShape_CreateTetrahedron( Vec3_Set( 0, 0, 0.5 ), Vec3_Set( 0, 1, 0.5 ), Vec3_Set( 1, 0, 0.5 ), Vec3_Set( 0, 0, 1.5 ));
- TShape * shape2 = ConvexShape_CreateTetrahedron( Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ), Vec3_Set( 0, 0, 1 ));
- TSimplex finalSimplex;
- GJK_IsIntersects( shape1, shape2, &finalSimplex );
- ConvexShape_Delete( shape1 );
- ConvexShape_Delete( shape2 );
- }
- {
- printf( "Sphere-Sphere Intersection Test - " );
- TShape * shape1 = ConvexShape_CreateSphere( Vec3_Set( 1,0,0 ), 1 );
- TShape * shape2 = ConvexShape_CreateSphere( Vec3_Set( 0,0,0 ), 1 );
- TSimplex finalSimplex;
- GJK_IsIntersects( shape1, shape2, &finalSimplex );
- ConvexShape_Delete( shape1 );
- ConvexShape_Delete( shape2 );
- } */
- }
Advertisement
Add Comment
Please, Sign In to add comment