public void CoordinateSystemsTestScriptsSimplePasses()
    {
        // Use the Assert class to test conditions.
        for (int test = 0; test < tests; ++test)
        {
            NormalizedCartesianCoordinates cartesian = new NormalizedCartesianCoordinates(Random.onUnitSphere);
            NormalizedCartesianCoordinates reconverted_cartesian;

            // Test cubemap
            CubeUVCoordinates cubemap = cartesian;
            reconverted_cartesian = cubemap;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test octahedron map
            OctahedronUVCoordinates octahedron_map = cartesian;
            reconverted_cartesian = octahedron_map;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test spherical coordinates
            NormalizedSphericalCoordinates sphere = cartesian;
            reconverted_cartesian = sphere;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test stereoscopic coordinates
            StereoscopicProjectionCoordinates stereoscopic = cartesian;
            reconverted_cartesian = stereoscopic;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test polar coordinates
            PolarCoordinates polar = cartesian;
            reconverted_cartesian = polar;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test spherical rectangle
            float   x1      = Random.Range(-Mathf.PI, +Mathf.PI); // FIXME: [-PI, +PI]
            float   x2      = Random.Range(-Mathf.PI, +Mathf.PI);
            float   y1      = Random.Range(-Mathf.PI, +Mathf.PI);
            float   y2      = Random.Range(-Mathf.PI, +Mathf.PI);
            Vector2 minimum = new Vector2(Mathf.Min(x1, x2), Mathf.Min(y1, y2));
            Vector2 size    = new Vector2(Mathf.Abs(x2 - x1), Mathf.Abs(y2 - y1));
            Rect    canvas  = new Rect(minimum, size);
            SphericalRectangleUVCoordinates spherical_rectangle = cartesian.to_spherical_rectangle(canvas);
            reconverted_cartesian = spherical_rectangle;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data.ToString("F6") + " versus " + reconverted_cartesian.data.ToString("F6") + " intermediate: " + spherical_rectangle.canvas.ToString("F4") + " " + spherical_rectangle.uv.ToString("F4"));

            // Test normalized octahedron
            NormalizedOctahedronCoordinates octahedron = cartesian;
            bool same_signs = Mathf.Sign(octahedron.data.x) == Mathf.Sign(cartesian.data.x) &&
                              Mathf.Sign(octahedron.data.y) == Mathf.Sign(cartesian.data.y) &&
                              Mathf.Sign(octahedron.data.z) == Mathf.Sign(cartesian.data.z);
            Assert.IsTrue(same_signs, cartesian.data + " versus " + reconverted_cartesian.data);

            // Test normalized cube
            NormalizedCubeCoordinates cube = cartesian;
            same_signs = Mathf.Sign(cube.data.x) == Mathf.Sign(cartesian.data.x) &&
                         Mathf.Sign(cube.data.y) == Mathf.Sign(cartesian.data.y) &&
                         Mathf.Sign(cube.data.z) == Mathf.Sign(cartesian.data.z);
            Assert.IsTrue(same_signs, cartesian.data + " versus " + reconverted_cartesian.data);
        }
    }
Esempio n. 2
0
        public override void setup()
        {
            Vector3 start_position = self.GetComponent <PlanetariaCollider>().shape.center_of_mass();
            NormalizedSphericalCoordinates spherical         = new NormalizedCartesianCoordinates(start_position);
            NormalizedSphericalCoordinates shifted_spherical = new NormalizedSphericalCoordinates(spherical.elevation + Mathf.PI * 0.75f, spherical.azimuth);
            NormalizedCartesianCoordinates shifted_cartesian = shifted_spherical;
            Vector3 end_position = shifted_cartesian.data;

            rotator = Quaternion.FromToRotation(start_position, end_position);
        }