Microsoft Surface Pro 配备陀螺仪和加速度计、Windows 8 和完整的 .NET 框架。
我发现大多数谈论运动 API 的文章都指向 Windows Phone 8 API。
我应该使用哪些 .NET Framework 命名空间和类来获取陀螺仪和加速度计数据?
最佳答案
我只是根据文档工作 - http://msdn.microsoft.com/en-us/library/ie/windows.devices.sensors
using Windows.Devices.Sensors;
private Accelerometer _accelerometer;
private void DoStuffWithAccel()
{
_accelerometer = Accelerometer.GetDefault();
if (_accelerometer != null)
{
AccelerometerReading reading = _accelerometer.GetCurrentReading();
if (reading != null)
double xreading = reading.AccelerationX;
... etc.
}
}
尚未对其进行测试,但它应该适用于任何 Windows 应用商店应用程序 - 如果您试图使其作为控制台/Windows 窗体应用程序运行,您需要通过以下方式更改目标平台:
- 右键单击您的项目 -> 卸载项目
- 按照此 https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications 的其余部分进行操作
关于c# - 来自 Windows 的陀螺仪和加速度计数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25271834/