Abacus.SinglePrecision.Vector3Tests.TestStaticFn_TransformNormal_i C# (CSharp) Метод

TestStaticFn_TransformNormal_i() приватный Метод

private TestStaticFn_TransformNormal_i ( ) : void
Результат void
        public void TestStaticFn_TransformNormal_i ()
        {
            Single one = 1;
            Single six = 6;
            Single eight = 8;
            Single ten = 10;
            Single root3; Maths.Root3 (out root3);
            Single pi; Maths.Pi (out pi);
            Single minusPi = -pi;
            Single piOver2 = pi / (Single) 2;
            Single oneOverRoot3 = one / root3;
            Single sixTenths = six / ten;
            Single eightTenths = eight / ten;

            // todo: find a set of 3 fraction that make up a 3D unit vector
            //       for now just use the 2D one
            Vector3 v1 = new Vector3 (sixTenths, 0, eightTenths);
            Vector3 v2 = new Vector3 (oneOverRoot3, oneOverRoot3, oneOverRoot3);

            Matrix44 rotmati = Matrix44.Identity;
            Matrix44 rotmat1; Matrix44.CreateRotationX(ref pi, out rotmat1);
            Matrix44 rotmat2; Matrix44.CreateRotationY(ref piOver2, out rotmat2);
            Matrix44 rotmat3; Matrix44.CreateRotationZ(ref minusPi, out rotmat3);
            Matrix44 rotmat4 = rotmat1 * rotmat2 * rotmat3;

            var tests = new Tuple<Vector3, Matrix44, Vector3>[]
            {
                //normal -> transform -> expected
                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmati, v1),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmat1, new Vector3 (sixTenths, 0, -eightTenths)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmat2, new Vector3 (eightTenths, 0, -sixTenths)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmat3, new Vector3 (-sixTenths, 0, eightTenths)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmat4, new Vector3 (eightTenths, 0, -sixTenths)),

                //normal -> transform -> expected
                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmati, v2),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmat1, new Vector3 (oneOverRoot3, -oneOverRoot3, -oneOverRoot3)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmat2, new Vector3 (oneOverRoot3, oneOverRoot3, -oneOverRoot3)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmat3, new Vector3 (-oneOverRoot3, -oneOverRoot3, oneOverRoot3)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmat4, new Vector3 (oneOverRoot3, oneOverRoot3, -oneOverRoot3)),
            };

            for (Int32 i = 0; i < tests.Length; ++i)
            {
                var test = tests [i];
                Vector3 normalVec = test.Item1;
                Matrix44 trans = test.Item2;
                Vector3 expected = test.Item3;

                Vector3 result;

                Vector3.TransformNormal (ref normalVec, ref trans, out result);
                AssertEqualWithinReason(result, expected);

                // should also work with the standard transform fn
                Vector3.Transform (ref normalVec, ref trans, out result);
                AssertEqualWithinReason(result, expected);
            }
        }
Vector3Tests