zoukankan      html  css  js  c++  java
  • Windows Phone 十八、加速计

    加速度传感器

    手机的加速度传感器工作时是通过 x、y、z 三个轴的偏移来计算的

    在代码基本的 API 主要集中在 Accelerometer 类型中

    主要是使用该类型的对象捕获 ReadingChanged 事件监视加速度值变化的

    X、Y、Z 加速度传感值

    1     <StackPanel>
    2         <TextBox x:Name="txtX" Header="X:"/>
    3         <TextBox x:Name="txtY" Header="Y:"/>
    4         <TextBox x:Name="txtZ" Header="Z:"/>
    5     </StackPanel>
     1         protected override void OnNavigatedTo(NavigationEventArgs e)
     2         {
     3             // 先拿到传感器对象
     4             Accelerometer a = Accelerometer.GetDefault();
     5             if (a == null)
     6             {
     7                 // 代表没有加速计传感器对象
     8                 System.Diagnostics.Debug.WriteLine("没有加速计传感器");
     9                 return;
    10             }
    11             a.ReadingChanged += a_ReadingChanged;
    12             a.ReportInterval = a.MinimumReportInterval * 5;
    13         }
    14 
    15         async void a_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
    16         {
    17             System.Diagnostics.Debug.WriteLine(args + "改变了。。。");
    18             // 拿到变化值
    19             await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
    20             {
    21                 txtX.Text = args.Reading.AccelerationX.ToString();
    22                 txtY.Text = args.Reading.AccelerationY.ToString();
    23                 txtZ.Text = args.Reading.AccelerationZ.ToString();
    24             });
    25         }

    平衡检测

    1     <Grid>
    2 
    3         <Path Data="M180.348,341.493 L144.279,392.488 L162.935,391.244 L161.692,630.05 L200.249,630.05 L196.517,392.488 L216.418,393.731 z" Fill="#FF6AEA00" HorizontalAlignment="Center" Height="289.557" Stretch="Fill" Stroke="Black" UseLayoutRounding="False" VerticalAlignment="Bottom" Width="73.139" RenderTransformOrigin="0.5,1">
    4             <Path.RenderTransform>
    5                 <CompositeTransform x:Name="rotate" Rotation="0"/>
    6             </Path.RenderTransform>
    7         </Path>
    8 
    9     </Grid>
     1         protected override void OnNavigatedTo(NavigationEventArgs e)
     2         {
     3             DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
     4             // 先拿到传感器对象
     5             Accelerometer a = Accelerometer.GetDefault();
     6             if (a == null)
     7             {
     8                 // 代表没有加速计传感器对象
     9                 System.Diagnostics.Debug.WriteLine("没有加速计传感器");
    10                 return;
    11             }
    12             a.ReadingChanged += a_ReadingChanged;
    13             a.ReportInterval = a.MinimumReportInterval * 10;
    14         }
    15 
    16         async void a_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
    17         {
    18             System.Diagnostics.Debug.WriteLine(args + "改变了。。。");
    19             // 拿到变化值
    20             await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
    21             {
    22                 rotate.Rotation = args.Reading.AccelerationY * 90;
    23             });
    24         }
  • 相关阅读:
    深度解析VC中的消息传递机制(上)
    DLL的远程注入技术
    一些游戏编程的书[转]
    [转]小小C的C++之歌
    Windows Server 2008无法使用arp命令添加静态MAC绑定
    如何调用未公开的API函数[转]
    IOCP中的socket错误和资源释放处理方法
    TinyXML应用例子
    微软C/C++ 编译器选项参考
    [摘录]这几本游戏编程书籍你看过吗?
  • 原文地址:https://www.cnblogs.com/includeling/p/4601351.html
Copyright © 2011-2022 走看看