NavigationMesh.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. namespace AtomicEngine
  5. {
  6. public partial class NavigationMesh : Component
  7. {
  8. public bool FindPath(List<Vector3> results, Vector3 start, Vector3 end)
  9. {
  10. return FindPath(results, start, end, Vector3.One);
  11. }
  12. public bool FindPath(List<Vector3> results, Vector3 start, Vector3 end, Vector3 extents)
  13. {
  14. results.Clear();
  15. int count;
  16. IntPtr resultVector;
  17. var ptr = csi_Atomic_NavigationMesh_FindPath(nativeInstance, ref start, ref end, ref extents, out resultVector, out count);
  18. if (ptr == IntPtr.Zero)
  19. {
  20. return false;
  21. }
  22. int structSize = Marshal.SizeOf(typeof(Vector3));
  23. for (int i = 0; i < count; i++)
  24. {
  25. IntPtr data = new IntPtr(ptr.ToInt64() + structSize * i);
  26. Vector3 v3 = (Vector3)Marshal.PtrToStructure(data, typeof(Vector3));
  27. results.Add(v3);
  28. }
  29. csi_Atomic_NavigationMesh_FindPath_FreeResult(resultVector);
  30. return true;
  31. }
  32. // Any resultVector returned here, must be freed with csi_Atomic_Octree_Raycast_FreeResult
  33. [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
  34. internal static extern IntPtr csi_Atomic_NavigationMesh_FindPath(IntPtr self, ref Vector3 start, ref Vector3 end, ref Vector3 extents, out IntPtr resultVector, out int count);
  35. [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
  36. internal static extern IntPtr csi_Atomic_NavigationMesh_FindPath_FreeResult(IntPtr resultVector);
  37. };
  38. }