So I have a C API with the following struct
typedef struct mat4f_ { float m[4][4]; } mat4f;
It gets passed as a parameter to one of my API functions:
void myFunction(const mat4f matrix);
I am exporting this function to C# in Unity using a dll:
[DllImport ("mylib")]
private static extern void myFunction(mat4f matrix);
My question is, what should I make the corresponding C# struct be?
Right now I have the following:
[StructLayout(LayoutKind.Sequential)]
public struct mat4f
{
public float[,] m;
}
and use try to use the function as follows:
//Just make an identity matrix
mat4f matrix;
matrix.m = new float[4, 4] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } };
myFunction(matrix); //Call dll function
Is this the correct thing to do? Is there a better way to do this?