Ejemplo n.º 1
0
        static void timer_Tick(object sender, EventArgs e)
        {
            if (mutex == null)
            {
                mutex = new Mutex(false, "test");
            }

            if (mutex.WaitOne(TimeSpan.FromSeconds(0.0), false))
            {
                System.Diagnostics.Debug.WriteLine("------------------------------------");
                int num = r.Next(MaxDownPointsFrame + 1);


                for (int i = 0; i < num; i++)
                {
                    System.Diagnostics.Debug.WriteLine(i.ToString() + "down point");
                    CursorAdded(TouchCursor.GetRandomCursor(GetAvailableID(), _w, _h));
                }

                for (int i = 0; i < Contacts.Count; i++)
                {
                    double probability = r.NextDouble();
                    if (probability < UpRate)
                    {
                        TouchProvider tp = Contacts.ElementAt(i).Value as TouchProvider;
                        TouchCursor   tc = new TouchCursor(tp.Id, tp.Position.X, tp.Position.Y);
                        CursorRemoved(tc);
                    }
                    else
                    {
                        TouchProvider tp = Contacts.ElementAt(i).Value as TouchProvider;
                        double        nx = tp.Position.X;
                        double        ny = tp.Position.Y;
                        if (r.NextDouble() < 0.5)
                        {
                            nx += MaxUpdateDistance * r.NextDouble();
                            if (nx >= _w)
                            {
                                nx = _w - 1;
                            }
                        }
                        else
                        {
                            nx -= MaxUpdateDistance * r.NextDouble();
                            if (nx < 0)
                            {
                                nx = 0;
                            }
                        }

                        if (r.NextDouble() < 0.5)
                        {
                            ny += MaxUpdateDistance * r.NextDouble();
                            if (ny > _h - 1)
                            {
                                ny = _h - 1;
                            }
                        }
                        else
                        {
                            ny -= MaxUpdateDistance * r.NextDouble();
                            if (ny < 0)
                            {
                                ny = 0;
                            }
                        }
                    }
                }
            }
        }