Exemplo n.º 1
0
        public MotionSequence GenerateSynchronousSingleSequence(int dimention)
        {
            var uniform         = new ContinuousUniform(0, 1, _randomGenerator);
            var ValueRangeRatio = (float)uniform.Sample();
            var InitialForce    = (float)uniform.Sample();

            if (_numControlPoints != InitialTimes.Length)
            {
                throw new ArgumentException("コントロールポイント数が不一致");
            }

            // 位相にノイズを入れる
            var offset = Mathf.PI * (uniform.Sample() > 0.5 ? 1 : 0);

            var sequence = new MotionTarget[InitialTimes.Length];

            for (var i = 0; i < InitialTimes.Length; i++)
            {
                var values = new float[dimention];
                values[0] = InitialForce;
                for (var d = 1; d < dimention; d++)
                {
                    // control point value
                    var radian = InitialTimes[i] * 2f * Mathf.PI + offset;
                    values[d] = 0.5f + ValueRangeRatio * Mathf.Sin(radian) / 2f; // [0,1]に正規化;
                }

                sequence[i] = new MotionTarget(InitialTimes[i] * _timeRange, values);
            }

            return(new MotionSequence(sequence));
        }
Exemplo n.º 2
0
        public void MotionSequenceのシリアライズ()
        {
            var a = new MotionTarget(0.0f, new List <float> {
                0.0f, 1.0f, 2.0f
            });
            var b = new MotionTarget(1.0f, new List <float> {
                0.0f, 2.0f, 4.0f
            });

            var src = new MotionSequence(new List <MotionTarget> {
                a, b
            });
            var dst = new MotionSequence(MotionGeneratorSerialization.DeepClone(src.Save()));

            Assert.AreEqual(src.Sequences.Length, dst.Sequences.Length);
            for (int n = 0; n < src.Sequences.Length; ++n)
            {
                var s = src[n];
                var d = dst[n];
                Assert.AreEqual(s.Time, d.Time);
                Assert.AreEqual(s.Values.Length, d.Values.Length);
                for (int m = 0; m < s.Values.Length; ++m)
                {
                    Assert.AreEqual(s.Values[m], d.Values[m]);
                }
            }
        }
Exemplo n.º 3
0
 public MotionTarget(MotionTarget origin)
 {
     Time   = origin.Time;
     Values = origin.Values.ToArray();
 }