C# P/INVOKE for cpSpaceAddCollisionHandler
Posted: Sat Jun 18, 2016 1:07 am
Hello, I am trying to write a wrapper using C# and call the ChipmunkAPI. I can see that some things have changed in v7.0.1 and I am not sure how to integrate the 4 delegates needed for "begin", "preSolve", "postSolve" and "Separate" functions.
I am doing something like the following
The problem I have is that I am not sure how to bind the "beginFunc" function pointer to my C# function lets say the following
Any ideas?
Kind regards,
John.
I am doing something like the following
Code: Select all
UIntPtr ptrForTypeA = new UIntPtr((ulong)typePair.a);
UIntPtr ptrForTypeB = new UIntPtr((ulong)typePair.b);
IntPtr collisionPtr = cpSpaceAddCollisionHandler(_handle, ptrForTypeA, ptrForTypeB);
cpCollisionHandler collisionHandler = (cpCollisionHandler)Marshal.PtrToStructure(collisionPtr, typeof(cpCollisionHandler));
and my cpCollisionHandler struct is
private struct cpCollisionHandler {
public UIntPtr typeA;
public UIntPtr typeB;
public IntPtr beginFunc;
public IntPtr preSolveFunc;
public IntPtr postSolveFunc;
public IntPtr separateFunc;
public IntPtr userData;
}
Code: Select all
public bool onBegin(IntPtr arb, IntPtr space, IntPtr userData){
return false;
}
Kind regards,
John.