Octree.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. namespace Urho
  5. {
  6. partial class Octree
  7. {
  8. [DllImport(Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  9. internal static extern IntPtr Octree_RaycastSingle(IntPtr handle, ref Ray ray, ref RayQueryLevel level, float maxDistance, uint drawableFlags, uint viewMask, out int count);
  10. public List<RayQueryResult> RaycastSingle(Ray ray, RayQueryLevel level, float maxDistance, DrawableFlags drawableFlags, uint viewMask = UInt32.MaxValue)
  11. {
  12. List<RayQueryResult> result = new List<RayQueryResult>();
  13. int count;
  14. var ptr = Octree_RaycastSingle(Handle, ref ray, ref level, maxDistance, (uint)drawableFlags, viewMask, out count);
  15. if (ptr == IntPtr.Zero)
  16. return result;
  17. int structSize = Marshal.SizeOf(typeof (RayQueryResult));
  18. for (int i = 0; i < count; i++)
  19. {
  20. IntPtr data = new IntPtr(ptr.ToInt64() + structSize * i);
  21. RayQueryResult item = (RayQueryResult)Marshal.PtrToStructure(data, typeof(RayQueryResult));
  22. result.Add(item);
  23. }
  24. return result;
  25. }
  26. }
  27. }