<!--TitlePanel contains the name of the application and page title--> <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:Name="ApplicationTitle" Text=" WINDOWS PHONE" Style="{StaticResource PhoneTextNormalStyle}"/> <TextBlock x:Name="PageTitle" Text="motion api" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> </StackPanel> <!--ContentPanel - place additional content here--> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <TextBlock Name="MotionNotPresented" Text=" Motion API" FontSize="22" Visibility="Collapsed"></TextBlock> <Polyline Name="ArrowPitch" HorizontalAlignment="Center" VerticalAlignment="Center" Points="0,0 -10,150 0,140 10,150 0,0" Stroke="Green" StrokeThickness="2" Fill="Green" Margin="-300 -300 0 0"> <Polyline.Projection> <PlaneProjection x:Name="MotionPitchProjection"></PlaneProjection> </Polyline.Projection> </Polyline> <Polyline Name="ArrowRoll" HorizontalAlignment="Center" VerticalAlignment="Center" Points="0,0 -10,150 0,140 10,150 0,0" Stroke="Yellow" StrokeThickness="2" Fill="Yellow" Margin="300 -300 0 0"> <Polyline.Projection> <PlaneProjection x:Name="MotionRollProjection"></PlaneProjection> </Polyline.Projection> </Polyline> <Polyline Name="ArrowYaw" HorizontalAlignment="Center" VerticalAlignment="Center" Points="0,0 -10,150 0,140 10,150 0,0" Stroke="Red" StrokeThickness="2" Fill="Red"> <Polyline.Projection> <PlaneProjection x:Name="MotionYawProjection"></PlaneProjection> </Polyline.Projection> </Polyline> <TextBlock Height="50" HorizontalAlignment="Left" Margin="25,250,0,0" Text="Pitch" VerticalAlignment="Top" FontWeight="Bold" Foreground="Green" FontSize="40" /> <TextBlock FontSize="40" FontWeight="Bold" Foreground="Yellow" Height="50" HorizontalAlignment="Right" Margin="0,250,45,0" Text="Roll" VerticalAlignment="Top" /> <TextBlock FontSize="40" FontWeight="Bold" Foreground="Red" Height="50" HorizontalAlignment="Left" Margin="185,396,0,0" Text="Yaw" VerticalAlignment="Top" /> </Grid>
using Microsoft.Devices.Sensors;
Motion motion = null; // Constructor public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded(object sender, RoutedEventArgs e) { if (Motion.IsSupported) { motion = new Motion(); motion.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<MotionReading>>(motion_CurrentValueChanged); motion.Start(); } else MotionNotPresented.Visibility = Visibility.Visible; }
void motion_CurrentValueChanged(object sender, SensorReadingEventArgs<MotionReading> e) { Dispatcher.BeginInvoke(() => { MotionPitchProjection.RotationZ = e.SensorReading.Attitude.Pitch * 180 / Math.PI; MotionRollProjection.RotationZ = e.SensorReading.Attitude.Roll * 180 / Math.PI; MotionYawProjection.RotationZ = e.SensorReading.Attitude.Yaw * 180 / Math.PI; }); }
Source: https://habr.com/ru/post/134835/
All Articles