For Mono, use single precision - note that this does not work in unity

fixes-turtlebasket
Mattia Montanari 2023-04-02 12:07:12 +02:00
parent 14fc2d80d6
commit bb5b5d44dd
2 changed files with 23 additions and 22 deletions

View File

@ -30,8 +30,9 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
- run: apt-get update && apt-get install gcc cmake -y - run: apt-get update && apt-get install gcc cmake -y
- run: cmake -E make_directory build - run: cmake -E make_directory build
- run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MONO=ON .. # Using single precision
- run: cmake --build build - run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MONO=ON -DSINGLE_PRECISION=ON ..
- run: cmake --build build --target opengjk_ce
- run: cmake -E chdir build make install - run: cmake -E chdir build make install
- run: cd examples/cs/ && mcs -out:main.exe main.cs && mono main.exe - run: cd examples/cs/ && mcs -out:main.exe main.cs && mono main.exe

View File

@ -40,26 +40,26 @@ public class Tester
[DllImport("libopengjk_ce", EntryPoint = "csFunction", CallingConvention = CallingConvention.StdCall)] [DllImport("libopengjk_ce", EntryPoint = "csFunction", CallingConvention = CallingConvention.StdCall)]
#endif #endif
static extern double compute_minimum_distance(int na, double [,] ia, int nb, double [,] ib); static extern float compute_minimum_distance(int na, float[,] ia, int nb, float[,] ib);
public static void Main(string[] args) public static void Main(string[] args)
{ {
double dist; float dist;
// Define array A with coordinates // Define array A with coordinates
int nCoordsA = 9; int nCoordsA = 9;
var inCoordsA = new double[3,9] { {0.0 , 2.3 , 8.1 , 4.3 ,2.5 , 7.1 , 1.0 , 3.3 , 6.0} , { 5.5 , 1.0 , 4.0 , 5.0 ,1.0, 1.0, 1.5, 0.5 , 1.4} ,{ 0.0 , -2.0, 2.4, 2.2, 2.3 , 2.4 , 0.3 , 0.3 , 0.2} }; var inCoordsA = new float[3, 9] { { 0.0, 2.3, 8.1, 4.3, 2.5, 7.1, 1.0, 3.3, 6.0 }, { 5.5, 1.0, 4.0, 5.0, 1.0, 1.0, 1.5, 0.5, 1.4 }, { 0.0, -2.0, 2.4, 2.2, 2.3, 2.4, 0.3, 0.3, 0.2 } };
// Define array B with coordinates // Define array B with coordinates
int nCoordsB = 9; int nCoordsB = 9;
var inCoordsB = new double[3,9] { {-0.0 , -2.3 , -8.1 , -4.3 ,-2.5 , -7.1 , -1.0 , -3.3 , -6.0} , { -5.5 , -1.0 ,- 4.0 ,- 5.0 ,-1.0, -1.0, -1.5, -0.5 , -1.4} ,{ -0.0 , 2.0, -2.4, -2.2, -2.3 , -2.4 , -0.3 , -0.3 , -0.2} }; var inCoordsB = new float[3, 9] { { -0.0, -2.3, -8.1, -4.3, -2.5, -7.1, -1.0, -3.3, -6.0 }, { -5.5, -1.0, -4.0, -5.0, -1.0, -1.0, -1.5, -0.5, -1.4 }, { -0.0, 2.0, -2.4, -2.2, -2.3, -2.4, -0.3, -0.3, -0.2 } };
// Invoke GJK to compute distance // Invoke GJK to compute distance
dist = compute_minimum_distance( nCoordsA, inCoordsA, nCoordsB, inCoordsB ); dist = compute_minimum_distance(nCoordsA, inCoordsA, nCoordsB, inCoordsB);
// Output results // Output results
var s = string.Format("{0:0.##}", dist); var s = string.Format("{0:0.##}", dist);
var message = string.Format("The distance between {0} is {1}","A and B",s); var message = string.Format("The distance between {0} is {1}", "A and B", s);
Console.WriteLine(message); Console.WriteLine(message);
} }
} }