ZIM 1 jaar geleden
bovenliggende
commit
ff18303808

+ 6 - 6
Assets/BowArrow/Scripts/Bluetooth/New/o0663Axis.cs

@@ -68,7 +68,7 @@ namespace o0.Bow
             var (Gyr, Acc, Mag, TimeGap) = Attitude.Update(gyr1Byte, gyr2Byte, acc1Byte, acc2Byte, magByte, min, sec, ms1, ms2);
 
 
-            var GyrOperator = Geometry.Quaternion.Euler((Gyr * TimeGap));
+            var GyrOperator = Geometry.Quaternion.Euler((Gyr * TimeGap).To<float>());
 
 
             var Last = States.LastOrDefault() ?? new State();
@@ -124,15 +124,15 @@ namespace o0.Bow
 
 
 
-            var GyrOperator = Geometry.Quaternion.Euler((Gyr * TimeGap));
+            var GyrOperator = Geometry.Quaternion.Euler((Gyr * TimeGap).To<float>());
             var quaGyr = LastQuaternion * GyrOperator;
 
 
             //TestVector.Update9AxisRotation(GyrOperator, 1);
             //TestVector.SetAcc(Acc / 10, 1);
             //TestVector.SetMag(Mag, 1);
-            var accTest = Geometry.Quaternion.FromToRotation(Last.Acc, Acc).Inversed;
-            var magTest = Geometry.Quaternion.FromToRotation(Last.Mag, Mag).Inversed;
+            var accTest = Geometry.Quaternion.FromToRotation(Last.Acc.To<float>(), Acc.To<float>()).Inversed;
+            var magTest = Geometry.Quaternion.FromToRotation(Last.Mag.To<float>(), Mag.To<float>()).Inversed;
             //TestVector.Set9AxisRotation(Last.Qua, 3);
 
             double AccLengthToAngle = 5;//1倍引力差相当于多少度方差
@@ -163,7 +163,7 @@ namespace o0.Bow
             if (double.IsNaN(state.Variance))
                 state.Variance = 0.0000001;
 
-            var quaAccMag = Geometry.Quaternion.FormQuaternion(AccIdentity, MagIdentity, state.Acc, state.Mag, (float)(AccVariance / (AccVariance + MagVariance)));
+            var quaAccMag = Geometry.Quaternion.FormQuaternion(AccIdentity.To<float>(), MagIdentity.To<float>(), state.Acc.To<float>(), state.Mag.To<float>(), (float)(AccVariance / (AccVariance + MagVariance)));
             var quaMinRate = GyrVariance / (GyrVariance + Math.Max(AccVariance, MagVariance));
             var quaMaxRate = GyrVariance / (GyrVariance + Math.Min(AccVariance, MagVariance));
             Geometry.Quaternion quaFirst = Geometry.Quaternion.SLerp(quaGyr, quaAccMag, (float)quaMinRate);
@@ -172,7 +172,7 @@ namespace o0.Bow
 
             var quaSecondRate = (quaMaxRate - quaMinRate) / (1 - quaMinRate);
 
-            state.Qua = AccVariance < MagVariance ? Geometry.Quaternion.FormQuaternion(quaFirst, AccIdentity, state.Acc, (float)quaSecondRate) : Geometry.Quaternion.FormQuaternion(quaFirst, MagIdentity, state.Mag, (float)quaSecondRate);
+            state.Qua = AccVariance < MagVariance ? Geometry.Quaternion.FormQuaternion(quaFirst, AccIdentity.To<float>(), state.Acc.To<float>(), (float)quaSecondRate) : Geometry.Quaternion.FormQuaternion(quaFirst, MagIdentity.To<float>(), state.Mag.To<float>(), (float)quaSecondRate);
 
 
 

+ 3 - 3
Assets/BowArrow/Scripts/Bluetooth/New/o09AxisAfterXiaMenFromDll.cs

@@ -213,7 +213,7 @@ namespace o0.Bow
 
 
 
-            var GyrOperator = Geometry.Quaternion.Euler(Gyr * TimeGap);
+            var GyrOperator = Geometry.Quaternion.Euler((Gyr * TimeGap).To<float>());
             var quaGyr = LastQuaternion * GyrOperator;
 
 
@@ -227,7 +227,7 @@ namespace o0.Bow
 
             var (GyrVariance, AccVariance, MagVariance) = CalVariance(Last, state);
 
-            var quaAccMag = Geometry.Quaternion.FormQuaternion(AccIdentity, MagIdentity, Acc, Mag, (float)(AccVariance / (AccVariance + MagVariance)));
+            var quaAccMag = Geometry.Quaternion.FormQuaternion(AccIdentity.To<float>(), MagIdentity.To<float>(), Acc.To<float>(), Mag.To<float>(), (float)(AccVariance / (AccVariance + MagVariance)));
             var quaMinRate = GyrVariance / (GyrVariance + Math.Max(AccVariance, MagVariance));//静止时约0.01效果最好
             var quaMaxRate = GyrVariance / (GyrVariance + Math.Min(AccVariance, MagVariance));
             Geometry.Quaternion quaFirst = Geometry.Quaternion.SLerp(quaGyr, quaAccMag, (float)quaMinRate);//运算到这里如果视角校准有漂移,说明需要重新校准陀螺仪//不是代码问题
@@ -237,7 +237,7 @@ namespace o0.Bow
 
             // Debug.Log((quaMinRate, AccVariance, quaSecondRate));
 
-            state.Qua = AccVariance < MagVariance ? Geometry.Quaternion.FormQuaternion(quaFirst, AccIdentity, Acc, (float)quaSecondRate) : Geometry.Quaternion.FormQuaternion(quaFirst, MagIdentity, Mag, (float)quaSecondRate);/**/
+            state.Qua = AccVariance < MagVariance ? Geometry.Quaternion.FormQuaternion(quaFirst, AccIdentity.To<float>(), Acc.To<float>(), (float)quaSecondRate) : Geometry.Quaternion.FormQuaternion(quaFirst, MagIdentity.To<float>(), Mag.To<float>(), (float)quaSecondRate);/**/
             //state.Qua = quaFirst;
 
             QuaCheck(ref state.Qua, LastQuaternion);//防止数值溢出

+ 1 - 1
Assets/BowArrow/Scripts/Bluetooth/o09AxisCS.cs

@@ -62,7 +62,7 @@ namespace o0.Bow
         {
 
             //var GyrOperator = Geometry.Quaternion.Euler(Gyr * GapMS);
-            var GyrOperator = Geometry.Quaternion.Euler(Gyr * GapMS);
+            var GyrOperator = Geometry.Quaternion.Euler((Gyr * GapMS).To<float>());
             //Debug.Log(Acc +" | "+ Acc.Length);
             //var GyrOperator = new UnityEngine.Quaternion();
             //GyrOperator.eulerAngles = (Gyr * GapMS).ToUnityVector();

+ 3 - 3
Assets/BowArrow/Scripts/Bluetooth/o0DistanceToAxis.cs

@@ -52,7 +52,7 @@ namespace o0.Bow
             }
             if(LockAcc != default)
             {
-                var GyrOperator = -Geometry.Quaternion.Euler((Gyr * GapMS));
+                var GyrOperator = -Geometry.Quaternion.Euler((Gyr * GapMS).To<float>());
                 LockAcc = (GyrOperator * LockAcc.To<float>()).To<double>();
                 Speed = (GyrOperator * Speed.To<float>()).To<double>();
                 Speed += (Acc - LockAcc) * 9.8 * (LastGapMS + GapMS) / 1000 / 2;
@@ -94,7 +94,7 @@ namespace o0.Bow
         //////// 米/秒                      度/毫秒
         public Vector<double> GyrToSpeed(Vector<double> Gyr, double GapMS)
         {
-            var GyrOperator = Geometry.Quaternion.Euler(Gyr * GapMS).Inversed;
+            var GyrOperator = Geometry.Quaternion.Euler((Gyr * GapMS).To<float>()).Inversed;
             var axis = Vector<double>.Back * Distance;
             axis = (GyrOperator * axis.To<float>() - axis.To<float>()).To<double>() / GapMS * 1000;
             // TestVector.SetAcc(axis.ToUnityVector(), 2);
@@ -112,7 +112,7 @@ namespace o0.Bow
                 //var Speed = 
                 return Acc;
             }
-            var GyrOperator = Geometry.Quaternion.Euler(Gyr * GapMS).Inversed;
+            var GyrOperator = Geometry.Quaternion.Euler((Gyr * GapMS).To<float>()).Inversed;
             var RotatedLastSpeed = GyrOperator * LastSpeed.To<float>();
             var AccCorrection = (Speed - RotatedLastSpeed.To<double>()) / 9.8 / GapMS * 1000;
             // TestVector.SetMag(AccCorrection.ToUnityVector(), 2);

BIN
Assets/BowArrow/Scripts/Bluetooth/o0Lib/o0NetLib.dll


+ 54 - 1
Assets/BowArrow/Scripts/Bluetooth/o0Lib/o0NetLib.dll.meta

@@ -11,6 +11,24 @@ PluginImporter:
   isExplicitlyReferenced: 0
   validateReferences: 1
   platformData:
+  - first:
+      : Any
+    second:
+      enabled: 0
+      settings:
+        Exclude Android: 0
+        Exclude Editor: 0
+        Exclude Linux64: 0
+        Exclude OSXUniversal: 0
+        Exclude Win: 0
+        Exclude Win64: 0
+        Exclude iOS: 0
+  - first:
+      Android: Android
+    second:
+      enabled: 1
+      settings:
+        CPU: ARMv7
   - first:
       Any: 
     second:
@@ -19,15 +37,50 @@ PluginImporter:
   - first:
       Editor: Editor
     second:
-      enabled: 0
+      enabled: 1
       settings:
+        CPU: AnyCPU
         DefaultValueInitialized: true
+        OS: AnyOS
+  - first:
+      Standalone: Linux64
+    second:
+      enabled: 1
+      settings:
+        CPU: None
+  - first:
+      Standalone: OSXUniversal
+    second:
+      enabled: 1
+      settings:
+        CPU: None
+  - first:
+      Standalone: Win
+    second:
+      enabled: 1
+      settings:
+        CPU: None
+  - first:
+      Standalone: Win64
+    second:
+      enabled: 1
+      settings:
+        CPU: None
   - first:
       Windows Store Apps: WindowsStoreApps
     second:
       enabled: 0
       settings:
         CPU: AnyCPU
+  - first:
+      iPhone: iOS
+    second:
+      enabled: 1
+      settings:
+        AddToEmbeddedBinaries: false
+        CPU: AnyCPU
+        CompileFlags: 
+        FrameworkDependencies: 
   userData: 
   assetBundleName: 
   assetBundleVariant: 

+ 6 - 6
Assets/InfraredProject/WebCamera/Script/ZIM/InfraredLocate/ScreenIdentification.cs

@@ -508,7 +508,7 @@ namespace o0.Project
             {
                 if (l != null)
                 {
-                    drawLineMap.DrawLine(l, (x, y) => 1, new Geometry2D.Float.Vector(0, 10));
+                    o0Extension.DrawLine(drawLineMap.DrawLine(l, (x, y) => 1, new Geometry2D.Float.Vector(0, 10));
                     lineCount++;
                 }
             }
@@ -530,7 +530,7 @@ namespace o0.Project
             //var drawLineMap = new MatrixF2D(edge..Size.x, edge.Size.y);
             //var returnMaxLines = lines.Sub(0, 10);
             //foreach (var (line, sum, gradient) in returnMaxLines)
-            //    drawLineMap.DrawLine(line, (x, y) => 1, new Geometry2D.Float.Vector(0, 10));
+            //    o0Extension.DrawLine(drawLineMap.DrawLine(line, (x, y) => 1, new Geometry2D.Float.Vector(0, 10));
 
 
             ScreenLocate.DebugTexture(3, drawLineMap.ToTex());
@@ -685,7 +685,7 @@ namespace o0.Project
 
             var drawScreenMap = new Matrix(ScreenLocateTexLightedMat.Size, Tiling: true);
             foreach (var l in LineIdentified)
-                drawScreenMap.DrawLine(l, (x, y) => 1, new Geometry2D.Float.Vector(0, lineWidth));
+                o0Extension.DrawLine(drawScreenMap, l, (x, y) => 1, new Geometry2D.Float.Vector(0, lineWidth));
             ScreenQuadTex = drawScreenMap.ToTex();      // out ScreenQuadTex
 
             QuadrilateralInCamera screenQuad = null;
@@ -715,17 +715,17 @@ namespace o0.Project
             foreach (var l in lightLines)
             {
                 if (l != null && !quadLines.Contains(l))
-                    LSDLineMap.DrawLine(l, (x, y) => 3, new Geometry2D.Float.Vector(0, 2), true); // 其他的备选线段
+                    o0Extension.DrawLine(LSDLineMap, l, (x, y) => 3, new Geometry2D.Float.Vector(0, 2), true); // 其他的备选线段
             }
             foreach (var l in quadLines)
             {
                 if (l != null)
-                    LSDLineMap.DrawLine(l, (x, y) => 2, new Geometry2D.Float.Vector(0, 4)); // 这次识别到的线段
+                    o0Extension.DrawLine(LSDLineMap, l, (x, y) => 2, new Geometry2D.Float.Vector(0, 4)); // 这次识别到的线段
             }
             if (oldLines != null)
             {
                 foreach (var l in oldLines)
-                    LSDLineMap.DrawLine(l, (x, y) => 1, new Geometry2D.Float.Vector(0, 2), true);     // 旧的屏幕线段(例如上次手动识别的)
+                    o0Extension.DrawLine(LSDLineMap, l, (x, y) => 1, new Geometry2D.Float.Vector(0, 2), true);     // 旧的屏幕线段(例如上次手动识别的)
             }
             ChoosableLineTex = LSDLineMap.ToTexRGBA(FloatValueToColor);
 

+ 8 - 0
Assets/InfraredProject/WebCamera/Script/ZIM/o0Extension.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 9fc1e66a04f7d744aa313eb43d231d9b
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 99 - 0
Assets/InfraredProject/WebCamera/Script/ZIM/o0Extension/o0Extension.cs

@@ -0,0 +1,99 @@
+using o0.Geometry2D.Float;
+using System;
+
+namespace o0.Project
+{
+    internal class o0Extension
+    {
+        public static void DrawLine(Matrix matrix, Line line, Func<int, int, float> setValue, Geometry2D.Float.Vector size = default, bool dashedLine = false)
+        {
+            if (size == default)
+                size = new Geometry2D.Float.Vector(0, 1);
+            if (size.x != 0)
+            {
+                var halfExtLength = size.x / 2;
+                var offset = new Geometry2D.Float.Vector(halfExtLength / line.Length * (line.B.x - line.A.x), halfExtLength / line.Length * (line.B.y - line.A.y));
+                line = new Geometry2D.Float.Line(line.A - offset, line.B + offset);
+            }
+
+            int drawCount = 0;
+            void _draw(int x, int y)
+            {
+                try
+                {
+                    if (dashedLine)
+                    {
+                        if (drawCount++ % 80 < 50)
+                            matrix[x, y] = setValue(x, y);
+                    }
+                    else
+                        matrix[x, y] = setValue(x, y);
+                }
+                catch { }
+            }
+
+            var halfWidth = size.y / 2;
+            if (line.A.y == line.B.y)
+            {
+                var xRange = ((int)Math.Round(line.A.x), (int)Math.Round(line.B.x) + 1);
+                foreach (var y in ((int)Math.Round(line.A.y - halfWidth)).Range((int)Math.Round(line.A.y + halfWidth) + 1))
+                    foreach (var x in xRange.Item1.Range(xRange.Item2))
+                        _draw(x, y);
+                return;
+            }
+            else if (line.A.x == line.B.x)
+            {
+                var yRange = ((int)Math.Round(line.A.y), (int)Math.Round(line.B.y) + 1);
+                foreach (var x in ((int)Math.Round(line.A.x - halfWidth)).Range((int)Math.Round(line.A.x + halfWidth) + 1))
+                    foreach (var y in yRange.Item1.Range(yRange.Item2))
+                        _draw(x, y);
+                return;
+            }
+            var upOffset = new Geometry2D.Float.Vector(halfWidth / line.Length * (line.A.y - line.B.y), halfWidth / line.Length * (line.B.x - line.A.x));
+            if (upOffset.y < 0)
+                upOffset = -upOffset;
+            Geometry2D.Float.Vector up, down, left, right;
+            if (upOffset.x < 0)//0-90度
+            {
+                up = line.B + upOffset;
+                down = line.A - upOffset;
+                left = line.A + upOffset;
+                right = line.B - upOffset;
+            }
+            else
+            {
+                up = line.A + upOffset;
+                down = line.B - upOffset;
+                left = line.A - upOffset;
+                right = line.B + upOffset;
+            }
+            var topLeft = new Geometry2D.Float.Line(left, up);
+            var bottomLeft = new Geometry2D.Float.Line(left, down);
+            var topRight = new Geometry2D.Float.Line(up, right);
+            var bottomRight = new Geometry2D.Float.Line(down, right);
+
+            var topLeftXToYRate = topLeft.XToYRate;
+            var bottomLeftXToYRate = bottomLeft.XToYRate;
+            var topRightXToYRate = topRight.XToYRate;
+            var bottomRightXToYRate = bottomRight.XToYRate;
+            foreach (var y in ((int)Math.Round(down.y)).Range((int)Math.Round(up.y) + 1))
+                foreach (var x in ((int)Math.Max(topLeft.YToX(y, topLeftXToYRate), bottomLeft.YToX(y, bottomLeftXToYRate)))
+                    .Range((int)Math.Min(topRight.YToX(y, topRightXToYRate), bottomRight.YToX(y, bottomRightXToYRate)) + 1))
+                    _draw(x, y);
+        }
+
+        /// <summary>计算点到直线的垂足,垂足坐标可能在Line的延长线上</summary>
+        public static Vector PointPedal(Line l, in Vector v)
+        {
+            Vector d = l.B - l.A;
+            float dotD = d.Dot(d);
+            if (dotD == 0)
+                throw new DivideByZeroException();
+            float dotL = (v - l.A).Dot(d);
+            Vector proj = d * (dotL / dotD);
+            return l.A + proj;
+        }
+
+
+    }
+}

+ 11 - 0
Assets/InfraredProject/WebCamera/Script/ZIM/o0Extension/o0Extension.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6c8c66b9a7f5dc04b9ea6c552d43f0fd
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 3 - 3
Assets/InfraredProject/o0/zimIdentifyLineLSD.cs

@@ -130,7 +130,7 @@ namespace o0.Project
                 foreach (var l in lines)
                 {
                     if (l.Item1 != null)
-                        LSDLineMap.DrawLine(l.Item1, (x, y) => 3, new Geometry2D.Float.Vector(0, 2), true); // 其他的备选线段
+                        o0Extension.DrawLine(LSDLineMap, l.Item1, (x, y) => 3, new Geometry2D.Float.Vector(0, 2), true); // 其他的备选线段
                 }
                 ScreenLocate.DebugTexture(1, LSDLineMap.ToTexRGBA(ScreenIdentification.FloatValueToColor));
             }
@@ -173,7 +173,7 @@ namespace o0.Project
                 var calibration = ScreenLocate.Main.ReDoLocateCalibrationRatio * screenLocateMat.Size.y;
                 oldLines = screen.QuadInCamera.GetLines();
 
-                var pedals = oldLines.Select((i) => i.PointPedal(avgPoint)).ToArray();     // 当前定位的垂足,下、右、上、左
+                var pedals = oldLines.Select((i) => o0Extension.PointPedal(i, avgPoint)).ToArray();     // 当前定位的垂足,下、右、上、左
 
                 foreach (var i in lines)
                 {
@@ -181,7 +181,7 @@ namespace o0.Project
                     int index = -1;
                     foreach (var j in pedals.Index())
                     {
-                        var d = (i.Item1.PointPedal(avgPoint) - pedals[j]).Length;
+                        var d = (o0Extension.PointPedal(i.Item1, avgPoint) - pedals[j]).Length;
                         if (d < minDistance)
                         {
                             minDistance = d;