Пример #1
0
        public override void step()
        {
            NormalizedSphericalCoordinates self_position   = new NormalizedCartesianCoordinates(self.position);
            NormalizedSphericalCoordinates target_position = new NormalizedCartesianCoordinates(target.position);
            NormalizedCartesianCoordinates next_position   = new NormalizedSphericalCoordinates(self_position.elevation, target_position.azimuth);

            self.position = next_position.data;
        }
Пример #2
0
        private static Vector3 grid_snap(Vector3 position) // FIXME: optimize
        {
            if (!Event.current.shift)                      // only snap when shift key is held
            {
                return(position);
            }

            NormalizedCartesianCoordinates cartesian_position = new NormalizedCartesianCoordinates(position);

            NormalizedSphericalCoordinates clamped_coordinates = new NormalizedSphericalCoordinates(0, 0);
            NormalizedSphericalCoordinates desired_coordinates = cartesian_position;

            for (float row = 0; row <= EditorGlobal.self.rows + 1; ++row)    //going over with off by one errors won't ruin the program...
            {
                float angle = Mathf.PI * row / (EditorGlobal.self.rows + 1); // TODO: verify the row/columns are not swapped
                float x     = Mathf.Sin(angle);
                float y     = Mathf.Cos(angle);
                NormalizedSphericalCoordinates test_coordinates = new NormalizedCartesianCoordinates(new Vector3(x, y, 0));

                float error     = Mathf.Abs(Mathf.DeltaAngle(desired_coordinates.elevation * Mathf.Rad2Deg, test_coordinates.elevation * Mathf.Rad2Deg));
                float old_error = Mathf.Abs(Mathf.DeltaAngle(desired_coordinates.elevation * Mathf.Rad2Deg, clamped_coordinates.elevation * Mathf.Rad2Deg));

                if (error < old_error)
                {
                    clamped_coordinates = new NormalizedSphericalCoordinates(test_coordinates.elevation, clamped_coordinates.azimuth);
                }
            }

            for (float column = 0; column < EditorGlobal.self.columns * 2; ++column) //... but going under is bad
            {
                float angle = column / EditorGlobal.self.columns * Mathf.PI;
                float x     = Mathf.Sin(angle);
                float z     = Mathf.Cos(angle);
                NormalizedSphericalCoordinates test_coordinates = new NormalizedCartesianCoordinates(new Vector3(x, 0, z));

                float error     = Mathf.Abs(Mathf.DeltaAngle(desired_coordinates.azimuth * Mathf.Rad2Deg, test_coordinates.azimuth * Mathf.Rad2Deg));
                float old_error = Mathf.Abs(Mathf.DeltaAngle(desired_coordinates.azimuth * Mathf.Rad2Deg, clamped_coordinates.azimuth * Mathf.Rad2Deg));

                if (error < old_error)
                {
                    clamped_coordinates = new NormalizedSphericalCoordinates(clamped_coordinates.elevation, test_coordinates.azimuth);
                }
            }

            cartesian_position = clamped_coordinates;

            return(cartesian_position.data);
        }