예제 #1
0
파일: RMathFTests.cs 프로젝트: n0n4/RelaNet
        public void AngleBlendTest()
        {
            void test(float dega, float degb, float degresult, float percent)
            {
                // check extrema
                AssertFloatEqualsRadians(RMathF.ToRad(dega),
                                         RMathF.AngleBlend(RMathF.ToRad(dega), RMathF.ToRad(degb),
                                                           0));
                AssertFloatEqualsRadians(RMathF.ToRad(degb),
                                         RMathF.AngleBlend(RMathF.ToRad(dega), RMathF.ToRad(degb),
                                                           1f));

                // check midpoint
                AssertFloatEqualsRadians(
                    RMathF.AngleMidpoint(RMathF.ToRad(dega), RMathF.ToRad(degb)),
                    RMathF.AngleBlend(RMathF.ToRad(dega), RMathF.ToRad(degb),
                                      0.5f));

                AssertFloatEqualsRadians(RMathF.ToRad(degresult),
                                         RMathF.AngleBlend(RMathF.ToRad(dega), RMathF.ToRad(degb),
                                                           percent));
            }

            test(100f, 200f, 125f, 0.25f);
            test(200f, 100f, 125f, 0.75f);
            test(100f, 200f, 175f, 0.75f);
            test(200f, 100f, 175f, 0.25f);

            test(350f, 10f, 355f, 0.25f);
            test(10f, 350f, 355f, 0.75f);
            test(350f, 10f, 5f, 0.75f);
            test(10f, 350f, 5f, 0.25f);
        }
예제 #2
0
파일: RMathFTests.cs 프로젝트: n0n4/RelaNet
        public void AngleMidpointTest()
        {
            void test(float dega, float degb, float degresult)
            {
                AssertFloatEqualsRadians(RMathF.ToRad(degresult),
                                         RMathF.AngleMidpoint(RMathF.ToRad(dega), RMathF.ToRad(degb)));
                AssertFloatEqualsRadians(RMathF.ToRad(degresult),
                                         RMathF.AngleMidpoint(RMathF.ToRad(degb), RMathF.ToRad(dega)));
            }

            test(45f, 135f, 90f);
            test(30f, 340f, 5f);
            test(200f, 100f, 150f);
            test(10f, 200f, 285f);
        }
예제 #3
0
        private void InterpolateSnapLogic(SnapHistory <NentBasic2d, NentStaticBasic2d> h)
        {
            // interpolates from Prev to Next to create Current
            h.Shots[h.CurrentIndex] = h.Shots[h.PrevIndex];

            // always inherit ids from previous
            //h.Prev.Id1 = h.Prev.Id1;
            //h.Prev.Id2 = h.Prev.Id2;

            // pos/vel is easy, just average them
            h.Shots[h.CurrentIndex].X    = (h.Shots[h.NextIndex].X + h.Shots[h.CurrentIndex].X) / 2f;
            h.Shots[h.CurrentIndex].Y    = (h.Shots[h.NextIndex].Y + h.Shots[h.CurrentIndex].Y) / 2f;
            h.Shots[h.CurrentIndex].XVel = (h.Shots[h.NextIndex].XVel + h.Shots[h.CurrentIndex].XVel) / 2f;
            h.Shots[h.CurrentIndex].YVel = (h.Shots[h.NextIndex].YVel + h.Shots[h.CurrentIndex].YVel) / 2f;

            // in our case, we use Free1 as a timer, so it makes
            // sense to average this as well. May not be the case
            // if Free1 is used for a different kind of value
            h.Shots[h.CurrentIndex].Free1 = (h.Shots[h.NextIndex].Free1 + h.Shots[h.CurrentIndex].Free1) / 2f;

            // rotation is more complicated to find the midpoint
            h.Shots[h.CurrentIndex].Rot = RMathF.AngleMidpoint(h.Shots[h.CurrentIndex].Rot, h.Shots[h.NextIndex].Rot);
        }