I'm trying to use the Bullet Physics library within MATLAB. I need to do Collision detection and therefore I wanna use the GJK algorithm. In MATLAB it is possible to compile a so-called MEX function. With the MEX function it is possible to call your own C or C++ programs from the MATLAB command line as if they were built-in functions. My problem is that the Bullet library is very big with a lot of files, header function and so on and I am not really familiar with programming. I looked for simpler implementations and found:
https://github.com/ElsevierSoftwareX/SOFTX_2018_38
It is GJK wrote in C code with a file that gains the wanted MEX function. This file looks like this:
% CLEAR ALL VARIABLES
clearvars
% SELECT OPTIMISATION FLAG - FASTER BUT NOT SUITABLE FOR DEBUGGING
if 0
optflug = '-g'; %#ok<*UNRCH>
else
optflug = '-O';
end
% SELECT SILET COMPILATION MODE.
if 1
silflag = '-silent';
else
silflag = '-v';
end
% TRY COMPILING MEX FILE
fprintf('Compiling mex function... ')
try
mex('../lib/src/openGJK.c',... % Source of openGJK
'-largeArrayDims', ... % Support large arrays
optflug, ... % Compiler flag for debug/optimisation
'-I../lib/include',... % Folder to header files
'-outdir', pwd,... % Ouput directory for writing mex function
'-output', 'openGJK',... % Name of ouput mex file
'-DMATLABDOESMEXSTUFF',... % Define variable for mex function in source files
silflag ) % Silent/verbose flag
% File compiled without errors. Return path and name of mex file
fprintf('completed!\n')
fprintf('The following mex file has been generated:')
fprintf('\t%s\n',[pwd,filesep,'openGJK.',mexext])
catch
% Build failed, refer to documentation
fprintf('\n\n ERROR DETECTED! Mex file cannot be compiled.\n')
fprintf('\tFor more information, see ')
fprintf('<a href="http://www.mathworks.com/help/matlab/ref/mex.html">this documentation page</a>.\n\n')
return
end
So I tried to do a similar thing with the Bullet library, but I even don't know which source file to use. I tried the 'btBulletCollisionAll.cpp' in the 'src' folder. But like I'm said I'm not really familiar with C++ and I'm wondering why there are only a lot oof header files. Also I need to tell MATLAB where the header files are and how to link them.
So basically I just want to call a function on MATLAB like this:
dist = GJK(shapeA,shapeB);
Here is the Bullet depository: https://github.com/bulletphysics/bullet3
Thanks a lot for your help
Addit: I don't use the SOFTX_2018_38 because I also need EPA algorithm and I think the Bullet library is efficient and robust implementation.
[dist,simplex] = GJK(shapeA, shapeB)andpenetrationDepth = EPA(shapeA, shapeB, simplex)- Marius S.