Ejemplo n.º 1
0
        // ** Begin
        public void Draw3D(RenderContext renderContext, float opacity, Vector3d centerPoint)
        {
            Matrix3d orbitalPlaneOrientation = Matrix3d.MultiplyMatrix(Matrix3d.RotationZ(Coordinates.DegreesToRadians(elements.w)),
                                                                       Matrix3d.MultiplyMatrix(Matrix3d.RotationX(Coordinates.DegreesToRadians(elements.i)),
                                                                                               Matrix3d.RotationZ(Coordinates.DegreesToRadians(elements.omega))));

            // Extra transformation required because the ellipse shader uses the xy-plane, but WWT uses the
            // xz-plane as the reference.
            orbitalPlaneOrientation = Matrix3d.MultiplyMatrix(orbitalPlaneOrientation, orbitalToWwt);

            Matrix3d worldMatrix = Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(orbitalPlaneOrientation, Matrix3d.Translation(centerPoint)), renderContext.World);

            double M = elements.n * (SpaceTimeController.JNow - elements.T);
            double F = 1;

            if (M < 0)
            {
                F = -1;
            }
            M = Math.Abs(M) / 360.0;
            M = (M - (int)(M)) * 360.0 * F;

            Color color = Color.FromArgbColor((int)(opacity * 255.0f), orbitColor);

            // Newton-Raphson iteration to solve Kepler's equation.
            // This is faster than calling CAAKepler.Calculate(), and 5 steps
            // is more than adequate for draw the orbit paths of small satellites
            // (which are ultimately rendered using single-precision floating point.)
            M = Coordinates.DegreesToRadians(M);
            double E = M;

            for (int i = 0; i < 5; i++)
            {
                E += (M - E + elements.e * Math.Sin(E)) / (1 - elements.e * Math.Cos(E));
            }

            EllipseRenderer.DrawEllipse(renderContext, elements.a / scale, elements.e, E, color, worldMatrix);
        }