public void CreateView(Graphics g, Vector3D pos, Matrix44 wem)
        {
            Scine scn = new Scine();

            scn.optamb = oa;
            scn.Add(MakeEarth(pos).Transform(wem));
            Scine view = scn.MakeView(clip, proj, false);

            // g.SetColor(bgColor);
            //g.FillRect((int)clip.vp_xmin, (int)clip.vp_ymin, (int)(clip.vp_xmax - clip.vp_xmin + 1.0D), (int)(clip.vp_ymax - clip.vp_ymin + 1.0D));
            g.FillRectangle(new SolidBrush(bgColor), (int)clip.vp_xmin, (int)clip.vp_ymin, (int)(clip.vp_xmax - clip.vp_xmin + 1.0D), (int)(clip.vp_ymax - clip.vp_ymin + 1.0D));
            view.Draw(g);
        }
        public LocusViewer(double sX0, double sY0, double sX1, double sY1,
                           AirPlane ap, Recorder rec)
        {
            planeM = new Material(new LightColor(0.0D, 0.0D, 0.6D),
                                  new LightColor(0.5D, 0.5D, 0.5D), 10.0D, new LightColor(0.0D, 0.0D,
                                                                                          0.0D));
            planeM2 = new Material(new LightColor(0.6D, 0.0D, 0.0D),
                                   new LightColor(0.5D, 0.5D, 0.5D), 10.0D, new LightColor(0.0D, 0.0D,
                                                                                           0.0D));
            light = Jp.Maker1.Vsys3.Tools.Light.Parallel(new LightColor(255.0D, 255.0D, 255.0D),
                                                         new Vector3D(0.5D, -0.5D, 1.0D));
            amblight         = Jp.Maker1.Vsys3.Tools.Light.Ambience(new LightColor(128.0D, 128.0D, 128.0D));
            infoCol          = Color.FromArgb(64, 64, 64);
            dataCol          = Color.Gray;
            cursolCol        = Color.FromArgb(255, 0, 0);
            suisenCol        = Color.Gray;
            stdFont          = new Font("SansSelif", 12);
            smallFont        = new Font("SansSelif", 11);
            sc               = new Scine();
            oa               = new OpticalAmbience();
            viewAngle        = 25.0D;
            grid             = new LocusGrid();
            rmat             = new Matrix44();
            tmat             = new Matrix44();
            mat_bef          = new Matrix44();
            mat              = new Matrix44();
            moveingTime      = 5.0D;
            rotationTime     = 7.0D;
            currentDataIndex = 0;
            proj             = new Projector(sX1 - sX0 + 1.0D, sY1 - sY0 + 1.0D, MathTool.DegToRad(25.0D));
            clip             = new Clipper(sX0, sY0, sX1, sY1);
            oa.AddLight(light);
            oa.AddLight(amblight);

            recorder = rec;

            locus = new Locus(ap, rec, planeM, planeM2);
            InitDispParam();

            fastMoveStep = (recorder.N_record() / 50);
            if (fastMoveStep <= 0)
            {
                fastMoveStep = 1;
            }
        }
        public void DrawLocus(Graphics g, int mode)
        {
            if (mode == 1)
            {
                // g.SetColor(Java.Awt.Color.white);
                //g.FillRect((int)clip.vp_xmin, (int)clip.vp_ymin, (int)(clip.vp_xmax - clip.vp_xmin + 1.0D), (int)(clip.vp_ymax - clip.vp_ymin + 1.0D));
            }

            mat = mat_bef.MultMat(rmat).MultMat(tmat);

            sc        = new Scine();
            sc.optamb = oa;
            sc.Add((VsElement)grid.MakeGrid(locus.locusBBox, dist, 25.0D).Transform(mat));
            Scine view = sc.MakeView(clip, proj, false);

            view.Draw(g);

            if (mode == 1)
            {
                sc        = new Scine();
                sc.optamb = oa;
                sc.Add((VsElement)locus.locus.Transform(mat));
                sc.Add((VsElement)locus.groundLocus.Transform(mat));
                sc.Add((VsElement)locus.ybaseLocus.Transform(mat));
                view = sc.MakeView(clip, proj, true);

                view.Draw(g, 1);

                if (recorder.N_record() > 0)
                {
                    //g.SetColor(infoCol);
                    //g.SetFont(stdFont);
                    //g.DrawString("REC. FROM " + Jp.Maker1.Sim.Tools.Tool.TimeStr1(recorder.GetData(0).t) + " TO " + Jp.Maker1.Sim.Tools.Tool.TimeStr1(recorder.GetData(recorder.N_record() - 1).t), 3, 13);
                }
            }
        }
        public void DrawInstrument(Graphics g, AirPlane ap, SimulatorInterface simif, double dt)
        {
            Matrix44 tmat  = new Matrix44();
            Matrix44 smat  = new Matrix44();
            Matrix44 rmat  = new Matrix44();
            Matrix44 rzmat = new Matrix44();
            Matrix44 rxmat = new Matrix44();
            Matrix44 mat   = new Matrix44();
            Scine    scine = new Scine();

            //g.SetColor(informationColor);
            //g.SetFont(stdFont);

            SolidBrush informationBrush = new SolidBrush(informationColor);
            Pen        informationPen   = new Pen(informationColor);

            g.DrawString(ap.plane.name, stdFont, informationBrush, 300 - ap.plane.name.Length * 3, 365);

            if (simif.dispInformationSw == 1)
            {
                double x = ap.pMotion.ov.Length();
                //g.DrawString("V: " + Jp.Maker1.Util.DispFormat.DoubleFormat(x, 3, 1) + " m/s", v_true_x, v_true_y);
                //g.DrawString("V: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Sim.Tools.UnitConvert.Mps2kmph(x), 3, 1) + " km/h", v_true_x, v_true_y + 12);
                //g.DrawString("V: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Sim.Tools.UnitConvert.Mps2kt(x), 3, 1) + " kt", v_true_x, v_true_y + 24);

                x = ap.pMotion.wpos.y;
                //g.DrawString("ALT: " + Jp.Maker1.Util.DispFormat.DoubleFormat(x, 5, 1) + " m", alt_x, alt_y);
                //g.DrawString("ALT: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Sim.Tools.UnitConvert.M2ft(x), 5, 1) + " ft", alt_x, alt_y + 12);
            }

            double pitch = ap.pMotion.pitch.GetValue();
            double roll  = ap.pMotion.roll.GetValue();

            g.DrawString("PIT: " + DispFormat.DoubleFormat(MathTool.RadToDeg(pitch), 5, 1) + " deg", stdFont, informationBrush, 515, 12);
            g.DrawString("ROL: " + DispFormat.DoubleFormat(MathTool.RadToDeg(roll), 5, 1) + " deg", stdFont, informationBrush, 512, 89);
            tmat.SetTMat(550.0D, 45.0D, 0.0D);
            smat.SetSMat(30.0D, -30.0D, 0.0D);
            if ((roll > 1.570796326794897D) || (roll < -1.570796326794897D))
            {
                rmat.SetRzMat(Math.PI - pitch);
            }
            else
            {
                rmat.SetRzMat(pitch);
            }
            mat = smat.MultMat(rmat).MultMat(tmat);
            scine.Add(pitch_miniature_aircraft.Transform(mat));
            g.DrawEllipse(informationPen, 520, 15, 60, 60);
            tmat.SetTMat(550.0D, 121.0D, 0.0D);
            smat.SetSMat(30.0D, -30.0D, 0.0D);
            rmat.SetRzMat(-roll);
            mat = smat.MultMat(rmat).MultMat(tmat);
            scine.Add(roll_miniature_aircraft.Transform(mat));
            g.DrawEllipse(informationPen, 520, 91, 60, 60);

            if (simif.dispInformationSw == 1)
            {
                double x_0 = ap.atmos.h;
                //g.DrawString("H': " + Jp.Maker1.Util.DispFormat.DoubleFormat(x_0, 5, 1) + " m'", atmo_x, atmo_y);
                x_0 = ap.atmos.tc;
                //g.DrawString("t: " + Jp.Maker1.Util.DispFormat.DoubleFormat(x_0, 4, 1) + " ��", atmo_x, atmo_y + 12);
                x_0 = ap.atmos.t;
                //g.DrawString("T: " + Jp.Maker1.Util.DispFormat.DoubleFormat(x_0, 4, 1) + " K", atmo_x, atmo_y + 24);
                x_0 = ap.atmos.p;
                //g.DrawString("p: " + Jp.Maker1.Util.DispFormat.DoubleFormat(x_0 / 100.0D, 4, 1) + " hPa", atmo_x + 90, atmo_y);
                x_0 = ap.atmos.rho;
                //g.DrawString("��: " + Jp.Maker1.Util.DispFormat.DoubleFormat(x_0, 1, 3) + " kg/m3", atmo_x + 90, atmo_y + 12);
                x_0 = ap.atmos.a;
                // g.DrawString("a: " + Jp.Maker1.Util.DispFormat.DoubleFormat(x_0, 3, 1) + " m/sec", atmo_x + 90, atmo_y + 24);
            }

            double alpha = ap.pMotion.alpha;
            double beta  = ap.pMotion.beta;

            if (simif.dispInformationSw == 1)
            {
                //g.DrawString("��: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Util.MathTool.RadToDeg(alpha), 3, 1) + " deg", 2, 60);
                // g.DrawString("��: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Util.MathTool.RadToDeg(beta), 3, 1) + " deg", 2, 72);
            }

            Vector3D vec = ap.pMotion.ov.SclProd(60000000.0D).MultMat(ap.pilot.ViewMatrix());

            if ((vec != null) && (vec.z > 0.0D))
            {
                vec = proj.Project(vec);
                tmat.SetTMat(vec.x, vec.y, vec.z);
                scine.Add(velocity_vector.Transform(tmat));
            }

            vec.SetVec(0.0D, 0.0D, 60000000.0D);
            vec = vec.MultMat(ap.pilot.ViewMatrix());
            if ((vec != null) && (vec.z > 0.0D))
            {
                vec = proj.Project(vec);
                tmat.SetTMat(vec.x, vec.y, vec.z);
                scine.Add(front_point.Transform(tmat));
            }

            vec   = ap.pMotion.force.R2l().SclProd(-1.0D / ap.inp.m);
            vec.z = 0.0D;
            double   x_1  = vec.Length();
            Vector3D vec2 = vec.NmlVec().SclProd(50.0D);

            vec = vec.NmlVec().SclProd(100.0D);
            Vector3D vec3 = vec.NmlVec().SclProd(113.0D);

            Jp.Maker1.Util.Symbol.DrawArrow(g, 300 + (int)vec2.x, 200 - (int)vec2.y, 300 + (int)vec.x, 200 - (int)vec.y, 50.0D, x_1 * 4.0D);
            //g.DrawString(Jp.Maker1.Util.DispFormat.DoubleFormat(x_1 / 9.80655D, 2) + "G", 286 + (int)vec3.x, 200 - (int)vec3.y);

            vec = ap.pMotion.force.R2l().SclProd(-1.0D / ap.inp.m);
            x_1 = vec.z;
            //  g.DrawString(Jp.Maker1.Util.DispFormat.DoubleFormat(x_1 / 9.80655D, 2) + "G", 120, 192);
            if (Math.Abs((int)(x_1 * 10.0D)) >= 1)
            {
                Jp.Maker1.Util.Symbol.DrawArrow(g, 150, 200, 150 + (int)(x_1 * 10.0D), 200, (int)(Math.Abs(x_1) * 10.0D), 10.0D);
                Jp.Maker1.Util.Symbol.DrawArrow(g, 450, 200, 450 - (int)(x_1 * 10.0D), 200, (int)(Math.Abs(x_1) * 10.0D), 10.0D);
            }

            int xx = 2;
            int yy = 100;

            vec = ap.pMotion.force.SclProd(-1.0D / ap.inp.m / 9.80655D);
            if (simif.dispInformationSw == 1)
            {
                //g.DrawString("Gx: " + Jp.Maker1.Util.DispFormat.DoubleFormat(vec.x, 2, 4) + " [G]", xx, yy);
                yy += 11;
                // g.DrawString("Gy: " + Jp.Maker1.Util.DispFormat.DoubleFormat(vec.y, 2, 4) + " [G]", xx, yy);
                yy += 11;
                //g.DrawString("Gz: " + Jp.Maker1.Util.DispFormat.DoubleFormat(vec.z, 2, 4) + " [G]", xx, yy);
                yy += 11;
            }

            if (ap.max_k_stall_wing > 1.0D)
            {
                //g.DrawString("STALL", stallAlert_x + 25, stallAlert_y);
            }
            else if (ap.max_k_stall_wing > 0.95D)
            {
                //g.DrawString("STALL WARNING", stallAlert_x, stallAlert_y);
            }

            //g.SetColor(instrumentColor);

            double yaw = ap.pMotion.yaw.GetValue();

            //g.DrawString("HDG: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Util.MathTool.RadToDeg(yaw), 5, 1) + " deg", 512, 165);
            tmat.SetTMat(550.0D, 197.0D, 0.0D);
            smat.SetSMat(30.0D, 30.0D, 0.0D);
            rmat.SetRzMat(yaw);
            mat = smat.MultMat(rmat).MultMat(tmat);
            scine.Add(heading_miniature_aircraft.Transform(mat));
            // g.DrawOval(520, 167, 60, 60);

            rzmat.SetRzMat(-ap.pMotion.roll.GetValue());
            rxmat.SetRxMat(-ap.pMotion.pitch.GetValue());
            mat = rxmat.MultMat(rzmat);
            Scine scine2 = new Scine();

            scine2.Add(artificial_horizon.Transform(mat.MultMat(ap.pilot.ViewMatrix())));
            Scine view = new Scine();

            view = scine2.MakeView(clip, proj, false);
            view.Draw(g);

            // g.SetFont(bigFont);
            x_1 = ap.pMotion.vc.Length() * Math.Sqrt(ap.atmos.rho / 1.225D);
            // g.DrawString("ASI: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Sim.Tools.UnitConvert.Mps2kt(x_1), 3, 0) + " kt", 190, 380);

            x_1 = ap.pMotion.wpos.y;
            //g.DrawString("ALT: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Sim.Tools.UnitConvert.M2ft(x_1), 5, 0) + " ft", 190, 396);

            x_1 = ap.pMotion.wv.y;
            //g.DrawString("VSI: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Sim.Tools.UnitConvert.M2ft(x_1) * 60.0D, 5, 0) + " fpm", 305, 380);

            x_1 = ap.pMotion.omega.z;
            //           g.DrawString("YRT: " + Jp.Maker1.Util.DispFormat.DoubleFormat(Jp.Maker1.Util.MathTool.RadToDeg(x_1) * 60.0D, 3, 0) + " deg/m", 305, 396);

            for (int i = 0; i < ap.n_LandingGear; i++)
            {
                if (ap.landing_gear[i, 1].flag == 1)
                {
                    xx = gear_x;
                }
                else
                {
                    xx = gear_x - gear_box_maegine / 2;
                }
                yy = gear_y + i * gear_box_maegine * 3;
                for (int lr = 0; lr <= 1; lr++)
                {
                    if (ap.landing_gear[i, lr].flag == 1)
                    {
                        int xx1;

                        if (lr == 0)
                        {
                            xx1 = xx + gear_box_maegine;
                        }
                        else
                        {
                            xx1 = xx;
                        }
                        x_1 = ap.landing_gear[i, lr].delta;
                        if (x_1 == 0.0D)
                        {
                            //g.SetColor(instrumentRed);
                            //g.FillRect(xx1 + 2, yy + 2, gear_box_size - 3, gear_box_size - 3);
                        }
                        else if (x_1 == 1.0D)
                        {
                            //g.SetColor(instrumentGreen);
                            //g.FillRect(xx1 + 2, yy + 2 + gear_box_maegine * 2, gear_box_size - 3, gear_box_size - 3);
                        }
                        else
                        {
                            // g.SetColor(instrumentYellow);
                            // g.FillRect(xx1 + 2, yy + 2 + gear_box_maegine, gear_box_size - 3, gear_box_size - 3);
                        }
                        //g.SetColor(instrumentColor);
                        //g.DrawRect(xx1, yy, gear_box_size, gear_box_size);
                        //g.DrawRect(xx1, yy + gear_box_maegine, gear_box_size, gear_box_size);
                        //g.DrawRect(xx1, yy + gear_box_maegine * 2, gear_box_size, gear_box_size);
                    }
                }
            }

            //g.SetFont(smallFont);
            ControlPlane flap = ap.t_flap[0, 0];

            if (ap.t_flap[0, 0].type != 0)
            {
                xx = flap_x;
                yy = flap_y;
                // g.DrawRect(xx, yy - flap_width, 10, flap_width);
                for (double ang = 0.0D; ang < MathTool.RadToDeg(flap.delta_max) + 0.1D; ang += 10.0D)
                {
                    x_1 = (MathTool.DegToRad(ang) - flap.delta_min) / (flap.delta_max - flap.delta_min);
                    int yy1 = yy - flap_width + (int)(flap_width * x_1 + 0.5D);
                    // g.DrawLine(xx + 10, yy1, xx + 13, yy1);
                    // g.DrawString("" + (int)ang, xx + 14, yy1);
                }
                x_1 = (flap.delta - flap.delta_min) / (flap.delta_max - flap.delta_min);
                int yy1_2 = (int)(flap_width * x_1 + 0.5D);
                // g.FillRect(xx + 2, yy - flap_width, 7, yy1_2);
            }
            //g.SetFont(stdFont);

            scine.Draw(g);
            //g.SetFont(stdFont);
        }
        public GraphicsGenerator(Uri codeBase, double sX0, double sY0, double sX1, double sY1)
        {
            sc                     = new Scine();
            oa                     = new OpticalAmbience();
            bgColor                = Color.FromArgb(134, 171, 225);
            earthColorRed          = 50;
            earthColorGreen        = 93;
            earthColorBlue         = 45;
            glid1mColor            = Color.FromArgb(55, 102, 48);
            glid10mColor           = Color.FromArgb(61, 113, 59);
            glid100mColor          = Color.FromArgb(67, 124, 65);
            glid1kmColor           = Color.FromArgb(61, 113, 59);
            glid10kmColor          = Color.FromArgb(55, 102, 48);
            runwayColorRed         = 151;
            runwayColorGreen       = 151;
            runwayColorBlue        = 159;
            gridRunwayColor        = Color.FromArgb(160, 160, 170);
            interfaceColorPen      = new Pen(Color.FromArgb(200, 200, 255));
            interfaceColorBrush    = new SolidBrush(Color.FromArgb(200, 200, 255));
            interfaceColorDPen     = new Pen(Color.FromArgb(180, 180, 235));
            instrumentColor        = Color.FromArgb(255, 255, 255);
            instrumentGreen        = Color.FromArgb(128, 200, 128);
            instrumentYellow       = Color.FromArgb(200, 200, 128);
            instrumentRed          = Color.FromArgb(200, 128, 128);
            informationColor       = Color.FromArgb(220, 220, 255);
            simInterfaceColor      = Color.FromArgb(230, 255, 200);
            padLockColor           = Color.FromArgb(200, 200, 255);
            stdFont                = new Font("SansSelif", 12);
            bigFont                = new Font("SansSelif", 16);
            smallFont              = new Font("SansSelif", 9);
            padFont                = new Font("SansSelif", 11);
            stick_center_x         = 300;
            stick_center_y         = 200;
            stick_x_width          = 140;
            stick_y_width          = 140;
            rudder_center_x        = 300;
            rudder_center_y        = 320;
            rudder_x_witdh         = 45;
            rudder_y_width         = 30;
            throttle_x             = 10;
            throttle_y             = 390;
            throttle_width         = 100;
            mixture_x              = 25;
            mixture_y              = 390;
            mixture_width          = 100;
            prop_pitch_x           = 40;
            prop_pitch_y           = 390;
            prop_pitch_width       = 100;
            brake_right_x          = 580;
            brake_right_y          = 390;
            brake_right_width      = 100;
            brake_left_x           = 565;
            brake_left_y           = 390;
            brake_left_width       = 100;
            instrument_object_list = new VsObjectList();
            v_true_x               = 100;
            v_true_y               = 12;
            alt_x                  = 185;
            alt_y                  = 12;
            atmo_x                 = 280;
            atmo_y                 = 12;
            gear_x                 = 130;
            gear_y                 = 325;
            gear_box_size          = 9;
            gear_box_maegine       = 12;
            flap_x                 = 450;
            flap_y                 = 395;
            flap_width             = 100;
            stallAlert_x           = 257;
            stallAlert_y           = 140;
            pause_x                = 275;
            pause_y                = 100;
            slowMoton_x            = 245;
            slowMoton_y            = 115;
            proj                   = new Projector(sX1 - sX0 + 1.0D, sY1 - sY0 + 1.0D, MathTool.DegToRad(45.0D));
            proj.SetVerticalParamer(0.0D, 0.0D, sX1 - sX0 + 1.0D, sY1 - sY0 + 1.0D, MathTool.DegToRad(45.0D));
            clip = new Clipper(sX0, sY0, sX1, sY1);

            Matrix44 mtemp = new Matrix44();
            Matrix44 smat  = new Matrix44();

            mtemp.SetRxMat(MathTool.DegToRad(90.0D));
            earth = ((VsPolygon)Jp.Maker1.Vsys3.Tools.BasicObject.RegularPolygon(32, earthColorRed, earthColorGreen, earthColorBlue).Transform(mtemp));

            glid10km = Jp.Maker1.Vsys3.Tools.BasicObject.XzGlid(0.0D, -50000.0D, -50000.0D, 50000.0D, 50000.0D, 10000.0D, 10000.0D, glid10kmColor);
            glid1km  = Jp.Maker1.Vsys3.Tools.BasicObject.XzGlid(0.0D, -10000.0D, -10000.0D, 10000.0D, 10000.0D, 1000.0D, 1000.0D, glid1kmColor);
            glid100m = Jp.Maker1.Vsys3.Tools.BasicObject.XzGlid(0.0D, -1000.0D, -1000.0D, 1000.0D, 1000.0D, 100.0D, 100.0D, glid100mColor);
            glid10m  = Jp.Maker1.Vsys3.Tools.BasicObject.XzGlid(0.0D, -200.0D, -200.0D, 200.0D, 200.0D, 10.0D, 10.0D, glid10mColor);
            glid1m   = Jp.Maker1.Vsys3.Tools.BasicObject.XzGlid(0.0D, -30.0D, -30.0D, 30.0D, 30.0D, 1.0D, 1.0D, glid1mColor);

            smat.SetSMat(60.0D, 0.0D, 1000.0D);
            runway      = ((VsPolygon)Jp.Maker1.Vsys3.Tools.BasicObject.Square(runwayColorRed, runwayColorGreen, runwayColorBlue).Transform(mtemp.MultMat(smat)));
            glid_runway = Jp.Maker1.Vsys3.Tools.BasicObject.XzGlid(0.1D, -30.0D, -500.0D, 30.0D, 500.0D, 10.0D, 10.0D, gridRunwayColor);

            FormUnitFile fmu = new FormUnitFile(instrument_object_list, codeBase, "data/instrument.fmu", "data/instrument.mdf");

            pitch_miniature_aircraft = instrument_object_list.Get("PITCH_MINIATURE_ARECRAFT");
            pitch_miniature_aircraft.SetColor(informationColor);
            roll_miniature_aircraft = instrument_object_list.Get("ROLL_MINIATURE_ARECRAFT");
            roll_miniature_aircraft.SetColor(informationColor);
            heading_miniature_aircraft = instrument_object_list.Get("HEADING_MINIATURE_ARECRAFT");
            heading_miniature_aircraft.SetColor(instrumentColor);
            velocity_vector = instrument_object_list.Get("VELOCITY_VECTOR");
            velocity_vector.SetColor(informationColor);
            artificial_horizon = instrument_object_list.Get("ARTIFICIAL_HORIZON");
            artificial_horizon.SetColor(instrumentColor);
            front_point = instrument_object_list.Get("FRONT_POINT");
            front_point.SetColor(informationColor);
        }