如何通过罗盘数据动画网格旋转? c#windows phone 8

时间:2022-03-24 11:52:48

I am creating an augmented reality app for wp8. It looks something like the image shown below.如何通过罗盘数据动画网格旋转? c#windows phone 8

我正在为wp8创建一个增强现实应用程序。它看起来像下面显示的图像。

The black screen will be filled by video source from cam. And for the small circle in the top left, I am using two grids one upon another. First grid contains the limegreen segment, this grid will be stationary. Second grid contains the bigger circle with the letter N on top. This must rotate to show the north direction by taking the data from device compass.

黑屏将由来自cam的视频源填充。对于左上角的小圆圈,我一个接一个地使用两个网格。第一个网格包含limegreen段,此网格将是静止的。第二个网格包含较大的圆圈,顶部带有字母N.必须通过从设备指南针获取数据来旋转以显示北方向。

I followed the below given article to mimic the production of compass. http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202974(v=vs.105).aspx

我按照下面给出的文章来模仿罗盘的制作。 http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202974(v=vs.105).aspx

But in the timer_Tick event, I must update the rotation of the brownish grid with the letter N. I am completely clueless on how to obtain the realtime rotation of the grid from the compass data. How can I use storyboard to do feed the angle ? Or is there any simpler way without starting and stopping storyboard and all the fuss ?

但是在timer_Tick事件中,我必须用字母N更新褐色网格的旋转。我完全不知道如何从罗盘数据中获得网格的实时旋转。如何使用故事板来提供角度?或者有没有更简单的方法没有启动和停止故事板和所有的大惊小怪?

The grid xaml code is given below.

网格xaml代码如下。

<Grid Name="StationaryLittleMap" Width="150" Height="150" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="20,20,0,0">
            <Path Stroke="White" Fill="LimeGreen" StrokeThickness="1">
                <Path.Data>
                    <PathGeometry>
                        <PathGeometry.Figures>
                            <PathFigureCollection>
                                <PathFigure StartPoint="38,10">
                                    <PathFigure.Segments>
                                        <PathSegmentCollection>
                                            <ArcSegment Size="75,75" RotationAngle="36" IsLargeArc="False" SweepDirection="Clockwise" Point="112,10" />
                                            <LineSegment Point="75,75" />
                                            <LineSegment Point="38,10" />
                                        </PathSegmentCollection>
                                    </PathFigure.Segments>
                                </PathFigure>
                            </PathFigureCollection>
                        </PathGeometry.Figures>
                    </PathGeometry>
                </Path.Data>
            </Path>
        </Grid>

        <Grid Name="MoveLittleMap" Width="150" Height="150" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="20,20,0,0" >
            <Grid.RenderTransform>
                <CompositeTransform />
            </Grid.RenderTransform>
            <Ellipse Fill="Orange"  Height="150" Width="150"  RenderTransformOrigin="0.5,0.5" Opacity="0.4" />
            <TextBlock Text="N" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,0,0,0" />
        </Grid>

1 个解决方案

#1


1  

If you're not interested by the animation, you can directly update the CompositeTransform.

如果您对动画不感兴趣,可以直接更新CompositeTransform。

First, give it a name in the XAML:

首先,在XAML中为它命名:

<CompositeTransform x:Name="CompassTransform" />

Then, change the angle directly from the code:

然后,直接从代码更改角度:

this.CompassTransform.Rotation = 45;

But if you want the compass to rotate smoothly, then you have no other choice than using a storyboard.

但是如果你想让指南针顺畅地旋转,那么除了使用故事板之外别无选择。

#1


1  

If you're not interested by the animation, you can directly update the CompositeTransform.

如果您对动画不感兴趣,可以直接更新CompositeTransform。

First, give it a name in the XAML:

首先,在XAML中为它命名:

<CompositeTransform x:Name="CompassTransform" />

Then, change the angle directly from the code:

然后,直接从代码更改角度:

this.CompassTransform.Rotation = 45;

But if you want the compass to rotate smoothly, then you have no other choice than using a storyboard.

但是如果你想让指南针顺畅地旋转,那么除了使用故事板之外别无选择。