Пример #1
0
        private void AddLabel(GeoCoordinate location, string label)
        {
            // We'll use the specified text for the content and we'll let
            // the system automatically project the item into world space
            // for us based on the Geo location.
            ARItem item = new ARItem()
            {
                Content     = label,
                GeoLocation = location,
            };

            ARDisplay.ARItems.Add(item);
        }
Пример #2
0
        /// <summary>
        /// Occurs when the value of the <see cref="Attitude"/> property has changed.
        /// </summary>
        /// <param name="e">
        /// A <see cref="DependencyPropertyChangedEventArgs"/> containing event information.
        /// </param>
        protected override void OnAttitudeChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnAttitudeChanged(e);

            // Ensure that the viewport has been created
            EnsureViewport();

            // Get the RotationMatrix from the MotionReading.
            // Rotate it 90 degrees around the X axis to put it in the XNA Framework coordinate system.
            Matrix xnaAttitude = Matrix.CreateRotationX(MathHelper.PiOver2) * Attitude;

            // Loop through our items
            for (int i = 0; i < Items.Count; i++)
            {
                // Get the WorldVIewItem that matches the index
                WorldViewItem wvItem = ItemContainerGenerator.ContainerFromIndex(i) as WorldViewItem;

                // If we couldn't get a WorldViewItem for the index, skip
                if (wvItem == null)
                {
                    continue;
                }

                // Get the ARItem that the WorldViewItem represents
                ARItem arItem = (ARItem)wvItem.DataContext;

                // Create a World matrix for the ARItems WorldLocation
                Matrix world = Matrix.CreateWorld(arItem.WorldLocation, new Vector3(0, 0, 1), new Vector3(0, 1, 0));

                // Use Viewport.Project to project the ARItems location in 3D space into screen coordinates
                Vector3 projected = viewport.Project(Vector3.Zero, projection, view, world * xnaAttitude);

                // If the point is outside of this range, it is behind the camera
                if (projected.Z > 1 || projected.Z < 0)
                {
                    // Out of range, just hide
                    wvItem.Visibility = Visibility.Collapsed;
                }
                else
                {
                    // In range so show
                    wvItem.Visibility = Visibility.Visible;

                    /*
                     * // Create a TranslateTransform to position the WorldViewItem
                     * TranslateTransform tt = new TranslateTransform();
                     *
                     * // Offset by half of the WorldViewItems size to center it on the point
                     * tt.X = projected.X - (wvItem.ActualWidth / 2);
                     * tt.Y = projected.Y - (wvItem.ActualHeight / 2);
                     *
                     * // Set the transform, which moves the item
                     * wvItem.RenderTransform = tt;
                     */

                    // Create a CompositeTransform to position and scale the WorldViewItem
                    CompositeTransform ct = new CompositeTransform();

                    // Offset by half of the WorldViewItems size to center it on the point

                    // TODO: Expose vertical limit property
                                        #if WIN_RT
                    ct.TranslateX = projected.X - (wvItem.ActualWidth / 2) - (this.ActualWidth / 2);

                    // Ricky; Keep the y value within the screen
                    double y  = projected.Y - (wvItem.ActualHeight / 2);
                    double h2 = this.Height / 2;
                    y             = (y < -h2) ? -h2 : ((y > h2) ? h2 : y);
                    ct.TranslateY = y;
                                        #endif

                                        #if WINDOWS_PHONE
                    ct.TranslateX = projected.X - (wvItem.ActualWidth / 2);
                    ct.TranslateY = projected.Y - (wvItem.ActualHeight / 2);
                                        #endif


                    #if WP7
                    double scale = MathHelper.Lerp((float)MinItemScale, (float)MaxItemScale, ((float)FarClippingPlane - Math.Abs(arItem.WorldLocation.Z)) / (float)FarClippingPlane);
                    #else
                    double scale = MathHelper.Lerp(MinItemScale, MaxItemScale, (FarClippingPlane - Math.Abs(arItem.WorldLocation.Z)) / FarClippingPlane);
                    #endif
                    ct.ScaleX = scale;
                    ct.ScaleY = scale;

                    // Set the transform, which moves the item
                    wvItem.RenderTransform = ct;

                    // Set the items z-index so that the closest item is always rendered on top
                    Canvas.SetZIndex(wvItem, (int)(scale * 255));
                }
            }
        }