示例#1
0
        /// <summary>
        /// This is a hook that is called when the flight look starts to run,
        /// that is, when the simulator is fully loaded. Only then will <see cref="IXPlaneScenery.LookupObjects(string, float, float)"/>
        /// reasonable results, because the scenery indexes are loaded only after the
        /// plugins are started.  After the work is done the flight loop hook is
        /// disposed because we no longer need it.
        /// </summary>
        private FlightLoopTime SimLoaded(TimeSpan elapsedTimeSinceLastCall, TimeSpan elapsedTimeSinceLastFlightLoop, int counter)
        {
            m_api.Log.Log($"GraphicsTestPlugin: Entered SimLoaded flightloop (just called once)");

            m_api.Log.Log($"GraphicsTestPlugin: Loading objects with path {TUGPATH}");
            var tugs = m_api.Scenery.LookupObjects(TUGPATH, 0, 0);

            foreach (var p in tugs)
            {
                m_api.Log.Log($"GraphicsTestPlugin: Filename: {p}");
            }

            m_testTug          = m_api.Scenery.LoadObject(tugs.First());
            m_testTugInstances = Enumerable.Range(0, 10).Select(_ => m_api.Instance.Create(m_testTug, new string[]
            {
                "sim/graphics/animation/ground_traffic/tire_steer_deg"
            })).ToList();

            m_tireTurning = m_api.Processing.RegisterFlightLoopHook(FlightLoopTime.FromCycles(1), TurnTheWheel);

            m_api.Log.Log($"Loaded and still living, reference is {m_testTug}");
            m_firstFlightLoopHook.Dispose();
            m_firstFlightLoopHook = null;
            m_api.Log.Log($"GraphicsTestPlugin: Leaving SimLoaded flightloop");

            return(FlightLoopTime.Unscheduled);
        }
示例#2
0
        private FlightLoopTime TurnTheWheel(TimeSpan elapsedTimeSinceLastCall, TimeSpan elapsedTimeSinceLastFlightLoop, int counter)
        {
            m_api.Log.Log($"GraphicsTestPlugin: Entering TurnTheWheel flightloop");
            var(x, y, z) = m_api.Graphics.WorldToLocal(47.437644, 19.259498, 0);
            var res = m_probe.ProbeTerrainXYZ((float)x, 0, (float)z);

            m_api.Log.Log($"Probed terrain, got result {res.LocationY} with code {res.Result}");

            var(lat, lon, alt) = m_api.Graphics.LocalToWorld(res.LocationX, res.LocationY, res.LocationZ);

            int height = 0;

            foreach (var instance in m_testTugInstances)
            {
                instance.SetPosition(new XPDrawInfo((float)res.LocationX, (float)res.LocationY + (10 * height++), (float)res.LocationZ, (float)0, (float)0, (float)0),
                                     new float[] { m_tireAngle });
            }

            m_tireAngle++;
            if (m_tireAngle > 45)
            {
                m_tireAngle -= 90;
            }
            m_api.Log.Log($"GraphicsTestPlugin: Leaving TurnTheWheel flightloop");

            return(FlightLoopTime.FromCycles(1));
        }
示例#3
0
        public GraphicsTestPlugin(IXPlaneApi api)
        {
            m_api = api ?? throw new ArgumentNullException(nameof(api));

            m_api.Log.Log("GraphicsTestPlugin: Displaytest started");
            m_drawingLoopHook = m_api.Display.RegisterDrawHook(DrawingHook, XPLMDrawingPhase.xplm_Phase_Airplanes, 0);
            m_flightLoopHook  = m_api.Processing.RegisterFlightLoopHook(FlightLoopTime.FromCycles(1), SimLoaded);
            m_api.Log.Log("GraphicsTestPlugin: And now create a probe");
            m_probe = m_api.Scenery.CreateProbe();
            m_api.Log.Log("GraphicsTestPlugin: Probe created");
        }
示例#4
0
        public GraphicsTestPlugin(IXPlaneApi api)
        {
            m_api = api ?? throw new ArgumentNullException(nameof(api));

            m_api.Log.Log("GraphicsTestPlugin: Displaytest started");
            m_drawingLoopHook     = m_api.Display.RegisterDrawHook(DrawingHook, XPDrawingPhase.Airplanes, 0);
            m_firstFlightLoopHook = m_api.Processing.RegisterFlightLoopHook(FlightLoopTime.FromCycles(1), SimLoaded);
            m_api.Data.RegisterDataAccessor("BSUB/CounterDataRef",
                                            getDataf: () => 3);
            m_api.Log.Log("GraphicsTestPlugin: And now create a probe");
            m_probe = m_api.Scenery.CreateProbe();
            m_api.Log.Log("GraphicsTestPlugin: Probe created");
        }