Example #1
0
        private void OnShaken(Accelerometer sender, AccelerometerShakenEventArgs args)
        {
            ((MainPageVM) DataContext).WasShaken();
            Path[] paths;

            if (zoom.IsZoomedInViewActive)
            {
                paths = GetVisiblePaths();
            }
            else
            {
                paths = GetAllPaths();
            }

            int MaxParts = 100;

            foreach (Path geo in paths)
            {
                for (int i = 0; i < MaxParts; i++)
                {
                    // The geometry allows us to get the position and  
                    // the tangent at a given fraction length.
                    Geometry flattened = GetFlattenedPathGeometry(geo.Data);
                    Point tangent;
                    Point point;
                    GetPointAtFractionLength(flattened, (i/MaxParts), out point, out tangent);

                    // Create the visual representation of the broken part.  
                    var rectangle = new Rectangle
                                        {
                                            Width = 8,
                                            Height = 3,
                                            Fill = new SolidColorBrush(Colors.Black),
                                            RadiusX = 1.5,
                                            RadiusY = 1.5
                                        };

                    // Add the rectangle to the explosion area and set the position  
                    Canvas.SetLeft(rectangle, point.X - (rectangle.Width/2));
                    Canvas.SetTop(rectangle, point.Y - (rectangle.Height/2));
                    ((Canvas) geo.Parent).Children.Add(rectangle);

                    // For a good look, the rectangle shall be rotated,  
                    // based on the tangent of the point.  
                    var v = new Vector(tangent.X, tangent.Y);
                    v.Normalize();

                    double angle = Vector.AngleBetween(new Vector(1, 0), v);
                    rectangle.RenderTransform = new RotateTransform
                                                    {
                                                        Angle = angle,
                                                        CenterX = rectangle.Width/2,
                                                        CenterY = rectangle.Height/2
                                                    };
                }
            }
        }
Example #2
0
 public static double AngleBetween(Vector v1, Vector v2)
 {
     return 0;
 }