Browse Source

added 2d raycasting

Alan Q 8 years ago
parent
commit
696e7b7a27

+ 27 - 0
Script/AtomicNET/AtomicNET/Atomic2D/PhysicsWorld2D.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace AtomicEngine
+{
+    [StructLayout(LayoutKind.Sequential)]
+    public struct PhysicsRaycastResult2D
+    {
+        public Vector2 Position;
+        public Vector2 Normal;
+        public float Distance;
+
+        IntPtr bodyPtr;
+        public RigidBody2D Body => bodyPtr == IntPtr.Zero ? null : NativeCore.WrapNative<RigidBody2D>(bodyPtr);
+    }
+
+    public partial class PhysicsWorld2D : Component
+    {
+        public void RaycastSingle(ref PhysicsRaycastResult2D result, Vector2 startPoint, Vector2 endPoint, uint collisionMask = uint.MaxValue)
+        {
+            csi_Atomic_PhysicsWorld2D_RaycastSingle(nativeInstance, ref startPoint, ref endPoint, collisionMask, out result);
+        }
+
+        [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
+        internal static extern IntPtr csi_Atomic_PhysicsWorld2D_RaycastSingle(IntPtr self, ref Vector2 origin, ref Vector2 direction, uint collisionMask, out PhysicsRaycastResult2D result);
+    }
+}

+ 10 - 0
Source/AtomicNET/NETNative/NETCInterop.cpp

@@ -29,6 +29,7 @@
 
 
 #include "NETCore.h"
+#include "Atomic/Atomic2D/PhysicsWorld2D.h"
 
 #ifdef ATOMIC_PLATFORM_WINDOWS
 #define ATOMIC_EXPORT_API __declspec(dllexport)
@@ -536,6 +537,15 @@ namespace Atomic
 
         }
 
+        // PhysicsWorld2D
+
+        ATOMIC_EXPORT_API void csi_Atomic_PhysicsWorld2D_RaycastSingle(PhysicsWorld2D* world2D, Vector2* startPoint, Vector2* endPoint, unsigned collisionMask, PhysicsRaycastResult2D* result)
+        {
+            if (!world2D || !result)
+                return;
+            world2D->RaycastSingle(*result, *startPoint, *endPoint, collisionMask);
+        }
+
         // Controls
         
         ATOMIC_EXPORT_API unsigned csi_Atomic_Controls_GetButtons(Controls *controls)