コード例 #1
0
        /// <summary>
        /// オブジェクトの追加
        /// indexを返り値で返す
        /// </summary>
        /// <param name="newObject"></param>
        int IVRiscuitObjectSet.Add(IVRiscuitObject newObject)
        {
            var type = newObject.Type;

            if (_table.ContainsKey(type))
            {
                _table[type].Add(newObject);
            }
            else
            {
                var lis = new List <IVRiscuitObject>
                {
                    newObject
                };
                _table.Add(type, lis);
            }
            UpdateArray();
            var ary = (this as IVRiscuitObjectSet).ObjectArray;

            for (int i = 0; i < ary.Length; i++)
            {
                if (ary[i] == newObject)
                {
                    return(i);
                }
            }
            return(-1);
        }
コード例 #2
0
        protected static float Norm(IVRiscuitObject x, IVRiscuitObject y)
        {
            var result = (x.Position - y.Position).magnitude;

#if UNITY_EDITOR
            //Debug.Log(String.Format("Norm({0}, {1}) = {2}", x.Type, y.Type, result));
#endif
            return(result);
        }
コード例 #3
0
        protected static Vector3 Angle(IVRiscuitObject x, IVRiscuitObject y)
        {
            var result = x.Rotation.eulerAngles - y.Rotation.eulerAngles;

#if UNITY_EDITOR
//            Debug.Log(String.Format("Angle({0}, {1}) = {2}", x.Rotation, y.Rotation, result));
#endif
            return(result);
        }
コード例 #4
0
        /// <summary>
        /// a,bは必ずルール内のオブジェクトなので、ルール中は不変
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="ef"></param>
        /// <returns></returns>
        public static float[] CalcTwoObjectSimilarity(IVRiscuitObject a, IVRiscuitObject b, IVRiscuitObject x, IVRiscuitObject y, ScoreCoefficient ef)
        {
            var fs    = CalcTwoObjectSimilarityparameters(a, b, x, y, ef);
            var score = fs[0] + fs[1] + fs[2] + fs[3];

            return(new float[2] {
                score, fs[4]
            });
        }
コード例 #5
0
 void IVRiscuitObjectSet.Delete(IVRiscuitObject obj)
 {
     if (_table.ContainsKey(obj.Type) && _table[obj.Type].Contains(obj))
     {
         _table[obj.Type].Remove(obj);
         obj.Delete();
         UpdateArray();
     }
     else
     {
         Debug.LogError("ERROR: 削除予定のオブジェクトが見つかりませんでした: " + obj.Type);
     }
 }
コード例 #6
0
        protected static float[] CalcTwoObjectSimilarityparameters(IVRiscuitObject a, IVRiscuitObject b, IVRiscuitObject x, IVRiscuitObject y, ScoreCoefficient ef)
        {
            var eps   = Eps(a, b, x, y, ef);
            var max   = ef.NormWeight + eps * (ef.RdirWeight1 + ef.RdirWeight2) + ef.AngleWeight;
            var score = new float[] {
                ef.NormWeight *Delta(Norm(a, b), Norm(x, y), ef.NormLeveling),
                ef.RdirWeight1 *eps *Delta(Rdir(a, b), Rdir(x, y), ef.RdirLeveling1),
                ef.RdirWeight2 *eps *Delta(Rdir(b, a), Rdir(y, x), ef.RdirLeveling2),
                ef.AngleWeight *Delta3(Angle(a, b), Angle(x, y), ef.AngleLeveling),
                max
            };

            return(score);
        }
コード例 #7
0
        protected static float Rdir(IVRiscuitObject x, IVRiscuitObject y)
        {
            var xtoy = y.Position - x.Position;

            if (xtoy.magnitude == 0)
            {
            }
            var result = Vector3.Angle(x.Rotation * Vector3.forward, xtoy);

            // xからyへのベクトルvとxの回転クオータニオンqとの関係
#if UNITY_EDITOR
            //Debug.Log(String.Format("Rdir({0}, {1}) = {2}", x.Type, y.Type, result));
#endif
            return(result);
        }
コード例 #8
0
        protected static float Eps(IVRiscuitObject a, IVRiscuitObject b, IVRiscuitObject x, IVRiscuitObject y, ScoreCoefficient ef)
        {
            var ab = Norm(a, b);
            var xy = Norm(x, y);

            if (ab == 0)
            {
                return(0);
            }
            var result = (float)(1 - Math.Exp(-ef.EpsWeight1 / Math.Pow(ab /*+ xy*/ + ef.EpsWeight2, 2)));

#if UNITY_EDITOR
            // Debug.Log(String.Format("Eps({0}, {1}, {2}, {3}) = {4}", a.Type, b.Type, x.Type, y.Type, result));
#endif
            return(result);
        }
コード例 #9
0
 public CalculateObject(IVRiscuitObject obj)
 {
     _position = obj.Position;
     _rotation = obj.Rotation;
     _type     = obj.Type;
 }
コード例 #10
0
 protected static float[] CalcTwoObjectSimilarityparameters(IVRiscuitObject a, IVRiscuitObject b, IVRiscuitObject x, IVRiscuitObject y)
 {
     return(CalcTwoObjectSimilarityparameters(a, b, x, y, new ScoreCoefficient()));
 }
コード例 #11
0
 public static float[] CalcTwoObjectSimilarity(IVRiscuitObject a, IVRiscuitObject b, IVRiscuitObject x, IVRiscuitObject y)
 {
     return(CalcTwoObjectSimilarity(a, b, x, y, new ScoreCoefficient()));
 }