فهرست منبع

Collider experiments

Marcel Zickler 3 سال پیش
والد
کامیت
632f1ce0cc

+ 1 - 0
Assembly-CSharp.csproj

@@ -305,6 +305,7 @@
      <Compile Include="Assets\Scripts\Sensors\Polar\PolarEcgData.cs" />
      <Compile Include="Assets\Scripts\Sensors\Polar\PolarReceiver.cs" />
      <Compile Include="Assets\Scripts\Sensors\Polar\UdpConnection.cs" />
+     <Compile Include="Assets\Scripts\SlopeCollider.cs" />
      <Compile Include="Assets\Scripts\Tracking\CalibratableTracker.cs" />
      <Compile Include="Assets\Scripts\Tracking\FrontWheelTracker.cs" />
      <Compile Include="Assets\Scripts\Tracking\KineticLegTracker.cs" />

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 4 - 4078
Assets/Plotting/.idea/workspace.xml


+ 15 - 2
Assets/Scenes/MainScene.unity

@@ -397031,7 +397031,7 @@ SphereCollider:
   m_GameObject: {fileID: 1689915694}
   m_Material: {fileID: 0}
   m_IsTrigger: 0
-  m_Enabled: 1
+  m_Enabled: 0
   serializedVersion: 2
   m_Radius: 1.07
   m_Center: {x: 0, y: 0.025737524, z: 0}
@@ -397068,6 +397068,19 @@ MonoBehaviour:
   rotatePoint: {fileID: 457671768}
   timeDifferenceTolerance: 0.1
   dif: {x: 0, y: 0, z: 0}
+--- !u!114 &1689915703
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1689915694}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 0795bc064a1648f9a8ab938cafb8fec7, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  collisionLayer: 11
 --- !u!1001 &1690450701
 PrefabInstance:
   m_ObjectHideFlags: 0
@@ -454255,7 +454268,7 @@ PrefabInstance:
     - target: {fileID: 4988978073311274400, guid: 3b07d6594636ab04d9c1fac04c1cde7e,
         type: 3}
       propertyPath: m_Enabled
-      value: 0
+      value: 1
       objectReference: {fileID: 0}
     - target: {fileID: 4988978073311274401, guid: 3b07d6594636ab04d9c1fac04c1cde7e,
         type: 3}

+ 19 - 10
Assets/Scripts/Helpers.cs

@@ -2,22 +2,23 @@
 
 public class Helpers
 {
-    public static void DrawPlane(Vector3 position , Vector3 normal) {
- 
+    public static void DrawPlane(Vector3 position, Vector3 normal)
+    {
         Vector3 v3;
- 
+
         if (normal.normalized != Vector3.forward)
             v3 = Vector3.Cross(normal, Vector3.forward).normalized * normal.magnitude;
         else
-            v3 = Vector3.Cross(normal, Vector3.up).normalized * normal.magnitude;;
-     
+            v3 = Vector3.Cross(normal, Vector3.up).normalized * normal.magnitude;
+        ;
+
         var corner0 = position + v3;
         var corner2 = position - v3;
         var q = Quaternion.AngleAxis(90.0f, normal);
         v3 = q * v3;
         var corner1 = position + v3;
         var corner3 = position - v3;
- 
+
         Debug.DrawLine(corner0, corner2, Color.green);
         Debug.DrawLine(corner1, corner3, Color.green);
         Debug.DrawLine(corner0, corner1, Color.green);
@@ -26,7 +27,7 @@ public class Helpers
         Debug.DrawLine(corner3, corner0, Color.green);
         Debug.DrawRay(position, normal, Color.red);
     }
-    
+
     public static void DrawLine(Vector3 p1, Vector3 p2, float width)
     {
         int count = 1 + Mathf.CeilToInt(width); // how many lines are needed.
@@ -42,19 +43,27 @@ public class Helpers
                 Debug.LogError("Camera.current is null");
                 return;
             }
+
             var scp1 = c.WorldToScreenPoint(p1);
             var scp2 = c.WorldToScreenPoint(p2);
- 
+
             Vector3 v1 = (scp2 - scp1).normalized; // line direction
             Vector3 n = Vector3.Cross(v1, Vector3.forward); // normal vector
- 
+
             for (int i = 0; i < count; i++)
             {
-                Vector3 o = 0.99f * n * width * ((float)i / (count - 1) - 0.5f);
+                Vector3 o = 0.99f * n * width * ((float) i / (count - 1) - 0.5f);
                 Vector3 origin = c.ScreenToWorldPoint(scp1 + o);
                 Vector3 destiny = c.ScreenToWorldPoint(scp2 + o);
                 Gizmos.DrawLine(origin, destiny);
             }
         }
     }
+
+    public static float GetMinComponent(Vector3 vector)
+    {
+        if (vector.x <= vector.y && vector.x <= vector.z) return vector.x;
+        if (vector.y <= vector.x && vector.y <= vector.z) return vector.y;
+        return vector.z;
+    }
 }

+ 72 - 0
Assets/Scripts/SlopeCollider.cs

@@ -0,0 +1,72 @@
+using System;
+using UnityEngine;
+
+
+[RequireComponent(typeof(BoxCollider))]
+public class SlopeCollider : MonoBehaviour
+{
+    public int collisionLayer = 11;
+
+    private readonly ContactPoint[] contacts = new ContactPoint[4];
+    private Transform t;
+    private BoxCollider bikeCollider;
+
+    private void Start()
+    {
+        t = transform;
+        bikeCollider = GetComponent<BoxCollider>();
+    }
+
+    private void OnCollisionStay(Collision other)
+    {
+        if (other.gameObject.layer == collisionLayer)
+        {
+            var numberOfContacts = other.GetContacts(this.contacts);
+            //Debug.Log($"Has {numberOfContacts} contacts with {other.gameObject.name}");
+            /*foreach (var c in contacts)
+            {
+                Debug.DrawLine(c.point, c.point + c.normal * 0.5f, Color.red);
+            }*/
+
+            var bounds = bikeCollider.bounds;
+            var leftBackCorner = t.TransformPoint(bikeCollider.center - bikeCollider.size / 2);
+            var localExtends = bikeCollider.size;
+            localExtends.Scale(t.localScale);
+
+            var rightBackCorner = leftBackCorner + t.right * localExtends.x;
+            var forward = t.forward;
+            var leftFrontCorner = leftBackCorner + forward * localExtends.z;
+            var rightFrontCorner = rightBackCorner + forward * localExtends.z;
+
+            var minSide = Helpers.GetMinComponent(localExtends);
+
+            Debug.DrawLine(leftBackCorner, rightBackCorner, Color.red);
+            Debug.DrawLine(leftBackCorner, leftBackCorner + t.up * localExtends.y, Color.green);
+            Debug.DrawLine(leftBackCorner, leftFrontCorner, Color.blue);
+            
+            foreach(var c in contacts)
+            {
+                if ((leftBackCorner - c.point).magnitude < minSide/2.2f)
+                {
+                    Debug.Log("Hit LeftBackCorner");
+                }
+                else if ((rightBackCorner - c.point).magnitude < minSide/2.2f)
+                {
+                    Debug.Log("Hit RightBackCorner");
+                }
+                else if ((leftFrontCorner - c.point).magnitude < minSide/2.2f)
+                {
+                    Debug.Log("Hit LeftFrontCorner");
+                }
+                else if ((rightFrontCorner - c.point).magnitude < minSide/2.2f)
+                {
+                    Debug.Log("Hit RightFrontCorner");
+                }
+            }
+
+
+            //Debug.Log($"Bounds = {bounds}");
+            //Debug.Log($"LocalCenter = {localCenter}, localExtends = {localExtends}");
+        }
+    }
+}

+ 3 - 0
Assets/Scripts/SlopeCollider.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 0795bc064a1648f9a8ab938cafb8fec7
+timeCreated: 1609852368

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است