Пример #1
0
        public static Matrix3 AzimuthElevation(float elevation, float azimuth, float oneOverd)
        {
            Matrix3 result = new Matrix3();
            Matrix3 rotate = new Matrix3();

            // make sure elevation in the range of [-90, 90]:
            if (elevation > 90)
            {
                elevation = 90;
            }
            else if (elevation < -90)
            {
                elevation = -90;
            }
            // Make sure azimuth in the range of [-180, 180]:
            if (azimuth > 180)
            {
                azimuth = 180;
            }
            else if (azimuth < -180)
            {
                azimuth = -180;
            }

            elevation = elevation * (float)Math.PI / 180.0f;
            float sne = (float)Math.Sin(elevation);
            float cne = (float)Math.Cos(elevation);

            azimuth = azimuth * (float)Math.PI / 180.0f;
            float sna = (float)Math.Sin(azimuth);
            float cna = (float)Math.Cos(azimuth);

            rotate.M[0, 0] = cna;
            rotate.M[0, 1] = sna;
            rotate.M[0, 2] = 0;
            rotate.M[1, 0] = -sne * sna;
            rotate.M[1, 1] = sne * cna;
            rotate.M[1, 2] = cne;
            rotate.M[2, 0] = cne * sna;
            rotate.M[2, 1] = -cne * cna;
            rotate.M[2, 2] = sne;

            if (oneOverd <= 0)
            {
                result = rotate;
            }
            else if (oneOverd > 0)
            {
                Matrix3 perspective = Matrix3.Perspective(1 / oneOverd);
                result = perspective * rotate;
            }
            return(result);
        }