/
EugenyCh7
/
Puppet2D.Net
Обзор
Документация
Войти
/
EugenyCh7
/
Puppet2D.Net
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Puppet2D.Window/Sensor.cs
80 строк
3 KB
EugenyCh7
comments fix
24 июл 2025, 22:54
24 июл 2025, 22:54
421ed1f
Код
Авторство
О чём код?
using System.Runtime.InteropServices; using System.Security; using Puppet2D.System; namespace Puppet2D.Window { /// <summary> /// Give access to the real-time state of sensors /// </summary> public static class Sensor { /// <summary> /// Sensor types /// </summary> public enum Type { /// <summary>Measures the raw acceleration (m/s^2)</summary> Accelerometer, /// <summary>Measures the raw rotation rates (degrees/s)</summary> Gyroscope, /// <summary>Measures the ambient magnetic field (micro-teslas)</summary> Magnetometer, /// <summary>Measures the direction and intensity of gravity, independent of device acceleration (m/s^2)</summary> Gravity, /// <summary>Measures the direction and intensity of device acceleration, independent of the gravity (m/s^2)</summary> UserAcceleration, /// <summary>Measures the absolute 3D orientation (degrees)</summary> Orientation, /// <summary>Keep last -- the total number of sensor types</summary> TypeCount }; /// <summary> /// Check if a sensor is available on the underlying platform /// </summary> /// <param name="Sensor">Sensor to check</param> /// <returns>True if the sensor is available, false otherwise</returns> public static bool IsAvailable(Type Sensor) { return sfSensor_isAvailable(Sensor); } /// <summary> /// Enable or disable a sensor /// </summary> /// <param name="Sensor">Sensor to check</param> /// <param name="Enabled">True to enable, false to disable</param> public static void SetEnabled(Type Sensor, bool Enabled) { sfSensor_setEnabled(Sensor, Enabled); } /// <summary> /// Get the current sensor value /// </summary> /// <param name="Sensor">Sensor to check</param> /// <returns>The current sensor value</returns> public static Vector3 GetValue(Type Sensor) { return sfSensor_getValue(Sensor); } #region Imports [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfSensor_isAvailable(Type Sensor); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfSensor_setEnabled(Type Sensor, bool Enabled); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector3 sfSensor_getValue(Type Sensor); #endregion } }