Example #1
0
 void TestWindow_Loaded(object sender, RoutedEventArgs e)
 {
     RandomMersene.init_genrand((uint)DateTime.Now.Ticks);
     for (int i = 0; i < 200; i++)
     {
         lb.Items.Add(RandomMersene.genrand_real1());
     }
 }
Example #2
0
        public void autoTranslateRotate(double distance, Direction dir, bool random = true)
        {
            if (random)
            {
                double oldRatio = ext.EngineRatio;
                do
                {
                    ext.EngineRatio = oldRatio + RandomMersene.genrand_real1() * ext.deviationPercent * 50 / 100 * (RandomMersene.genrand_bool() ? -1.0 : 1.0);
                } while (ext.EngineRatio <= 1);
                this.autoTranslateRotate(distance, dir, false);

                //funcs.Log("r r w: " + (ext.EngineRatio - oldRatio).ToString());

                ext.EngineRatio = oldRatio;
                return;
            }

            if (ext.EngineRatio == 1)
            {
                this.Move(distance, false);
                return;
            }
            double actualWidth = ext.MapWindow.theCar.ActualWidth;
            double engineRatio = actualWidth / (ext.EngineRatio - 1);
            double num         = engineRatio + actualWidth / 2;
            double num1        = 360 * distance / (6.28318530717959 * num);
            double num2        = 2 * Math.Pow(num, 2);
            double num3        = Math.Sqrt(num2 - num2 * Math.Cos(num1 * 3.14159265358979 / 180));
            double num4        = (180 - num1) / 2;
            double num5        = num3 * Math.Cos(num4 * 3.14159265358979 / 180);
            double num6        = num3 * Math.Sin(num4 * 3.14159265358979 / 180);

            if (dir == Direction.Left)
            {
                num1 = -num1;
                num5 = -num5;
            }
            if (distance < 0)
            {
                num5 = -num5;
                num6 = -num6;
            }
            double num7 = Math.Sin(this.RotationAngleRads) * num6;

            num7 = num7 + Math.Cos(this.RotationAngleRads) * num5;
            double num8 = Math.Cos(this.RotationAngleRads) * num6;

            num8 = num8 - Math.Sin(this.RotationAngleRads) * num5;
            Car top = this;

            top.Top = top.Top - num8;
            Car left = this;

            left.Left = left.Left + num7;
            Car rotationAngle = this;

            rotationAngle.RotationAngle = rotationAngle.RotationAngle + num1;
        }
Example #3
0
        public MainWindow()
        {
            RandomMersene.init_genrand(DateTime.Now.Ticks);
            this.InitializeComponent();
            MapWindow mapWindow = new MapWindow();

            ext.MapWindow = mapWindow;
            mapWindow.Show();
            base.Close();
        }
Example #4
0
        public void Move(double dist, bool random = true)
        {
            if (random)
            {
                double oldRatio = ext.EngineRatio;
                ext.EngineRatio = RandomMersene.genrand_real1() * ext.deviationPercent * 40 / 100 + 1;
                this.autoTranslateRotate(dist, RandomMersene.genrand_bool() ? Direction.Left : Direction.Right, false);
                //funcs.Log("m r w:" + (ext.EngineRatio - 1).ToString());
                ext.EngineRatio = oldRatio;
                return;
            }

            Car top = this;

            top.Top = top.Top - dist * Math.Cos(this.RotationAngleRads);
            Car left = this;

            left.Left = left.Left + dist * Math.Sin(this.RotationAngleRads);
        }
Example #5
0
        private void theTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            double movingStep;

            if (ext.ActionsList.Count != 0)
            {
                CarAction carAction = ext.ActionsList[0];
                if (carAction.Duration > 0)
                {
                    Action action = null;
                    double num    = RandomMersene.genrand_real1() * ((RandomMersene.genrand_bool() ? -1.0 : 1.0));
                    if (carAction.MoveAction == MoveAction.SmartMovement)
                    {
                        action              = () => this.theCar.translateRotateCuplu();
                        carAction.Duration -= this.theTimer.Interval / 1000;
                    }
                    else if (carAction.Direction != Direction.Straight)
                    {
                        movingStep         = (double)((carAction.MoveAction == MoveAction.Forward ? 1 : -1)) * ext.MovingStep + num * ext.deviationPercent / 100 * ext.MovingStep;
                        action             = () => this.theCar.autoTranslateRotate(movingStep, carAction.Direction);
                        carAction.Duration = carAction.Duration - this.theTimer.Interval / 1000;
                    }
                    else
                    {
                        movingStep         = (double)((carAction.MoveAction == MoveAction.Forward ? 1 : -1)) * ext.MovingStep + num * ext.deviationPercent / 100 * ext.MovingStep;
                        action             = () => this.theCar.Move(movingStep);
                        carAction.Duration = carAction.Duration - this.theTimer.Interval / 1000;
                    }
                    System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher;
                    if (action != null)
                    {
                        Action action1 = () =>
                        {
                            if (action != null)
                            {
                                action();
                            }
                            this.RefreshShits();
                        };
                        if (!dispatcher.CheckAccess())
                        {
                            try
                            {
                                dispatcher.Invoke(action1);
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            action1();
                        }
                    }
                }
                else
                {
                    ext.ActionsList.Remove(carAction);
                }
            }
            if (tmpRefreshShitsTimes > 0)
            {
                Action action1 = () =>
                {
                    this.theCar.autoTranslateRotate(0, Direction.Left);
                    this.RefreshShits();
                };
                System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher;
                if (!dispatcher.CheckAccess())
                {
                    try
                    {
                        dispatcher.Invoke(action1);
                    }
                    catch
                    {
                    }
                }
                else
                {
                    action1();
                }
                tmpRefreshShitsTimes--;
            }
        }